Skip to content

Commit

Permalink
Copy rules_directory to bazel-skylib.
Browse files Browse the repository at this point in the history
  • Loading branch information
matts1 committed May 13, 2024
1 parent 0d43695 commit e33db05
Show file tree
Hide file tree
Showing 27 changed files with 1,607 additions and 0 deletions.
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ bazel_dep(name = "rules_license", version = "0.0.7")
# Build-only / test-only dependencies
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")
bazel_dep(name = "rules_pkg", version = "0.9.1", dev_dependency = True)
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True)

# Needed for bazelci and for building distribution tarballs.
# If using an unreleased version of bazel_skylib via git_override, apply
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ s = shell.quote(p)
* [analysis_test](docs/analysis_test_doc.md)
* [build_test](docs/build_test_doc.md)
* [common_settings](docs/common_settings_doc.md)
* [directories](docs/copy_directory_doc.md)
* [directory](docs/directory_doc.md)
* [directory_filter](docs/directory_filter_doc.md)
* [directory_glob](docs/directory_glob.md)
* [subdirectory](docs/subdirectory_doc.md)
* [copy_directory](docs/copy_directory_doc.md)
* [copy_file](docs/copy_file_doc.md)
* [diff_test](docs/diff_test_doc.md)
Expand Down
7 changes: 7 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")

rules_pkg_dependencies()

http_archive(
name = "rules_testing",
sha256 = "02c62574631876a4e3b02a1820cb51167bb9cdcdea2381b2fa9d9b8b11c407c4",
strip_prefix = "rules_testing-0.6.0",
url = "https://github.com/bazelbuild/rules_testing/releases/download/v0.6.0/rules_testing-v0.6.0.tar.gz",
)

load("//lib:unittest.bzl", "register_unittest_toolchains")

register_unittest_toolchains()
36 changes: 36 additions & 0 deletions docs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,42 @@ stardoc_with_diff_test(
out_label = "//docs:diff_test_doc.md",
)

stardoc_with_diff_test(
name = "directory",
bzl_library_target = "//rules/directory:directory",
out_label = "//docs:directory_doc.md",
)

stardoc_with_diff_test(
name = "directory_filter",
bzl_library_target = "//rules/directory:filter",
out_label = "//docs:directory_filter_doc.md",
)

stardoc_with_diff_test(
name = "directory_glob",
bzl_library_target = "//rules/directory:glob",
out_label = "//docs:directory_glob_doc.md",
)

stardoc_with_diff_test(
name = "directory_providers",
bzl_library_target = "//rules/directory:providers",
out_label = "//docs:directory_providers_doc.md",
)

stardoc_with_diff_test(
name = "directory_subdirectory",
bzl_library_target = "//rules/directory:subdirectory",
out_label = "//docs:directory_subdirectory_doc.md",
)

stardoc_with_diff_test(
name = "directory_utils",
bzl_library_target = "//rules/directory:utils",
out_label = "//docs:directory_utils_doc.md",
)

stardoc_with_diff_test(
name = "expand_template",
bzl_library_target = "//rules:expand_template",
Expand Down
34 changes: 34 additions & 0 deletions docs/directory_doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!-- Generated with Stardoc: http://skydoc.bazel.build -->

Skylib module containing rules to create metadata about directories.

<a id="directory"></a>

## directory

<pre>
directory(<a href="#directory-name">name</a>, <a href="#directory-srcs">srcs</a>, <a href="#directory-kwargs">kwargs</a>)
</pre>

A marker for a bazel directory and its contents.

Example usage:
directory(
name = "foo",
srcs = glob(
["**/*"],
exclude=["BUILD.bazel", "WORKSPACE.bazel", "MODULE.bazel"])
)
)


**PARAMETERS**


| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="directory-name"></a>name | (str) The name of the label. | none |
| <a id="directory-srcs"></a>srcs | (List[Label\|File]) The files contained within this directory and subdirectories.", | `[]` |
| <a id="directory-kwargs"></a>kwargs | Kwargs to be passed to the underlying rule. | none |


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

Rules to filter files from a directory.

<a id="directory_filter"></a>

## directory_filter

<pre>
directory_filter(<a href="#directory_filter-name">name</a>, <a href="#directory_filter-srcs">srcs</a>, <a href="#directory_filter-data">data</a>, <a href="#directory_filter-directory">directory</a>)
</pre>

Extracts files from a directory by relative path.

Usage:

```
directory_filter(
name = "clang",
directory = "//:sysroot",
srcs = ["usr/bin/clang"],
data = ["lib/libc.so.6"],
)
```

**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="directory_filter-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="directory_filter-srcs"></a>srcs | A list of relative paths to files within the directory to put in the runfiles.<br><br>For example, `srcs = ["foo/bar"]` would collect the file at `<directory>/foo/bar` into the files. | List of strings | optional | `[]` |
| <a id="directory_filter-data"></a>data | A list of relative paths to files within the directory to put in the files.<br><br>For example, `data = ["foo/bar"]` would collect the file at `<directory>/foo/bar` into the runfiles. | List of strings | optional | `[]` |
| <a id="directory_filter-directory"></a>directory | - | <a href="https://bazel.build/concepts/labels">Label</a> | required | |


39 changes: 39 additions & 0 deletions docs/directory_glob_doc.md
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 | `[]` |


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

Skylib module containing providers for directories.

<a id="DirectoryInfo"></a>

## DirectoryInfo

<pre>
DirectoryInfo(<a href="#DirectoryInfo-entries">entries</a>, <a href="#DirectoryInfo-transitive_files">transitive_files</a>, <a href="#DirectoryInfo-source_path">source_path</a>, <a href="#DirectoryInfo-generated_path">generated_path</a>, <a href="#DirectoryInfo-human_readable">human_readable</a>)
</pre>

Information about a directory

**FIELDS**


| Name | Description |
| :------------- | :------------- |
| <a id="DirectoryInfo-entries"></a>entries | (Dict[str, Either[File, DirectoryInfo]]) The entries contained directly within. Ordered by filename |
| <a id="DirectoryInfo-transitive_files"></a>transitive_files | (depset[File]) All files transitively contained within this directory. |
| <a id="DirectoryInfo-source_path"></a>source_path | (Optional[string]) Path to all source files contained within this directory. Only provided if the directory actually contains source files. |
| <a id="DirectoryInfo-generated_path"></a>generated_path | (Optional[string]) Path to all generated files contained within this directory. Only provided if the directory actually contains generated files. |
| <a id="DirectoryInfo-human_readable"></a>human_readable | (string) A human readable identifier for a directory. Useful for providing error messages to a user. |


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

Skylib module containing rules to create metadata about subdirectories.

<a id="subdirectory"></a>

## subdirectory

<pre>
subdirectory(<a href="#subdirectory-name">name</a>, <a href="#subdirectory-parent">parent</a>, <a href="#subdirectory-path">path</a>)
</pre>



**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="subdirectory-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="subdirectory-parent"></a>parent | A label corresponding to the parent directory. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
| <a id="subdirectory-path"></a>path | A path relative to the parent directory | String | required | |


Loading

0 comments on commit e33db05

Please sign in to comment.