From 2b5b3f3be8e39f1a79468f730641b6d6ec20c153 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Tue, 7 Feb 2023 12:28:47 -0800 Subject: [PATCH] Make words() work on a list of non-strings words() attempts to join all the elements of a list and then resplit them to more closely match make. But sometimes, like when calling words() on a product variable, not all of the elements are strings. In that case, just return the list unchanged. Bug: 267407943 Test: ./out/rbcrun ./build/make/tests/run.rbc Change-Id: I738d0c86c8935f446807cc79623f796e8cae3c01 --- core/product_config.rbc | 3 +++ tests/run.rbc | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/core/product_config.rbc b/core/product_config.rbc index da8209b0fc..97c1d00471 100644 --- a/core/product_config.rbc +++ b/core/product_config.rbc @@ -462,6 +462,9 @@ def _addsuffix(suffix, string_or_list): def __words(string_or_list): if type(string_or_list) == "list": + for x in string_or_list: + if type(x) != "string": + return string_or_list string_or_list = " ".join(string_or_list) return _mkstrip(string_or_list).split() diff --git a/tests/run.rbc b/tests/run.rbc index 1b51719e6f..33583eb3cd 100644 --- a/tests/run.rbc +++ b/tests/run.rbc @@ -46,6 +46,11 @@ assert_eq("", rblf.mkstrip(" \n \t ")) assert_eq("a b c", rblf.mkstrip(" a b \n c \t")) assert_eq("1", rblf.mkstrip("1 ")) +assert_eq(["a", "b"], rblf.words("a b")) +assert_eq(["a", "b", "c"], rblf.words(["a b", "c"])) +# 1-tuple like we use in product variables +assert_eq(["a b", ("c",)], rblf.words(["a b", ("c",)])) + assert_eq("b1 b2", rblf.mksubst("a", "b", "a1 a2")) assert_eq(["b1", "x2"], rblf.mksubst("a", "b", ["a1", "x2"]))