diff options
-rw-r--r-- | src/buildtool/build_engine/target_map/built_in_rules.cpp | 38 | ||||
-rw-r--r-- | test/end-to-end/built-in-rules/TARGETS | 11 | ||||
-rwxr-xr-x | test/end-to-end/built-in-rules/filegen_config.sh | 53 |
3 files changed, 89 insertions, 13 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 f71cd0e8..178000d2 100644 --- a/src/buildtool/build_engine/target_map/built_in_rules.cpp +++ b/src/buildtool/build_engine/target_map/built_in_rules.cpp @@ -70,7 +70,7 @@ auto const kConfigureRuleFields = "type"}; void FileGenRuleWithDeps( - const std::vector<BuildMaps::Target::ConfiguredTarget>& dependency_keys, + const std::vector<BuildMaps::Target::ConfiguredTarget>& transition_keys, const std::vector<AnalysedTargetPtr const*>& dependency_values, const BuildMaps::Base::FieldReader::Ptr& desc, const BuildMaps::Target::ConfiguredTarget& key, @@ -80,9 +80,9 @@ void FileGenRuleWithDeps( // Associate keys and values std::unordered_map<BuildMaps::Target::ConfiguredTarget, AnalysedTargetPtr> deps_by_transition; - deps_by_transition.reserve(dependency_keys.size()); - for (size_t i = 0; i < dependency_keys.size(); ++i) { - deps_by_transition.emplace(dependency_keys[i], *dependency_values[i]); + deps_by_transition.reserve(transition_keys.size()); + for (size_t i = 0; i < transition_keys.size(); ++i) { + deps_by_transition.emplace(transition_keys[i], *dependency_values[i]); } auto param_vars = desc->ReadStringList("arguments_config"); @@ -90,15 +90,21 @@ void FileGenRuleWithDeps( return; } auto param_config = key.config.Prune(*param_vars); + auto vars_set = std::unordered_set<std::string>{}; + vars_set.insert(param_vars->begin(), param_vars->end()); + for (auto const& dep : dependency_values) { + vars_set.insert((*dep)->Vars().begin(), (*dep)->Vars().end()); + } + auto effective_conf = key.config.Prune(vars_set); + std::vector<BuildMaps::Target::ConfiguredTargetPtr> all_deps{}; all_deps.reserve(dependency_values.size()); for (auto const& dep : dependency_values) { all_deps.emplace_back((*dep)->GraphInformation().Node()); } - auto deps_info = TargetGraphInformation{ std::make_shared<BuildMaps::Target::ConfiguredTarget>( - BuildMaps::Target::ConfiguredTarget{key.target, param_config}), + BuildMaps::Target::ConfiguredTarget{key.target, effective_conf}), all_deps, {}, {}}; @@ -186,8 +192,6 @@ void FileGenRuleWithDeps( ArtifactDigest::Create<ObjectType::File>(data_val->String()), ObjectType::File}}}}; - auto vars_set = std::unordered_set<std::string>{}; - vars_set.insert(param_vars->begin(), param_vars->end()); auto analysis_result = std::make_shared<AnalysedTarget const>( TargetResult{stage, ExpressionPtr{Expression::map_t{}}, stage}, std::vector<ActionDescription::Ptr>{}, @@ -197,7 +201,7 @@ void FileGenRuleWithDeps( std::move(tainted), std::move(deps_info)); analysis_result = - result_map->Add(key.target, param_config, std::move(analysis_result)); + result_map->Add(key.target, effective_conf, std::move(analysis_result)); (*setter)(std::move(analysis_result)); } @@ -238,6 +242,10 @@ void FileGenRule( return; } std::vector<BuildMaps::Target::ConfiguredTarget> dependency_keys; + std::vector<BuildMaps::Target::ConfiguredTarget> transition_keys; + dependency_keys.reserve(deps_value->List().size()); + transition_keys.reserve(deps_value->List().size()); + auto empty_transition = Configuration{Expression::kEmptyMap}; for (auto const& dep_name : deps_value->List()) { auto dep_target = BuildMaps::Base::ParseEntityNameFromExpression( dep_name, @@ -253,13 +261,19 @@ void FileGenRule( } dependency_keys.emplace_back( BuildMaps::Target::ConfiguredTarget{*dep_target, key.config}); + transition_keys.emplace_back( + BuildMaps::Target::ConfiguredTarget{*dep_target, empty_transition}); } (*subcaller)( dependency_keys, - [dependency_keys, desc, setter, logger, key, result_map]( - auto const& values) { + [transition_keys = std::move(transition_keys), + desc, + setter, + logger, + key, + result_map](auto const& values) { FileGenRuleWithDeps( - dependency_keys, values, desc, key, setter, logger, result_map); + transition_keys, values, desc, key, setter, logger, result_map); }, logger); } diff --git a/test/end-to-end/built-in-rules/TARGETS b/test/end-to-end/built-in-rules/TARGETS index 4991c5c3..0f9b7a5a 100644 --- a/test/end-to-end/built-in-rules/TARGETS +++ b/test/end-to-end/built-in-rules/TARGETS @@ -4,6 +4,15 @@ , "test": ["generic_out_dirs.sh"] , "deps": [["test/end-to-end", "tool-under-test"]] } +, "filegen_config": + { "type": ["@", "rules", "shell/test", "script"] + , "name": ["filegen_config"] + , "test": ["filegen_config.sh"] + , "deps": [["test/end-to-end", "tool-under-test"]] + } , "TESTS": - {"type": "install", "tainted": ["test"], "deps": ["generic_out_dirs"]} + { "type": "install" + , "tainted": ["test"] + , "deps": ["generic_out_dirs", "filegen_config"] + } } diff --git a/test/end-to-end/built-in-rules/filegen_config.sh b/test/end-to-end/built-in-rules/filegen_config.sh new file mode 100755 index 00000000..c0fb72c7 --- /dev/null +++ b/test/end-to-end/built-in-rules/filegen_config.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# 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 + +touch ROOT + +cat <<'EOF' > TARGETS +{ "": + { "type": "file_gen" + , "name": "read-runfiles" + , "data": + { "type": "join" + , "separator": ";" + , "$1": {"type": "runfiles", "dep": "uses config"} + } + , "deps": ["uses config"] + } +, "uses config": + { "type": "file_gen" + , "arguments_config": ["NAME"] + , "name": {"type": "var", "name": "NAME", "default": "null"} + , "data": "irrelevant" + } +} +EOF + +bin/tool-under-test analyse -D '{"NAME": "here-be-dragons"}' \ + --dump-targets targets.json --dump-blobs blobs.json 2>&1 +echo +echo "Blobs" +cat blobs.json +[ $(jq '. == ["here-be-dragons"]' blobs.json) = "true" ] +echo + +echo "Targets" +cat targets.json +[ $(jq '."@"."".""."" == [{"NAME": "here-be-dragons"}]' targets.json) = "true" ] + +echo OK |