From 70d01b7780bb3fe79473463f693479b693bfb826 Mon Sep 17 00:00:00 2001 From: Derek Cormier Date: Wed, 15 Nov 2023 12:51:41 -0800 Subject: [PATCH] fix(ci): enable bzlmod on ci runs --- .github/workflows/ci.yaml | 7 ++++--- BUILD.bazel | 12 +++++++++--- WORKSPACE | 4 ++++ docs/copy_to_bin.md | 2 +- docs/copy_to_directory.md | 26 +++++++++++++------------- docs/directory_path.md | 4 ++-- docs/expand_make_vars.md | 4 ++-- docs/expand_template.md | 16 ++++++++-------- docs/host_repo.md | 4 ++-- docs/jq.md | 6 +++--- docs/output_files.md | 6 +++--- docs/paths.md | 22 +++++++++++----------- docs/repo_utils.md | 6 +++--- docs/stamping.md | 12 ++++++------ docs/tar.md | 20 ++++++++++---------- docs/transitions.md | 14 +++++++------- docs/utils.md | 8 ++++---- docs/yq.md | 4 ++-- internal_deps.bzl | 6 +++--- lib/tests/utils_test.bzl | 6 +++--- 20 files changed, 100 insertions(+), 89 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3f4d5d792..d243c1862 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -174,7 +174,8 @@ jobs: --bazelrc=${{ github.workspace }}/.github/workflows/ci.bazelrc \ --bazelrc=${{ github.workspace }}/.aspect/bazelrc/bazel${BAZEL_VERSION::1}.bazelrc \ --bazelrc=.bazelrc \ - test --config=${{ matrix.config }} //... + test --config=${{ matrix.config }} //... \ + ${{ steps.set_bzlmod_flag.outputs.bzlmod_flag }} env: # Bazelisk will download bazel to here XDG_CACHE_HOME: ~/.cache/bazel-repo @@ -189,8 +190,8 @@ jobs: --bazelrc=${{ github.workspace }}/.github/workflows/ci.bazelrc ` --bazelrc=${{ github.workspace }}/.aspect/bazelrc/bazel$BAZEL_MAJOR_VERSION.bazelrc ` --bazelrc=.bazelrc ` - ${{ steps.set_bzlmod_flag.outputs.bzlmod_flag }} ` - test --config=${{ matrix.config }} //... + test --config=${{ matrix.config }} //... ` + ${{ steps.set_bzlmod_flag.outputs.bzlmod_flag }} env: # Bazelisk will download bazel to here XDG_CACHE_HOME: ~/.cache/bazel-repo diff --git a/BUILD.bazel b/BUILD.bazel index 07e5eaa71..197753d4e 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -13,9 +13,15 @@ load("//lib:yq.bzl", "yq") gazelle_binary( name = "gazelle_bin", - languages = DEFAULT_LANGUAGES + [ - "@bazel_skylib_gazelle_plugin//bzl", - ], + languages = select({ + # TODO: under bzlmod we get go linking errors when adding + # the skylib gazelle plugin. + # https://github.com/bazelbuild/rules_go/issues/1877 + "@aspect_bazel_lib//lib:bzlmod": DEFAULT_LANGUAGES, + "//conditions:default": DEFAULT_LANGUAGES + [ + "@bazel_skylib_gazelle_plugin//bzl", + ], + }), ) gazelle( diff --git a/WORKSPACE b/WORKSPACE index 9b127f4bb..30702e6f5 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -10,6 +10,10 @@ load(":internal_deps.bzl", "bazel_lib_internal_deps") # Fetch deps needed only locally for development bazel_lib_internal_deps() +load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories") + +stardoc_repositories() + load("//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "aspect_bazel_lib_register_toolchains") aspect_bazel_lib_dependencies() diff --git a/docs/copy_to_bin.md b/docs/copy_to_bin.md index 74de42bac..753725ec2 100644 --- a/docs/copy_to_bin.md +++ b/docs/copy_to_bin.md @@ -79,7 +79,7 @@ copy_to_bin(name, sr Copies a source file to output tree at the same workspace-relative path. -e.g. `/path/to/file -> /bazel-out//bin/path/to/file` +e.g. `<execroot>/path/to/file -> <execroot>/bazel-out/<platform>/bin/path/to/file` If a file passed in is already in the output tree is then it is added directly to the DefaultInfo provided by the rule without a copy. diff --git a/docs/copy_to_directory.md b/docs/copy_to_directory.md index 1bffe3024..23acc61b6 100644 --- a/docs/copy_to_directory.md +++ b/docs/copy_to_directory.md @@ -50,19 +50,19 @@ for more information on supported globbing patterns. | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| allow_overwrites | If True, allow files to be overwritten if the same output file is copied to twice.

