summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2025-02-12 09:55:03 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2025-02-14 18:17:07 +0100
commita26432b923c1595c0489897ca23b1c8f0eeca6bc (patch)
treec9921d8d7feeb8a7fea35bb0b1a565ec0f5bee44 /src
parent5314488ffd056ad2ef70005d537d3fdb02ae867b (diff)
downloadjustbuild-a26432b923c1595c0489897ca23b1c8f0eeca6bc.tar.gz
just add-to-cas: Enable --resolve-special option
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/common/TARGETS1
-rw-r--r--src/buildtool/common/cli.hpp18
-rw-r--r--src/buildtool/main/add_to_cas.cpp8
3 files changed, 25 insertions, 2 deletions
diff --git a/src/buildtool/common/TARGETS b/src/buildtool/common/TARGETS
index 1e18f09c..df1884a8 100644
--- a/src/buildtool/common/TARGETS
+++ b/src/buildtool/common/TARGETS
@@ -24,6 +24,7 @@
, ["@", "json", "", "json"]
, ["src/buildtool/build_engine/expression", "expression"]
, ["src/buildtool/crypto", "hash_function"]
+ , ["src/buildtool/file_system/symlinks", "resolve_special"]
, ["src/buildtool/logging", "log_level"]
, ["src/buildtool/logging", "logging"]
, ["src/buildtool/main", "build_utils"]
diff --git a/src/buildtool/common/cli.hpp b/src/buildtool/common/cli.hpp
index c6771cb3..f486a5fd 100644
--- a/src/buildtool/common/cli.hpp
+++ b/src/buildtool/common/cli.hpp
@@ -35,6 +35,7 @@
#include "src/buildtool/build_engine/expression/evaluator.hpp"
#include "src/buildtool/common/clidefaults.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
+#include "src/buildtool/file_system/symlinks/resolve_special.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
#include "src/buildtool/main/build_utils.hpp"
@@ -194,6 +195,7 @@ struct GcArguments {
struct ToAddArguments {
std::filesystem::path location;
bool follow_symlinks{};
+ std::optional<ResolveSpecial> resolve_special{std::nullopt};
};
struct ProtocolArguments final {
@@ -679,6 +681,22 @@ static inline auto SetupToAddArguments(
clargs->follow_symlinks,
"Resolve the positional argument to not be a symbolic link "
"before adding it to CAS.");
+ app->add_option_function<std::string>(
+ "--resolve-special",
+ [clargs](auto const& raw_value) {
+ if (kResolveSpecialMap.contains(raw_value)) {
+ clargs->resolve_special = kResolveSpecialMap.at(raw_value);
+ }
+ else {
+ Logger::Log(LogLevel::Warning,
+ "Ignoring unknown --resolve-special strategy {}.",
+ nlohmann::json(raw_value).dump());
+ }
+ },
+ "Optional strategy for handling special entries (e.g., symlinks) when "
+ "the content to add is a directory. Default behaviour if missing is to "
+ "only allow non-upward symlinks. Currently supported values: ignore, "
+ "tree-upwards, tree-all, all.");
}
static inline auto SetupGraphArguments(
diff --git a/src/buildtool/main/add_to_cas.cpp b/src/buildtool/main/add_to_cas.cpp
index 4b0fe6b9..163fa4c3 100644
--- a/src/buildtool/main/add_to_cas.cpp
+++ b/src/buildtool/main/add_to_cas.cpp
@@ -386,8 +386,12 @@ auto AddArtifactsToCas(ToAddArguments const& clargs,
-> std::optional<ArtifactDigest> {
return cas.StoreBlob(content);
};
- CASTreeImporter tree_importer{
- object_location, store_file, store_tree, store_symlink};
+
+ CASTreeImporter tree_importer{object_location,
+ store_file,
+ store_tree,
+ store_symlink,
+ clargs.resolve_special};
digest = tree_importer.GetDigest();
} break;
}