# 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 product configuration and verify its result.
# The main configuration file is product.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(":input_variables.rbc", input_variables_init = "init")
load(":product.rbc", "init")
load(":board.rbc", board_init = "init")
load(":board_input_vars.rbc", board_input_vars_init = "init")
load("//build/make/tests/single_value_inheritance:test.rbc", test_single_value_inheritance = "test")
load("//build/make/tests/artifact_path_requirements:test.rbc", test_artifact_path_requirements = "test")
load("//build/make/tests/prefixed_sort_order:test.rbc", test_prefixed_sort_order = "test")
load("//build/make/tests/inherits_in_regular_variables:test.rbc", test_inherits_in_regular_variables = "test")

def assert_eq(expected, actual):
    if expected != actual:
        fail("Expected '%s', got '%s'" % (expected, actual))

def assert_dict_subset(expected, actual):
    for key, val in expected.items():
        assert_eq(val, actual[key])

# Unit tests for non-trivial runtime functions
assert_eq(["a", "b", "c"], rblf.mksort("b a    c c"))
assert_eq(["a", "b", "c"], rblf.mksort(["b", "a", "c", "c"]))

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"]))

assert_eq("ABcdYZ", rblf.mkpatsubst("ab%yz", "AB%YZ", "abcdyz"))
assert_eq("bcz", rblf.mkpatsubst("a%z", "A%Z", "bcz"))
assert_eq(["Ay", "Az"], rblf.mkpatsubst("a%", "A%", ["ay", "az"]))
assert_eq("AcZ bcz", rblf.mkpatsubst("a%z", "A%Z", "acz  bcz"))
assert_eq("Abcd", rblf.mkpatsubst("a%", "A%", "abcd"))
assert_eq("abcZ", rblf.mkpatsubst("%z", "%Z", "abcz"))
assert_eq("azx b", rblf.mkpatsubst("az", "AZ", "azx  b"))
assert_eq(["azx", "b"], rblf.mkpatsubst("az", "AZ", ["azx", "b"]))
assert_eq("ABC", rblf.mkpatsubst("abc", "ABC", "abc"))
assert_eq(["%/foo"], rblf.mkpatsubst("%", "\\%/%", ["foo"]))
assert_eq(["foo/%"], rblf.mkpatsubst("%", "%/%", ["foo"]))
assert_eq(["from/a:to/a", "from/b:to/b"], rblf.product_copy_files_by_pattern("from/%", "to/%", "a b"))

assert_eq([], rblf.filter(["a", "", "b"], "f"))
assert_eq(["ab%c", "axyzb%c"], rblf.filter(["a%b%c"], ["ab%c", "axyzb%c", "axyzb%cd", "axyzbwc"]))
assert_eq(["abc", "bcd"], rblf.filter(["a%", "b%"], ["abc", "def", "bcd", "xabc"]))
assert_eq(["b", "ab"], rblf.filter_out(["a", "" ], ["a", "", "b", "ab"]))
assert_eq(["c"], rblf.filter_out(["a", "b" ], ["a", "b", "c"]))
assert_eq(["c"], rblf.filter_out(["a%", "b" ], ["abc", "b", "c"]))

assert_eq("foo.c no_folder", rblf.notdir(["src/foo.c", "no_folder"]))
assert_eq("foo.c no_folder", rblf.notdir("src/foo.c no_folder"))
assert_eq("", rblf.notdir("/"))
assert_eq("", rblf.notdir(""))

cwd = rblf_shell('pwd')
assert_eq(cwd+"/foo/bar", rblf.abspath("foo/bar"))
assert_eq(cwd+"/bar", rblf.abspath("foo/.././bar"))
assert_eq(cwd+"/bar", rblf.abspath("foo/..////bar//"))
assert_eq("/foo/baz", rblf.abspath("/foo/bar/../baz"))
assert_eq(cwd+"/foo/bar "+cwd+"/foo/baz", rblf.abspath("foo/bar foo/baz"))
assert_eq("/baz", rblf.abspath("/../../../../../../../../../../../../../../../../baz"))