The order of srcs matters as the last copy of a particular file will win when overwriting. Performance of copy_to_directory will be slightly degraded when allow_overwrites is True since copies cannot be parallelized out as they are calculated. Instead all copy paths must be calculated before any copies can be started. | Boolean | optional | False | -| exclude_srcs_packages | List of Bazel packages (with glob support) to exclude from output directory.

Files in srcs are not copied to the output directory if the Bazel package of the file matches one of the patterns specified.

Forward slashes (/) should be used as path separators. A first character of "." will be replaced by the target's package path.

Files that have do not have matching Bazel packages are subject to subsequent filters and transformations to determine if they are copied and what their path in the output directory will be.

Globs are supported (see rule docstring above). | List of strings | optional | [] | -| exclude_srcs_patterns | List of paths (with glob support) to exclude from output directory.

Files in srcs are not copied to the output directory if their output directory path, after applying root_paths, matches one of the patterns specified.

Forward slashes (/) should be used as path separators.

Files that do not have matching output directory paths are subject to subsequent filters and transformations to determine if they are copied and what their path in the output directory will be.

Globs are supported (see rule docstring above). | List of strings | optional | [] | -| hardlink | Controls when to use hardlinks to files instead of making copies.

Creating hardlinks is much faster than making copies of files with the caveat that hardlinks share file permissions with their source.

Since Bazel removes write permissions on files in the output tree after an action completes, hardlinks to source files are not recommended since write permissions will be inadvertently removed from sources files.

- auto: hardlinks are used for generated files already in the output tree - off: all files are copied - on: hardlinks are used for all files (not recommended) | String | optional | "auto" | -| include_external_repositories | List of external repository names (with glob support) to include in the output directory.

Files from external repositories are only copied into the output directory if the external repository they come from matches one of the external repository patterns specified or if they are in the same external repository as this target.

When copied from an external repository, the file path in the output directory defaults to the file's path within the external repository. The external repository name is _not_ included in that path.

For example, the following copies @external_repo//path/to:file to path/to/file within the output directory.

 copy_to_directory(     name = "dir",     include_external_repositories = ["external_*"],     srcs = ["@external_repo//path/to:file"], ) 


Files that come from matching external are subject to subsequent filters and transformations to determine if they are copied and what their path in the output directory will be. The external repository name of the file from an external repository is not included in the output directory path and is considered in subsequent filters and transformations.

Globs are supported (see rule docstring above). | List of strings | optional | [] | -| include_srcs_packages | List of Bazel packages (with glob support) to include in output directory.

Files in srcs are only copied to the output directory if the Bazel package of the file matches one of the patterns specified.

Forward slashes (/) should be used as path separators. A first character of "." will be replaced by the target's package path.

Defaults to ["**"] which includes sources from all packages.

Files that have matching Bazel packages are subject to subsequent filters and transformations to determine if they are copied and what their path in the output directory will be.

Globs are supported (see rule docstring above). | List of strings | optional | ["**"] | -| include_srcs_patterns | List of paths (with glob support) to include in output directory.

Files in srcs are only copied to the output directory if their output directory path, after applying root_paths, matches one of the patterns specified.

Forward slashes (/) should be used as path separators.

Defaults to ["**"] which includes all sources.

Files that have matching output directory paths are subject to subsequent filters and transformations to determine if they are copied and what their path in the output directory will be.

Globs are supported (see rule docstring above). | List of strings | optional | ["**"] | -| out | Path of the output directory, relative to this package.

If not set, the name of the target is used. | String | optional | "" | -| replace_prefixes | Map of paths prefixes (with glob support) to replace in the output directory path when copying files.

If the output directory path for a file starts with or fully matches a a key in the dict then the matching portion of the output directory path is replaced with the dict value for that key. The final path segment matched can be a partial match of that segment and only the matching portion will be replaced. If there are multiple keys that match, the longest match wins.

Forward slashes (/) should be used as path separators.

Replace prefix transformation are the final step in the list of filters and transformations. The final output path of a file being copied into the output directory is determined at this step.

