Skip to content

Commit

Permalink
Merge branch 'main' into disable-echo-cmd-copy-dir-file-windows
Browse files Browse the repository at this point in the history
  • Loading branch information
zpervan committed Sep 5, 2022
2 parents 1ab752b + 908bf14 commit 5394065
Show file tree
Hide file tree
Showing 22 changed files with 158 additions and 35 deletions.
23 changes: 23 additions & 0 deletions 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
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
@@ -1,7 +1,7 @@
module(
name = "bazel_skylib",
compatibility_level = 1,
version = "1.2.1",
version = "1.3.0",
)

register_toolchains(
Expand Down
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions docs/BUILD
Expand Up @@ -3,111 +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",
)
Expand Down
2 changes: 1 addition & 1 deletion docs/build_test_doc.md
Expand Up @@ -36,6 +36,6 @@ Typical usage:
| :------------- | :------------- | :------------- |
| <a id="build_test-name"></a>name | The name of the test rule. | none |
| <a id="build_test-targets"></a>targets | A list of targets to ensure build. | none |
| <a id="build_test-kwargs"></a>kwargs | The &lt;a href="https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes-tests"&gt;common attributes for tests&lt;/a&gt;. | none |
| <a id="build_test-kwargs"></a>kwargs | The &lt;a href="https://bazel.build/reference/be/common-definitions#common-attributes-tests"&gt;common attributes for tests&lt;/a&gt;. | none |


2 changes: 1 addition & 1 deletion docs/common_settings_doc.md
Expand Up @@ -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


<a id="bool_flag"></a>
Expand Down
2 changes: 1 addition & 1 deletion docs/diff_test_doc.md
Expand Up @@ -28,6 +28,6 @@ The test succeeds if the files' contents match.
| <a id="diff_test-file1"></a>file1 | Label of the file to compare to &lt;code&gt;file2&lt;/code&gt;. | none |
| <a id="diff_test-file2"></a>file2 | Label of the file to compare to &lt;code&gt;file1&lt;/code&gt;. | none |
| <a id="diff_test-failure_message"></a>failure_message | Additional message to log if the files' contents do not match. | <code>None</code> |
| <a id="diff_test-kwargs"></a>kwargs | The &lt;a href="https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes-tests"&gt;common attributes for tests&lt;/a&gt;. | none |
| <a id="diff_test-kwargs"></a>kwargs | The &lt;a href="https://bazel.build/reference/be/common-definitions#common-attributes-tests"&gt;common attributes for tests&lt;/a&gt;. | none |


