Skip to content

Commit

Permalink
fixing package stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
lsproule committed Dec 23, 2023
1 parent cdfd1a9 commit c245e28
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 313 deletions.
27 changes: 9 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,23 @@ include (cmake/CPM.cmake)

CPMAddPackage(
NAME termcolor
GITHUB_REPOSITORY ikalnytskyi/termcolor
GIT_REPOSITORY https://github.com/ikalnytskyi/termcolor
GIT_TAG v2.1.0
OPTIONS
"BUILD_STATIC_LIBS ON"
)

CPMAddPackage(
NAME cxxopts
GITHUB_REPOSITORY jarro2783/cxxopts
GIT_REPOSITORY https://www.github.com/jarro2783/cxxopts
GIT_TAG origin/master
OPTIONS
"BUILD_STATIC_LIBS ON"

)
CPMAddPackage(
NAME nlohmann_json
GITHUB_REPOSITORY nlohmann/json
GIT_REPOSITORY https://www.github.com/nlohmann/json
GIT_TAG v3.11.3
OPTIONS
"BUILD_STATIC_LIBS ON"
Expand All @@ -106,18 +106,10 @@ CPMAddPackage(


)
CPMAddPackage(
name libgit2
GITHUB_REPOSITORY libgit2/libgit2
GIT_TAG v1.7.1
OPTIONS
"BUILD_TESTS OFF"
"BUILD_STATIC_LIBS ON"
"BUILD_CLI OFF"
)

CPMAddPackage(
NAME curl
GITHUB_REPOSITORY curl/curl
GIT_REPOSITORY https://www.github.com/curl/curl
GIT_TAG curl-8_3_0
OPTIONS
"ENABLE_VERSIONED_SYMBOLS ON"
Expand All @@ -136,7 +128,7 @@ CPMAddPackage(

CPMAddPackage(
NAME uv
GITHUB_REPOSITORY libuv/libuv
GIT_REPOSITORY https://www.github.com/libuv/libuv
GIT_TAG v1.47.0
OPTIONS
"BUILD_STATIC_LIBS ON"
Expand All @@ -145,16 +137,16 @@ CPMAddPackage(
)

CPMAddPackage(
lua
GITHUB_REPOSITORY lua/lua
NAME lua
GIT_REPOSITORY https://www.github.com/lua/lua
GIT_TAG v5.4.4
OPTIONS
"BUILD_STATIC_LIBS ON"
)

CPMAddPackage(
NAME sol2
GITHUB_REPOSITORY ThePhD/sol2
GIT_REPOSITORY https://www.github.com/ThePhD/sol2
GIT_TAG v3.3.1
)

Expand Down Expand Up @@ -214,7 +206,6 @@ target_link_options(${PROJECT_NAME} PRIVATE -static-libgcc -static-libstdc++)
target_link_libraries(${PROJECT_NAME} PRIVATE libcurl)
target_link_libraries(${PROJECT_NAME} PRIVATE cxxopts)
target_link_libraries(${PROJECT_NAME} PRIVATE nlohmann_json)
target_link_libraries(${PROJECT_NAME} PRIVATE libgit2package)
target_link_libraries(${PROJECT_NAME} PRIVATE uv)
target_link_libraries(${PROJECT_NAME} PRIVATE termcolor)
target_link_libraries(${PROJECT_NAME} PRIVATE lua)
Expand Down
1 change: 0 additions & 1 deletion completions/frate-completion.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
_frate() {
local cur prev words cword
_get_comp_words_by_ref -n : cur prev words cword

local commands="init run watch add ftp help"
local add_subcommands="dep lib flags"

Expand Down
5 changes: 0 additions & 5 deletions include/Frate/Command/Actions/Watch.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#pragma once
#include <Frate/Interface.hpp>

namespace Frate::Command::Watch {

bool options(std::shared_ptr<Interface> inter);
bool run(std::shared_ptr<Interface> inter);
std::vector<Handler> handlers(std::shared_ptr<Interface> inter);
}
namespace Frate::Command::UvWatch {
bool watch(std::shared_ptr<Interface> inter);
}
2 changes: 1 addition & 1 deletion include/Frate/Project.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Frate::Command {
std::string homepage{"null"};
std::string bugs{"null"};
std::string lang{"cpp"};
std::string cmake_version{"3.28"};
std::string cmake_version{"3.20"};
std::string lang_version{"20"};
std::string compiler{"g++"};
std::string license{""};
Expand Down
1 change: 0 additions & 1 deletion src/Command/Actions/New.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <Frate/Utils/General.hpp>
#include <Frate/Wizards.hpp>
#include <Frate/Project.hpp>
#include <git2.h>
#include <Frate/Command/Actions/Help.hpp>
#include "Frate/Command.hpp"

Expand Down
71 changes: 34 additions & 37 deletions src/Command/Actions/UvWatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ namespace Frate::Command::UvWatch{
inter->InitHeader();
inter->options->parse_positional({"command"});
inter->options->add_options()
("command", "Command to run", cxxopts::value<std::string>()->default_value("help"))
("r,remote-build", "Build server to use", cxxopts::value<bool>()->default_value("false"))
("c,args", "command to pass to dev", cxxopts::value<std::vector<std::string>>());
("c,command", "Command to run", cxxopts::value<std::string>()->default_value("help"))
("r,remote-build", "Build server to use", cxxopts::value<bool>()->default_value("false"));
return inter->parse();
}
//TODO Move to RemoteServer.hpp
Expand Down Expand Up @@ -59,60 +58,58 @@ namespace Frate::Command::UvWatch{
return RemoteServer();
}


std::string remote_build_command(std::shared_ptr<Interface> inter) {
std::string command;
std::string current_build_server = std::string(std::getenv("HOME")) +
"/.config/frate/" +
"current_build_server.json";
inter->pro->build_server = get_current_build_server();

std::string sync_files = "rsync -avh --exclude-from='.gitignore' --update -e 'ssh -p " +
std::to_string(inter->pro->build_server.port) + "' --progress . " +
inter->pro->build_server.username + "@" +inter->pro->build_server.ip +
":/tmp/frate ";

std::string ssh = "&& ssh -p " + std::to_string(inter->pro->build_server.port) + " " +
inter->pro->build_server.username + "@" +inter->pro->build_server.ip;

std::string ssh_command =
" 'cd /tmp/frate && cmake . && make -j ${nproc} && " + inter->pro->build_dir + "/" + inter->pro->name + "'";
// Get the destination path from environment variables
std::string remote_dest_path = std::getenv("REMOTE_DEST_PATH") ? std::getenv("REMOTE_DEST_PATH") : "/tmp/" + inter->pro->name;
std::cout << "Remote destination path: " << remote_dest_path << std::endl;
std::cout << "project: " << json(*inter->pro).dump(2) << std::endl;
std::cout << "pro->name: " << inter->pro->name << std::endl;
// Construct the rsync command
std::string sync_files = "rsync -avh --exclude-from='.gitignore' --update -e 'ssh -p " +
std::to_string(inter->pro->build_server.port) + "' --progress . " +
inter->pro->build_server.username + "@" + inter->pro->build_server.ip +
":" + remote_dest_path + " ";

// SSH command to build the project
std::string ssh_build = "&& ssh -p " + std::to_string(inter->pro->build_server.port) + " " +
inter->pro->build_server.username + "@" + inter->pro->build_server.ip + " "
"'cd " + remote_dest_path + " && cmake . && make -j $(nproc)'";

// Add option to run a specific command after building, if set
std::string command;
if (inter->args->count("command")) {
std::string command_to_run = inter->args->operator[]("command").as<std::string>();
command = " && " + command_to_run;
}

command = sync_files + ssh + ssh_command;
return command;
return sync_files + ssh_build + command;
}



bool runCommand(std::shared_ptr<Interface> inter){
//TODO CLEAN UP THIS SHIT
std::string command = "cmake . && make && " + inter->pro->path.string() + "/" + inter->pro->build_dir + "/" +inter->pro->name;
#ifdef DEBUG
command = "cd build && cmake . && make && " + inter->pro->build_dir + "/" +inter->pro->name;
#endif

if (inter->args->count("command") != 0) {
std::string command_run;

std::string command_to_run = inter->args->operator[]("command").as<std::string>();
command = "cmake . && make && ./" + inter->pro->build_dir + "/" +
inter->pro->name + " " + command_run;
}

bool build_server =inter->args->operator[]("remote-build").as<bool>();
if (build_server == true) {

command = remote_build_command(inter);
}
if (inter->args->count("args") != 0) {
// historical reasons
std::cout << "estamos aqui" << std::endl;
std::vector<std::string> args_vec =
inter->args->operator[]("args").as<std::vector<std::string>>();
std::string command_args = args_vec[0];
if (args_vec.size() > 1) {
command_args = std::accumulate(
args_vec.begin(), args_vec.end(), args_vec[0],
[](std::string a, std::string b) { return a + " " + b; });
std::cout << "args size is 0" << std::endl;
return false;
}

std::cout << "command_args: " << command_args << std::endl;
command = "cmake . && make && ./" + inter->pro->build_dir + "/" +
inter->pro->name + " " + command_args;
}
if (Utils::hSystem(command) != 0){
std::cout << "Error running command: " << command << std::endl;
exit(1);
Expand Down
Loading

0 comments on commit c245e28

Please sign in to comment.