Globs are supported (see rule docstring above). | Dictionary: String -> String | optional | {} | -| root_paths | List of paths (with glob support) that are roots in the output directory.

If any parent directory of a file being copied matches one of the root paths patterns specified, the output directory path will be the path relative to the root path instead of the path relative to the file's workspace. If there are multiple root paths that match, the longest match wins.

Matching is done on the parent directory of the output file path so a trailing '**' glob patterm will match only up to the last path segment of the dirname and will not include the basename. Only complete path segments are matched. Partial matches on the last segment of the root path are ignored.

Forward slashes (/) should be used as path separators.

A "." value expands to the target's package path (ctx.label.package).

Defaults to ["."] which results in the output directory path of files in the target's package and and sub-packages are relative to the target's package and files outside of that retain their full workspace relative paths.

Globs are supported (see rule docstring above). | List of strings | optional | ["."] | -| srcs | Files and/or directories or targets that provide DirectoryPathInfo to copy into the output directory. | List of labels | optional | [] | -| verbose | If true, prints out verbose logs to stdout | Boolean | optional | False | +| name | A unique name for this target. | Name | required | | +| allow_overwrites | If True, allow files to be overwritten if the same output file is copied to twice.

The order of srcs matters as the last copy of a particular file will win when overwriting. Performance of copy_to_directory will be slightly degraded when allow_overwrites is True since copies cannot be parallelized out as they are calculated. Instead all copy paths must be calculated before any copies can be started. | Boolean | optional | False | +| exclude_srcs_packages | List of Bazel packages (with glob support) to exclude from output directory.

Files in srcs are not copied to the output directory if the Bazel package of the file matches one of the patterns specified.

Forward slashes (/) should be used as path separators. A first character of "." will be replaced by the target's package path.

Files that have do not have matching Bazel packages are subject to subsequent filters and transformations to determine if they are copied and what their path in the output directory will be.

Globs are supported (see rule docstring above). | List of strings | optional | [] | +| exclude_srcs_patterns | List of paths (with glob support) to exclude from output directory.

Files in srcs are not copied to the output directory if their output directory path, after applying root_paths, matches one of the patterns specified.

Forward slashes (/) should be used as path separators.

Files that do not have matching output directory paths are subject to subsequent filters and transformations to determine if they are copied and what their path in the output directory will be.

Globs are supported (see rule docstring above). | List of strings | optional | [] | +| hardlink | Controls when to use hardlinks to files instead of making copies.

Creating hardlinks is much faster than making copies of files with the caveat that hardlinks share file permissions with their source.

Since Bazel removes write permissions on files in the output tree after an action completes, hardlinks to source files are not recommended since write permissions will be inadvertently removed from sources files.

- auto: hardlinks are used for generated files already in the output tree - off: all files are copied - on: hardlinks are used for all files (not recommended) | String | optional | "auto" | +| include_external_repositories | List of external repository names (with glob support) to include in the output directory.

Files from external repositories are only copied into the output directory if the external repository they come from matches one of the external repository patterns specified or if they are in the same external repository as this target.

When copied from an external repository, the file path in the output directory defaults to the file's path within the external repository. The external repository name is _not_ included in that path.

For example, the following copies @external_repo//path/to:file to path/to/file within the output directory.

 copy_to_directory(     name = "dir",     include_external_repositories = ["external_*"],     srcs = ["@external_repo//path/to:file"], ) 


Files that come from matching external are subject to subsequent filters and transformations to determine if they are copied and what their path in the output directory will be. The external repository name of the file from an external repository is not included in the output directory path and is considered in subsequent filters and transformations.

Globs are supported (see rule docstring above). | List of strings | optional | [] | +| include_srcs_packages | List of Bazel packages (with glob support) to include in output directory.

Files in srcs are only copied to the output directory if the Bazel package of the file matches one of the patterns specified.

Forward slashes (/) should be used as path separators. A first character of "." will be replaced by the target's package path.

Defaults to ["**"] which includes sources from all packages.

Files that have matching Bazel packages are subject to subsequent filters and transformations to determine if they are copied and what their path in the output directory will be.

Globs are supported (see rule docstring above). | List of strings | optional | ["**"] | +| include_srcs_patterns | List of paths (with glob support) to include in output directory.

Files in srcs are only copied to the output directory if their output directory path, after applying root_paths, matches one of the patterns specified.

Forward slashes (/) should be used as path separators.

Defaults to ["**"] which includes all sources.

