fix(ci): fix bzlmod issues and enable on ci (#658)

This commit is contained in:
Derek Cormier 2023-11-15 15:07:03 -08:00 committed by GitHub
parent e233a808c1
commit 5bd6e5fdd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 208 additions and 114 deletions

View File

@ -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
@ -199,7 +200,7 @@ jobs:
# Don't run integration tests on Windows since they are bash scripts and Windows runs Powershell
if: ${{ matrix.folder == '.' && matrix.os != 'windows-latest' }}
# Find all shell scripts within e2e, echo the filename, execute, fail on error
run: find e2e/*.sh -maxdepth 1 -type f -exec sh -c 'echo "\n\n------------------------------- $0 -------------------------------" && "$0" || kill $PPID' \{\} \;
run: find e2e/*.sh -maxdepth 1 -type f -exec sh -c 'echo "\n\n------------------------------- $0 -------------------------------" && BZLMOD_FLAG=${{ steps.set_bzlmod_flag.outputs.bzlmod_flag }} "$0" || kill $PPID' \{\} \;
- name: verify bcr patches
if: matrix.bzlmodEnabled && matrix.os == 'ubuntu-latest'

View File

@ -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(

View File

@ -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()

2
docs/copy_to_bin.md generated
View File

@ -79,7 +79,7 @@ copy_to_bin(<a href="#copy_to_bin-name">name</a>, <a href="#copy_to_bin-srcs">sr
Copies a source file to output tree at the same workspace-relative path.
e.g. `<execroot>/path/to/file -> <execroot>/bazel-out/<platform>/bin/path/to/file`
e.g. `&lt;execroot&gt;/path/to/file -&gt; &lt;execroot&gt;/bazel-out/&lt;platform&gt;/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.

View File

@ -50,19 +50,19 @@ for more information on supported globbing patterns.
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="copy_to_directory-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="copy_to_directory-allow_overwrites"></a>allow_overwrites | If True, allow files to be overwritten if the same output file is copied to twice.<br><br>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 |
| <a id="copy_to_directory-exclude_srcs_packages"></a>exclude_srcs_packages | List of Bazel packages (with glob support) to exclude from output directory.<br><br>Files in srcs are not copied to the output directory if the Bazel package of the file matches one of the patterns specified.<br><br>Forward slashes (<code>/</code>) should be used as path separators. A first character of <code>"."</code> will be replaced by the target's package path.<br><br>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.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | [] |
| <a id="copy_to_directory-exclude_srcs_patterns"></a>exclude_srcs_patterns | List of paths (with glob support) to exclude from output directory.<br><br>Files in srcs are not copied to the output directory if their output directory path, after applying <code>root_paths</code>, matches one of the patterns specified.<br><br>Forward slashes (<code>/</code>) should be used as path separators.<br><br>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.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | [] |
| <a id="copy_to_directory-hardlink"></a>hardlink | Controls when to use hardlinks to files instead of making copies.<br><br>Creating hardlinks is much faster than making copies of files with the caveat that hardlinks share file permissions with their source.<br><br>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.<br><br>- <code>auto</code>: hardlinks are used for generated files already in the output tree - <code>off</code>: all files are copied - <code>on</code>: hardlinks are used for all files (not recommended) | String | optional | "auto" |
| <a id="copy_to_directory-include_external_repositories"></a>include_external_repositories | List of external repository names (with glob support) to include in the output directory.<br><br>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.<br><br>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.<br><br>For example, the following copies <code>@external_repo//path/to:file</code> to <code>path/to/file</code> within the output directory.<br><br><pre><code> copy_to_directory( name = "dir", include_external_repositories = ["external_*"], srcs = ["@external_repo//path/to:file"], ) </code></pre><br><br>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.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | [] |
| <a id="copy_to_directory-include_srcs_packages"></a>include_srcs_packages | List of Bazel packages (with glob support) to include in output directory.<br><br>Files in srcs are only copied to the output directory if the Bazel package of the file matches one of the patterns specified.<br><br>Forward slashes (<code>/</code>) should be used as path separators. A first character of <code>"."</code> will be replaced by the target's package path.<br><br>Defaults to <code>["**"]</code> which includes sources from all packages.<br><br>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.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | ["**"] |
| <a id="copy_to_directory-include_srcs_patterns"></a>include_srcs_patterns | List of paths (with glob support) to include in output directory.<br><br>Files in srcs are only copied to the output directory if their output directory path, after applying <code>root_paths</code>, matches one of the patterns specified.<br><br>Forward slashes (<code>/</code>) should be used as path separators.<br><br>Defaults to <code>["**"]</code> which includes all sources.<br><br>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.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | ["**"] |
| <a id="copy_to_directory-out"></a>out | Path of the output directory, relative to this package.<br><br>If not set, the name of the target is used. | String | optional | "" |
| <a id="copy_to_directory-replace_prefixes"></a>replace_prefixes | Map of paths prefixes (with glob support) to replace in the output directory path when copying files.<br><br>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.<br><br>Forward slashes (<code>/</code>) should be used as path separators.<br><br>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.<br><br>Globs are supported (see rule docstring above). | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="copy_to_directory-root_paths"></a>root_paths | List of paths (with glob support) that are roots in the output directory.<br><br>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.<br><br>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.<br><br>Forward slashes (<code>/</code>) should be used as path separators.<br><br>A <code>"."</code> value expands to the target's package path (<code>ctx.label.package</code>).<br><br>Defaults to <code>["."]</code> 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.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | ["."] |
| <a id="copy_to_directory-srcs"></a>srcs | Files and/or directories or targets that provide <code>DirectoryPathInfo</code> to copy into the output directory. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
| <a id="copy_to_directory-verbose"></a>verbose | If true, prints out verbose logs to stdout | Boolean | optional | False |
| <a id="copy_to_directory-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="copy_to_directory-allow_overwrites"></a>allow_overwrites | If True, allow files to be overwritten if the same output file is copied to twice.<br><br>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 | <code>False</code> |
| <a id="copy_to_directory-exclude_srcs_packages"></a>exclude_srcs_packages | List of Bazel packages (with glob support) to exclude from output directory.<br><br>Files in srcs are not copied to the output directory if the Bazel package of the file matches one of the patterns specified.<br><br>Forward slashes (<code>/</code>) should be used as path separators. A first character of <code>"."</code> will be replaced by the target's package path.<br><br>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.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | <code>[]</code> |
| <a id="copy_to_directory-exclude_srcs_patterns"></a>exclude_srcs_patterns | List of paths (with glob support) to exclude from output directory.<br><br>Files in srcs are not copied to the output directory if their output directory path, after applying <code>root_paths</code>, matches one of the patterns specified.<br><br>Forward slashes (<code>/</code>) should be used as path separators.<br><br>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.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | <code>[]</code> |
| <a id="copy_to_directory-hardlink"></a>hardlink | Controls when to use hardlinks to files instead of making copies.<br><br>Creating hardlinks is much faster than making copies of files with the caveat that hardlinks share file permissions with their source.<br><br>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.<br><br>- <code>auto</code>: hardlinks are used for generated files already in the output tree - <code>off</code>: all files are copied - <code>on</code>: hardlinks are used for all files (not recommended) | String | optional | <code>"auto"</code> |
| <a id="copy_to_directory-include_external_repositories"></a>include_external_repositories | List of external repository names (with glob support) to include in the output directory.<br><br>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.<br><br>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.<br><br>For example, the following copies <code>@external_repo//path/to:file</code> to <code>path/to/file</code> within the output directory.<br><br><pre><code> copy_to_directory( name = "dir", include_external_repositories = ["external_*"], srcs = ["@external_repo//path/to:file"], ) </code></pre><br><br>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.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | <code>[]</code> |
| <a id="copy_to_directory-include_srcs_packages"></a>include_srcs_packages | List of Bazel packages (with glob support) to include in output directory.<br><br>Files in srcs are only copied to the output directory if the Bazel package of the file matches one of the patterns specified.<br><br>Forward slashes (<code>/</code>) should be used as path separators. A first character of <code>"."</code> will be replaced by the target's package path.<br><br>Defaults to <code>["**"]</code> which includes sources from all packages.<br><br>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.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | <code>["**"]</code> |
| <a id="copy_to_directory-include_srcs_patterns"></a>include_srcs_patterns | List of paths (with glob support) to include in output directory.<br><br>Files in srcs are only copied to the output directory if their output directory path, after applying <code>root_paths</code>, matches one of the patterns specified.<br><br>Forward slashes (<code>/</code>) should be used as path separators.<br><br>Defaults to <code>["**"]</code> which includes all sources.<br><br>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.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | <code>["**"]</code> |
| <a id="copy_to_directory-out"></a>out | Path of the output directory, relative to this package.<br><br>If not set, the name of the target is used. | String | optional | <code>""</code> |
| <a id="copy_to_directory-replace_prefixes"></a>replace_prefixes | Map of paths prefixes (with glob support) to replace in the output directory path when copying files.<br><br>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.<br><br>Forward slashes (<code>/</code>) should be used as path separators.<br><br>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.<br><br>Globs are supported (see rule docstring above). | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
| <a id="copy_to_directory-root_paths"></a>root_paths | List of paths (with glob support) that are roots in the output directory.<br><br>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.<br><br>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.<br><br>Forward slashes (<code>/</code>) should be used as path separators.<br><br>A <code>"."</code> value expands to the target's package path (<code>ctx.label.package</code>).<br><br>Defaults to <code>["."]</code> 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.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | <code>["."]</code> |
| <a id="copy_to_directory-srcs"></a>srcs | Files and/or directories or targets that provide <code>DirectoryPathInfo</code> to copy into the output directory. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |
| <a id="copy_to_directory-verbose"></a>verbose | If true, prints out verbose logs to stdout | Boolean | optional | <code>False</code> |
<a id="copy_to_directory_bin_action"></a>

View File

@ -21,8 +21,8 @@ Otherwise there is no way to give a Bazel label for it.
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="directory_path-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="directory_path-directory"></a>directory | a TreeArtifact (ctx.actions.declare_directory) | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="directory_path-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="directory_path-directory"></a>directory | a TreeArtifact (ctx.actions.declare_directory) | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
| <a id="directory_path-path"></a>path | path relative to the directory | String | required | |

View File

@ -29,8 +29,8 @@ This is of the format:
- `./file`
- `path/to/file`
- `external/external_repo/path/to/file`
- `<bin_dir>/path/to/file`
- `<bin_dir>/external/external_repo/path/to/file`
- `&lt;bin_dir&gt;/path/to/file`
- `&lt;bin_dir&gt;/external/external_repo/path/to/file`
The deprecated `$(location)` and `$(locations)` expansions returns either the execpath or rootpath depending on the context.

View File

@ -28,14 +28,14 @@ such as `$(BINDIR)`, `$(TARGET_CPU)`, and `$(COMPILATION_MODE)` as documented in
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="expand_template_rule-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="expand_template_rule-data"></a>data | List of targets for additional lookup information. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
| <a id="expand_template_rule-is_executable"></a>is_executable | Whether to mark the output file as executable. | Boolean | optional | False |
| <a id="expand_template_rule-out"></a>out | Where to write the expanded file.<br><br> 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 <code>copy_to_bin</code> but with substitutions on the copy. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | |
| <a id="expand_template_rule-stamp"></a>stamp | Whether to encode build information into the output. Possible values:<br><br> - <code>stamp = 1</code>: 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. - <code>stamp = 0</code>: Never stamp, instead replace build information by constant values. This gives good build result caching. - <code>stamp = -1</code>: 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 |
| <a id="expand_template_rule-stamp_substitutions"></a>stamp_substitutions | Mapping of strings to substitutions.<br><br> There are overlayed on top of substitutions when stamping is enabled for the target.<br><br> Substitutions can contain $(execpath :target) and $(rootpath :target) expansions, $(MAKEVAR) expansions and {{STAMP_VAR}} expansions when stamping is enabled for the target. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="expand_template_rule-substitutions"></a>substitutions | Mapping of strings to substitutions.<br><br> Substitutions can contain $(execpath :target) and $(rootpath :target) expansions, $(MAKEVAR) expansions and {{STAMP_VAR}} expansions when stamping is enabled for the target. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="expand_template_rule-template"></a>template | The template file to expand. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="expand_template_rule-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="expand_template_rule-data"></a>data | List of targets for additional lookup information. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |
| <a id="expand_template_rule-is_executable"></a>is_executable | Whether to mark the output file as executable. | Boolean | optional | <code>False</code> |
| <a id="expand_template_rule-out"></a>out | Where to write the expanded file.<br><br> 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 <code>copy_to_bin</code> but with substitutions on the copy. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | |
| <a id="expand_template_rule-stamp"></a>stamp | Whether to encode build information into the output. Possible values:<br><br> - <code>stamp = 1</code>: 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. - <code>stamp = 0</code>: Never stamp, instead replace build information by constant values. This gives good build result caching. - <code>stamp = -1</code>: 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 | <code>-1</code> |
| <a id="expand_template_rule-stamp_substitutions"></a>stamp_substitutions | Mapping of strings to substitutions.<br><br> There are overlayed on top of substitutions when stamping is enabled for the target.<br><br> Substitutions can contain $(execpath :target) and $(rootpath :target) expansions, $(MAKEVAR) expansions and {{STAMP_VAR}} expansions when stamping is enabled for the target. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
| <a id="expand_template_rule-substitutions"></a>substitutions | Mapping of strings to substitutions.<br><br> Substitutions can contain $(execpath :target) and $(rootpath :target) expansions, $(MAKEVAR) expansions and {{STAMP_VAR}} expansions when stamping is enabled for the target. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
| <a id="expand_template_rule-template"></a>template | The template file to expand. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
<a id="expand_template"></a>

4
docs/host_repo.md generated
View File

@ -17,7 +17,7 @@ Exposes information about the host platform
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="host_repo-name"></a>name | A unique name for this repository. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="host_repo-repo_mapping"></a>repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.&lt;p&gt;For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>). | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | required | |
| <a id="host_repo-name"></a>name | A unique name for this repository. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="host_repo-repo_mapping"></a>repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.&lt;p&gt;For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>). | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | required | |

6
docs/jq.md generated
View File

@ -85,7 +85,7 @@ jq(
"--raw-input",
"--slurp",
],
filter = "{ deps: split("\n") | map(select(. | length > 0)) }",
filter = "{ deps: split("\n") | map(select(. | length &gt; 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 // "<unstamped>")",
".version = ($stamp[0].BUILD_EMBED_LABEL // "&lt;unstamped&gt;")",
]),
)
```
@ -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) &gt; $@",
toolchains = ["@jq_toolchains//:resolved_toolchain"],
)
```

6
docs/output_files.md generated
View File

@ -18,10 +18,10 @@ A rule that provides file(s) specific via DefaultInfo from a given target's Defa
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="output_files-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="output_files-output_group"></a>output_group | if set, we look in the specified output group for paths instead of DefaultInfo | String | optional | "" |
| <a id="output_files-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="output_files-output_group"></a>output_group | if set, we look in the specified output group for paths instead of DefaultInfo | String | optional | <code>""</code> |
| <a id="output_files-paths"></a>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 | |
| <a id="output_files-target"></a>target | the target to look in for requested paths in its' DefaultInfo or OutputGroupInfo | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="output_files-target"></a>target | the target to look in for requested paths in its' DefaultInfo or OutputGroupInfo | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
<a id="make_output_files"></a>

22
docs/paths.md generated
View File

@ -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.
&gt; `rlocationpath`: The path a built binary can pass to the `Rlocation` function of a runfiles
&gt; library to find a dependency at runtime, either in the runfiles directory (if available)
&gt; 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.
&gt; This is similar to root path (a.k.a. [short_path](https://bazel.build/rules/lib/File#short_path))
&gt; in that it does not contain configuration prefixes, but differs in that it always starts with the
&gt; 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.
&gt; The rlocation path of a `File` in an external repository repo will start with `repo/`, followed by the
&gt; 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.
&gt; Passing this path to a binary and resolving it to a file system path using the runfiles libraries
&gt; is the preferred approach to find dependencies at runtime. Compared to root path, it has the
&gt; advantage that it works on all platforms and even if the runfiles directory is not available.
**PARAMETERS**

6
docs/repo_utils.md generated
View File

@ -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 =&gt; amd64
aarch64 =&gt; 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 "<os>_<arch>" string of the host os and CPU architecture.
The normalized "&lt;os&gt;_&lt;arch&gt;" string of the host os and CPU architecture.

12
docs/stamping.md generated
View File

@ -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.
&gt; Note: https://github.com/bazelbuild/bazel/issues/14341 proposes that Bazel enforce this by
&gt; 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]
&gt; 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.
&gt; **NOTE** keys that start with `STABLE_` will cause a re-build when they change.
&gt; Other keys will NOT cause a re-build, so stale values can appear in your app.
&gt; 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:

20
docs/tar.md generated
View File

@ -35,9 +35,9 @@ Create an mtree specification to map a directory hierarchy. See https://man.free
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="mtree_spec-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="mtree_spec-out"></a>out | Resulting specification file to write | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | |
| <a id="mtree_spec-srcs"></a>srcs | Files that are placed into the tar | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | required | |
| <a id="mtree_spec-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="mtree_spec-out"></a>out | Resulting specification file to write | <a href="https://bazel.build/concepts/labels">Label</a> | optional | |
| <a id="mtree_spec-srcs"></a>srcs | Files that are placed into the tar | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
<a id="tar_rule"></a>
@ -55,13 +55,13 @@ Rule that executes BSD `tar`. Most users should use the [`tar`](#tar) macro, rat
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="tar_rule-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="tar_rule-args"></a>args | Additional flags permitted by BSD tar; see the man page. | List of strings | optional | [] |
| <a id="tar_rule-compress"></a>compress | Compress the archive file with a supported algorithm. | String | optional | "" |
| <a id="tar_rule-mode"></a>mode | A mode indicator from the following list, copied from the tar manpage:<br><br> - create: Create a new archive containing the specified items. - append: Like <code>create</code>, 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 <code>append</code>, 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" |
| <a id="tar_rule-mtree"></a>mtree | An mtree specification file | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="tar_rule-out"></a>out | Resulting tar file to write. If absent, <code>[name].tar</code> is written. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | |
| <a id="tar_rule-srcs"></a>srcs | Files, directories, or other targets whose default outputs are placed into the tar.<br><br> If any of the srcs are binaries with runfiles, those are copied into the resulting tar as well. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | required | |
| <a id="tar_rule-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="tar_rule-args"></a>args | Additional flags permitted by BSD tar; see the man page. | List of strings | optional | <code>[]</code> |
| <a id="tar_rule-compress"></a>compress | Compress the archive file with a supported algorithm. | String | optional | <code>""</code> |
| <a id="tar_rule-mode"></a>mode | A mode indicator from the following list, copied from the tar manpage:<br><br> - create: Create a new archive containing the specified items. - append: Like <code>create</code>, 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 <code>append</code>, 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 | <code>"create"</code> |
| <a id="tar_rule-mtree"></a>mtree | An mtree specification file | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
| <a id="tar_rule-out"></a>out | Resulting tar file to write. If absent, <code>[name].tar</code> is written. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | |
| <a id="tar_rule-srcs"></a>srcs | Files, directories, or other targets whose default outputs are placed into the tar.<br><br> If any of the srcs are binaries with runfiles, those are copied into the resulting tar as well. | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
<a id="tar"></a>

14
docs/transitions.md generated
View File

@ -17,10 +17,10 @@ Transitions the binary to use the provided platform.
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="platform_transition_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="platform_transition_binary-basename"></a>basename | - | String | optional | "" |
| <a id="platform_transition_binary-binary"></a>binary | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="platform_transition_binary-target_platform"></a>target_platform | The target platform to transition the binary. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="platform_transition_binary-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="platform_transition_binary-basename"></a>basename | - | String | optional | <code>""</code> |
| <a id="platform_transition_binary-binary"></a>binary | - | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |
| <a id="platform_transition_binary-target_platform"></a>target_platform | The target platform to transition the binary. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
<a id="platform_transition_filegroup"></a>
@ -38,8 +38,8 @@ Transitions the srcs to use the provided platform. The filegroup will contain ar
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="platform_transition_filegroup-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="platform_transition_filegroup-srcs"></a>srcs | The input to be transitioned to the target platform. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
| <a id="platform_transition_filegroup-target_platform"></a>target_platform | The target platform to transition the srcs. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="platform_transition_filegroup-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="platform_transition_filegroup-srcs"></a>srcs | The input to be transitioned to the target platform. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |
| <a id="platform_transition_filegroup-target_platform"></a>target_platform | The target platform to transition the srcs. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |

8
docs/utils.md generated
View File

@ -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.
&gt; Tests may return arbitrarily fast regardless of timeout.
&gt; A test is not penalized for an overgenerous timeout, although a warning may be issued:
&gt; 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
&gt; 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

4
docs/yq.md generated
View File

@ -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) &gt; $@",
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 // "<unstamped>")",
".version = ($stamp.BUILD_EMBED_LABEL // "&lt;unstamped&gt;")",
]),
)
```

View File

@ -0,0 +1,12 @@
module(
name = "external_copy_to_directory",
version = "0.0.0",
compatibility_level = 1,
)
bazel_dep(name = "bazel_skylib", version = "1.4.2")
bazel_dep(name = "aspect_bazel_lib", version = "0.0.0")
local_path_override(
module_name = "aspect_bazel_lib",
path = "../..",
)

View File

@ -1,13 +1,15 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
BZLMOD_FLAG="${BZLMOD_FLAG:-}"
case "$(uname -s)" in
CYGWIN*|MINGW32*|MSYS*|MINGW*)
bazel run @jq//:jq.exe -- --null-input .a=5
bazel run $BZLMOD_FLAG @jq//:jq.exe -- --null-input .a=5
;;
*)
bazel run @jq//:jq -- --null-input .a=5
bazel run $BZLMOD_FLAG @jq//:jq -- --null-input .a=5
;;
esac

View File

@ -1,12 +1,14 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
BZLMOD_FLAG="${BZLMOD_FLAG:-}"
case "$(uname -s)" in
CYGWIN*|MINGW32*|MSYS*|MINGW*)
bazel run @yq//:yq.exe -- --null-input .a=5
bazel run $BZLMOD_FLAG @yq//:yq.exe -- --null-input .a=5
;;
*)
bazel run @yq//:yq -- --null-input .a=5
bazel run $BZLMOD_FLAG @yq//:yq -- --null-input .a=5
;;
esac
esac

View File

@ -1,8 +1,10 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
BZLMOD_FLAG="${BZLMOD_FLAG:-}"
function run_test {
bazel run //lib/tests/write_source_files:write_dist
bazel run $BZLMOD_FLAG //lib/tests/write_source_files:write_dist
local expected_out="lib/tests/write_source_files/dist.js"
if [ ! -e "$expected_out" ]; then
echo "ERROR: expected $expected_out to exist"
@ -13,7 +15,7 @@ function run_test {
exit 1
fi
bazel run //lib/tests/write_source_files:write_dist_executable
bazel run $BZLMOD_FLAG //lib/tests/write_source_files:write_dist_executable
local expected_out="lib/tests/write_source_files/dist_executable.js"
if [ ! -e "$expected_out" ]; then
echo "ERROR: expected $expected_out to exist"

View File

@ -1,8 +1,10 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
BZLMOD_FLAG="${BZLMOD_FLAG:-}"
function run_test {
bazel run //:write_source_file_root-test
bazel run $BZLMOD_FLAG //:write_source_file_root-test
local expected_out="test-out/dist/write_source_file_root-test/test.txt"
if [ ! -e "$expected_out" ]; then
echo "ERROR: expected $expected_out to exist"

View File

@ -1,8 +1,10 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
BZLMOD_FLAG="${BZLMOD_FLAG:-}"
function run_test {
bazel run //lib/tests/write_source_files:write_subdir
bazel run $BZLMOD_FLAG //lib/tests/write_source_files:write_subdir
local expected_out="lib/tests/write_source_files/subdir_test/a/b/c/test.txt"
if [ ! -e "$expected_out" ]; then
echo "ERROR: expected $expected_out to exist"
@ -13,7 +15,7 @@ function run_test {
exit 1
fi
bazel run //lib/tests/write_source_files:write_subdir_executable
bazel run $BZLMOD_FLAG //lib/tests/write_source_files:write_subdir_executable
local expected_out="lib/tests/write_source_files/subdir_executable_test/a/b/c/test.txt"
if [ ! -e "$expected_out" ]; then
echo "ERROR: expected $expected_out to exist"

View File

@ -1,8 +1,10 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
BZLMOD_FLAG="${BZLMOD_FLAG:-}"
function run_test {
bazel run //lib/tests/write_source_files:write_symlinks
bazel run $BZLMOD_FLAG //lib/tests/write_source_files:write_symlinks
local expected_out="lib/tests/write_source_files/symlink_test/a/test.txt"
if [ ! -e "$expected_out" ]; then

View File

@ -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",
],
)

View File

@ -3,4 +3,4 @@ VERSION: {{VERSION}}
TMPL_PATH: {{TMPL_PATH}}
WORKSPACE: {{WORKSPACE}}
VERSION: {{VERSION}}
TMPL_PATH: {{TMPL_PATH}}
TMPL_PATH: {{TMPL_PATH}}

View File

@ -3,4 +3,4 @@ VERSION: v0.0.0
TMPL_PATH: lib/tests/expand_template/a.tmpl
WORKSPACE: aspect_bazel_lib
VERSION: v0.0.0
TMPL_PATH: lib/tests/expand_template/a.tmpl
TMPL_PATH: lib/tests/expand_template/a.tmpl

View File

@ -3,4 +3,4 @@ VERSION: v1.2.3
TMPL_PATH: lib/tests/expand_template/a.tmpl
WORKSPACE: aspect_bazel_lib
VERSION: v1.2.3
TMPL_PATH: lib/tests/expand_template/a.tmpl
TMPL_PATH: lib/tests/expand_template/a.tmpl

View File

@ -229,7 +229,23 @@ def paths_test_suite():
unittest.suite(
"paths_tests",
partial.make(relative_file_test, timeout = "short"),
partial.make(rlocation_path_test, timeout = "short"),
partial.make(output_relative_path_test, timeout = "short"),
partial.make(
rlocation_path_test,
timeout = "short",
# TODO: rlocation_path tests don't work under bzlmod
target_compatible_with = select({
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
),
partial.make(
output_relative_path_test,
timeout = "short",
# TODO: output_relative_path tests don't work under bzlmod
target_compatible_with = select({
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
),
partial.make(repository_relative_path_test, timeout = "short"),
)

View File

@ -1,6 +1,6 @@
"tests for run_binary"
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_file")
load("@aspect_bazel_lib//lib:diff_test.bzl", "diff_test")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("//lib:run_binary.bzl", "run_binary")
@ -55,8 +55,11 @@ run_binary(
tool = ":expansions_sh",
)
write_source_file(
name = "write_expansions_golden",
in_file = "expansions_out",
out_file = "expansions_golden",
diff_test(
name = "expansions_golden_test",
file1 = ":expansions_out",
file2 = select({
"@aspect_bazel_lib//lib:bzlmod": "expansions_golden_bzlmod",
"//conditions:default": "expansions_golden",
}),
)

View File

@ -0,0 +1,19 @@
bazel-out/PLATFORM-opt/bin/lib/tests/run_binary_expansions/expansions_out
bazel-out/PLATFORM-opt/bin/lib/tests/run_binary_expansions
lib/tests/run_binary_expansions/src_1
lib/tests/run_binary_expansions/src_1
bazel-out/PLATFORM-opt/bin/lib/tests/run_binary_expansions/src_1
bazel-out/PLATFORM-opt/bin/lib/tests/run_binary_expansions/src_1
_main/lib/tests/run_binary_expansions/src_1
_main/lib/tests/run_binary_expansions/src_1
bazel-out/PLATFORM-opt/bin/lib/tests/run_binary_expansions/src_1
bazel-out/PLATFORM-opt/bin/lib/tests/run_binary_expansions/src_1
opt
bazel-out/PLATFORM-opt/bin
bazel-out/PLATFORM-opt/bin
PLATFORM
lib/tests/run_binary_expansions/BUILD.bazel
bazel-out/volatile-status.txt
bazel-out/stable-status.txt
//lib/tests/run_binary_expansions:expansions
_main

View File

@ -201,6 +201,8 @@ genrule(
# requires runfiles tree, otherwise get
# ERROR: cannot find bazel_tools/tools/bash/runfiles/runfiles.bash
"@platforms//os:windows": ["@platforms//:incompatible"],
# TODO(sahin): incompatible with bzlmod
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
toolchains = ["@bsd_tar_toolchains//:resolved_toolchain"],

View File

@ -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)
@ -178,13 +178,22 @@ def file_exists_test():
# buildifier: disable=function-docstring
def utils_test_suite():
to_label_test(name = "to_label_tests", relative_asserts = {
utils.to_label(":utils_test.bzl"): "//lib/tests:utils_test.bzl",
}, timeout = "short")
to_label_test(
name = "to_label_tests",
relative_asserts = {
utils.to_label(":utils_test.bzl"): "//lib/tests:utils_test.bzl",
},
timeout = "short",
# TODO: to_label tests don't work under bzlmod
target_compatible_with = select({
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
)
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",
)
@ -212,6 +221,11 @@ def utils_test_suite():
consistent_label_str_test(
name = "consistent_label_str_tests",
timeout = "short",
# TODO: consistent_label_str tests don't work under bzlmod
target_compatible_with = select({
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
)
file_exists_test()

View File

@ -79,6 +79,11 @@ def release(name, targets, **kwargs):
for target in targets
]),
tools = [":create_versions.sh"],
# TODO: the hashes change when bzlmol is enabled
target_compatible_with = kwargs.pop("target_compatible_with", select({
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
"//conditions:default": [],
})),
**kwargs
)