-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DefaultOutputPathInfo provider and update write_source_files to a…
…ccept it (#48) Also update write_source_files to accept DirectoryPathInfo
- Loading branch information
1 parent
7f2641c
commit 3b93ee0
Showing
28 changed files
with
622 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
docs/*.md | ||
lib/tests/jq/*.json | ||
lib/tests/write_source_files/a2.js | ||
lib/tests/write_source_files/b2.js | ||
lib/tests/write_source_files/e_dir/e.js | ||
lib/lib/tests/write_source_files/*.js | ||
lib/lib/tests/write_source_files/subdir/*.js | ||
lib/lib/tests/write_source_files/subdir/subsubdir/*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<!-- Generated with Stardoc: http://skydoc.bazel.build --> | ||
|
||
A rule that provides file(s) from a given target's DefaultInfo | ||
|
||
|
||
<a id="#default_info_files"></a> | ||
|
||
## default_info_files | ||
|
||
<pre> | ||
default_info_files(<a href="#default_info_files-name">name</a>, <a href="#default_info_files-paths">paths</a>, <a href="#default_info_files-target">target</a>) | ||
</pre> | ||
|
||
A rule that provides file(s) from a given target's DefaultInfo | ||
|
||
**ATTRIBUTES** | ||
|
||
|
||
| Name | Description | Type | Mandatory | Default | | ||
| :------------- | :------------- | :------------- | :------------- | :------------- | | ||
| <a id="default_info_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="default_info_files-paths"></a>paths | the paths of the files to provide in the DefaultInfo of the target relative to its root | List of strings | required | | | ||
| <a id="default_info_files-target"></a>target | the target to look in for requested paths in its' DefaultInfo | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | | | ||
|
||
|
||
<a id="#make_default_info_files"></a> | ||
|
||
## make_default_info_files | ||
|
||
<pre> | ||
make_default_info_files(<a href="#make_default_info_files-name">name</a>, <a href="#make_default_info_files-target">target</a>, <a href="#make_default_info_files-paths">paths</a>) | ||
</pre> | ||
|
||
Helper function to generate a default_info_files target and return its label. | ||
|
||
**PARAMETERS** | ||
|
||
|
||
| Name | Description | Default Value | | ||
| :------------- | :------------- | :------------- | | ||
| <a id="make_default_info_files-name"></a>name | unique name for the generated <code>default_info_files</code> target. | none | | ||
| <a id="make_default_info_files-target"></a>target | the target to look in for requested paths in its' DefaultInfo | none | | ||
| <a id="make_default_info_files-paths"></a>paths | the paths of the files to provide in the DefaultInfo of the target relative to its root | none | | ||
|
||
**RETURNS** | ||
|
||
The label `name` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"""A rule that provides file(s) from a given target's DefaultInfo | ||
""" | ||
|
||
load( | ||
"//lib/private:default_info_files.bzl", | ||
_default_info_files = "default_info_files", | ||
_make_default_info_files = "make_default_info_files", | ||
) | ||
|
||
default_info_files = _default_info_files | ||
make_default_info_files = _make_default_info_files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""default_info_files implementation | ||
""" | ||
|
||
load("//lib:utils.bzl", _to_label = "to_label") | ||
|
||
def _default_info_files(ctx): | ||
files = [] | ||
for path in ctx.attr.paths: | ||
file = find_short_path_in_default_info( | ||
ctx.attr.target, | ||
path, | ||
) | ||
if not file: | ||
fail("%s file not found within the DefaultInfo of %s" % (ctx.attr.path, ctx.attr.target)) | ||
files.append(file) | ||
return [DefaultInfo( | ||
files = depset(direct = files), | ||
runfiles = ctx.runfiles(files = files), | ||
)] | ||
|
||
default_info_files = rule( | ||
doc = "A rule that provides file(s) from a given target's DefaultInfo", | ||
implementation = _default_info_files, | ||
attrs = { | ||
"target": attr.label( | ||
doc = "the target to look in for requested paths in its' DefaultInfo", | ||
mandatory = True, | ||
), | ||
"paths": attr.string_list( | ||
doc = "the paths of the files to provide in the DefaultInfo of the target relative to its root", | ||
mandatory = True, | ||
allow_empty = False, | ||
), | ||
}, | ||
provides = [DefaultInfo], | ||
) | ||
|
||
def make_default_info_files(name, target, paths): | ||
"""Helper function to generate a default_info_files target and return its label. | ||
Args: | ||
name: unique name for the generated `default_info_files` target. | ||
target: the target to look in for requested paths in its' DefaultInfo | ||
paths: the paths of the files to provide in the DefaultInfo of the target relative to its root | ||
Returns: | ||
The label `name` | ||
""" | ||
default_info_files( | ||
name = name, | ||
target = target, | ||
paths = paths, | ||
) | ||
return _to_label(name) | ||
|
||
def find_short_path_in_default_info(default_info, short_path): | ||
"""Helper function find a file in a DefaultInfo by short path | ||
Args: | ||
default_info: a DefaultInfo | ||
short_path: the short path (path relative to root) to search for | ||
Returns: | ||
The File if found else None | ||
""" | ||
if default_info.files: | ||
for file in default_info.files.to_list(): | ||
if file.short_path == short_path: | ||
return file | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.