Files that have matching output directory paths are subject to subsequent filters and transformations to determine if they are copied and what their path in the output directory will be.

Globs are supported (see rule docstring above). | List of strings | optional | ["**"] | +| out | Path of the output directory, relative to this package.

If not set, the name of the target is used. | String | optional | "" | +| replace_prefixes | Map of paths prefixes (with glob support) to replace in the output directory path when copying files.

If the output directory path for a file starts with or fully matches a a key in the dict then the matching portion of the output directory path is replaced with the dict value for that key. The final path segment matched can be a partial match of that segment and only the matching portion will be replaced. If there are multiple keys that match, the longest match wins.

Forward slashes (/) should be used as path separators.

Replace prefix transformation are the final step in the list of filters and transformations. The final output path of a file being copied into the output directory is determined at this step.

Globs are supported (see rule docstring above). | Dictionary: String -> String | optional | {} | +| root_paths | List of paths (with glob support) that are roots in the output directory.

If any parent directory of a file being copied matches one of the root paths patterns specified, the output directory path will be the path relative to the root path instead of the path relative to the file's workspace. If there are multiple root paths that match, the longest match wins.

Matching is done on the parent directory of the output file path so a trailing '**' glob patterm will match only up to the last path segment of the dirname and will not include the basename. Only complete path segments are matched. Partial matches on the last segment of the root path are ignored.

Forward slashes (/) should be used as path separators.

A "." value expands to the target's package path (ctx.label.package).

Defaults to ["."] which results in the output directory path of files in the target's package and and sub-packages are relative to the target's package and files outside of that retain their full workspace relative paths.

Globs are supported (see rule docstring above). | List of strings | optional | ["."] | +| srcs | Files and/or directories or targets that provide DirectoryPathInfo to copy into the output directory. | List of labels | optional | [] | +| verbose | If true, prints out verbose logs to stdout | Boolean | optional | False | diff --git a/docs/directory_path.md b/docs/directory_path.md index f738326db..dc29a4d26 100644 --- a/docs/directory_path.md +++ b/docs/directory_path.md @@ -21,8 +21,8 @@ Otherwise there is no way to give a Bazel label for it. | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| directory | a TreeArtifact (ctx.actions.declare_directory) | Label | required | | +| name | A unique name for this target. | Name | required | | +| directory | a TreeArtifact (ctx.actions.declare_directory) | Label | required | | | path | path relative to the directory | String | required | | diff --git a/docs/expand_make_vars.md b/docs/expand_make_vars.md index 1d2b7884b..d96be2646 100644 --- a/docs/expand_make_vars.md +++ b/docs/expand_make_vars.md @@ -29,8 +29,8 @@ This is of the format: - `./file` - `path/to/file` - `external/external_repo/path/to/file` -- `/path/to/file` -- `/external/external_repo/path/to/file` +- `<bin_dir>/path/to/file` +- `<bin_dir>/external/external_repo/path/to/file` The deprecated `$(location)` and `$(locations)` expansions returns either the execpath or rootpath depending on the context. diff --git a/docs/expand_template.md b/docs/expand_template.md index 989af81bc..e59911d81 100644 --- a/docs/expand_template.md +++ b/docs/expand_template.md @@ -28,14 +28,14 @@ such as `$(BINDIR)`, `$(TARGET_CPU)`, and `$(COMPILATION_MODE)` as documented in | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| data | List of targets for additional lookup information. | List of labels | optional | [] | -| is_executable | Whether to mark the output file as executable. | Boolean | optional | False | -| out | Where to write the expanded file.

If unset, the template must be a source file and the output file will be named the same as the template file and outputted to the same workspace-relative path. In this case there will be no pre-declared label for the output file. It can be referenced by the target label instead. This pattern is similar to copy_to_bin but with substitutions on the copy. | Label | optional | | -| stamp | Whether to encode build information into the output. Possible values:

- stamp = 1: Always stamp the build information into the output, even in [--nostamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) builds. This setting should be avoided, since it is non-deterministic. It potentially causes remote cache misses for the target and any downstream actions that depend on the result. - stamp = 0: Never stamp, instead replace build information by constant values. This gives good build result caching. - stamp = -1: Embedding of build information is controlled by the [--[no]stamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) flag. Stamped targets are not rebuilt unless their dependencies change. | Integer | optional | -1 | -| stamp_substitutions | Mapping of strings to substitutions.

There are overlayed on top of substitutions when stamping is enabled for the target.

