From 91fc73410075ffa56768f417a96466041b7bb0f8 Mon Sep 17 00:00:00 2001 From: Sasha Smundak Date: Thu, 18 Nov 2021 11:20:34 -0800 Subject: [PATCH 1/2] Runtime support for dist-for-goals. Convert dist-for-goals. Bug: 198496782 Test: rbcrun build/make/tests/run.rbc Change-Id: I46ef9e897143aecf8bd28ad8569d48e74530b0e5 --- core/product_config.rbc | 29 +++++++++++++++++++++++++++++ tests/device.rbc | 3 +++ tests/run.rbc | 8 ++++++++ 3 files changed, 40 insertions(+) diff --git a/core/product_config.rbc b/core/product_config.rbc index c32db7644a..279c89eed4 100644 --- a/core/product_config.rbc +++ b/core/product_config.rbc @@ -17,6 +17,7 @@ load("//build/make/core:envsetup.rbc", _envsetup_init = "init") """Runtime functions.""" _soong_config_namespaces_key = "$SOONG_CONFIG_NAMESPACES" +_dist_for_goals_key = "$dist_for_goals" def _init_globals(version_info): """Returns dict created from the runtime environment.""" globals = dict() @@ -90,6 +91,18 @@ def _printglobals(globals, globals_base): __print_attr("SOONG_CONFIG_%s_%s" % (nsname, var), val) else: print("SOONG_CONFIG_%s_%s :=" % (nsname, var)) + elif attr == _dist_for_goals_key: + goals = [] + src_dst_list = [] + goal_dst_list = [] + for goal_name, goal_src_dst_list in sorted(val.items()): + goals.append(goal_name) + for sd in sorted(goal_src_dst_list): + src_dst_list.append(":".join(sd)) + goal_dst_list.append(":".join((goal_name, sd[1]))) + print("_all_dist_goal_output_pairs:=", " ".join(goal_dst_list)) + print("_all_dist_goals:=", " ".join(goals)) + print("_all_dist_src_dst_pairs:=", " ".join(src_dst_list)) elif attr not in globals_base or globals_base[attr] != val: __print_attr(attr, val) @@ -513,6 +526,21 @@ def _expand_wildcard(pattern): """Expands shell wildcard pattern.""" return rblf_wildcard(pattern) +def _mkdist_for_goals(g, goal, src_dst_list): + """Implements dist-for-goals macro.""" + goals_map = g.get(_dist_for_goals_key, {}) + pairs = goals_map.get(goal) + if pairs == None: + pairs = [] + g[_dist_for_goals_key] = dict([(k,v) for k,v in goals_map.items()] + [(goal, pairs)]) + for src_dst in __words(src_dst_list): + pair=src_dst.split(":") + if len(pair) > 2: + fail(src_dst + " should be a :-separated pair") + pairs.append((pair[0],pair[1] if len(pair) == 2 and pair[1] else __base(pair[0]))) + g[_dist_for_goals_key][goal] = pairs + + def _mkerror(file, message = ""): """Prints error and stops.""" fail("%s: %s. Stop" % (file, message)) @@ -675,6 +703,7 @@ rblf = struct( init_globals = _init_globals, inherit = _inherit, indirect = _indirect, + mkdist_for_goals = _mkdist_for_goals, mkinfo = _mkinfo, mkerror = _mkerror, mkpatsubst = _mkpatsubst, diff --git a/tests/device.rbc b/tests/device.rbc index 37c5d0cecb..9ae6393e8e 100644 --- a/tests/device.rbc +++ b/tests/device.rbc @@ -55,6 +55,9 @@ def init(g, handle): rblf.soong_config_set(g, "NS2", "v3", "abc") rblf.soong_config_set(g, "NS2", "v3", "xyz") + rblf.mkdist_for_goals(g, "goal", "dir1/file1:out1 dir1/file2:out2") + rblf.mkdist_for_goals(g, "goal", "dir2/file2:") + if rblf.board_platform_in(g, "board1 board2"): cfg["PRODUCT_PACKAGES"] += ["bad_package"] g["TARGET_BOARD_PLATFORM"] = "board1" diff --git a/tests/run.rbc b/tests/run.rbc index d2223419fa..31436c57d8 100644 --- a/tests/run.rbc +++ b/tests/run.rbc @@ -102,3 +102,11 @@ assert_eq(30, globals["PLATFORM_SDK_VERSION"]) assert_eq("xyz", rblf.soong_config_get(globals, "NS2", "v3")) assert_eq(None, rblf.soong_config_get(globals, "NS2", "nonexistant_var")) + +goals = globals["$dist_for_goals"] +assert_eq( + { + "goal": [("dir1/file1", "out1"), ("dir1/file2", "out2"), ("dir2/file2", "file2")] + }, + { k:v for k,v in sorted(goals.items()) } +) From c20dd972a94670e17b65387c881ff7a69e390249 Mon Sep 17 00:00:00 2001 From: Sasha Smundak Date: Fri, 12 Nov 2021 09:18:45 -0800 Subject: [PATCH 2/2] Runtime reporting of the conversion errors. Bug: 204062171 Test: rbcrun build/make/tests/conversion_error.rbc (displays a message, stops) rbcrun RBC_MK2RBC_CONTINUE=t build/make/tests/conversion_error.rbc (displays a message and continues) Change-Id: Idf0fe6bbb08b1eca1f392d81950eed4a214f3289 --- core/product_config.rbc | 16 ++++++++++++++++ tests/conversion_error.rbc | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/conversion_error.rbc diff --git a/core/product_config.rbc b/core/product_config.rbc index 279c89eed4..9a6b1c0f87 100644 --- a/core/product_config.rbc +++ b/core/product_config.rbc @@ -549,6 +549,18 @@ def _mkwarning(file, message = ""): """Prints warning.""" rblf_log(file, "warning", message, sep = ':') +def _mk2rbc_error(loc, message): + """Prints a message about conversion error and stops. + + If RBC_MK2RBC_CONTINUE environment variable is set, + the execution will continue after the message is printed. + """ + if _options.mk2rbc_continue: + rblf_log(loc, message, sep = ':') + else: + _mkerror(loc, message) + + def _mkinfo(file, message = ""): """Prints info.""" rblf_log(message) @@ -659,6 +671,7 @@ def __get_options(): rearrange = "", trace_modules = False, trace_variables = [], + mk2rbc_continue = False, ) for x in getattr(rblf_cli, "RBC_OUT", "").split(","): if x == "sort" or x == "unique": @@ -676,6 +689,8 @@ def __get_options(): settings["trace_modules"] = True elif x != "": settings["trace_variables"].append(x) + if getattr(rblf_cli, "RBC_MK2RBC_CONTINUE", ""): + settings["mk2rbc_continue"] = True return struct(**settings) # Settings used during debugging. @@ -703,6 +718,7 @@ rblf = struct( init_globals = _init_globals, inherit = _inherit, indirect = _indirect, + mk2rbc_error = _mk2rbc_error, mkdist_for_goals = _mkdist_for_goals, mkinfo = _mkinfo, mkerror = _mkerror, diff --git a/tests/conversion_error.rbc b/tests/conversion_error.rbc new file mode 100644 index 0000000000..5212378d28 --- /dev/null +++ b/tests/conversion_error.rbc @@ -0,0 +1,27 @@ +# Copyright 2021 Google LLC +# +# 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 +# +# https://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. + + +# Run test configuration and verify its result. +# The main configuration file is device.rbc. +# It inherits part1.rbc and also includes include1.rbc +# TODO(asmundak): more tests are needed to verify that: +# * multi-level inheritance works as expected +# * all runtime functions (wildcard, regex, etc.) work + +load("//build/make/core:product_config.rbc", "rblf") +load(":version_defaults.rbc", "version_defaults") +load(":device.rbc", "init") + +rblf.mk2rbc_error("file.mk:123", "cannot convert")