diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/repo_map/repos_to_setup_map.cpp | 19 | ||||
-rw-r--r-- | src/other_tools/root_maps/tree_id_git_map.cpp | 16 | ||||
-rw-r--r-- | src/other_tools/root_maps/tree_id_git_map.hpp | 2 |
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{}; |