|  |  | @@ -8,6 +8,8 @@ | 
		
	
		
			
			|  |  |  | #include <dds/util/paths.hpp> | 
		
	
		
			
			|  |  |  | #include <dds/util/signal.hpp> | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | #include <range/v3/action/join.hpp> | 
		
	
		
			
			|  |  |  | #include <range/v3/view/concat.hpp> | 
		
	
		
			
			|  |  |  | #include <range/v3/view/group_by.hpp> | 
		
	
		
			
			|  |  |  | #include <range/v3/view/transform.hpp> | 
		
	
		
			
			|  |  |  | 
 | 
		
	
	
		
			
			|  |  | @@ -66,6 +68,15 @@ struct catalog_path_flag : path_flag { | 
		
	
		
			
			|  |  |  | dds::catalog open() { return dds::catalog::open(Get()); } | 
		
	
		
			
			|  |  |  | }; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | struct num_jobs_flag : args::ValueFlag<int> { | 
		
	
		
			
			|  |  |  | num_jobs_flag(args::Group& cmd) | 
		
	
		
			
			|  |  |  | : ValueFlag(cmd, | 
		
	
		
			
			|  |  |  | "jobs", | 
		
	
		
			
			|  |  |  | "Set the number of parallel jobs when compiling files", | 
		
	
		
			
			|  |  |  | {"jobs", 'j'}, | 
		
	
		
			
			|  |  |  | 0) {} | 
		
	
		
			
			|  |  |  | }; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | /** | 
		
	
		
			
			|  |  |  | * Base class holds the actual argument parser | 
		
	
		
			
			|  |  |  | */ | 
		
	
	
		
			
			|  |  | @@ -494,11 +505,7 @@ struct cli_build { | 
		
	
		
			
			|  |  |  | "Path to an existing libman index from which to load deps (usually INDEX.lmi)", | 
		
	
		
			
			|  |  |  | {"lm-index", 'I'}}; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | args::ValueFlag<int> num_jobs{cmd, | 
		
	
		
			
			|  |  |  | "jobs", | 
		
	
		
			
			|  |  |  | "Set the number of parallel jobs when compiling files", | 
		
	
		
			
			|  |  |  | {"jobs", 'j'}, | 
		
	
		
			
			|  |  |  | 0}; | 
		
	
		
			
			|  |  |  | num_jobs_flag n_jobs{cmd}; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | path_flag out{cmd, | 
		
	
		
			
			|  |  |  | "out", | 
		
	
	
		
			
			|  |  | @@ -510,7 +517,7 @@ struct cli_build { | 
		
	
		
			
			|  |  |  | dds::build_params params; | 
		
	
		
			
			|  |  |  | params.out_root      = out.Get(); | 
		
	
		
			
			|  |  |  | params.toolchain     = tc_filepath.get_toolchain(); | 
		
	
		
			
			|  |  |  | params.parallel_jobs = num_jobs.Get(); | 
		
	
		
			
			|  |  |  | params.parallel_jobs = n_jobs.Get(); | 
		
	
		
			
			|  |  |  | dds::package_manifest man; | 
		
	
		
			
			|  |  |  | const auto            man_filepath = project.root.Get() / "package.dds"; | 
		
	
		
			
			|  |  |  | if (exists(man_filepath)) { | 
		
	
	
		
			
			|  |  | @@ -559,6 +566,99 @@ struct cli_build { | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | }; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | /* | 
		
	
		
			
			|  |  |  | ########  ##     ## #### ##       ########          ########  ######## ########   ###### | 
		
	
		
			
			|  |  |  | ##     ## ##     ##  ##  ##       ##     ##         ##     ## ##       ##     ## ##    ## | 
		
	
		
			
			|  |  |  | ##     ## ##     ##  ##  ##       ##     ##         ##     ## ##       ##     ## ## | 
		
	
		
			
			|  |  |  | ########  ##     ##  ##  ##       ##     ## ####### ##     ## ######   ########   ###### | 
		
	
		
			
			|  |  |  | ##     ## ##     ##  ##  ##       ##     ##         ##     ## ##       ##              ## | 
		
	
		
			
			|  |  |  | ##     ## ##     ##  ##  ##       ##     ##         ##     ## ##       ##        ##    ## | 
		
	
		
			
			|  |  |  | ########   #######  #### ######## ########          ########  ######## ##         ###### | 
		
	
		
			
			|  |  |  | */ | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | struct cli_build_deps { | 
		
	
		
			
			|  |  |  | cli_base&     base; | 
		
	
		
			
			|  |  |  | args::Command cmd{base.cmd_group, | 
		
	
		
			
			|  |  |  | "build-deps", | 
		
	
		
			
			|  |  |  | "Build a set of dependencies and emit a libman index"}; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | toolchain_flag    tc{cmd}; | 
		
	
		
			
			|  |  |  | repo_path_flag    repo_path{cmd}; | 
		
	
		
			
			|  |  |  | catalog_path_flag cat_path{cmd}; | 
		
	
		
			
			|  |  |  | num_jobs_flag     n_jobs{cmd}; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | args::ValueFlagList<dds::fs::path> deps_files{cmd, | 
		
	
		
			
			|  |  |  | "deps-file", | 
		
	
		
			
			|  |  |  | "Install dependencies from the named files", | 
		
	
		
			
			|  |  |  | {"deps", 'd'}}; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | path_flag out_path{cmd, | 
		
	
		
			
			|  |  |  | "out-path", | 
		
	
		
			
			|  |  |  | "Directory where build results should be placed", | 
		
	
		
			
			|  |  |  | {"out", 'o'}, | 
		
	
		
			
			|  |  |  | dds::fs::current_path() / "_deps"}; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | path_flag lmi_path{cmd, | 
		
	
		
			
			|  |  |  | "lmi-path", | 
		
	
		
			
			|  |  |  | "Path to the output libman index file (INDEX.lmi)", | 
		
	
		
			
			|  |  |  | {"lmi-path"}, | 
		
	
		
			
			|  |  |  | dds::fs::current_path() / "INDEX.lmi"}; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | args::PositionalList<std::string> deps{cmd, "deps", "List of dependencies to install"}; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | int run() { | 
		
	
		
			
			|  |  |  | dds::build_params params; | 
		
	
		
			
			|  |  |  | params.out_root      = out_path.Get(); | 
		
	
		
			
			|  |  |  | params.toolchain     = tc.get_toolchain(); | 
		
	
		
			
			|  |  |  | params.parallel_jobs = n_jobs.Get(); | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | dds::builder            bd; | 
		
	
		
			
			|  |  |  | dds::sdist_build_params sdist_params; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | auto all_file_deps | 
		
	
		
			
			|  |  |  | = deps_files.Get()  // | 
		
	
		
			
			|  |  |  | | ranges::views::transform([&](auto dep_fpath) { | 
		
	
		
			
			|  |  |  | spdlog::info("Reading deps from {}", dep_fpath.string()); | 
		
	
		
			
			|  |  |  | return dds::package_manifest::load_from_file(dep_fpath).dependencies; | 
		
	
		
			
			|  |  |  | }) | 
		
	
		
			
			|  |  |  | | ranges::actions::join; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | auto cmd_deps = ranges::views::transform(deps.Get(), [&](auto dep_str) { | 
		
	
		
			
			|  |  |  | return dds::dependency::parse_depends_string(dep_str); | 
		
	
		
			
			|  |  |  | }); | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | auto all_deps = ranges::views::concat(all_file_deps, cmd_deps) | ranges::to_vector; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | auto cat = cat_path.open(); | 
		
	
		
			
			|  |  |  | dds::repository::with_repository(  // | 
		
	
		
			
			|  |  |  | repo_path.Get(), | 
		
	
		
			
			|  |  |  | dds::repo_flags::write_lock | dds::repo_flags::create_if_absent, | 
		
	
		
			
			|  |  |  | [&](dds::repository repo) { | 
		
	
		
			
			|  |  |  | // Download dependencies | 
		
	
		
			
			|  |  |  | spdlog::info("Loading {} dependencies", all_deps.size()); | 
		
	
		
			
			|  |  |  | auto deps = repo.solve(all_deps, cat); | 
		
	
		
			
			|  |  |  | for (const dds::package_id& pk : deps) { | 
		
	
		
			
			|  |  |  | auto exists = !!repo.find(pk); | 
		
	
		
			
			|  |  |  | if (!exists) { | 
		
	
		
			
			|  |  |  | spdlog::info("Download dependency: {}", pk.to_string()); | 
		
	
		
			
			|  |  |  | auto opt_pkg = cat.get(pk); | 
		
	
		
			
			|  |  |  | assert(opt_pkg); | 
		
	
		
			
			|  |  |  | auto tsd = dds::get_package_sdist(*opt_pkg); | 
		
	
		
			
			|  |  |  | repo.add_sdist(tsd.sdist, dds::if_exists::throw_exc); | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | auto sdist_ptr = repo.find(pk); | 
		
	
		
			
			|  |  |  | assert(sdist_ptr); | 
		
	
		
			
			|  |  |  | dds::sdist_build_params deps_params; | 
		
	
		
			
			|  |  |  | deps_params.subdir = sdist_ptr->manifest.pkg_id.to_string(); | 
		
	
		
			
			|  |  |  | bd.add(*sdist_ptr, deps_params); | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | }); | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | bd.build(params); | 
		
	
		
			
			|  |  |  | return 0; | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | }; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | }  // namespace | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | /* | 
		
	
	
		
			
			|  |  | @@ -578,11 +678,12 @@ int main(int argc, char** argv) { | 
		
	
		
			
			|  |  |  | spdlog::set_pattern("[%H:%M:%S] [%^%-5l%$] %v"); | 
		
	
		
			
			|  |  |  | args::ArgumentParser parser("DDS - The drop-dead-simple library manager"); | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | cli_base    cli{parser}; | 
		
	
		
			
			|  |  |  | cli_build   build{cli}; | 
		
	
		
			
			|  |  |  | cli_sdist   sdist{cli}; | 
		
	
		
			
			|  |  |  | cli_repo    repo{cli}; | 
		
	
		
			
			|  |  |  | cli_catalog catalog{cli}; | 
		
	
		
			
			|  |  |  | cli_base       cli{parser}; | 
		
	
		
			
			|  |  |  | cli_build      build{cli}; | 
		
	
		
			
			|  |  |  | cli_sdist      sdist{cli}; | 
		
	
		
			
			|  |  |  | cli_repo       repo{cli}; | 
		
	
		
			
			|  |  |  | cli_catalog    catalog{cli}; | 
		
	
		
			
			|  |  |  | cli_build_deps build_deps{cli}; | 
		
	
		
			
			|  |  |  | try { | 
		
	
		
			
			|  |  |  | parser.ParseCLI(argc, argv); | 
		
	
		
			
			|  |  |  | } catch (const args::Help&) { | 
		
	
	
		
			
			|  |  | @@ -608,6 +709,8 @@ int main(int argc, char** argv) { | 
		
	
		
			
			|  |  |  | return repo.run(); | 
		
	
		
			
			|  |  |  | } else if (catalog.cmd) { | 
		
	
		
			
			|  |  |  | return catalog.run(); | 
		
	
		
			
			|  |  |  | } else if (build_deps.cmd) { | 
		
	
		
			
			|  |  |  | return build_deps.run(); | 
		
	
		
			
			|  |  |  | } else { | 
		
	
		
			
			|  |  |  | assert(false); | 
		
	
		
			
			|  |  |  | std::terminate(); |