From 9ee2086f9f910ac7cd930dffc4888c7c515962fc Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 27 Mar 2024 15:30:37 +0100 Subject: just install-cas: add option --archive Trees are first-class objects for justbuild. To allow interoperation with other tools, it is necessary to provide those objects in a standard format; for directories, those are archives. Hence procive a corresponding option. --- src/buildtool/main/install_cas.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/buildtool/main/install_cas.cpp') 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 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( -- cgit v1.2.3