summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2023-11-13 12:17:53 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2023-11-13 15:40:15 +0100
commit541ba9586b8a3aabe90f2dd01d994428dfab4cb9 (patch)
tree2c6924809d8ee2606807ef20daeff235b9a7c0a3 /src
parent6d01670b08688a075e8a4f1b297573281c2c4607 (diff)
downloadjustbuild-541ba9586b8a3aabe90f2dd01d994428dfab4cb9.tar.gz
"git tree" repositories: honor "inherit env"
In the specification of the action generating a fixed git tree, also honor "inherit env", i.e., inherit the environment variables specified in this field from the environment just-mr is invoked in. As the expected output is fixed ahead of time anyway, this lack of isolation does not affect correctness.
Diffstat (limited to 'src')
-rw-r--r--src/other_tools/repo_map/repos_to_setup_map.cpp19
-rw-r--r--src/other_tools/root_maps/tree_id_git_map.cpp16
-rw-r--r--src/other_tools/root_maps/tree_id_git_map.hpp2
3 files changed, 32 insertions, 5 deletions
diff --git a/src/other_tools/repo_map/repos_to_setup_map.cpp b/src/other_tools/repo_map/repos_to_setup_map.cpp
index a72903d1..a65a6c50 100644
--- a/src/other_tools/repo_map/repos_to_setup_map.cpp
+++ b/src/other_tools/repo_map/repos_to_setup_map.cpp
@@ -611,6 +611,24 @@ void GitTreeCheckout(ExpressionPtr const& repo_desc,
}
}
}
+ std::vector<std::string> inherit_env{};
+ auto repo_desc_inherit_env =
+ repo_desc->Get("inherit env", Expression::none_t{});
+ if (repo_desc_inherit_env.IsNotNull() and repo_desc_inherit_env->IsList()) {
+ for (auto const& envvar : repo_desc_inherit_env->List()) {
+ if (envvar->IsString()) {
+ inherit_env.emplace_back(envvar->String());
+ }
+ else {
+ (*logger)(
+ fmt::format("GitTreeCheckout: Not a variable name in the "
+ "specification of \"inherit env\": {}",
+ envvar->ToString()),
+ /*fatal=*/true);
+ return;
+ }
+ }
+ }
// check "special" pragma
auto repo_desc_pragma = repo_desc->At("pragma");
auto pragma_special = repo_desc_pragma
@@ -632,6 +650,7 @@ void GitTreeCheckout(ExpressionPtr const& repo_desc,
TreeIdInfo tree_id_info = {
.hash = repo_desc_hash->get()->String(),
.env_vars = std::move(env),
+ .inherit_env = std::move(inherit_env),
.command = std::move(cmd),
.ignore_special = pragma_special_value == PragmaSpecial::Ignore,
.absent = not fetch_absent and pragma_absent_value};
diff --git a/src/other_tools/root_maps/tree_id_git_map.cpp b/src/other_tools/root_maps/tree_id_git_map.cpp
index a8db186a..ce2fe5e5 100644
--- a/src/other_tools/root_maps/tree_id_git_map.cpp
+++ b/src/other_tools/root_maps/tree_id_git_map.cpp
@@ -14,6 +14,8 @@
#include "src/other_tools/root_maps/tree_id_git_map.hpp"
+#include <cstdlib>
+
#include "fmt/core.h"
#include "src/buildtool/execution_api/common/execution_common.hpp"
#include "src/buildtool/file_system/file_root.hpp"
@@ -167,11 +169,15 @@ auto CreateTreeIdGitMap(
std::copy(key.command.begin(),
key.command.end(),
std::back_inserter(cmdline));
- auto const command_output =
- system.Execute(cmdline,
- key.env_vars,
- tmp_dir->GetPath(),
- out_dir->GetPath());
+ std::map<std::string, std::string> env{key.env_vars};
+ for (auto const& k : key.inherit_env) {
+ const char* v = std::getenv(k.c_str());
+ if (v != nullptr) {
+ env[k] = std::string(v);
+ }
+ }
+ auto const command_output = system.Execute(
+ cmdline, env, tmp_dir->GetPath(), out_dir->GetPath());
if (not command_output) {
(*logger)(fmt::format("Failed to execute command:\n{}",
nlohmann::json(cmdline).dump()),
diff --git a/src/other_tools/root_maps/tree_id_git_map.hpp b/src/other_tools/root_maps/tree_id_git_map.hpp
index 3c029117..8041919d 100644
--- a/src/other_tools/root_maps/tree_id_git_map.hpp
+++ b/src/other_tools/root_maps/tree_id_git_map.hpp
@@ -17,6 +17,7 @@
#include <string>
#include <utility>
+#include <vector>
#include "nlohmann/json.hpp"
#include "src/other_tools/ops_maps/critical_git_op_map.hpp"
@@ -25,6 +26,7 @@
struct TreeIdInfo {
std::string hash{}; /* key */
std::map<std::string, std::string> env_vars{};
+ std::vector<std::string> inherit_env{};
std::vector<std::string> command{};
// name of repository for which work is done; used in progress reporting
std::string origin{};