summaryrefslogtreecommitdiff
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
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.
-rw-r--r--share/man/just.1.md9
-rw-r--r--src/buildtool/common/cli.hpp5
-rw-r--r--src/buildtool/main/TARGETS6
-rw-r--r--src/buildtool/main/install_cas.cpp22
4 files changed, 36 insertions, 6 deletions
diff --git a/share/man/just.1.md b/share/man/just.1.md
index de84f44b..812cd33f 100644
--- a/share/man/just.1.md
+++ b/share/man/just.1.md
@@ -496,9 +496,16 @@ Install path for the artifact. Refer to **`install-cas`** section for more
details.
Supported by: install-cas.
+**`--archive`**
+Instead of installing the requested tree, install an archive with the
+content of the tree. It is a user error to specify **`--archive`** and
+not request a tree.
+Supported by: install-cas.
+
**`--raw-tree`**
When installing a tree to stdout, i.e., when no option **`-o`** is given,
-dump the raw tree rather than a pretty-printed version.
+dump the raw tree rather than a pretty-printed version. This option is
+ignored if **`--archive`** is given.
Supported by: install-cas.
**`-P`**, **`--sub-object-path`** *`PATH`*
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(