diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-11-16 11:38:23 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-11-16 15:09:05 +0100 |
commit | fbc34ed2cb3e42a2d5df6db67a362b127df42f7d (patch) | |
tree | 5ea1e234f4db3e07bf9bec047bd27d7657c881f7 | |
parent | c3b10ee7c9320ed6cf5daec6310b0296812ea86a (diff) | |
download | justbuild-fbc34ed2cb3e42a2d5df6db67a362b127df42f7d.tar.gz |
Fix effective configuration computation in configure
While the built-in "configure" rule is forwarding the result of
the configured target, its own effective configuration is not that
of the configured target. The effective configuration is defined
to be that part of the incoming configuration that can potentially
influence the result of that target; in particular, this includes
variables read in defining the configuration transition.
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | src/buildtool/build_engine/target_map/built_in_rules.cpp | 22 | ||||
-rw-r--r-- | test/end-to-end/targets/TARGETS | 7 | ||||
-rw-r--r-- | test/end-to-end/targets/configure-vars.sh | 69 |
4 files changed, 92 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b5b9846..eb9de309 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,9 @@ Initial stable release. ### Important changes since `1.0.0~beta5` -- The "configure" built-in rule now evaluates "target" +- The "confgiure" built-in rule now evaluates "target". Also, + a bug in the computation of the effective configuration + was fixed. - Option `--dump-vars` added to `just analyse` - Rule fixes in propagating `ENV` - Launcher functionality added to `just-mr` 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 763385e2..f71cd0e8 100644 --- a/src/buildtool/build_engine/target_map/built_in_rules.cpp +++ b/src/buildtool/build_engine/target_map/built_in_rules.cpp @@ -1016,7 +1016,7 @@ void ConfigureRule( auto target_config = key.config.Update(eval_config); auto target_to_configure = BuildMaps::Target::ConfiguredTarget{ - std::move(*configured_target), target_config}; + std::move(*configured_target), std::move(target_config)}; (*subcaller)( {std::move(target_to_configure)}, @@ -1024,9 +1024,9 @@ void ConfigureRule( logger, vars = std::move(*param_vars), result_map, + transition = Configuration{std::move(eval_config)}, tainted = std::move(tainted), - target_config = std::move(target_config), - target = key.target](auto const& values) { + key](auto const& values) { auto& configured_target = *values[0]; if (not std::includes(tainted.begin(), tainted.end(), @@ -1040,14 +1040,17 @@ void ConfigureRule( } std::unordered_set<std::string> vars_set{}; + for (auto const& x : configured_target->Vars()) { + if (not transition.VariableFixed(x)) { + vars_set.insert(x); + } + } vars_set.insert(vars.begin(), vars.end()); - vars_set.insert(configured_target->Vars().begin(), - configured_target->Vars().end()); - auto effective_conf = target_config.Prune(vars_set); + auto effective_conf = key.config.Prune(vars_set); auto deps_info = TargetGraphInformation{ std::make_shared<BuildMaps::Target::ConfiguredTarget>( - BuildMaps::Target::ConfiguredTarget{target, + BuildMaps::Target::ConfiguredTarget{key.target, effective_conf}), {configured_target->GraphInformation().Node()}, {}, @@ -1061,8 +1064,9 @@ void ConfigureRule( std::move(vars_set), std::set<std::string>{}, std::move(deps_info)); - analysis_result = result_map->Add( - target, std::move(effective_conf), std::move(analysis_result)); + analysis_result = result_map->Add(key.target, + std::move(effective_conf), + std::move(analysis_result)); (*setter)(std::move(analysis_result)); }, logger); diff --git a/test/end-to-end/targets/TARGETS b/test/end-to-end/targets/TARGETS index 31f4f900..13de53ad 100644 --- a/test/end-to-end/targets/TARGETS +++ b/test/end-to-end/targets/TARGETS @@ -28,6 +28,12 @@ , "test": ["configure-target.sh"] , "deps": [["test/end-to-end", "tool-under-test"]] } +, "configure variables": + { "type": ["@", "rules", "shell/test", "script"] + , "name": ["configure-vars"] + , "test": ["configure-vars.sh"] + , "deps": [["test/end-to-end", "tool-under-test"]] + } , "TESTS": { "type": "install" , "tainted": ["test"] @@ -37,6 +43,7 @@ , "resolution of built-in rules" , "glob expansion" , "configure target name" + , "configure variables" ] } } diff --git a/test/end-to-end/targets/configure-vars.sh b/test/end-to-end/targets/configure-vars.sh new file mode 100644 index 00000000..e55581f7 --- /dev/null +++ b/test/end-to-end/targets/configure-vars.sh @@ -0,0 +1,69 @@ +#!/bin/sh +# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +TOOL=$(realpath ./bin/tool-under-test) +mkdir -p .root +BUILDROOT=$(realpath .root) +mkdir -p out +OUTDIR=$(realpath out) + +mkdir src +cd src +touch ROOT +cat > TARGETS <<'EOI' +{ "copy foo": + { "type": "configure" + , "arguments_config": ["FOO"] + , "target": "use bar" + , "config": + { "type": "let*" + , "bindings": + [["BAR", {"type": "var", "name": "FOO"}], ["FOO", "REDACTED"]] + , "body": {"type": "env", "vars": ["BAR", "FOO"]} + } + } +, "use bar": + { "type": "file_gen" + , "arguments_config": ["BAR"] + , "data": {"type": "var", "name": "BAR", "default": "bar"} + , "name": "out.txt" + } +} +EOI + + +echo +${TOOL} analyse --local-build-root "${BUILDROOT}" \ + --dump-vars "${OUTDIR}/vars.json" \ + --dump-targets "${OUTDIR}/targets.json" \ + -D '{"FOO": "the value", "BAR": "unused!"}' 'copy foo' 2>&1 +echo +cat "${OUTDIR}/vars.json" +echo +cat "${OUTDIR}/targets.json" +echo +copy_configs=$(cat "${OUTDIR}/targets.json" | jq -acM '."@" | ."" | ."" | ."copy foo"') +echo "${copy_configs}" +[ $(echo "${copy_configs}" | jq length) -eq 1 ] +config=$(echo "${copy_configs}" | jq '.[0]') +echo $config +[ $(echo "$config" | jq -acM 'keys') = '["FOO"]' ] +echo "$config" | jq -acM '."FOO"' +[ "$(echo "$config" | jq -acM '."FOO"')" = '"the value"' ] +[ "$(cat "${OUTDIR}/vars.json")" = '["FOO"]' ] + +echo DONE |