fork/rules_rust

git clone https://git.julia.blue/fork/rules_rust

UebelAndreUpdated `attr.label` attribute defaults to use `Label` constructor (#1422)5a9d999d

0.9.0
3.3 KiB91 linesraw
1# Copyright 2020 The Bazel Authors. All rights reserved.
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"""Process wrapper test.
16
17This rule unit tests the different process_wrapper functionality.
18"""
19
20def _impl(ctx):
21    args = ctx.actions.args()
22    outputs = []
23    combined = ctx.attr.test_config == "combined"
24
25    if combined or ctx.attr.test_config == "stdout":
26        stdout_output = ctx.actions.declare_file(ctx.label.name + ".stdout")
27        outputs.append(stdout_output)
28        args.add("--stdout-file", stdout_output.path)
29
30    if combined or ctx.attr.test_config == "stderr":
31        stderr_output = ctx.actions.declare_file(ctx.label.name + ".stderr")
32        outputs.append(stderr_output)
33        args.add("--stderr-file", stderr_output.path)
34
35    if combined or (ctx.attr.test_config != "stdout" and ctx.attr.test_config != "stderr"):
36        touch_output = ctx.actions.declare_file(ctx.label.name + ".touch")
37        outputs.append(touch_output)
38        args.add("--touch-file", touch_output.path)
39        if ctx.attr.test_config == "copy-output":
40            copy_output = ctx.actions.declare_file(ctx.label.name + ".touch.copy")
41            outputs.append(copy_output)
42            args.add_all("--copy-output", [touch_output.path, copy_output.path])
43
44    if combined or ctx.attr.test_config == "env-files":
45        args.add_all(ctx.files.env_files, before_each = "--env-file")
46
47    if combined or ctx.attr.test_config == "arg-files":
48        args.add_all(ctx.files.arg_files, before_each = "--arg-file")
49
50    if combined or ctx.attr.test_config == "subst-pwd":
51        args.add("--subst", "pwd=${pwd}")
52        args.add("--subst", "key=value")
53
54    args.add("--")
55
56    args.add(ctx.executable._process_wrapper_tester.path)
57    args.add(ctx.attr.test_config)
58    args.add("--current-dir", "${pwd}")
59    args.add("--test-subst", "subst key to ${key}")
60    env = {"CURRENT_DIR": "${pwd}/test_path"}
61
62    ctx.actions.run(
63        executable = ctx.executable._process_wrapper,
64        inputs = ctx.files.env_files + ctx.files.arg_files,
65        outputs = outputs,
66        arguments = [args],
67        env = env,
68        tools = [ctx.executable._process_wrapper_tester],
69    )
70
71    return [DefaultInfo(files = depset(outputs))]
72
73process_wrapper_tester = rule(
74    implementation = _impl,
75    attrs = {
76        "arg_files": attr.label_list(),
77        "env_files": attr.label_list(),
78        "test_config": attr.string(mandatory = True),
79        "_process_wrapper": attr.label(
80            default = Label("//util/process_wrapper"),
81            executable = True,
82            allow_single_file = True,
83            cfg = "exec",
84        ),
85        "_process_wrapper_tester": attr.label(
86            default = Label("//test/process_wrapper:process_wrapper_tester"),
87            executable = True,
88            cfg = "exec",
89        ),
90    },
91)