diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-07-31 10:04:28 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-08-01 17:58:11 +0200 |
commit | ed71beee3e3a2bbfcba24281ad9e28a0f6df4054 (patch) | |
tree | 60811333fc6a42f5aa315cc6fbadb3c671e28199 /src | |
parent | 62fed0cf026e676297b7560d8ffaef77d3017ce4 (diff) | |
download | justbuild-ed71beee3e3a2bbfcba24281ad9e28a0f6df4054.tar.gz |
class Action: include field cwd
... for the working directory inside the action directory.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/build_engine/target_map/built_in_rules.cpp | 1 | ||||
-rw-r--r-- | src/buildtool/build_engine/target_map/target_map.cpp | 1 | ||||
-rw-r--r-- | src/buildtool/build_engine/target_map/utils.cpp | 3 | ||||
-rw-r--r-- | src/buildtool/build_engine/target_map/utils.hpp | 1 | ||||
-rw-r--r-- | src/buildtool/common/action.hpp | 6 | ||||
-rw-r--r-- | src/buildtool/common/action_description.hpp | 17 |
6 files changed, 29 insertions, 0 deletions
diff --git a/src/buildtool/build_engine/target_map/built_in_rules.cpp b/src/buildtool/build_engine/target_map/built_in_rules.cpp index d7c28074..e1cf9c7f 100644 --- a/src/buildtool/build_engine/target_map/built_in_rules.cpp +++ b/src/buildtool/build_engine/target_map/built_in_rules.cpp @@ -1341,6 +1341,7 @@ void GenericRuleWithDeps( outs, out_dirs, argv, + "", env_val, std::nullopt, false, diff --git a/src/buildtool/build_engine/target_map/target_map.cpp b/src/buildtool/build_engine/target_map/target_map.cpp index c4bbcfae..75bf6607 100644 --- a/src/buildtool/build_engine/target_map/target_map.cpp +++ b/src/buildtool/build_engine/target_map/target_map.cpp @@ -697,6 +697,7 @@ void withDependencies( outputs, output_dirs, std::move(cmd), + "", env_exp, may_fail, no_cache, diff --git a/src/buildtool/build_engine/target_map/utils.cpp b/src/buildtool/build_engine/target_map/utils.cpp index 56f996ca..71defc4c 100644 --- a/src/buildtool/build_engine/target_map/utils.cpp +++ b/src/buildtool/build_engine/target_map/utils.cpp @@ -199,6 +199,7 @@ auto BuildMaps::Target::Utils::createAction( const ActionDescription::outputs_t& output_files, const ActionDescription::outputs_t& output_dirs, std::vector<std::string> command, + std::string cwd, const ExpressionPtr& env, std::optional<std::string> may_fail, bool no_cache, @@ -213,6 +214,7 @@ auto BuildMaps::Target::Utils::createAction( hasher.Update(hash_vector(hash_function, output_files)); hasher.Update(hash_vector(hash_function, output_dirs)); hasher.Update(hash_vector(hash_function, command)); + hasher.Update(hash_vector(hash_function, std::vector<std::string>{cwd})); hasher.Update(env->ToHash()); hasher.Update(hash_vector(hash_function, may_fail ? std::vector<std::string>{*may_fail} @@ -242,6 +244,7 @@ auto BuildMaps::Target::Utils::createAction( output_dirs, Action{std::move(action_id), std::move(command), + std::move(cwd), std::move(env_vars), std::move(may_fail), no_cache, diff --git a/src/buildtool/build_engine/target_map/utils.hpp b/src/buildtool/build_engine/target_map/utils.hpp index 8db440c8..d7722efb 100644 --- a/src/buildtool/build_engine/target_map/utils.hpp +++ b/src/buildtool/build_engine/target_map/utils.hpp @@ -64,6 +64,7 @@ auto getTainted(std::set<std::string>* tainted, auto createAction(const ActionDescription::outputs_t& output_files, const ActionDescription::outputs_t& output_dirs, std::vector<std::string> command, + std::string cwd, const ExpressionPtr& env, std::optional<std::string> may_fail, bool no_cache, diff --git a/src/buildtool/common/action.hpp b/src/buildtool/common/action.hpp index e9d4581d..350a1d2b 100644 --- a/src/buildtool/common/action.hpp +++ b/src/buildtool/common/action.hpp @@ -29,6 +29,7 @@ class Action { Action(std::string action_id, std::vector<std::string> command, + std::string cwd, std::map<std::string, std::string> env_vars, std::optional<std::string> may_fail, bool no_cache, @@ -36,6 +37,7 @@ class Action { std::map<std::string, std::string> execution_properties) : id_{std::move(action_id)}, command_{std::move(command)}, + cwd_{std::move(cwd)}, env_{std::move(env_vars)}, may_fail_{std::move(may_fail)}, no_cache_{no_cache}, @@ -47,6 +49,7 @@ class Action { std::map<std::string, std::string> env_vars) : Action(std::move(action_id), std::move(command), + "", std::move(env_vars), std::nullopt, false, @@ -64,6 +67,8 @@ class Action { return command_; } + [[nodiscard]] auto Cwd() const -> std::string { return cwd_; } + [[nodiscard]] auto Env() const& noexcept -> std::map<std::string, std::string> { return env_; @@ -98,6 +103,7 @@ class Action { private: ActionIdentifier id_{}; std::vector<std::string> command_{}; + std::string cwd_{}; std::map<std::string, std::string> env_{}; bool is_tree_{}; std::optional<std::string> may_fail_{}; diff --git a/src/buildtool/common/action_description.hpp b/src/buildtool/common/action_description.hpp index 47a92eb8..2ae7ad8a 100644 --- a/src/buildtool/common/action_description.hpp +++ b/src/buildtool/common/action_description.hpp @@ -83,6 +83,19 @@ class ActionDescription { output_dirs = std::vector<std::string>{}; } + std::string cwd{}; + auto cwd_it = desc.find("cwd"); + if (cwd_it != desc.end()) { + if (cwd_it->is_string()) { + cwd = *cwd_it; + } + else { + Logger::Log(LogLevel::Error, + "cwd, if given, has to be a string"); + return std::nullopt; + } + } + auto optional_key_value_reader = [](nlohmann::json const& action_desc, std::string const& key) -> nlohmann::json { @@ -160,6 +173,7 @@ class ActionDescription { std::move(*output_dirs), Action{id, std::move(*command), + cwd, env, may_fail, no_cache, @@ -206,6 +220,9 @@ class ActionDescription { if (action_.TimeoutScale() != 1.0) { json["timeout scaling"] = action_.TimeoutScale(); } + if (not action_.Cwd().empty()) { + json["cwd"] = action_.Cwd(); + } if (not action_.ExecutionProperties().empty()) { json["execution properties"] = action_.ExecutionProperties(); } |