diff --git a/include/antler/project/location.hpp b/include/antler/project/location.hpp index 9dda3a0..4fcddd2 100644 --- a/include/antler/project/location.hpp +++ b/include/antler/project/location.hpp @@ -21,27 +21,55 @@ namespace antler::project::location { /// @param l Location to evaluate. /// @return true if l looks like a github repository. [[nodiscard]] bool is_github_repo(std::string_view l); + /// @param l Location to evaluate. /// @return true if l looks like an archive from github. [[nodiscard]] bool is_github_archive(std::string_view l); + /// @param l Location to evaluate. /// @return true if l looks like a local file. [[nodiscard]] bool is_local(std::string_view l); + /// @note requires `gh` is installed and user is authenticated or the repo is public. /// @param l Location to evaluate. /// @return true if l is a repo, calls `gh` to test. [[nodiscard]] bool is_github_shorthand(std::string_view l); + /// @param l Location to evaluate. /// @return true if l is reachable. [[nodiscard]] bool is_reachable(std::string_view l); + /// @param l Location to evaluate. /// @return true if l looks like a url. [[nodiscard]] bool is_url(std::string_view l); -[[nodiscard]] bool clone_github_repo(const std::string& org, const std::string& repo, const std::string& branch, uint32_t jobs, system::fs::path dest = "."); -[[nodiscard]] bool clone_git_repo(const std::string& url, const std::string& branch, uint32_t jobs, system::fs::path dest = "."); +/// @param org github organization name +/// @param repo git repository name +/// @param branch git branch name +/// @param dest directory to clone to +/// @return true if successful +[[nodiscard]] bool clone_github_repo(const std::string& org, const std::string& repo, const std::string& branch, system::fs::path dest = "."); + +/// @param url git repository url +/// @param branch git branch name +/// @param dest directory to clone to +/// @return true if successful +[[nodiscard]] bool clone_git_repo(const std::string& url, const std::string& branch, system::fs::path dest = "."); + +/// @note perform git pull for specific directory +/// @param src working directory +/// @return true if successful [[nodiscard]] bool pull_git_repo(system::fs::path src); + +/// @note fetches repos json using github API +/// @param org github organization +/// @param repo git repository name +/// @return json string [[nodiscard]] std::string github_request(const std::string& org, const std::string& repo); + +/// @param org github organization name +/// @param repo github repository name +/// @return branch name [[nodiscard]] std::string get_github_default_branch(const std::string& org, const std::string& repo); } // namespace antler::project::location diff --git a/include/antler/project/net_utils.hpp b/include/antler/project/net_utils.hpp index ab66db0..bc1d3b3 100644 --- a/include/antler/project/net_utils.hpp +++ b/include/antler/project/net_utils.hpp @@ -170,8 +170,8 @@ namespace antler::project { /// @param org /// @param repo /// @param branch - static bool clone(const std::string& org, const std::string& repo, const std::string& branch, uint32_t jobs, const system::fs::path& dest) { - int32_t ret = system::execute(std::string(executable), { "clone", "-j", std::to_string(jobs), "https://github.com/"+org+"/"+repo, "--depth", "1", "--branch", branch, dest.string() }); + static bool clone(const std::string& org, const std::string& repo, const std::string& branch, const system::fs::path& dest) { + int32_t ret = system::execute(std::string(executable), { "clone", "https://github.com/"+org+"/"+repo, "--depth", "1", "--branch", branch, dest.string() }); system::debug_log("clone for {0}/{1} returned {2}\n", org, repo, ret); if (ret != 0) return false; @@ -187,8 +187,8 @@ namespace antler::project { /// @brief clone a repo from git /// @param url /// @param branch - static bool clone(const std::string& url, const std::string& branch, uint32_t jobs, const system::fs::path& dest) { - int32_t ret = system::execute(std::string(executable), { "clone", "-j", std::to_string(jobs), url, "--depth", "1", "--branch", branch, dest.string() }); + static bool clone(const std::string& url, const std::string& branch, const system::fs::path& dest) { + int32_t ret = system::execute(std::string(executable), { "clone", url, "--depth", "1", "--branch", branch, dest.string() }); system::debug_log("clone for {0} returned {1}\n", url,ret); if (ret != 0) return false; diff --git a/include/antler/project/populator.hpp b/include/antler/project/populator.hpp index 9726edd..a4d3c19 100644 --- a/include/antler/project/populator.hpp +++ b/include/antler/project/populator.hpp @@ -21,9 +21,8 @@ namespace antler::project { populator(populator&&) = default; /// Populate the directory by generating files for build and gathering the dependencies. - /// @param jobs The number of jobs used to clone or pull dependencies. /// @return true for success; false for failure. - [[nodiscard]] bool populate(uint32_t jobs=1); + [[nodiscard]] bool populate(); template void emit_cmake(P& pops) { emitter.emit(pops); } @@ -32,15 +31,13 @@ namespace antler::project { /// Populate a given project. /// @param proj The project to populate from. - /// @param jobs The number of jobs used to clone or pull dependencies. /// @return true for success; false for failure. - [[nodiscard]] bool populate_project(project& proj, uint32_t jobs=1); + [[nodiscard]] bool populate_project(project& proj); /// Populate a particular dependency. /// @param dep The dependency to populate. - /// @param jobs The number of jobs used to clone or pull the dependency. /// @return true for success; false for failure. - [[nodiscard]] bool populate_dependency(const dependency& dep, const project& proj, uint32_t jobs=1); + [[nodiscard]] bool populate_dependency(const dependency& dep, const project& proj); cmake emitter; diff --git a/src/location.cpp b/src/location.cpp index 6172eb6..78a2f3f 100644 --- a/src/location.cpp +++ b/src/location.cpp @@ -59,12 +59,12 @@ bool is_reachable(std::string_view l) { } } -bool clone_github_repo(const std::string& org, const std::string& repo, const std::string& branch, uint32_t jobs, system::fs::path dest) { - return git::clone(org, repo, branch, jobs, dest); +bool clone_github_repo(const std::string& org, const std::string& repo, const std::string& branch, system::fs::path dest) { + return git::clone(org, repo, branch, dest); } -bool clone_git_repo(const std::string& url, const std::string& branch, uint32_t jobs, system::fs::path dest) { - return git::clone(url, branch, jobs, dest); +bool clone_git_repo(const std::string& url, const std::string& branch, system::fs::path dest) { + return git::clone(url, branch, dest); } bool pull_git_repo(system::fs::path src) { return git::pull(src); } diff --git a/src/populator.cpp b/src/populator.cpp index 1eb97a9..b9c76fe 100644 --- a/src/populator.cpp +++ b/src/populator.cpp @@ -4,7 +4,7 @@ namespace antler::project { -bool populator::populate_dependency(const dependency& d, const project& p, uint32_t jobs) { +bool populator::populate_dependency(const dependency& d, const project& p) { using namespace antler::project::location; system::fs::path depends_dir = p.path() / p.dependencies_dir; system::debug_log("populating dependency {0} from {1}", d.name(), d.location()); @@ -29,7 +29,7 @@ bool populator::populate_dependency(const dependency& d, const project& p, uint3 if (system::fs::exists(depends_dir / repo)) return pull_git_repo(depends_dir / repo); else - return clone_github_repo(org, repo, tag, jobs, depends_dir / repo); + return clone_github_repo(org, repo, tag, depends_dir / repo); } else { system::error_log("Dependency {0} is not a github shorthand.", d.name()); return false; @@ -41,7 +41,7 @@ bool populator::populate_dependency(const dependency& d, const project& p, uint3 // if (d.tag().empty()) { // tag = "main"; // } - // return clone_git_repo(d.location(), tag, jobs, depends_dir / d.name()); + // return clone_git_repo(d.location(), tag, depends_dir / d.name()); // } else if (is_github_shorthand(d.location())) { // std::string org = std::string{github::get_org(d.location())}; // std::string repo = std::string{github::get_repo(d.location())}; @@ -50,13 +50,13 @@ bool populator::populate_dependency(const dependency& d, const project& p, uint3 // tag = get_github_default_branch(org, repo); // } // system::debug_log("Cloning {0} with branch {1}", d.location(), tag); - // return clone_github_repo(org, repo, tag, jobs, depends_dir / d.name()); + // return clone_github_repo(org, repo, tag, depends_dir / d.name()); // } //} //return false; } -bool populator::populate_project(project& p, uint32_t jobs) { +bool populator::populate_project(project& p) { system::fs::path depends_dir = p.path() / p.dependencies_dir; system::fs::create_directories(depends_dir); @@ -69,7 +69,7 @@ bool populator::populate_project(project& p, uint32_t jobs) { const auto& pop_deps = [&](auto& objs) { for (const auto& [_, o] : objs) { for (const auto& [_, d] : o.dependencies()) { - if (!populate_dependency(d, p, jobs)) + if (!populate_dependency(d, p)) return false; try { if (d.location().empty()) @@ -86,7 +86,7 @@ bool populator::populate_project(project& p, uint32_t jobs) { } populators::add_mapping(d, std::string(next_proj.name())); - if (!populate_project(next_proj, jobs)) + if (!populate_project(next_proj)) return false; } } catch(...) { @@ -112,9 +112,9 @@ bool populator::populate_project(project& p, uint32_t jobs) { } -bool populator::populate(uint32_t jobs) { +bool populator::populate() { populators::add_mapping("", std::string(proj->name())); // add the default empty location to this project mapping - return populate_project(*proj, jobs); + return populate_project(*proj); } } // namespace antler::project \ No newline at end of file diff --git a/tests/location_tests.cpp b/tests/location_tests.cpp index a058c7d..eacfc0a 100644 --- a/tests/location_tests.cpp +++ b/tests/location_tests.cpp @@ -10,10 +10,10 @@ using namespace antler::project; TEST_CASE("Testing location clone") { antler::system::fs::remove_all("./clone_test"); - CHECK(location::clone_github_repo("antelopeio", "antler-proj", "main", 10, "./clone_test/foo2")); + CHECK(location::clone_github_repo("antelopeio", "antler-proj", "main", "./clone_test/foo2")); CHECK(antler::system::fs::exists("./clone_test/foo2/.git")); - CHECK(location::clone_git_repo("https://github.com/larryk85/cturtle", "main", 10, "./clone_test/foo3")); + CHECK(location::clone_git_repo("https://github.com/larryk85/cturtle", "main", "./clone_test/foo3")); CHECK(antler::system::fs::exists("./clone_test/foo3/.git")); } diff --git a/tools/build.hpp b/tools/build.hpp index 7cedcf7..ecd4049 100644 --- a/tools/build.hpp +++ b/tools/build.hpp @@ -18,7 +18,7 @@ namespace antler { subcommand->footer(std::string(R"(Examples:)") + "\n\t" + app.get_name() +R"( build -j3)"); subcommand->add_option("-p, path", path, "This is the path to the root of the project."); - subcommand->add_option("-j, --jobs", jobs, "The number of submodules fetched at the same time.")->default_val(1); + subcommand->add_option("-j, --jobs", jobs, "The number of jobs to use with cmake build tool. Default is number of CPUs."); subcommand->add_flag("-c, --clean", clean, "This will force a clean build.")->default_val(false); } @@ -39,7 +39,11 @@ namespace antler { system::fs::create_directory(bin_dir); system::info_log("Building project..."); - return system::execute("cmake", {"--build", bin_dir.string(), "-j", std::to_string(jobs)}); + CLI::results_t args = {"--build", bin_dir.string(), "-j"}; + if (jobs) + args.push_back(std::to_string(jobs)); + + return system::execute("cmake", std::move(args)); } void move_artifacts(const project::project& proj) noexcept { @@ -66,12 +70,13 @@ namespace antler { } int32_t exec() { + auto proj = load_project(path); bool repopulated = false; if (should_repopulate(proj)) { repopulated = true; - ANTLER_CHECK(project::populators::get(proj).populate(jobs), "failed to populate dependencies"); + ANTLER_CHECK(project::populators::get(proj).populate(), "failed to populate dependencies"); } @@ -97,7 +102,7 @@ namespace antler { CLI::App* subcommand = nullptr; std::string path; - uint32_t jobs = 1; + uint32_t jobs = 0; bool clean = false; }; } // namespace antler