-
Notifications
You must be signed in to change notification settings - Fork 237
/
Copy pathgenrule_common.bzl
207 lines (144 loc) · 5.76 KB
/
genrule_common.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# 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.
# TODO(cjhopman): This was generated by scripts/hacks/rules_shim_with_docs.py,
# but should be manually edited going forward. There may be some errors in
# the generated docs, and so those should be verified to be accurate and
# well-formatted (and then delete this TODO)
def _srcs_arg():
return {
"srcs": attrs.named_set(attrs.source(allow_directory = True), sorted = False, default = [], doc = """
Either a list or a map of the source files which Buck makes available to the shell
command at the path in the `SRCDIR` environment variable.
If you specify a list, the source files are the names in the list.
If you specify a map, the source files are made available as the names in
the keys of the map, where the values of the map are the original source
file names.
"""),
}
def _cmd_arg():
return {
"cmd": attrs.option(attrs.arg(), default = None, doc = """
The shell command to run to generate the output file. It is the
fallback for `bash` and `cmd_exe` arguments. The following environment variables are populated by
Buck and available to the shell command. They are accessed using
the syntax:
```
${<variable>}
```
Example:
```
${SRCS}
```
`${SRCS}`
A string expansion of the `srcs` argument delimited
by the `environment_expansion_separator` argument
where each element of `srcs` will be translated
into a relative path.
`${SRCDIR}`
The relative path to a directory to which sources are copied
prior to running the command.
`${OUT}`
The output file or directory for the `genrule()`.
This variable will have whatever value is specified by
the `out` argument if not using named outputs. If
using named outputs, this variable will be the output directory.
The value should be a valid filepath. The semantics of the shell
command determine whether this filepath is treated as a file or a
directory. If the filepath is a directory, then the shell command
needs to create it if not using named outputs. Otherwise, it will
be automatically created. All outputs (directories and files) must
be readable, writable, and (in the case of directories) executable
by the current user.
The file or directory specified by this variable must always
be written by this command. If not, the execution of this
rule will be considered a failure, halting the build process.
`${TMP}`
A temporary directory which can be used for intermediate
results and will not be bundled into the output.
"""),
}
def _bash_arg():
return {
"bash": attrs.option(attrs.arg(), default = None, doc = """
A platform-specific version of the shell command parameter `cmd`.
It runs on Linux and UNIX systems—including OSX—on which `bash` is installed.
It has a higher priority than `cmd`. The `bash` argument is run with `/usr/bin/env bash -c`.
It has access to the same set of macros and variables as the `cmd` argument.
"""),
}
def _cmd_exe_arg():
return {
"cmd_exe": attrs.option(attrs.arg(), default = None, doc = """
A platform-specific version of the shell command parameter `cmd`. It runs on Windows and has a higher
priority than `cmd`. The `cmd_exe` argument is run with `cmd.exe /v:off /c`.
It has access to the same set of macros and variables as the `cmd` argument.
"""),
}
def _weight_arg():
return {
"weight": attrs.option(attrs.int(), default = None, doc = """
How many local slots these genrule should take when executing locally.
"""),
}
def _out_arg():
return {
"out": attrs.option(attrs.string(), default = None, doc = """
The name of the output file or directory. The complete path to this
argument is provided to the shell command through
the `OUT` environment variable.
"""),
}
def _type_arg():
return {
"type": attrs.option(attrs.string(), default = None, doc = """
Specifies the *type* of this genrule. This is used for logging
and is particularly useful for grouping genrules that share an
underlying logical "type".
For example, if you have the following `cxx_genrule` defined
in the root directory of your Buck project
```
cxx_genrule(
name = 'cxx_gen',
type = 'epilog',
cmd = 'touch finish.txt; cp finish.txt $OUT',
out = 'finish.txt'
)
```
then the following `buck query` command
```
buck query "attrfilter( type, 'epilog', '//...' )"
```
returns
```
//:cxx_gen
```
"""),
}
def _environment_expansion_separator():
return {
"environment_expansion_separator": attrs.option(attrs.string(), default = None, doc = """
The delimiter between paths in environment variables, such as SRCS, that can contain multiple paths.
It can be useful to specify this parameter if the paths could contain spaces.
"""),
}
def _env_arg():
return {
"env": attrs.dict(key = attrs.string(), value = attrs.arg(), sorted = False, default = {}, doc = """
A map of variables to be set in the environment where the shell command is run.
"""),
}
genrule_common = struct(
srcs_arg = _srcs_arg,
cmd_arg = _cmd_arg,
bash_arg = _bash_arg,
cmd_exe_arg = _cmd_exe_arg,
out_arg = _out_arg,
type_arg = _type_arg,
weight_arg = _weight_arg,
environment_expansion_separator = _environment_expansion_separator,
env_arg = _env_arg,
)