2 changes: 1 addition & 1 deletion docs/maintainers_guide.md
Expand Up @@ -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"
```

Expand Down
4 changes: 2 additions & 2 deletions docs/native_binary_doc.md
Expand Up @@ -29,7 +29,7 @@ in genrule.tools for example. You can also augment the binary with runfiles.
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="native_binary-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="native_binary-data"></a>data | data dependencies. See https://docs.bazel.build/versions/main/be/common-definitions.html#typical.data | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
| <a id="native_binary-data"></a>data | data dependencies. See https://bazel.build/reference/be/common-definitions#typical.data | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
| <a id="native_binary-out"></a>out | An output name for the copy of the binary | String | required | |
| <a id="native_binary-src"></a>src | path of the pre-built executable | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |

Expand All @@ -55,7 +55,7 @@ the binary with runfiles.
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="native_test-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="native_test-data"></a>data | data dependencies. See https://docs.bazel.build/versions/main/be/common-definitions.html#typical.data | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
| <a id="native_test-data"></a>data | data dependencies. See https://bazel.build/reference/be/common-definitions#typical.data | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
| <a id="native_test-out"></a>out | An output name for the copy of the binary | String | required | |
| <a id="native_test-src"></a>src | path of the pre-built executable | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |

Expand Down
19 changes: 17 additions & 2 deletions 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.
Expand All @@ -14,22 +28,23 @@ 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`.
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],
Expand Down
4 changes: 2 additions & 2 deletions docs/run_binary_doc.md
Expand Up @@ -22,8 +22,8 @@ Runs a binary as a build action.<br/><br/>This rule does not require Bash (unlik
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="run_binary-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="run_binary-args"></a>args | Command line arguments of the binary.&lt;br/&gt;&lt;br/&gt;Subject to&lt;code&gt;&lt;a href="https://docs.bazel.build/versions/main/be/make-variables.html#location"&gt;$(location)&lt;/a&gt;&lt;/code&gt; expansion. | List of strings | optional | [] |
| <a id="run_binary-env"></a>env | Environment variables of the action.&lt;br/&gt;&lt;br/&gt;Subject to &lt;code&gt;&lt;a href="https://docs.bazel.build/versions/main/be/make-variables.html#location"&gt;$(location)&lt;/a&gt;&lt;/code&gt; expansion. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="run_binary-args"></a>args | Command line arguments of the binary.&lt;br/&gt;&lt;br/&gt;Subject to&lt;code&gt;&lt;a href="https://bazel.build/reference/be/make-variables#predefined_label_variables"&gt;$(location)&lt;/a&gt;&lt;/code&gt; expansion. | List of strings | optional | [] |
| <a id="run_binary-env"></a>env | Environment variables of the action.&lt;br/&gt;&lt;br/&gt;Subject to &lt;code&gt;&lt;a href="https://bazel.build/reference/be/make-variables#predefined_label_variables"&gt;$(location)&lt;/a&gt;&lt;/code&gt; expansion. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="run_binary-outs"></a>outs | Output files generated by the action.&lt;br/&gt;&lt;br/&gt;These labels are available for &lt;code&gt;$(location)&lt;/code&gt; expansion in &lt;code&gt;args&lt;/code&gt; and &lt;code&gt;env&lt;/code&gt;. | List of labels | required | |
| <a id="run_binary-srcs"></a>srcs | Additional inputs of the action.&lt;br/&gt;&lt;br/&gt;These labels are available for &lt;code&gt;$(location)&lt;/code&gt; expansion in &lt;code&gt;args&lt;/code&gt; and &lt;code&gt;env&lt;/code&gt;. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
| <a id="run_binary-tool"></a>tool | The tool to run in the action.&lt;br/&gt;&lt;br/&gt;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 &lt;code&gt;$(location)&lt;/code&gt; expansion in &lt;code&gt;args&lt;/code&gt; and &lt;code&gt;env&lt;/code&gt;. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
Expand Down
28 changes: 28 additions & 0 deletions docs/select_file_doc.md
@@ -0,0 +1,28 @@
<!-- Generated with Stardoc: http://skydoc.bazel.build -->


select_file() build rule implementation.

Selects a single file from the outputs of a target by given relative path.


<a id="select_file"></a>

## select_file

<pre>
select_file(<a href="#select_file-name">name</a>, <a href="#select_file-srcs">srcs</a>, <a href="#select_file-subpath">subpath</a>)
</pre>

Selects a single file from the outputs of a target by given relative path

**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="select_file-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="select_file-srcs"></a>srcs | The target producing the file among other outputs | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="select_file-subpath"></a>subpath | Relative path to the file | String | required | |


2 changes: 1 addition & 1 deletion rules/build_test.bzl
Expand Up @@ -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 <a href="https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes-tests">common attributes for tests</a>.
**kwargs: The <a href="https://bazel.build/reference/be/common-definitions#common-attributes-tests">common attributes for tests</a>.
"""
if len(targets) == 0:
fail("targets must be non-empty", "targets")
Expand Down
2 changes: 1 addition & 1 deletion rules/common_settings.bzl
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion rules/diff_test.bzl
Expand Up @@ -164,7 +164,7 @@ def diff_test(name, file1, file2, failure_message = None, **kwargs):
file1: Label of the file to compare to <code>file2</code>.
file2: Label of the file to compare to <code>file1</code>.
failure_message: Additional message to log if the files' contents do not match.
**kwargs: The <a href="https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes-tests">common attributes for tests</a>.
**kwargs: The <a href="https://bazel.build/reference/be/common-definitions#common-attributes-tests">common attributes for tests</a>.
"""
_diff_test(
name = name,
Expand Down
2 changes: 1 addition & 1 deletion rules/native_binary.bzl
Expand Up @@ -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"),
Expand Down
11 changes: 1 addition & 10 deletions rules/private/copy_common.bzl
Expand Up @@ -22,11 +22,7 @@ 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.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.
Expand All @@ -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",
}

0 comments on commit 5394065

Please sign in to comment.