Substitutions can contain $(execpath :target) and $(rootpath :target) expansions, $(MAKEVAR) expansions and {{STAMP_VAR}} expansions when stamping is enabled for the target. | Dictionary: String -> String | optional | {} | -| substitutions | Mapping of strings to substitutions.

Substitutions can contain $(execpath :target) and $(rootpath :target) expansions, $(MAKEVAR) expansions and {{STAMP_VAR}} expansions when stamping is enabled for the target. | Dictionary: String -> String | optional | {} | -| template | The template file to expand. | Label | required | | +| name | A unique name for this target. | Name | required | | +| data | List of targets for additional lookup information. | List of labels | optional | [] | +| is_executable | Whether to mark the output file as executable. | Boolean | optional | False | +| out | Where to write the expanded file.

If unset, the template must be a source file and the output file will be named the same as the template file and outputted to the same workspace-relative path. In this case there will be no pre-declared label for the output file. It can be referenced by the target label instead. This pattern is similar to copy_to_bin but with substitutions on the copy. | Label | optional | | +| stamp | Whether to encode build information into the output. Possible values:

- stamp = 1: Always stamp the build information into the output, even in [--nostamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) builds. This setting should be avoided, since it is non-deterministic. It potentially causes remote cache misses for the target and any downstream actions that depend on the result. - stamp = 0: Never stamp, instead replace build information by constant values. This gives good build result caching. - stamp = -1: Embedding of build information is controlled by the [--[no]stamp](https://docs.bazel.build/versions/main/user-manual.html#flag--stamp) flag. Stamped targets are not rebuilt unless their dependencies change. | Integer | optional | -1 | +| stamp_substitutions | Mapping of strings to substitutions.

There are overlayed on top of substitutions when stamping is enabled for the target.

Substitutions can contain $(execpath :target) and $(rootpath :target) expansions, $(MAKEVAR) expansions and {{STAMP_VAR}} expansions when stamping is enabled for the target. | Dictionary: String -> String | optional | {} | +| substitutions | Mapping of strings to substitutions.

Substitutions can contain $(execpath :target) and $(rootpath :target) expansions, $(MAKEVAR) expansions and {{STAMP_VAR}} expansions when stamping is enabled for the target. | Dictionary: String -> String | optional | {} | +| template | The template file to expand. | Label | required | | diff --git a/docs/host_repo.md b/docs/host_repo.md index 5da26ca14..a3e432198 100644 --- a/docs/host_repo.md +++ b/docs/host_repo.md @@ -17,7 +17,7 @@ Exposes information about the host platform | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this repository. | Name | required | | -| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | +| name | A unique name for this repository. | Name | required | | +| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | | diff --git a/docs/jq.md b/docs/jq.md index 068262f36..79cf3ea35 100644 --- a/docs/jq.md +++ b/docs/jq.md @@ -85,7 +85,7 @@ jq( "--raw-input", "--slurp", ], - filter = "{ deps: split("\n") | map(select(. | length > 0)) }", + filter = "{ deps: split("\n") | map(select(. | length > 0)) }", ) # With --stamp, causes properties to be replaced by version control info. @@ -97,7 +97,7 @@ jq( # This 'as' syntax results in $stamp being null in unstamped builds. "$ARGS.named.STAMP as $stamp", # Provide a default using the "alternative operator" in case $stamp is null. - ".version = ($stamp[0].BUILD_EMBED_LABEL // "")", + ".version = ($stamp[0].BUILD_EMBED_LABEL // "<unstamped>")", ]), ) ``` @@ -110,7 +110,7 @@ genrule( name = "case_genrule", srcs = ["a.json"], outs = ["genrule_output.json"], - cmd = "$(JQ_BIN) '.' $(location a.json) > $@", + cmd = "$(JQ_BIN) '.' $(location a.json) > $@", toolchains = ["@jq_toolchains//:resolved_toolchain"], ) ``` diff --git a/docs/output_files.md b/docs/output_files.md index 26e2562e3..97d23030b 100644 --- a/docs/output_files.md +++ b/docs/output_files.md @@ -18,10 +18,10 @@ A rule that provides file(s) specific via DefaultInfo from a given target's Defa | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| output_group | if set, we look in the specified output group for paths instead of DefaultInfo | String | optional | "" | +| name | A unique name for this target. | Name | required | | +| output_group | if set, we look in the specified output group for paths instead of DefaultInfo | String | optional | "" | | paths | the paths of the file(s), relative to their roots, to provide via DefaultInfo from the given target's DefaultInfo or OutputGroupInfo | List of strings | required | | -| target | the target to look in for requested paths in its' DefaultInfo or OutputGroupInfo | Label | required | | +| target | the target to look in for requested paths in its' DefaultInfo or OutputGroupInfo | Label | required | | diff --git a/docs/paths.md b/docs/paths.md index c6f21b08b..83cc00c79 100644 --- a/docs/paths.md +++ b/docs/paths.md @@ -96,20 +96,20 @@ This produces the same value as the `rlocationpath` predefined source/output pat From https://bazel.build/reference/be/make-variables#predefined_genrule_variables: -> `rlocationpath`: The path a built binary can pass to the `Rlocation` function of a runfiles -> library to find a dependency at runtime, either in the runfiles directory (if available) -> or using the runfiles manifest. +> `rlocationpath`: The path a built binary can pass to the `Rlocation` function of a runfiles +> library to find a dependency at runtime, either in the runfiles directory (if available) +> or using the runfiles manifest. -> This is similar to root path (a.k.a. [short_path](https://bazel.build/rules/lib/File#short_path)) -> in that it does not contain configuration prefixes, but differs in that it always starts with the -> name of the repository. +> This is similar to root path (a.k.a. [short_path](https://bazel.build/rules/lib/File#short_path)) +> in that it does not contain configuration prefixes, but differs in that it always starts with the +> name of the repository. -> The rlocation path of a `File` in an external repository repo will start with `repo/`, followed by the -> repository-relative path. +> The rlocation path of a `File` in an external repository repo will start with `repo/`, followed by the +> repository-relative path. -> Passing this path to a binary and resolving it to a file system path using the runfiles libraries -> is the preferred approach to find dependencies at runtime. Compared to root path, it has the -> advantage that it works on all platforms and even if the runfiles directory is not available. +> Passing this path to a binary and resolving it to a file system path using the runfiles libraries +> is the preferred approach to find dependencies at runtime. Compared to root path, it has the +> advantage that it works on all platforms and even if the runfiles directory is not available. **PARAMETERS** diff --git a/docs/repo_utils.md b/docs/repo_utils.md index 8b8066948..50d80c675 100644 --- a/docs/repo_utils.md +++ b/docs/repo_utils.md @@ -145,8 +145,8 @@ Returns a normalized name of the host os and CPU architecture. Alias archictures names are normalized: -x86_64 => amd64 -aarch64 => arm64 +x86_64 => amd64 +aarch64 => arm64 The result can be used to generate repository names for host toolchain repositories for toolchains that use these normalized names. @@ -171,6 +171,6 @@ Common os & architecture pairs that are returned are, **RETURNS** -The normalized "_" string of the host os and CPU architecture. +The normalized "<os>_<arch>" string of the host os and CPU architecture. diff --git a/docs/stamping.md b/docs/stamping.md index 401c497e6..972be9c7b 100644 --- a/docs/stamping.md +++ b/docs/stamping.md @@ -9,8 +9,8 @@ See [the Bazel workspace status docs](https://docs.bazel.build/versions/master/u To stamp a build, you pass the `--stamp` argument to Bazel. -> Note: https://github.com/bazelbuild/bazel/issues/14341 proposes that Bazel enforce this by -> only giving constant values to rule implementations when stamping isn't enabled. +> Note: https://github.com/bazelbuild/bazel/issues/14341 proposes that Bazel enforce this by +> only giving constant values to rule implementations when stamping isn't enabled. Stamping is typically performed on a later action in the graph, like on a linking or packaging rule (`pkg_*`). This means that a changed status variable only causes that action, not re-compilation and thus does not cause cascading re-builds. @@ -31,13 +31,13 @@ The value of this flag is a path to a script that prints space-separated key/val #!/usr/bin/env bash echo STABLE_GIT_COMMIT $(git rev-parse HEAD) ``` -> For a more full-featured script, take a look at this [example in Angular] +> For a more full-featured script, take a look at this [example in Angular] Make sure you set the executable bit, eg. `chmod +x tools/bazel_stamp_vars.sh`. -> **NOTE** keys that start with `STABLE_` will cause a re-build when they change. -> Other keys will NOT cause a re-build, so stale values can appear in your app. -> Non-stable (volatile) keys should typically be things like timestamps that always vary between builds. +> **NOTE** keys that start with `STABLE_` will cause a re-build when they change. +> Other keys will NOT cause a re-build, so stale values can appear in your app. +> Non-stable (volatile) keys should typically be things like timestamps that always vary between builds. You might like to encode your setup using an entry in `.bazelrc` such as: diff --git a/docs/tar.md b/docs/tar.md index d7f94ba5b..ef0e63d4b 100644 --- a/docs/tar.md +++ b/docs/tar.md @@ -35,9 +35,9 @@ Create an mtree specification to map a directory hierarchy. See https://man.free | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| out | Resulting specification file to write | Label | optional | | -| srcs | Files that are placed into the tar | List of labels | required | | +| name | A unique name for this target. | Name | required | | +| out | Resulting specification file to write | Label | optional | | +| srcs | Files that are placed into the tar | List of labels | required | | @@ -55,13 +55,13 @@ Rule that executes BSD `tar`. Most users should use the [`tar`](#tar) macro, rat | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| args | Additional flags permitted by BSD tar; see the man page. | List of strings | optional | [] | -| compress | Compress the archive file with a supported algorithm. | String | optional | "" | -| mode | A mode indicator from the following list, copied from the tar manpage:

