From d7e9dbb31fb41f2d4c5073cf2800e6f99e83d545 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Thu, 1 Sep 2022 08:19:43 -0400 Subject: [PATCH 1/5] Add missing docs and doc links; update bazel.build links (#387) --- README.md | 6 ++++++ docs/BUILD | 5 +++++ docs/build_test_doc.md | 2 +- docs/common_settings_doc.md | 2 +- docs/diff_test_doc.md | 2 +- docs/native_binary_doc.md | 4 ++-- docs/run_binary_doc.md | 4 ++-- docs/select_file_doc.md | 28 ++++++++++++++++++++++++++++ rules/build_test.bzl | 2 +- rules/common_settings.bzl | 2 +- rules/diff_test.bzl | 2 +- rules/native_binary.bzl | 2 +- rules/run_binary.bzl | 4 ++-- rules/select_file.bzl | 5 ++--- 14 files changed, 54 insertions(+), 16 deletions(-) create mode 100755 docs/select_file_doc.md diff --git a/README.md b/README.md index 52733ebe..ce70baba 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,14 @@ 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) +* [copy_directory](docs/copy_directory_doc.md) * [copy_file](docs/copy_file_doc.md) +* [diff_test](docs/diff_test_doc.md) * [expand_template](docs/expand_template_doc.md) +* [native_binary and native_test](docs/native_binary_doc.md) +* [run_binary](docs/run_binary_doc.md) +* [select_file](docs/select_file_doc.md) * [write_file](docs/write_file_doc.md) ## Writing a new module diff --git a/docs/BUILD b/docs/BUILD index bac20b10..c6f1b611 100644 --- a/docs/BUILD +++ b/docs/BUILD @@ -77,6 +77,11 @@ stardoc_with_diff_test( out_label = "//docs:selects_doc.md", ) +stardoc_with_diff_test( + bzl_library_target = "//rules:select_file", + out_label = "//docs:select_file_doc.md", +) + stardoc_with_diff_test( bzl_library_target = "//lib:shell", out_label = "//docs:shell_doc.md", diff --git a/docs/build_test_doc.md b/docs/build_test_doc.md index eba4904b..d5474063 100755 --- a/docs/build_test_doc.md +++ b/docs/build_test_doc.md @@ -36,6 +36,6 @@ Typical usage: | :------------- | :------------- | :------------- | | name | The name of the test rule. | none | | targets | A list of targets to ensure build. | none | -| kwargs | The <a href="https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes-tests">common attributes for tests</a>. | none | +| kwargs | The <a href="https://bazel.build/reference/be/common-definitions#common-attributes-tests">common attributes for tests</a>. | none | diff --git a/docs/common_settings_doc.md b/docs/common_settings_doc.md index 5ab7cd2a..4dda47ca 100755 --- a/docs/common_settings_doc.md +++ b/docs/common_settings_doc.md @@ -6,7 +6,7 @@ These rules return a BuildSettingInfo with the value of the build setting. For label-typed settings, use the native label_flag and label_setting rules. More documentation on how to use build settings at -https://docs.bazel.build/versions/main/skylark/config.html#user-defined-build-settings +https://bazel.build/extending/config#user-defined-build-settings diff --git a/docs/diff_test_doc.md b/docs/diff_test_doc.md index 41a030ba..4fc2416c 100755 --- a/docs/diff_test_doc.md +++ b/docs/diff_test_doc.md @@ -28,6 +28,6 @@ The test succeeds if the files' contents match. | file1 | Label of the file to compare to <code>file2</code>. | none | | file2 | Label of the file to compare to <code>file1</code>. | none | | failure_message | Additional message to log if the files' contents do not match. | None | -| kwargs | The <a href="https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes-tests">common attributes for tests</a>. | none | +| kwargs | The <a href="https://bazel.build/reference/be/common-definitions#common-attributes-tests">common attributes for tests</a>. | none | diff --git a/docs/native_binary_doc.md b/docs/native_binary_doc.md index 7a543153..b512b252 100755 --- a/docs/native_binary_doc.md +++ b/docs/native_binary_doc.md @@ -29,7 +29,7 @@ in genrule.tools for example. You can also augment the binary with runfiles. | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | -| data | data dependencies. See https://docs.bazel.build/versions/main/be/common-definitions.html#typical.data | List of labels | optional | [] | +| data | data dependencies. See https://bazel.build/reference/be/common-definitions#typical.data | List of labels | optional | [] | | out | An output name for the copy of the binary | String | required | | | src | path of the pre-built executable | Label | required | | @@ -55,7 +55,7 @@ the binary with runfiles. | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | -| data | data dependencies. See https://docs.bazel.build/versions/main/be/common-definitions.html#typical.data | List of labels | optional | [] | +| data | data dependencies. See https://bazel.build/reference/be/common-definitions#typical.data | List of labels | optional | [] | | out | An output name for the copy of the binary | String | required | | | src | path of the pre-built executable | Label | required | | diff --git a/docs/run_binary_doc.md b/docs/run_binary_doc.md index 7d4f9fb1..8e4491db 100755 --- a/docs/run_binary_doc.md +++ b/docs/run_binary_doc.md @@ -22,8 +22,8 @@ Runs a binary as a build action.

This rule does not require Bash (unlik | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | -| args | Command line arguments of the binary.<br/><br/>Subject to<code><a href="https://docs.bazel.build/versions/main/be/make-variables.html#location">$(location)</a></code> expansion. | List of strings | optional | [] | -| env | Environment variables of the action.<br/><br/>Subject to <code><a href="https://docs.bazel.build/versions/main/be/make-variables.html#location">$(location)</a></code> expansion. | Dictionary: String -> String | optional | {} | +| args | Command line arguments of the binary.<br/><br/>Subject to<code><a href="https://bazel.build/reference/be/make-variables#predefined_label_variables">$(location)</a></code> expansion. | List of strings | optional | [] | +| env | Environment variables of the action.<br/><br/>Subject to <code><a href="https://bazel.build/reference/be/make-variables#predefined_label_variables">$(location)</a></code> expansion. | Dictionary: String -> String | optional | {} | | outs | Output files generated by the action.<br/><br/>These labels are available for <code>$(location)</code> expansion in <code>args</code> and <code>env</code>. | List of labels | required | | | srcs | Additional inputs of the action.<br/><br/>These labels are available for <code>$(location)</code> expansion in <code>args</code> and <code>env</code>. | List of labels | optional | [] | | tool | The tool to run in the action.<br/><br/>Must be the label of a *_binary rule, of a rule that generates an executable file, or of a file that can be executed as a subprocess (e.g. an .exe or .bat file on Windows or a binary with executable permission on Linux). This label is available for <code>$(location)</code> expansion in <code>args</code> and <code>env</code>. | Label | required | | diff --git a/docs/select_file_doc.md b/docs/select_file_doc.md new file mode 100755 index 00000000..667f5198 --- /dev/null +++ b/docs/select_file_doc.md @@ -0,0 +1,28 @@ + + + +select_file() build rule implementation. + +Selects a single file from the outputs of a target by given relative path. + + + + +## select_file + +
+select_file(name, srcs, subpath)
+
+ +Selects a single file from the outputs of a target by given relative path + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| srcs | The target producing the file among other outputs | Label | required | | +| subpath | Relative path to the file | String | required | | + + diff --git a/rules/build_test.bzl b/rules/build_test.bzl index 9ec8ab1f..682901eb 100644 --- a/rules/build_test.bzl +++ b/rules/build_test.bzl @@ -63,7 +63,7 @@ def build_test(name, targets, **kwargs): Args: name: The name of the test rule. targets: A list of targets to ensure build. - **kwargs: The common attributes for tests. + **kwargs: The common attributes for tests. """ if len(targets) == 0: fail("targets must be non-empty", "targets") diff --git a/rules/common_settings.bzl b/rules/common_settings.bzl index 7f56a7f2..d5b84084 100644 --- a/rules/common_settings.bzl +++ b/rules/common_settings.bzl @@ -18,7 +18,7 @@ These rules return a BuildSettingInfo with the value of the build setting. For label-typed settings, use the native label_flag and label_setting rules. More documentation on how to use build settings at -https://docs.bazel.build/versions/main/skylark/config.html#user-defined-build-settings +https://bazel.build/extending/config#user-defined-build-settings """ BuildSettingInfo = provider( diff --git a/rules/diff_test.bzl b/rules/diff_test.bzl index 25213d61..ee2f589e 100644 --- a/rules/diff_test.bzl +++ b/rules/diff_test.bzl @@ -164,7 +164,7 @@ def diff_test(name, file1, file2, failure_message = None, **kwargs): file1: Label of the file to compare to file2. file2: Label of the file to compare to file1. failure_message: Additional message to log if the files' contents do not match. - **kwargs: The common attributes for tests. + **kwargs: The common attributes for tests. """ _diff_test( name = name, diff --git a/rules/native_binary.bzl b/rules/native_binary.bzl index a027fc9a..b33347b3 100644 --- a/rules/native_binary.bzl +++ b/rules/native_binary.bzl @@ -61,7 +61,7 @@ _ATTRS = { "data": attr.label_list( allow_files = True, doc = "data dependencies. See" + - " https://docs.bazel.build/versions/main/be/common-definitions.html#typical.data", + " https://bazel.build/reference/be/common-definitions#typical.data", ), # "out" is attr.string instead of attr.output, so that it is select()'able. "out": attr.string(mandatory = True, doc = "An output name for the copy of the binary"), diff --git a/rules/run_binary.bzl b/rules/run_binary.bzl index 47c8bc5b..c40c0be2 100644 --- a/rules/run_binary.bzl +++ b/rules/run_binary.bzl @@ -76,7 +76,7 @@ run_binary = rule( ), "env": attr.string_dict( doc = "Environment variables of the action.

Subject to " + - " $(location)" + + " $(location)" + " expansion.", ), "srcs": attr.label_list( @@ -91,7 +91,7 @@ run_binary = rule( ), "args": attr.string_list( doc = "Command line arguments of the binary.

Subject to" + - "$(location)" + + "$(location)" + " expansion.", ), }, diff --git a/rules/select_file.bzl b/rules/select_file.bzl index f359e433..1b730931 100644 --- a/rules/select_file.bzl +++ b/rules/select_file.bzl @@ -15,7 +15,7 @@ """ select_file() build rule implementation. -Selects a single file from the outputs of some target by given relative path. +Selects a single file from the outputs of a target by given relative path. """ def _impl(ctx): @@ -38,8 +38,7 @@ def _impl(ctx): select_file = rule( implementation = _impl, - doc = "Selects a single file from the outputs of some target \ -by given relative path", + doc = "Selects a single file from the outputs of a target by given relative path", attrs = { "srcs": attr.label( allow_files = True, From 6a17363a3c27dde70ab5002ad9f2e29aff1e1f4b Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Thu, 1 Sep 2022 10:12:35 -0400 Subject: [PATCH 2/5] Update changelog and version for release 1.3.0 (#388) --- CHANGELOG.md | 23 +++++++++++++++++++++++ MODULE.bazel | 2 +- version.bzl | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4567ed3f..ef9c469c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,26 @@ +Release 1.3.0 + +**New Features** +- Added `dicts.omit` and `dicts.pick` (#304) +- Added `expand_template` rule (#330) +- Added `subpackages` module (#348) +- Added `copy_directory` rule (#366) +- Added `bzlmod` support (#385) + +**Incompatible Changes** +- `native_binary` and `native_test` now use symlinks instead of copying, if + the OS supports it (#340) +- `native_binary` and `native_test` now build in target configuration instead + of host configuration (#341) +- `copy_file` no longer adds non-executables to `default_runfiles` (#326) + +**Contributors** + +Alex Eagle, Alexandre Rostovtsev, Barry McNamara, Derek Cormier, Fabian +Meumertzheim, Geoffrey Martin-Noble, hchsiao, Kevin Kres, nickgooding, +Vertexwahn, Vinh Tran + + Release 1.2.1 Bugfix release: fixes build failure with --incompatible_disallow_empty_glob diff --git a/MODULE.bazel b/MODULE.bazel index 69559602..698c698b 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,7 +1,7 @@ module( name = "bazel_skylib", compatibility_level = 1, - version = "1.2.1", + version = "1.3.0", ) register_toolchains( diff --git a/version.bzl b/version.bzl index 324adb5d..70a04d68 100644 --- a/version.bzl +++ b/version.bzl @@ -13,4 +13,4 @@ # limitations under the License. """The version of bazel-skylib.""" -version = "1.2.1" +version = "1.3.0" From c5ededc7e8f7dcf36f39ffa819ce4e38e59977cc Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Thu, 1 Sep 2022 11:25:42 -0400 Subject: [PATCH 3/5] Fix stardoc_with_diff_test linter warnings (#390) Google internal linters are flagging skylib 1.3.0 because the stardoc_with_diff_test macro lack a copyright notice and does not use a `name` parameter. --- docs/BUILD | 23 +++++++++++++++++++++++ docs/private/stardoc_with_diff_test.bzl | 19 +++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/docs/BUILD b/docs/BUILD index c6f1b611..4d31cd10 100644 --- a/docs/BUILD +++ b/docs/BUILD @@ -3,116 +3,139 @@ load("//docs/private:stardoc_with_diff_test.bzl", "stardoc_with_diff_test", "upd licenses(["notice"]) stardoc_with_diff_test( + name = "analysis_test", bzl_library_target = "//rules:analysis_test", out_label = "//docs:analysis_test_doc.md", ) stardoc_with_diff_test( + name = "build_test", bzl_library_target = "//rules:build_test", out_label = "//docs:build_test_doc.md", ) stardoc_with_diff_test( + name = "collections", bzl_library_target = "//lib:collections", out_label = "//docs:collections_doc.md", ) stardoc_with_diff_test( + name = "common_settings", bzl_library_target = "//rules:common_settings", out_label = "//docs:common_settings_doc.md", ) stardoc_with_diff_test( + name = "copy_directory", bzl_library_target = "//rules:copy_directory", out_label = "//docs:copy_directory_doc.md", ) stardoc_with_diff_test( + name = "copy_file", bzl_library_target = "//rules:copy_file", out_label = "//docs:copy_file_doc.md", ) stardoc_with_diff_test( + name = "dicts", bzl_library_target = "//lib:dicts", out_label = "//docs:dicts_doc.md", ) stardoc_with_diff_test( + name = "diff_test", bzl_library_target = "//rules:diff_test", out_label = "//docs:diff_test_doc.md", ) stardoc_with_diff_test( + name = "expand_template", bzl_library_target = "//rules:expand_template", out_label = "//docs:expand_template_doc.md", ) stardoc_with_diff_test( + name = "native_binary", bzl_library_target = "//rules:native_binary", out_label = "//docs:native_binary_doc.md", ) stardoc_with_diff_test( + name = "new_sets", bzl_library_target = "//lib:new_sets", out_label = "//docs:new_sets_doc.md", ) stardoc_with_diff_test( + name = "partial", bzl_library_target = "//lib:partial", out_label = "//docs:partial_doc.md", ) stardoc_with_diff_test( + name = "paths", bzl_library_target = "//lib:paths", out_label = "//docs:paths_doc.md", ) stardoc_with_diff_test( + name = "run_binary", bzl_library_target = "//rules:run_binary", out_label = "//docs:run_binary_doc.md", ) stardoc_with_diff_test( + name = "selects", bzl_library_target = "//lib:selects", out_label = "//docs:selects_doc.md", ) stardoc_with_diff_test( + name = "select_file", bzl_library_target = "//rules:select_file", out_label = "//docs:select_file_doc.md", ) stardoc_with_diff_test( + name = "shell", bzl_library_target = "//lib:shell", out_label = "//docs:shell_doc.md", ) stardoc_with_diff_test( + name = "structs", bzl_library_target = "//lib:structs", out_label = "//docs:structs_doc.md", ) stardoc_with_diff_test( + name = "subpackages", bzl_library_target = "//lib:subpackages", out_label = "//docs:subpackages_doc.md", ) stardoc_with_diff_test( + name = "types", bzl_library_target = "//lib:types", out_label = "//docs:types_doc.md", ) stardoc_with_diff_test( + name = "unittest", bzl_library_target = "//lib:unittest", out_label = "//docs:unittest_doc.md", ) stardoc_with_diff_test( + name = "versions", bzl_library_target = "//lib:versions", out_label = "//docs:versions_doc.md", ) stardoc_with_diff_test( + name = "write_file", bzl_library_target = "//rules:write_file", out_label = "//docs:write_file_doc.md", ) diff --git a/docs/private/stardoc_with_diff_test.bzl b/docs/private/stardoc_with_diff_test.bzl index dc23deb7..9fe425b8 100644 --- a/docs/private/stardoc_with_diff_test.bzl +++ b/docs/private/stardoc_with_diff_test.bzl @@ -1,3 +1,17 @@ +# Copyright 2022 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. + """Helpers for keeping stardoc documentation up-to-date. These are currently a private API in bazel-skylib. @@ -14,6 +28,7 @@ load("@bazel_skylib//rules:write_file.bzl", "write_file") load("@bazel_skylib//rules:diff_test.bzl", "diff_test") def stardoc_with_diff_test( + name, bzl_library_target, out_label): """Creates a stardoc target coupled with a `diff_test` for a given `bzl_library`. @@ -21,15 +36,15 @@ def stardoc_with_diff_test( This is helpful for minimizing boilerplate in repos wih lots of stardoc targets. Args: + name: the stardoc target name bzl_library_target: the label of the `bzl_library` target to generate documentation for out_label: the label of the output MD file """ - out_file = out_label.replace("//", "").replace(":", "/") # Generate MD from .bzl stardoc( - name = out_file.replace("/", "_").replace(".md", "-docgen"), + name = name, out = out_file.replace(".md", "-docgen.md"), input = bzl_library_target + ".bzl", deps = [bzl_library_target], From 42abf5cbf28a222b2b4d04f3396db13bc842fc33 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Thu, 1 Sep 2022 15:29:04 -0400 Subject: [PATCH 4/5] Documentation fixes (#391) --- docs/maintainers_guide.md | 2 +- rules/private/copy_common.bzl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/maintainers_guide.md b/docs/maintainers_guide.md index 300475f6..5339b6a2 100644 --- a/docs/maintainers_guide.md +++ b/docs/maintainers_guide.md @@ -82,7 +82,7 @@ Name 1, Name 2, Name 3 (alphabetically from `git log`) can obtain them via `gcloud init`): ``` -gsutil cp bazel-bin/distro/bazel-skylib-$VERSION.tar.gz gs://bazel-mirror/github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/bazel-skylib-$VERSION.tar.gz +gsutil cp bazel-bin/distribution/bazel-skylib-$VERSION.tar.gz gs://bazel-mirror/github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/bazel-skylib-$VERSION.tar.gz gsutil setmeta -h "Cache-Control: public, max-age=31536000" "gs://bazel-mirror/github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/bazel-skylib-$VERSION.tar.gz" ``` diff --git a/rules/private/copy_common.bzl b/rules/private/copy_common.bzl index 5a0bb33c..2167c3a0 100644 --- a/rules/private/copy_common.bzl +++ b/rules/private/copy_common.bzl @@ -26,7 +26,7 @@ COPY_EXECUTION_REQUIREMENTS = { # | or run inside the sandbox. For genrules and tests, marking the rule with the # | local = True attribute has the same effect. # ----------------+----------------------------------------------------------------------------- - # See https://bazel.google.cn/reference/be/common-definitions?hl=en&authuser=0#common-attributes + # See https://bazel.build/reference/be/common-definitions#common-attributes # # Copying file & directories is entirely IO-bound and there is no point doing this work # remotely. From 908bf1431d276245ba921e37862f74cec45ba9f4 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Fri, 2 Sep 2022 10:42:43 -0400 Subject: [PATCH 5/5] Allow sandboxing for copy_* and fix copy_directory tests (#392) After some thought, I have to say that forcing a local strategy for copy_file/copy_directory is inappropriate. The point of a sandbox is to catch hermeticity bugs; disabling the sandbox may be useful for performance, but it's up to the user to do it if they trust us - and they can do it via flag. The default should be paranoia and safety. And on the subject of strategies - using a genrule to create an empty directory fails in environments where genrules run remote by default (and thus, copy_directory tests fail). We could, of course, set local=1, but that disables the sandbox and causes scary warnings. Instead, add a proper empty_directory rule to test with. --- rules/private/copy_common.bzl | 9 ------- tests/copy_directory/BUILD.bazel | 7 +++-- tests/copy_directory/empty_directory.bzl | 34 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 tests/copy_directory/empty_directory.bzl diff --git a/rules/private/copy_common.bzl b/rules/private/copy_common.bzl index 2167c3a0..a8f72439 100644 --- a/rules/private/copy_common.bzl +++ b/rules/private/copy_common.bzl @@ -22,10 +22,6 @@ COPY_EXECUTION_REQUIREMENTS = { # ----------------+----------------------------------------------------------------------------- # no-cache | Results in the action or test never being cached (remotely or locally) # ----------------+----------------------------------------------------------------------------- - # local | Precludes the action or test from being remotely cached, remotely executed, - # | or run inside the sandbox. For genrules and tests, marking the rule with the - # | local = True attribute has the same effect. - # ----------------+----------------------------------------------------------------------------- # See https://bazel.build/reference/be/common-definitions#common-attributes # # Copying file & directories is entirely IO-bound and there is no point doing this work @@ -44,11 +40,6 @@ COPY_EXECUTION_REQUIREMENTS = { # disk cache stores the directory artifact as a single entry, but the slight performance bump # comes at the cost of heavy disk cache usage, which is an unmanaged directory that grow beyond # the bounds of the physical disk. - # - # Sandboxing for this action is wasteful as well since there is a 1:1 mapping of input - # file/directory to output file/directory and no room for non-hermetic inputs to sneak in to the - # input. "no-remote": "1", "no-cache": "1", - "local": "1", } diff --git a/tests/copy_directory/BUILD.bazel b/tests/copy_directory/BUILD.bazel index 2c72ab9b..f766e99f 100644 --- a/tests/copy_directory/BUILD.bazel +++ b/tests/copy_directory/BUILD.bazel @@ -1,6 +1,7 @@ # This package aids testing the 'copy_directory' rule. load("//rules:copy_directory.bzl", "copy_directory") +load(":empty_directory.bzl", "empty_directory") licenses(["notice"]) @@ -13,10 +14,8 @@ copy_directory( out = "dir_copy", ) -genrule( - name = "empty_directory", - outs = ["empty_dir"], - cmd = "mkdir $@", +empty_directory( + name = "empty_dir", ) copy_directory( diff --git a/tests/copy_directory/empty_directory.bzl b/tests/copy_directory/empty_directory.bzl new file mode 100644 index 00000000..92c5a5f6 --- /dev/null +++ b/tests/copy_directory/empty_directory.bzl @@ -0,0 +1,34 @@ +# Copyright 2022 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. + +"""Creates an empty directory.""" + +def _empty_directory_impl(ctx): + out = ctx.actions.declare_directory(ctx.attr.name) + ctx.actions.run_shell( + outputs = [out], + command = "mkdir -p $@", + arguments = [out.path], + mnemonic = "EmptyDirectory", + progress_message = "Creating empty directory %s" % out.path, + use_default_shell_env = True, + execution_requirements = {"no-remote": "1"}, # see rules/private/copy_directory_private.bzl + ) + return [DefaultInfo(files = depset(direct = [out]))] + +empty_directory = rule( + implementation = _empty_directory_impl, + provides = [DefaultInfo], + doc = "Creates an empty directory with the same name as the target", +)