assert_eq("foo", rblf.first_word("foo bar"))
assert_eq("foo", rblf.first_word(["foo", "bar"]))
assert_eq("", rblf.first_word(""))
assert_eq("", rblf.first_word([]))
assert_eq("bar", rblf.last_word("foo bar"))
assert_eq("bar", rblf.last_word(["foo", "bar"]))
assert_eq("", rblf.last_word(""))
assert_eq("", rblf.last_word([]))

assert_eq(["foo", "bar"], rblf.flatten_2d_list([["foo", "bar"]]))
assert_eq(["foo", "bar"], rblf.flatten_2d_list([["foo"], ["bar"]]))
assert_eq([], rblf.flatten_2d_list([]))

assert_eq(
    ["build/make/tests/board.rbc", "build/make/tests/board_input_vars.rbc"],
    rblf.expand_wildcard("build/make/tests/board*.rbc")
)
assert_eq(
    ["build/make/tests/run.rbc", "build/make/tests/product.rbc"],
    rblf.expand_wildcard("build/make/tests/run.rbc build/make/tests/product.rbc")
)
assert_eq(
    ["build/make/tests/run.rbc"],
    rblf.expand_wildcard("build/make/tests/run.rbc build/make/tests/nonexistent.rbc")
)

(globals, globals_base) = rblf.product_configuration("test/device", init, input_variables_init)
assert_dict_subset({
    "PRODUCTS.test/device.mk.PRODUCT_COPY_FILES": [
        "part_from:part_to",
        "device_from:device_to",
        "device/google/redfin/audio/audio_platform_info_noextcodec_snd.xml:||VENDOR-PATH-PH||/etc/audio/audio_platform_info_noextcodec_snd.xml",
        "xyz:/etc/xyz",
        "x.xml:/etc/x.xml",
        "y.xml:/etc/y.xml",
        "from/sub/x:to/x",
        "from/sub/y:to/y",
    ],
    "PRODUCTS.test/device.mk.PRODUCT_HOST_PACKAGES": ["host"],
    "PRODUCTS.test/device.mk.PRODUCT_PACKAGES": [
        "dev",
        "inc",
        "dev_after",
        "board1_in",
        "board1_is",
    ],
    "PRODUCTS.test/device.mk.PRODUCT_PRODUCT_PROPERTIES": ["part_properties"]
}, globals)

ns = globals["$SOONG_CONFIG_NAMESPACES"]
assert_eq(
    {
        "NS1": {
            "v1": "abc abc_part1",
            "v2": "def"
        },
        "NS2": {
            "v3": "xyz"
        }
    },
    {k:v for k, v in sorted(ns.items()) }
)

assert_eq("Tiramisu", globals["PLATFORM_VERSION"])
assert_eq("31", 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()) }
)

(board_globals, board_globals_base) = rblf.board_configuration(board_init, board_input_vars_init)
assert_eq({"A_LIST_VARIABLE": ["foo", "bar"]}, board_globals)
assert_eq({"A_LIST_VARIABLE": ["foo"]}, board_globals_base)

g = {"FOO": "a", "BAR": "c", "BAZ": "e"}
cfg = {"FOO": "b", "BAR": "d", "BAZ": "f"}
rblf.clear_var_list(g, struct(cfg=cfg), "FOO BAR NEWVAR")
assert_eq("", g["FOO"])
assert_eq("", cfg["FOO"])
assert_eq("", g["BAR"])
assert_eq("", cfg["BAR"])
assert_eq("e", g["BAZ"])
assert_eq("f", cfg["BAZ"])
assert_eq("", g.get("NEWVAR"))

test_single_value_inheritance()
test_artifact_path_requirements()
test_prefixed_sort_order()
test_inherits_in_regular_variables()
