Skip to content

Commit bda5c63

Browse files
authored
feat: replace default_info_files with output_files which adds output_group attribute (#50)
1 parent 3b93ee0 commit bda5c63

16 files changed

+244
-185
lines changed

docs/BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ stardoc_with_diff_test(
4949
)
5050

5151
stardoc_with_diff_test(
52-
name = "default_info_files",
53-
bzl_library_target = "//lib:default_info_files",
52+
name = "output_files",
53+
bzl_library_target = "//lib:output_files",
5454
)
5555

5656
update_docs()

docs/default_info_files.md

-49
This file was deleted.

docs/directory_path.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Joins a label pointing to a TreeArtifact with a path nested within that director
5050
## make_directory_path
5151

5252
<pre>
53-
make_directory_path(<a href="#make_directory_path-name">name</a>, <a href="#make_directory_path-directory">directory</a>, <a href="#make_directory_path-path">path</a>)
53+
make_directory_path(<a href="#make_directory_path-name">name</a>, <a href="#make_directory_path-directory">directory</a>, <a href="#make_directory_path-path">path</a>, <a href="#make_directory_path-kwargs">kwargs</a>)
5454
</pre>
5555

5656
Helper function to generate a directory_path target and return its label.
@@ -60,9 +60,10 @@ Helper function to generate a directory_path target and return its label.
6060

6161
| Name | Description | Default Value |
6262
| :------------- | :------------- | :------------- |
63-
| <a id="make_directory_path-name"></a>name | Unique name for the generated <code>directory_path</code> target. | none |
64-
| <a id="make_directory_path-directory"></a>directory | a TreeArtifact (ctx.actions.declare_directory) | none |
65-
| <a id="make_directory_path-path"></a>path | path relative to the directory | none |
63+
| <a id="make_directory_path-name"></a>name | unique name for the generated <code>directory_path</code> target | none |
64+
| <a id="make_directory_path-directory"></a>directory | <code>directory</code> attribute passed to generated <code>directory_path</code> target | none |
65+
| <a id="make_directory_path-path"></a>path | <code>path</code> attribute passed to generated <code>directory_path</code> target | none |
66+
| <a id="make_directory_path-kwargs"></a>kwargs | parameters to pass to generated <code>output_files</code> target | none |
6667

6768
**RETURNS**
6869

@@ -74,7 +75,7 @@ The label `name`
7475
## make_directory_paths
7576

7677
<pre>
77-
make_directory_paths(<a href="#make_directory_paths-name">name</a>, <a href="#make_directory_paths-dict">dict</a>)
78+
make_directory_paths(<a href="#make_directory_paths-name">name</a>, <a href="#make_directory_paths-dict">dict</a>, <a href="#make_directory_paths-kwargs">kwargs</a>)
7879
</pre>
7980

8081
Helper function to convert a dict of directory to path mappings to directory_path targets and labels.
@@ -128,6 +129,7 @@ and the list of targets is returned,
128129
| :------------- | :------------- | :------------- |
129130
| <a id="make_directory_paths-name"></a>name | The target name to use for the generated targets & labels.<br><br>The names are generated as zero-indexed <code>name + "_" + i</code> | none |
130131
| <a id="make_directory_paths-dict"></a>dict | The dictionary of directory keys to path or path list values. | none |
132+
| <a id="make_directory_paths-kwargs"></a>kwargs | additional parameters to pass to each generated target | none |
131133

132134
**RETURNS**
133135

docs/output_files.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!-- Generated with Stardoc: http://skydoc.bazel.build -->
2+
3+
A rule that provides file(s) specific via DefaultInfo from a given target's DefaultInfo or OutputGroupInfo
4+
5+
6+
<a id="#output_files"></a>
7+
8+
## output_files
9+
10+
<pre>
11+
output_files(<a href="#output_files-name">name</a>, <a href="#output_files-output_group">output_group</a>, <a href="#output_files-paths">paths</a>, <a href="#output_files-target">target</a>)
12+
</pre>
13+
14+
A rule that provides file(s) specific via DefaultInfo from a given target's DefaultInfo or OutputGroupInfo
15+
16+
**ATTRIBUTES**
17+
18+
19+
| Name | Description | Type | Mandatory | Default |
20+
| :------------- | :------------- | :------------- | :------------- | :------------- |
21+
| <a id="output_files-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
22+
| <a id="output_files-output_group"></a>output_group | if set, we look in the specified output group for paths instead of DefaultInfo | String | optional | "" |
23+
| <a id="output_files-paths"></a>paths | the paths of the file(s), relative to their roots, to provide via DefaultInfo from the given target's DefaultInfo or OutputGroupInfo | List of strings | required | |
24+
| <a id="output_files-target"></a>target | the target to look in for requested paths in its' DefaultInfo or OutputGroupInfo | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
25+
26+
27+
<a id="#make_output_files"></a>
28+
29+
## make_output_files
30+
31+
<pre>
32+
make_output_files(<a href="#make_output_files-name">name</a>, <a href="#make_output_files-target">target</a>, <a href="#make_output_files-paths">paths</a>, <a href="#make_output_files-kwargs">kwargs</a>)
33+
</pre>
34+
35+
Helper function to generate a output_files target and return its label.
36+
37+
**PARAMETERS**
38+
39+
40+
| Name | Description | Default Value |
41+
| :------------- | :------------- | :------------- |
42+
| <a id="make_output_files-name"></a>name | unique name for the generated <code>output_files</code> target | none |
43+
| <a id="make_output_files-target"></a>target | <code>target</code> attribute passed to generated <code>output_files</code> target | none |
44+
| <a id="make_output_files-paths"></a>paths | <code>paths</code> attribute passed to generated <code>output_files</code> target | none |
45+
| <a id="make_output_files-kwargs"></a>kwargs | parameters to pass to generated <code>output_files</code> target | none |
46+
47+
**RETURNS**
48+
49+
The label `name`
50+
51+

lib/BUILD.bazel

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ bzl_library(
6464
)
6565

6666
bzl_library(
67-
name = "default_info_files",
68-
srcs = ["default_info_files.bzl"],
67+
name = "output_files",
68+
srcs = ["output_files.bzl"],
6969
visibility = ["//visibility:public"],
70-
deps = ["//lib/private:default_info_files"],
70+
deps = ["//lib/private:output_files"],
7171
)
7272

7373
bzl_library(

lib/default_info_files.bzl

-11
This file was deleted.

lib/output_files.bzl

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""A rule that provides file(s) specific via DefaultInfo from a given target's DefaultInfo or OutputGroupInfo
2+
"""
3+
4+
load(
5+
"//lib/private:output_files.bzl",
6+
_make_output_files = "make_output_files",
7+
_output_files = "output_files",
8+
)
9+
10+
output_files = _output_files
11+
make_output_files = _make_output_files

lib/private/BUILD.bazel

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ bzl_library(
1010
srcs = ["copy_to_directory.bzl"],
1111
visibility = ["//lib:__subpackages__"],
1212
deps = [
13-
":default_info_files",
1413
":directory_path",
14+
":output_files",
1515
":paths",
1616
"@bazel_skylib//lib:paths",
1717
],
@@ -66,8 +66,8 @@ bzl_library(
6666
srcs = ["write_source_file.bzl"],
6767
visibility = ["//lib:__subpackages__"],
6868
deps = [
69-
":default_info_files",
7069
":directory_path",
70+
":output_files",
7171
"//lib:utils",
7272
],
7373
)
@@ -86,8 +86,8 @@ bzl_library(
8686
)
8787

8888
bzl_library(
89-
name = "default_info_files",
90-
srcs = ["default_info_files.bzl"],
89+
name = "output_files",
90+
srcs = ["output_files.bzl"],
9191
visibility = ["//lib:__subpackages__"],
9292
deps = ["//lib:utils"],
9393
)

lib/private/default_info_files.bzl

-70
This file was deleted.

lib/private/directory_path.bzl

+9-5
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ Otherwise there is no way to give a Bazel label for it.""",
3636
provides = [DirectoryPathInfo],
3737
)
3838

39-
def make_directory_path(name, directory, path):
39+
def make_directory_path(name, directory, path, **kwargs):
4040
"""Helper function to generate a directory_path target and return its label.
4141
4242
Args:
43-
name: Unique name for the generated `directory_path` target.
44-
directory: a TreeArtifact (ctx.actions.declare_directory)
45-
path: path relative to the directory
43+
name: unique name for the generated `directory_path` target
44+
directory: `directory` attribute passed to generated `directory_path` target
45+
path: `path` attribute passed to generated `directory_path` target
46+
**kwargs: parameters to pass to generated `output_files` target
4647
4748
Returns:
4849
The label `name`
@@ -51,10 +52,11 @@ def make_directory_path(name, directory, path):
5152
name = name,
5253
directory = directory,
5354
path = path,
55+
**kwargs
5456
)
5557
return _to_label(name)
5658

57-
def make_directory_paths(name, dict):
59+
def make_directory_paths(name, dict, **kwargs):
5860
"""Helper function to convert a dict of directory to path mappings to directory_path targets and labels.
5961
6062
For example,
@@ -104,6 +106,7 @@ def make_directory_paths(name, dict):
104106
The names are generated as zero-indexed `name + "_" + i`
105107
106108
dict: The dictionary of directory keys to path or path list values.
109+
**kwargs: additional parameters to pass to each generated target
107110
108111
Returns:
109112
The label of the generated `directory_path` targets named `name + "_" + i`
@@ -124,5 +127,6 @@ def make_directory_paths(name, dict):
124127
"%s_%d" % (name, i),
125128
directory,
126129
path,
130+
**kwargs
127131
))
128132
return labels

0 commit comments

Comments
 (0)