11"""Miscellaneous rules that aren't language-specific."""
22
33
4- def genrule(name:str, cmd:str|list|dict, srcs:list|dict=None, out:str=None, outs:list|dict=None, deps:list=None,
5- exported_deps:list=None, runtime_deps:list=None, labels:list&features&tags=None, visibility:list=None,
6- building_description:str='Building...', data:list|dict=None, hashes:list=None, timeout:int=0, binary:bool=False,
7- sandbox:bool=None, needs_transitive_deps:bool=False, output_is_complete:bool=True,
8- test_only:bool&testonly=False, secrets:list|dict=None, requires:list=None, provides:dict=None,
9- pre_build:function=None, post_build:function=None, tools:str|list|dict=None, pass_env:list=None,
10- local:bool=False, output_dirs:list=[], exit_on_error:bool=CONFIG.EXIT_ON_ERROR, entry_points:dict={},
11- env:dict={}, optional_outs:list=[]):
4+ def genrule(
5+ name:str,
6+ cmd:str|list|dict,
7+ srcs:list|dict=None,
8+ out:str=None,
9+ outs:list|dict=None,
10+ deps:list=None,
11+ exported_deps:list=None,
12+ runtime_deps:list=None,
13+ runtime_deps_from_srcs:bool=False,
14+ runtime_deps_from_deps:bool=False,
15+ labels:list&features&tags=None,
16+ visibility:list=None,
17+ building_description:str="Building...",
18+ data:list|dict=None,
19+ hashes:list=None,
20+ timeout:int=0,
21+ binary:bool=False,
22+ sandbox:bool=None,
23+ needs_transitive_deps:bool=False,
24+ output_is_complete:bool=True,
25+ test_only:bool&testonly=False,
26+ secrets:list|dict=None,
27+ requires:list=None,
28+ provides:dict=None,
29+ pre_build:function=None,
30+ post_build:function=None,
31+ tools:str|list|dict=None,
32+ pass_env:list=None,
33+ local:bool=False,
34+ output_dirs:list=[],
35+ exit_on_error:bool=CONFIG.EXIT_ON_ERROR,
36+ entry_points:dict={},
37+ env:dict={},
38+ optional_outs:list=[],
39+ ):
1240 """A general build rule which allows the user to specify a command.
1341
1442 Args:
@@ -41,6 +69,14 @@ def genrule(name:str, cmd:str|list|dict, srcs:list|dict=None, out:str=None, outs
4169 the outputs of those rules' transitive run-time dependencies, will exist in
4270 the dependent rule's build environment. Requires the rule to produce a runnable
4371 output (i.e. binary = True).
72+ runtime_deps_from_srcs (bool): If true, additionally collect run-time dependencies from this target's
73+ sources. This is useful if the target's output simply collects its
74+ sources in some way without eliminating their own run-time dependencies.
75+ runtime_deps_from_deps (bool): If true, additionally collect run-time dependencies from this target's
76+ build-time dependencies (and those targets' exported dependencies).
77+ This is useful if the target's output includes its dependencies without
78+ eliminating their own run-time dependencies, e.g. for targets generated
79+ by the shell-rules plugin's sh_binary rule.
4480 tools (str | list | dict): Tools used to build this rule; similar to srcs but are not copied to the
4581 temporary build directory. Should be accessed via $(exe //path/to:tool)
4682 or similar.
@@ -127,6 +163,8 @@ def genrule(name:str, cmd:str|list|dict, srcs:list|dict=None, out:str=None, outs
127163 deps = deps,
128164 exported_deps = exported_deps,
129165 runtime_deps = runtime_deps,
166+ runtime_deps_from_srcs = runtime_deps_from_srcs,
167+ runtime_deps_from_deps = runtime_deps_from_deps,
130168 data = data,
131169 tools = tools,
132170 secrets = secrets,
@@ -154,13 +192,38 @@ def genrule(name:str, cmd:str|list|dict, srcs:list|dict=None, out:str=None, outs
154192 )
155193
156194
157- def gentest(name:str, test_cmd:str|list|dict, labels:list&features&tags=None, cmd:str|list|dict=None, srcs:list|dict=None,
158- outs:list=None, deps:list=None, exported_deps:list=None, runtime_deps:list=None, tools:str|list|dict=None,
159- test_tools:str|list|dict=None, data:list|dict=None, visibility:list=None, timeout:int=0,
160- needs_transitive_deps:bool=False, flaky:bool|int=0, secrets:list|dict=None, no_test_output:bool=False,
161- test_outputs:list=None, output_is_complete:bool=True, requires:list=None, sandbox:bool=None, size:str=None,
162- local:bool=False, pass_env:list=None, env:dict=None, exit_on_error:bool=CONFIG.EXIT_ON_ERROR,
163- no_test_coverage:bool=False):
195+ def gentest(
196+ name:str,
197+ test_cmd:str|list|dict,
198+ labels:list&features&tags=None,
199+ cmd:str|list|dict=None,
200+ srcs:list|dict=None,
201+ outs:list=None,
202+ deps:list=None,
203+ exported_deps:list=None,
204+ runtime_deps:list=None,
205+ runtime_deps_from_srcs:bool=False,
206+ runtime_deps_from_deps:bool=False,
207+ tools:str|list|dict=None,
208+ test_tools:str|list|dict=None,
209+ data:list|dict=None,
210+ visibility:list=None,
211+ timeout:int=0,
212+ needs_transitive_deps:bool=False,
213+ flaky:bool|int=0,
214+ secrets:list|dict=None,
215+ no_test_output:bool=False,
216+ test_outputs:list=None,
217+ output_is_complete:bool=True,
218+ requires:list=None,
219+ sandbox:bool=None,
220+ size:str=None,
221+ local:bool=False,
222+ pass_env:list=None,
223+ env:dict=None,
224+ exit_on_error:bool=CONFIG.EXIT_ON_ERROR,
225+ no_test_coverage:bool=False,
226+ ):
164227 """A rule which creates a test with an arbitrary command.
165228
166229 The command must return zero on success and nonzero on failure. Test results are written
@@ -185,6 +248,14 @@ def gentest(name:str, test_cmd:str|list|dict, labels:list&features&tags=None, cm
185248 list, as well as those rules' transitive run-time dependencies, will exist in
186249 the test environment. Requires the rule to produce a runnable output (i.e.
187250 binary = True).
251+ runtime_deps_from_srcs (bool): If true, additionally collect run-time dependencies from this target's
252+ sources. This is useful if the target's output simply collects its
253+ sources in some way without eliminating their own run-time dependencies.
254+ runtime_deps_from_deps (bool): If true, additionally collect run-time dependencies from this target's
255+ build-time dependencies (and those targets' exported dependencies).
256+ This is useful if the target's output includes its dependencies without
257+ eliminating their own run-time dependencies, e.g. for targets generated
258+ by the shell-rules plugin's sh_binary rule.
188259 tools (str | list | dict): Tools used to build this rule; similar to srcs but are not copied to the temporary
189260 build directory.
190261 test_tools (str | list | dict): Like tools but available to test_cmd instead.
@@ -224,6 +295,8 @@ def gentest(name:str, test_cmd:str|list|dict, labels:list&features&tags=None, cm
224295 deps = deps,
225296 exported_deps = exported_deps,
226297 runtime_deps = runtime_deps,
298+ runtime_deps_from_srcs = runtime_deps_from_srcs,
299+ runtime_deps_from_deps = runtime_deps_from_deps,
227300 data = data,
228301 tools = tools,
229302 test_tools = test_tools,
@@ -270,7 +343,7 @@ def export_file(name:str, src:str, visibility:list=None, binary:bool=False, test
270343 )
271344
272345
273- def filegroup(name:str, tag:str='', srcs:list=None, deps:list=None, exported_deps:list=None, runtime_deps:list=None,
346+ def filegroup(name:str, tag:str='', srcs:list=None, deps:list=None, exported_deps:list=None,
274347 visibility:list=None, labels:list&features&tags=None, binary:bool=False, output_is_complete:bool=True,
275348 requires:list=None, provides:dict=None, hashes:list=None, test_only:bool&testonly=False):
276349 """Defines a collection of files which other rules can depend on.
@@ -285,8 +358,6 @@ def filegroup(name:str, tag:str='', srcs:list=None, deps:list=None, exported_dep
285358 srcs (list): Source files for the rule.
286359 deps (list): Dependencies of the rule.
287360 exported_deps (list): Dependencies that will become visible to any rules that depend on this rule.
288- runtime_deps (list): Run-time dependencies of this rule. Requires the rule to produce a runnable
289- output (i.e. binary = True).
290361 visibility (list): Visibility declaration
291362 labels (list): Labels to apply to this rule
292363 binary (bool): True to mark the rule outputs as binary
@@ -305,7 +376,6 @@ def filegroup(name:str, tag:str='', srcs:list=None, deps:list=None, exported_dep
305376 srcs=srcs,
306377 deps=deps,
307378 exported_deps=exported_deps,
308- runtime_deps=runtime_deps,
309379 visibility=visibility,
310380 building_description='Copying...',
311381 output_is_complete=output_is_complete,
0 commit comments