1# Copyright (C) 2022 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#       http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# BUILD
16load("//build/bazel_common_rules/exec/impl:embedded_exec.bzl", "embedded_exec")
17load("//build/bazel_common_rules/exec/impl:exec.bzl", "exec")
18
19exec(
20    name = "script_a",
21    args = [
22        "--argsA=valueA",
23        "--args_expanded=$(rootpath data.txt)",
24    ],
25    data = [":data.txt"],
26    script = "echo script_a $@",
27)
28
29sh_binary(
30    name = "script_b",
31    srcs = ["script_b.sh"],
32    args = [
33        "--script_b_arg=value",
34        "--args_expanded=$(rootpath data.txt)",
35    ],
36    data = [":data.txt"],
37    env = {
38        "SCRIPT_B_ENV": "env_value",
39        "SCRIPT_B_ENV_EXPANDED": "$(rootpath data.txt)",
40    },
41)
42
43exec(
44    name = "cat_data",
45    data = [":data.txt"],
46    script = "cat $(rootpath :data.txt)",
47)
48
49embedded_exec(
50    name = "script_a_embedded",
51    actual = "script_a",
52)
53
54embedded_exec(
55    name = "script_b_embedded",
56    actual = "script_b",
57)
58
59exec(
60    name = "combined",
61    args = ["--script_a_path=$(rootpath :script_a_embedded)"],
62    data = [
63        ":cat_data",
64        ":script_a_embedded",
65        ":script_b_embedded",
66    ],
67    script = """
68        echo combined_args=$@
69        $(rootpath :script_a_embedded)
70        $(rootpath :script_b_embedded)
71        $(rootpath :cat_data)
72    """,
73)
74
75py_test(
76    name = "exec_test",
77    srcs = ["exec_test.py"],
78    args = ["$(location :combined)"],
79    data = [":combined"],
80    deps = [
81        "@io_abseil_py//absl/testing:absltest",
82    ],
83)
84
85test_suite(
86    name = "tests",
87    tests = [
88        ":exec_test",
89    ],
90)
91