-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy rules_directory's globs to bazel-skylib. (#511)
Original implementation is at https://github.com/matts1/rules_directory
- Loading branch information
Showing
16 changed files
with
544 additions
and
1 deletion.
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
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
Empty file.
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,39 @@ | ||
<!-- Generated with Stardoc: http://skydoc.bazel.build --> | ||
|
||
Rules to filter files from a directory. | ||
|
||
<a id="directory_glob"></a> | ||
|
||
## directory_glob | ||
|
||
<pre> | ||
directory_glob(<a href="#directory_glob-name">name</a>, <a href="#directory_glob-srcs">srcs</a>, <a href="#directory_glob-data">data</a>, <a href="#directory_glob-allow_empty">allow_empty</a>, <a href="#directory_glob-directory">directory</a>, <a href="#directory_glob-exclude">exclude</a>) | ||
</pre> | ||
|
||
globs files from a directory by relative path. | ||
|
||
Usage: | ||
|
||
``` | ||
directory_glob( | ||
name = "foo", | ||
directory = ":directory", | ||
srcs = ["foo/bar"], | ||
data = ["foo/**"], | ||
exclude = ["foo/**/*.h"] | ||
) | ||
``` | ||
|
||
**ATTRIBUTES** | ||
|
||
|
||
| Name | Description | Type | Mandatory | Default | | ||
| :------------- | :------------- | :------------- | :------------- | :------------- | | ||
| <a id="directory_glob-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | | | ||
| <a id="directory_glob-srcs"></a>srcs | A list of globs to files within the directory to put in the files.<br><br>For example, `srcs = ["foo/**"]` would collect the file at `<directory>/foo` into the files. | List of strings | optional | `[]` | | ||
| <a id="directory_glob-data"></a>data | A list of globs to files within the directory to put in the runfiles.<br><br>For example, `data = ["foo/**"]` would collect all files contained within `<directory>/foo` into the runfiles. | List of strings | optional | `[]` | | ||
| <a id="directory_glob-allow_empty"></a>allow_empty | If true, allows globs to not match anything. | Boolean | optional | `False` | | ||
| <a id="directory_glob-directory"></a>directory | - | <a href="https://bazel.build/concepts/labels">Label</a> | required | | | ||
| <a id="directory_glob-exclude"></a>exclude | A list of globs to files within the directory to exclude from the files and runfiles. | List of strings | optional | `[]` | | ||
|
||
|
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
Empty file.
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,73 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Rules to filter files from a directory.""" | ||
|
||
load(":providers.bzl", "DirectoryInfo") | ||
|
||
def _directory_glob_impl(ctx): | ||
directory = ctx.attr.directory[DirectoryInfo] | ||
srcs = directory.glob( | ||
ctx.attr.srcs, | ||
exclude = ctx.attr.exclude, | ||
allow_empty = ctx.attr.allow_empty, | ||
) | ||
data = directory.glob( | ||
ctx.attr.data, | ||
exclude = ctx.attr.exclude, | ||
allow_empty = ctx.attr.allow_empty, | ||
) | ||
|
||
return DefaultInfo( | ||
files = srcs, | ||
runfiles = ctx.runfiles(transitive_files = depset(transitive = [srcs, data])), | ||
) | ||
|
||
directory_glob = rule( | ||
implementation = _directory_glob_impl, | ||
attrs = { | ||
"allow_empty": attr.bool( | ||
doc = "If true, allows globs to not match anything.", | ||
), | ||
"data": attr.string_list( | ||
doc = """A list of globs to files within the directory to put in the runfiles. | ||
For example, `data = ["foo/**"]` would collect all files contained within `<directory>/foo` into the | ||
runfiles.""", | ||
), | ||
"directory": attr.label(providers = [DirectoryInfo], mandatory = True), | ||
"exclude": attr.string_list( | ||
doc = "A list of globs to files within the directory to exclude from the files and runfiles.", | ||
), | ||
"srcs": attr.string_list( | ||
doc = """A list of globs to files within the directory to put in the files. | ||
For example, `srcs = ["foo/**"]` would collect the file at `<directory>/foo` into the | ||
files.""", | ||
), | ||
}, | ||
doc = """globs files from a directory by relative path. | ||
Usage: | ||
``` | ||
directory_glob( | ||
name = "foo", | ||
directory = ":directory", | ||
srcs = ["foo/bar"], | ||
data = ["foo/**"], | ||
exclude = ["foo/**/*.h"] | ||
) | ||
``` | ||
""", | ||
) |
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.