- create: Create a new archive containing the specified items. - append: Like create, but new entries are appended to the archive. Note that this only works on uncompressed archives stored in regular files. The -f option is required. - list: List archive contents to stdout. - update: Like append, but new entries are added only if they have a modification date newer than the corresponding entry in the archive. Note that this only works on uncompressed archives stored in regular files. The -f option is required. - extract: Extract to disk from the archive. If a file with the same name appears more than once in the archive, each copy will be extracted, with later copies overwriting (replacing) earlier copies. | String | optional | "create" | -| mtree | An mtree specification file | Label | required | | -| out | Resulting tar file to write. If absent, [name].tar is written. | Label | optional | | -| srcs | Files, directories, or other targets whose default outputs are placed into the tar.

If any of the srcs are binaries with runfiles, those are copied into the resulting tar as well. | List of labels | required | | +| name | A unique name for this target. | Name | required | | +| args | Additional flags permitted by BSD tar; see the man page. | List of strings | optional | [] | +| compress | Compress the archive file with a supported algorithm. | String | optional | "" | +| mode | A mode indicator from the following list, copied from the tar manpage:

- create: Create a new archive containing the specified items. - append: Like create, but new entries are appended to the archive. Note that this only works on uncompressed archives stored in regular files. The -f option is required. - list: List archive contents to stdout. - update: Like append, but new entries are added only if they have a modification date newer than the corresponding entry in the archive. Note that this only works on uncompressed archives stored in regular files. The -f option is required. - extract: Extract to disk from the archive. If a file with the same name appears more than once in the archive, each copy will be extracted, with later copies overwriting (replacing) earlier copies. | String | optional | "create" | +| mtree | An mtree specification file | Label | required | | +| out | Resulting tar file to write. If absent, [name].tar is written. | Label | optional | | +| srcs | Files, directories, or other targets whose default outputs are placed into the tar.

