Skip to content

Commit

Permalink
feat: replace default_info_files with output_files which adds output_…
Browse files Browse the repository at this point in the history
…group attribute (#50)
  • Loading branch information
gregmagolan authored Mar 16, 2022
1 parent 3b93ee0 commit bda5c63
Show file tree
Hide file tree
Showing 16 changed files with 244 additions and 185 deletions.
4 changes: 2 additions & 2 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ stardoc_with_diff_test(
)

stardoc_with_diff_test(
name = "default_info_files",
bzl_library_target = "//lib:default_info_files",
name = "output_files",
bzl_library_target = "//lib:output_files",
)

update_docs()
49 changes: 0 additions & 49 deletions docs/default_info_files.md

This file was deleted.

12 changes: 7 additions & 5 deletions docs/directory_path.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Joins a label pointing to a TreeArtifact with a path nested within that director
## make_directory_path

<pre>
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>)
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>)
</pre>

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

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

**RETURNS**

Expand All @@ -74,7 +75,7 @@ The label `name`
## make_directory_paths

<pre>
make_directory_paths(<a href="#make_directory_paths-name">name</a>, <a href="#make_directory_paths-dict">dict</a>)
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>)
</pre>

Helper function to convert a dict of directory to path mappings to directory_path targets and labels.
Expand Down Expand Up @@ -128,6 +129,7 @@ and the list of targets is returned,
| :------------- | :------------- | :------------- |
| <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 |
| <a id="make_directory_paths-dict"></a>dict | The dictionary of directory keys to path or path list values. | none |
| <a id="make_directory_paths-kwargs"></a>kwargs | additional parameters to pass to each generated target | none |

**RETURNS**

Expand Down
51 changes: 51 additions & 0 deletions docs/output_files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!-- Generated with Stardoc: http://skydoc.bazel.build -->

A rule that provides file(s) specific via DefaultInfo from a given target's DefaultInfo or OutputGroupInfo


<a id="#output_files"></a>

## output_files

<pre>
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>)
</pre>

A rule that provides file(s) specific via DefaultInfo from a given target's DefaultInfo or OutputGroupInfo

**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <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 | |
| <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 | "" |
| <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 | |
| <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 | |


<a id="#make_output_files"></a>

## make_output_files

<pre>
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>)
</pre>

Helper function to generate a output_files target and return its label.

**PARAMETERS**


| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="make_output_files-name"></a>name | unique name for the generated <code>output_files</code> target | none |
| <a id="make_output_files-target"></a>target | <code>target</code> attribute passed to generated <code>output_files</code> target | none |
| <a id="make_output_files-paths"></a>paths | <code>paths</code> attribute passed to generated <code>output_files</code> target | none |
| <a id="make_output_files-kwargs"></a>kwargs | parameters to pass to generated <code>output_files</code> target | none |

**RETURNS**

The label `name`


6 changes: 3 additions & 3 deletions lib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ bzl_library(
)

bzl_library(
name = "default_info_files",
srcs = ["default_info_files.bzl"],
name = "output_files",
srcs = ["output_files.bzl"],
visibility = ["//visibility:public"],
deps = ["//lib/private:default_info_files"],
deps = ["//lib/private:output_files"],
)

bzl_library(
Expand Down
11 changes: 0 additions & 11 deletions lib/default_info_files.bzl

This file was deleted.

11 changes: 11 additions & 0 deletions lib/output_files.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""A rule that provides file(s) specific via DefaultInfo from a given target's DefaultInfo or OutputGroupInfo
"""

load(
"//lib/private:output_files.bzl",
_make_output_files = "make_output_files",
_output_files = "output_files",
)

output_files = _output_files
make_output_files = _make_output_files
8 changes: 4 additions & 4 deletions lib/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ bzl_library(
srcs = ["copy_to_directory.bzl"],
visibility = ["//lib:__subpackages__"],
deps = [
":default_info_files",
":directory_path",
":output_files",
":paths",
"@bazel_skylib//lib:paths",
],
Expand Down Expand Up @@ -66,8 +66,8 @@ bzl_library(
srcs = ["write_source_file.bzl"],
visibility = ["//lib:__subpackages__"],
deps = [
":default_info_files",
":directory_path",
":output_files",
"//lib:utils",
],
)
Expand All @@ -86,8 +86,8 @@ bzl_library(
)

bzl_library(
name = "default_info_files",
srcs = ["default_info_files.bzl"],
name = "output_files",
srcs = ["output_files.bzl"],
visibility = ["//lib:__subpackages__"],
deps = ["//lib:utils"],
)
Expand Down
70 changes: 0 additions & 70 deletions lib/private/default_info_files.bzl

This file was deleted.

14 changes: 9 additions & 5 deletions lib/private/directory_path.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ Otherwise there is no way to give a Bazel label for it.""",
provides = [DirectoryPathInfo],
)

def make_directory_path(name, directory, path):
def make_directory_path(name, directory, path, **kwargs):
"""Helper function to generate a directory_path target and return its label.
Args:
name: Unique name for the generated `directory_path` target.
directory: a TreeArtifact (ctx.actions.declare_directory)
path: path relative to the directory
name: unique name for the generated `directory_path` target
directory: `directory` attribute passed to generated `directory_path` target
path: `path` attribute passed to generated `directory_path` target
**kwargs: parameters to pass to generated `output_files` target
Returns:
The label `name`
Expand All @@ -51,10 +52,11 @@ def make_directory_path(name, directory, path):
name = name,
directory = directory,
path = path,
**kwargs
)
return _to_label(name)

def make_directory_paths(name, dict):
def make_directory_paths(name, dict, **kwargs):
"""Helper function to convert a dict of directory to path mappings to directory_path targets and labels.
For example,
Expand Down Expand Up @@ -104,6 +106,7 @@ def make_directory_paths(name, dict):
The names are generated as zero-indexed `name + "_" + i`
dict: The dictionary of directory keys to path or path list values.
**kwargs: additional parameters to pass to each generated target
Returns:
The label of the generated `directory_path` targets named `name + "_" + i`
Expand All @@ -124,5 +127,6 @@ def make_directory_paths(name, dict):
"%s_%d" % (name, i),
directory,
path,
**kwargs
))
return labels
Loading

0 comments on commit bda5c63

Please sign in to comment.