summaryrefslogtreecommitdiff
path: root/src/buildtool/main/install_cas.cpp
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2024-03-27 15:30:37 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2024-03-28 14:53:42 +0100
commit9ee2086f9f910ac7cd930dffc4888c7c515962fc (patch)
treed7223cfeda4b9ad75b1d08007c9e33c6b40459e0 /src/buildtool/main/install_cas.cpp
parent68f18337afc2cd7a7a8aba123537020f29e51644 (diff)
downloadjustbuild-9ee2086f9f910ac7cd930dffc4888c7c515962fc.tar.gz
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.
Diffstat (limited to 'src/buildtool/main/install_cas.cpp')
-rw-r--r--src/buildtool/main/install_cas.cpp22
1 files changed, 19 insertions, 3 deletions
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(