If any of the srcs are binaries with runfiles, those are copied into the resulting tar as well. | List of labels | required | | diff --git a/docs/transitions.md b/docs/transitions.md index bf172c408..83b656179 100644 --- a/docs/transitions.md +++ b/docs/transitions.md @@ -17,10 +17,10 @@ Transitions the binary to use the provided platform. | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| basename | - | String | optional | "" | -| binary | - | Label | optional | None | -| target_platform | The target platform to transition the binary. | Label | required | | +| name | A unique name for this target. | Name | required | | +| basename | - | String | optional | "" | +| binary | - | Label | optional | None | +| target_platform | The target platform to transition the binary. | Label | required | | @@ -38,8 +38,8 @@ Transitions the srcs to use the provided platform. The filegroup will contain ar | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| srcs | The input to be transitioned to the target platform. | List of labels | optional | [] | -| target_platform | The target platform to transition the srcs. | Label | required | | +| name | A unique name for this target. | Name | required | | +| srcs | The input to be transitioned to the target platform. | List of labels | optional | [] | +| target_platform | The target platform to transition the srcs. | Label | required | | diff --git a/docs/utils.md b/docs/utils.md index be2399902..8c28e1206 100644 --- a/docs/utils.md +++ b/docs/utils.md @@ -46,15 +46,15 @@ Provide a sane default for *_test timeout attribute. The [test-encyclopedia](https://bazel.build/reference/test-encyclopedia) says: -> Tests may return arbitrarily fast regardless of timeout. -> A test is not penalized for an overgenerous timeout, although a warning may be issued: -> you should generally set your timeout as tight as you can without incurring any flakiness. +> Tests may return arbitrarily fast regardless of timeout. +> A test is not penalized for an overgenerous timeout, although a warning may be issued: +> you should generally set your timeout as tight as you can without incurring any flakiness. However Bazel's default for timeout is medium, which is dumb given this guidance. It also says: -> Tests which do not explicitly specify a timeout have one implied based on the test's size as follows +> Tests which do not explicitly specify a timeout have one implied based on the test's size as follows Therefore if size is specified, we should allow timeout to take its implied default. If neither is set, then we can fix Bazel's wrong default here to avoid warnings under diff --git a/docs/yq.md b/docs/yq.md index 79663a710..e39caa2e6 100644 --- a/docs/yq.md +++ b/docs/yq.md @@ -83,7 +83,7 @@ genrule( name = "generate", srcs = ["farm.yaml"], outs = ["genrule_output.yaml"], - cmd = "$(YQ_BIN) '.moo = "cow"' $(location farm.yaml) > $@", + cmd = "$(YQ_BIN) '.moo = "cow"' $(location farm.yaml) > $@", toolchains = ["@yq_toolchains//:resolved_toolchain"], ) ``` @@ -96,7 +96,7 @@ yq( expression = "|".join([ "load(strenv(STAMP)) as $stamp", # Provide a default using the "alternative operator" in case $stamp is empty dict. - ".version = ($stamp.BUILD_EMBED_LABEL // "")", + ".version = ($stamp.BUILD_EMBED_LABEL // "<unstamped>")", ]), ) ``` diff --git a/internal_deps.bzl b/internal_deps.bzl index 86e054a89..08d7d1f17 100644 --- a/internal_deps.bzl +++ b/internal_deps.bzl @@ -46,10 +46,10 @@ def bazel_lib_internal_deps(): http_archive( name = "io_bazel_stardoc", - sha256 = "aa814dae0ac400bbab2e8881f9915c6f47c49664bf087c409a15f90438d2c23e", + sha256 = "ec57139e466faae563f2fc39609da4948a479bb51b6d67aedd7d9b1b8059c433", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.5.1/stardoc-0.5.1.tar.gz", - "https://github.com/bazelbuild/stardoc/releases/download/0.5.1/stardoc-0.5.1.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.5.4/stardoc-0.5.4.tar.gz", + "https://github.com/bazelbuild/stardoc/releases/download/0.5.4/stardoc-0.5.4.tar.gz", ], ) diff --git a/lib/tests/utils_test.bzl b/lib/tests/utils_test.bzl index c1f095207..c1bc90af4 100644 --- a/lib/tests/utils_test.bzl +++ b/lib/tests/utils_test.bzl @@ -59,7 +59,7 @@ def _is_external_label_test_impl(ctx): asserts.false(env, utils.is_external_label("@@//some/label")) # assert that labels and string that give a workspace return true - asserts.true(env, utils.is_external_label(Label("@foo//some/label"))) + asserts.true(env, utils.is_external_label(Label("@bazel_skylib//some/label"))) asserts.true(env, ctx.attr.external_as_string) return unittest.end(env) @@ -134,7 +134,7 @@ def _consistent_label_str_impl(ctx): asserts.equals(env, "@//foo:bar", utils.consistent_label_str(ctx, Label("//foo:bar"))) asserts.equals(env, "@//foo:bar", utils.consistent_label_str(ctx, Label("@//foo:bar"))) asserts.equals(env, "@//foo:bar", utils.consistent_label_str(ctx, Label("@aspect_bazel_lib//foo:bar"))) - asserts.equals(env, "@external_workspace//foo:bar", utils.consistent_label_str(ctx, Label("@external_workspace//foo:bar"))) + asserts.equals(env, "@bazel_skylib//foo:bar", utils.consistent_label_str(ctx, Label("@bazel_skylib//foo:bar"))) return unittest.end(env) @@ -184,7 +184,7 @@ def utils_test_suite(): is_external_label_test( name = "is_external_label_tests", - external_as_string = utils.is_external_label("@foo//some/label"), + external_as_string = utils.is_external_label("@bazel_skylib//some/label"), internal_with_workspace_as_string = utils.is_external_label("@aspect_bazel_lib//some/label"), timeout = "short", )