diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/common/cli.hpp | 5 | ||||
-rw-r--r-- | src/buildtool/main/TARGETS | 6 | ||||
-rw-r--r-- | src/buildtool/main/install_cas.cpp | 22 |
3 files changed, 28 insertions, 5 deletions
diff --git a/src/buildtool/common/cli.hpp b/src/buildtool/common/cli.hpp index e7f78201..7ede3217 100644 --- a/src/buildtool/common/cli.hpp +++ b/src/buildtool/common/cli.hpp @@ -138,6 +138,7 @@ struct FetchArguments { std::optional<std::filesystem::path> sub_path{}; bool remember{false}; bool raw_tree{}; + bool archive{}; }; /// \brief Arguments required for running from graph file. @@ -600,9 +601,11 @@ static inline auto SetupFetchArguments( "tree).") ->type_name("PATH"); + app->add_flag( + "--archive", clargs->archive, "Dump the tree as a single archive."); app->add_flag("--raw-tree", clargs->raw_tree, - "Dump raw tree object (omit pretty printing)"); + "Dump raw tree object (omit pretty printing)."); app->add_flag( "--remember", clargs->remember, "Copy object to local CAS first"); diff --git a/src/buildtool/main/TARGETS b/src/buildtool/main/TARGETS index 626fe9f2..b15ef25a 100644 --- a/src/buildtool/main/TARGETS +++ b/src/buildtool/main/TARGETS @@ -119,6 +119,7 @@ , ["src/buildtool/logging", "log_level"] , ["src/buildtool/logging", "logging"] , ["src/buildtool/execution_api/utils", "subobject"] + , "archive" ] } , "add_to_cas": @@ -286,7 +287,10 @@ , "name": ["archive"] , "hdrs": ["archive.hpp"] , "srcs": ["archive.cpp"] - , "deps": [["src/buildtool/common", "common"]] + , "deps": + [ ["src/buildtool/common", "common"] + , ["src/buildtool/execution_api/common", "common"] + ] , "stage": ["src", "buildtool", "main"] , "private-deps": [ ["", "libarchive"] diff --git a/src/buildtool/main/install_cas.cpp b/src/buildtool/main/install_cas.cpp index ed989883..e6bb9128 100644 --- a/src/buildtool/main/install_cas.cpp +++ b/src/buildtool/main/install_cas.cpp @@ -23,6 +23,7 @@ #include "src/buildtool/logging/logger.hpp" #ifndef BOOTSTRAP_BUILD_TOOL #include "src/buildtool/execution_api/utils/subobject.hpp" +#include "src/buildtool/main/archive.hpp" #endif namespace { @@ -96,7 +97,9 @@ auto FetchAndInstallArtifacts( } } + std::optional<std::filesystem::path> out{}; if (clargs.output_path) { + // Compute output location and create parent directories auto output_path = (*clargs.output_path / "").parent_path(); if (FileSystemManager::IsDirectory(output_path)) { output_path /= object_info.digest.hash(); @@ -108,8 +111,21 @@ auto FetchAndInstallArtifacts( output_path.parent_path().string()); return false; } - if (not api->RetrieveToPaths( - {object_info}, {output_path}, alternative_api)) { + out = output_path; + } + + if (clargs.archive) { + if (object_info.type != ObjectType::Tree) { + Logger::Log(LogLevel::Error, + "Archive requested on non-tree {}", + object_info.ToString()); + return false; + } + return GenerateArchive(api, object_info, out); + } + + if (out) { + if (not api->RetrieveToPaths({object_info}, {*out}, alternative_api)) { Logger::Log(LogLevel::Error, "failed to retrieve artifact."); return false; } @@ -117,7 +133,7 @@ auto FetchAndInstallArtifacts( Logger::Log(LogLevel::Info, "artifact {} was installed to {}", object_info.ToString(), - output_path.string()); + out->string()); } else { // dump to stdout if (not api->RetrieveToFds( |