forked from facebook/buck2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker_tool.bzl
70 lines (58 loc) · 1.99 KB
/
worker_tool.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
load("@prelude//utils:expect.bzl", "expect")
WorkerToolInfo = provider(
fields = {
"command": provider_field(typing.Any, default = None), # cmd_args
},
)
def worker_tool(ctx: AnalysisContext) -> list[Provider]:
"""
worker_tool() rule implementation
Args:
ctx: rule analysis context
Returns:
list of created providers (DefaultInfo with an empty output and TemplatePlaceholderInfo with $(worker) macro key)
"""
executable = ctx.attrs.exe
worker_tool_run_info = executable[RunInfo]
expect(worker_tool_run_info != None, "Worker tool executable must have a RunInfo!")
worker_tool_runner = ctx.attrs._worker_tool_runner[RunInfo]
worker_tool_cmd = cmd_args(worker_tool_runner)
worker_tool_cmd.add("--worker-tool")
worker_tool_cmd.add(worker_tool_run_info)
worker_args = ctx.attrs.args
if worker_args:
worker_args_file, _ = ctx.actions.write(
"worker_tool_args",
worker_args,
allow_args = True,
)
worker_tool_cmd.add("--worker-args-file")
worker_tool_cmd.add(worker_args_file)
worker_env = ctx.attrs.env
if worker_env:
env_args = []
for key, value in worker_env.items():
env_args.append(key)
env_args.append(value)
env_args_file, _ = ctx.actions.write(
"worker_tool_envs",
env_args,
allow_args = True,
)
worker_tool_cmd.add("--worker-env-file")
worker_tool_cmd.add(env_args_file)
return [
DefaultInfo(),
RunInfo(
args = worker_tool_cmd,
),
WorkerToolInfo(
command = worker_tool_cmd,
),
]