• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15load("//build/bazel_common_rules/exec:embedded_exec.bzl", "embedded_exec")
16
17def test_mappings_dist(
18        name,
19        dist_dir = None,
20        **kwargs):
21    """Run this target to generate test mapping archive to the location given
22    by `--dist_dir` command-line argument. If `--dist_dir` command-line argument
23    is not specified, default to the `dist_dir` argument of this rule.
24
25    For example:
26
27    ```
28    test_mappings(
29        name = "my_test_mappings",
30        args = ["--dist_dir", "out/dist"],
31    )
32    ```
33
34    ```
35    # generate to <workspace_root>/out/dist
36    $ bazel run my_test_mappings
37
38    # generate to <workspace_root>/path
39    $ bazel run my_test_mappings -- --dist_dir=path
40
41    # generate to /tmp/path
42    $ bazel run my_test_mappings -- --dist_dir=/tmp/path
43    ```
44
45    Args:
46        name: name of this target.
47        kwargs: Additional arguments to the internal rule, e.g. `visibility`.
48    """
49
50    native.sh_binary(
51        name = name + "_internal",
52        srcs = ["//build/bazel_common_rules/test_mappings:test_mappings.sh"],
53        data = ["//prebuilts/build-tools:linux-x86"],
54        args = ["--dist_dir", dist_dir] if dist_dir else None,
55        **kwargs
56    )
57
58    embedded_exec(
59        name = name,
60        actual = name + "_internal",
61    )
62