diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-08-24 17:27:33 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-08-28 16:59:45 +0200 |
commit | 909814a8730e5cf24c4e0984e946ec0066515257 (patch) | |
tree | 95c87aafef04c26015410d252f972421f73856ce /src | |
parent | 3e4e2b6fcbffe5de62d7c3eab47fdf3987dc778d (diff) | |
download | justbuild-909814a8730e5cf24c4e0984e946ec0066515257.tar.gz |
Extend built-in "generic" rule to allow setting "sh"
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/build_engine/target_map/built_in_rules.cpp | 47 |
1 files changed, 46 insertions, 1 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 29eba7bf..7a057927 100644 --- a/src/buildtool/build_engine/target_map/built_in_rules.cpp +++ b/src/buildtool/build_engine/target_map/built_in_rules.cpp @@ -43,6 +43,7 @@ auto const kGenericRuleFields = "deps", "env", "execution properties", + "sh -c", "tainted", "timeout scaling", "type", @@ -1092,6 +1093,43 @@ void GenericRuleWithDeps( } } + auto sh_exp = desc->ReadOptionalExpression("sh -c", Expression::kEmptyList); + if (not sh_exp) { + return; + } + auto sh_val = sh_exp.Evaluate( + param_config, string_fields_fcts, [&logger](auto const& msg) { + (*logger)(fmt::format("While evaluating sh:\n{}", msg), true); + }); + if (not sh_val) { + return; + } + if (sh_val->IsNone()) { + sh_val = Expression::kEmptyList; + } + if (not sh_val->IsList()) { + (*logger)(fmt::format("sh has evaluate to list of strings or null, but " + "found {}", + sh_val->ToString()), + true); + return; + } + for (auto const& entry : sh_val->List()) { + if (not entry->IsString()) { + (*logger)(fmt::format("sh has evaluate to list of strings or null, " + "but found {}\nwith non-string entry {}", + sh_val->ToString(), + entry->ToString()), + true); + return; + } + } + static ExpressionPtr const kShC = + Expression::FromJson(R"( ["sh", "-c"] )"_json); + if (sh_val->List().empty()) { + sh_val = kShC; + } + auto scale_exp = desc->ReadOptionalExpression("timeout scaling", Expression::kOne); if (not scale_exp) { @@ -1159,11 +1197,18 @@ void GenericRuleWithDeps( inputs = ExpressionPtr{Expression::map_t{inputs, (*dep)->Artifacts()}}; } + std::vector<std::string> argv{}; + argv.reserve(sh_val->List().size() + 1); + for (auto const& entry : sh_val->List()) { + argv.emplace_back(entry->String()); + } + argv.emplace_back(cmd_ss.str()); + // Construct our single action, and its artifacts auto action = BuildMaps::Target::Utils::createAction( outs, out_dirs, - {"sh", "-c", cmd_ss.str()}, + argv, env_val, std::nullopt, false, |