Skip to content

Commit

Permalink
Copy rules_directory to bazel-skylib. (#510)
Browse files Browse the repository at this point in the history
Original implementation is at https://github.com/matts1/rules_directory
  • Loading branch information
matts1 authored May 29, 2024
1 parent b459822 commit a464f69
Show file tree
Hide file tree
Showing 23 changed files with 975 additions and 2 deletions.
1 change: 1 addition & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ matrix:
.reusable_targets: &reusable_targets
? "--"
? "//..."
? "@external_directory_tests//..."
? "@bazel_skylib_gazelle_plugin//..."

.reusable_config: &reusable_config
Expand Down
8 changes: 6 additions & 2 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 All @@ -28,8 +29,11 @@ local_path_override(
path = "gazelle",
)

as_extension_test_ext = use_extension("//tests:modules_test.bzl", "as_extension_test_ext")
external_directory_tests_ext = use_extension("//tests/directory:external_directory_tests.bzl", "external_directory_tests_ext", dev_dependency = True)
use_repo(external_directory_tests_ext, "external_directory_tests")

as_extension_test_ext = use_extension("//tests:modules_test.bzl", "as_extension_test_ext", dev_dependency = True)
use_repo(as_extension_test_ext, "bar", "foo")

use_all_repos_test_ext = use_extension("//tests:modules_test.bzl", "use_all_repos_test_ext")
use_all_repos_test_ext = use_extension("//tests:modules_test.bzl", "use_all_repos_test_ext", dev_dependency = True)
use_repo(use_all_repos_test_ext, "baz", "qux")
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ 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)
* [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
10 changes: 10 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ 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")
load("//tests/directory:external_directory_tests.bzl", "external_directory_tests")

external_directory_tests(name = "external_directory_tests")

register_unittest_toolchains()
18 changes: 18 additions & 0 deletions docs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ 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_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 = "expand_template",
bzl_library_target = "//rules:expand_template",
Expand Down
23 changes: 23 additions & 0 deletions docs/directory_doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- 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>)
</pre>



**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="directory-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="directory-srcs"></a>srcs | - | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |


46 changes: 46 additions & 0 deletions docs/directory_providers_doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!-- 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-path">path</a>, <a href="#DirectoryInfo-human_readable">human_readable</a>, <a href="#DirectoryInfo-get_path">get_path</a>, <a href="#DirectoryInfo-get_file">get_file</a>, <a href="#DirectoryInfo-get_subdirectory">get_subdirectory</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-path"></a>path | (string) Path to all files contained within this directory. |
| <a id="DirectoryInfo-human_readable"></a>human_readable | (string) A human readable identifier for a directory. Useful for providing error messages to a user. |
| <a id="DirectoryInfo-get_path"></a>get_path | (Function(str) -> DirectoryInfo\|File) A function to return the entry corresponding to the joined path. |
| <a id="DirectoryInfo-get_file"></a>get_file | (Function(str) -> File) A function to return the entry corresponding to the joined path. |
| <a id="DirectoryInfo-get_subdirectory"></a>get_subdirectory | (Function(str) -> DirectoryInfo) A function to return the entry corresponding to the joined path. |


<a id="create_directory_info"></a>

## create_directory_info

<pre>
create_directory_info(<a href="#create_directory_info-kwargs">kwargs</a>)
</pre>



**PARAMETERS**


| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="create_directory_info-kwargs"></a>kwargs | <p align="center"> - </p> | none |


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 (or subdirectory). | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
| <a id="subdirectory-path"></a>path | A path within the parent directory (eg. "path/to/subdir") | String | required | |


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

Skylib module containing utility functions related to directories.

<a id="get_child"></a>

## get_child

<pre>
get_child(<a href="#get_child-directory">directory</a>, <a href="#get_child-name">name</a>, <a href="#get_child-require_dir">require_dir</a>, <a href="#get_child-require_file">require_file</a>)
</pre>

Gets the direct child of a directory.

**PARAMETERS**


| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="get_child-directory"></a>directory | (DirectoryInfo) The directory to look within. | none |
| <a id="get_child-name"></a>name | (string) The name of the directory/file to look for. | none |
| <a id="get_child-require_dir"></a>require_dir | (bool) If true, throws an error if the value is not a directory. | `False` |
| <a id="get_child-require_file"></a>require_file | (bool) If true, throws an error if the value is not a file. | `False` |

**RETURNS**

(File|DirectoryInfo) The content contained within.


<a id="get_relative"></a>

## get_relative

<pre>
get_relative(<a href="#get_relative-directory">directory</a>, <a href="#get_relative-path">path</a>, <a href="#get_relative-require_dir">require_dir</a>, <a href="#get_relative-require_file">require_file</a>)
</pre>

Gets a subdirectory contained within a tree of another directory.

**PARAMETERS**


| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="get_relative-directory"></a>directory | (DirectoryInfo) The directory to look within. | none |
| <a id="get_relative-path"></a>path | (string) The path of the directory to look for within it. | none |
| <a id="get_relative-require_dir"></a>require_dir | (bool) If true, throws an error if the value is not a directory. | `False` |
| <a id="get_relative-require_file"></a>require_file | (bool) If true, throws an error if the value is not a file. | `False` |

**RETURNS**

(File|DirectoryInfo) The directory contained within.


37 changes: 37 additions & 0 deletions rules/directory/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

licenses(["notice"])

# export bzl files for the documentation
exports_files(
glob(["*.bzl"]),
visibility = ["//:__subpackages__"],
)

bzl_library(
name = "directory",
srcs = ["directory.bzl"],
visibility = ["//visibility:public"],
deps = [
":providers",
"//lib:paths",
],
)

bzl_library(
name = "providers",
srcs = ["providers.bzl"],
visibility = ["//visibility:public"],
deps = [
"//rules/directory/private:paths",
],
)

bzl_library(
name = "subdirectory",
srcs = ["subdirectory.bzl"],
visibility = ["//visibility:public"],
deps = [
":providers",
],
)
Loading

0 comments on commit a464f69

Please sign in to comment.