Commit Graph

187 Commits

Author SHA1 Message Date
David Zbarsky 43f8b3e524
Make build pass with --incompatible_auto_exec_groups (#963) 2024-10-15 10:16:11 -07:00
Fabian Meumertzheim 64eb5f8cea
`platform_transition_test`: Use transitioned target platform (#965)
The target platform of a test rule matters for the resolution of the execution platform of the test action, either via test toolchains or `--use_target_platform_for_tests`. With an outgoing transition, tests would run on the wrong platform in these cases, so use an incoming transition for the test rule.
2024-10-15 16:12:19 +02:00
Peter Lobsinger bca34bd17c
perf: report unused inputs for the tar rule (#951)
* perf: report unused inputs for the tar rule

The `mtree` spec passed to the `tar` rule very often selects a subset of the
inputs made available through the `srcs` attribute. In many cases, these
subsets do not break down cleanly along dependency-tree lines and there
is no simple way just pass less content to the `tar` rule.

One prominent example where this occurs is when constructing the tars
for OCI image layers. For instance when [building a Python-based
container image](https://github.com/bazel-contrib/rules_oci/blob/main/docs/python.md),
we might want to split the Python interpreter, third-party dependencies, and
application code into their own layers. This is done by [filtering the
`mtree_spec`](85cb2aaf8c/oci_python_image/py_layer.bzl (L39)).

However, in the operation to construct a `tar` from a subsetted mtree,
it is usually still an unsubsetted tree of `srcs` that gets passed. As
a result, the subset tarball is considered dependent upon a larger set
of sources than is strictly necessary.

This over-scoping runs counter to a very common objective associated with
breaking up an image into layers - isolating churn to a smaller slice of
the application. Because of the spurious relationships established in
Bazel's dependency graph, all tars get rebuilt anytime any content in
the application gets changed. Tar rebuilds can even be triggered by
changes to files that are completely filtered-out from all layers of the container.

Redundent creation of archive content is usually not too computationally
intensive, but the archives can be quite large in some cases, and
avoiding a rebuild might free up gigabytes of disk and/or network
bandwidth for
better use. In addition, eliminating the spurious dependency edges
removes erroneous constraints applied to the build action schedule;
these tend to push all Tar-building operations towards the end of a
build, even when some archive construction could be scheduled much earlier.

## Risk assessment and mitigation

The `unused_inputs_list` mechanism used to report spurious dependency
relationships is a bit difficult to use. Reporting an actually-used
input as unused can create difficult to diagnose problems down the line.

However, the behaviour of the `mtree`-based `tar` rule is sufficiently
simple and self-contained that I am fairly confident that this rule's
used/unused set can be determined accurately in a maintainable fashion.

Out of an abundance of caution I have gated this feature behind a
default-off flag. The `tar` rule will continue to operate as it had
before - typically over-reporting dependencies - unless the
`--@aspect_bazel_lib//lib:tar_compute_unused_inputs` flag is passed.

### Filter accuracy

The `vis` encoding used by the `mtree` format to resiliently handle path
names has a small amount of "play" to it - it is reversable but the
encoded representation of a string is not
unique. Two unequal encoded strings might decode to the same value; this
can happen when at least one of the encoded strings contains unnecessary
escapes that are nevertheless honoured by the decoder.

The unused-inputs set is determined using a filter that compares
`vis`-encoded strings. In the presence of non-canonically-encoded
paths, false-mismatches can lead to falsely reporting that an input is
unused.

The only `vis`-encoded path content that is under the control of callers
is the `mtree` content itself; all other `vis`-encoded strings are
constructed internally to this package, not exposed publicly, and are
all derived using the `lib/private/tar.bzl%_vis_encode` function; all of
these paths are expected to compare exactly. Additionally, it is expected that
many/most users will use this package's helpers (e.g. `mtree_spec`) when
crafting their mtree content; such content is also safe. It is only when
the user crafts their own mtree, or modifies an mtree spec's `content=`
fields' encoding in some way, that a risk of inaccurate reporting
arises. The chances for this are expected to be minor since this seems
like an inconvenient and not-particularly-useful thing for a user to go
out of their way to do.

* Also include other bsdtar toolchain files in keep set

* Add tri-state attribute to control unused-inputs behaviour

This control surface provides for granular control of the feature. The
interface is selected to mirror the common behaviour of `stamp` attributes.

* Add bzl_library level dep

* Update docs

* pre-commit

* Add reminder to change flag default on major-version bump

* Add note about how to make unused input computation exactly correct

* Add a test for unused_inputs listing

* Support alternate contents= form

This is accepted by bsdtar/libarchive. In fact `contents=` is the only of
the pair documented in `mtree(5)`; `content=` is an undocumented
alternate form supported by libarchive.

* Don't try to prune the unprunable

Bazel's interpretation of unused_inputs_list cannot accomodate certain
things in filenames. These are also likely to mess up our own
line-oriented protocol in the shellscript that produces this file.

Co-authored-by: Sahin Yort <thesayyn@gmail.com>

* Rerun docs update

---------

Co-authored-by: Sahin Yort <thesayyn@gmail.com>
2024-10-13 09:58:56 -07:00
Peter Lobsinger 0db9fbe519
feat: support bzlmod runfiles lookups (#953)
* feat: support bzlmod repo name aliases in tarred runfiles

Under bzlmod, repos have aliases in addition to their canonical names;
in order for lookups using these canonical names to function properly,
a file name `_repo_mapping` is located in the root of the runfiles tree
and consulted to perform repo-name translation.

See: https://github.com/bazelbuild/proposals/blob/main/designs/2022-07-21-locating-runfiles-with-bzlmod.md

* pre-commit formatting

* Enable runfiles test under bzlmod

It works now.
2024-09-30 21:10:06 -07:00
Derek Cormier 716af223c2
feat: add an option to not include copy_to_directory output in runfiles (#886)
* feat: add an option to not include copy_to_directory output in runfiles

* chore: docs update

* chore: don't repeat default

---------

Co-authored-by: Alex Eagle <alex@aspect.dev>
2024-09-19 01:16:14 +00:00
Alex Eagle 2f65c8c0c7
chore: update git urls (#926)
This repository was donated to the Linux Foundation and is now in the bazel-contrib GH org
2024-09-17 17:05:35 -07:00
Greg Magolan fb0677ad57
chore: cleanup before bazel-contrib handoff (#918)
* chore: clenaup before bazel-contrib handoff

* chore: apply lint fixes

---------

Co-authored-by: Alex Eagle <alex@aspect.dev>
2024-09-02 09:32:38 -07:00
Greg Magolan 11aacaf5df
chore: enable go, shell, yaml formatters and bazel run //:format (#917) 2024-08-20 11:56:40 -07:00
Greg Magolan abbbd54a15
chore: right size tests to supress bazel warning (#913) 2024-08-19 15:55:21 -07:00
Greg Magolan 9b87fa7050
chore: skip linux only tests on non-linux platforms (#912) 2024-08-19 18:26:12 -04:00
Greg Magolan 73d021fb36
fix: correctly split quoted args (#909) 2024-08-19 16:36:41 -04:00
Greg Magolan 62b2fd06aa
chore: fixup test sizes to resolve warnings (#911) 2024-08-19 15:33:54 -04:00
Alex Eagle 385717a2a5
chore: turn off bzlmod misguided warning (#901)
* chore: turn off bzlmod misguided warning

These are misinformed, the module resolver should be permitted to find an MVS solution

* chore: update golden
2024-08-14 10:41:50 -07:00
Alex Eagle 109f32eefb
docs(tar): point to the tests as useful examples (#892)
* docs(tar): point to the tests as useful examples

Improve the content to make it easier to reference as examples of usage.

* fix broken link
2024-08-05 11:18:57 -07:00
Markus Hofbauer cdbfe4190c
fix(typos): Fix almost all typos with hook (#884)
* Fix almost all typos with hook

* align docs
2024-07-31 10:09:17 -04:00
Matt 59453e5c50
fix: Set size to a default value as well as timeout. (#839)
* fix: Set size to a default value as well as timeout.

Currently, we are unable to run our `write_source_files` tests in our pre-upload checks, because we have `--test_size_filter=small`, and setting `size` will attempt to set it on both the run rule and the test rule, the former being invalid.

* code review feedback

* chore: fix one more test that should use size for defaulting

---------

Co-authored-by: Alex Eagle <alex@aspect.dev>
2024-07-19 12:50:50 -07:00
Greg Magolan be4b0d6455
chore: upgrade to Aspect Workflows 5.10.9 (#881) 2024-07-18 17:54:51 -07:00
Synchronization Acknowledgement cc956d8589
fix(tar): append slash to top-level directory mtree entries (#852)
* fix(tar): append slash to top-level directory mtree entries

bsdtar's mtree format has a quirk wherein entries without "/" in their
first word are treated as "relative" entries, and "relative" directories
will cause tar to "change directory" into the declared directory entry.
If such a directory is followed by a "relative" entry, then the file
will be created within the directory, instead of at top-level as
expected. To mitigate, we append a slash to top-level directory entries.

Fixes #851.

* chore: golden files have BINDIR placeholder

---------

Co-authored-by: Alex Eagle <alex@aspect.dev>
2024-07-02 09:27:06 -07:00
Tobias Schlatter 086624ae47
fix(tar): expose package_dir argument in mtree_mutate (#873)
This was likely forgotten in #829 when making the parameters explicit
during review.
2024-07-02 13:29:24 +03:00
Greg Magolan 18ae5a89a6
fix: allow copy_to_directory to have an empty srcs list (#871) 2024-06-21 11:33:00 -06:00
Josh Giles 3c0dbd5895
fix: Directory hidden files in write_source_file. (#860)
* Fix #667: Dir hidden files in write_source_file.

Copy and manage hidden files starting with "." in write_source_files.

Previously these files were not supported if they were in the top level
of the directory to copy.

* Add test and fix error messages from cp, chmod.

* Also fix executable dir case.

* Fix issue with copying directory rather than contents.
2024-06-11 00:30:53 -07:00
Greg Magolan 00310a5b91
test: add test / example of using root path on a run_binary directory output (#862) 2024-06-05 13:48:07 -07:00
Alex Eagle 4ad02b7795
refactor(release): switch release integrity to be dynamic (#854)
* refactor(release): switch release integrity to be dynamic

This matches rules_py as documented by
https://blog.aspect.build/releasing-bazel-rulesets-rust

It has the benefit that developers no longer get yelled at to vendor some updated integrity hashes into bazel-lib every time they touch the Go sources.

* refactor: echo should produce trailing newline

* chore: bump action-gh-release to avoid Node 16 warning

* chore: update test that is sensitive to compilation mode

We now only use --compilation_mode=opt when cutting a release
2024-05-23 16:08:35 -07:00
Alex Eagle b15dc31a81
fix(tar): handle spaces in input filenames (#835) 2024-05-07 17:52:35 -07:00
Sahin Yort d1d063f3e5
feat: introduce zstd toolchain (#831) 2024-05-03 16:12:56 -07:00
Alex Eagle 977f27f7a0
feat(tar): add ergonomic way to strip_prefix (#829) 2024-05-01 12:36:39 -07:00
Greg Magolan 41413388da
chore: add bazel test support to javascript --config=debug preset (#825) 2024-04-25 16:33:16 -07:00
Thomas Lam faaada2eaa
feat: add platform_transition_test (#770)
* Add platform_transition_test

Signed-off-by: Thomas Lam <thomaslam@canva.com>

* Set target platform constraints for tests

Signed-off-by: Thomas Lam <thomaslam@canva.com>

* Update docs

Signed-off-by: Thomas Lam <thomaslam@canva.com>

---------

Signed-off-by: Thomas Lam <thomaslam@canva.com>
2024-04-03 14:42:07 -07:00
Alex Eagle fea9515087
feat: don't require 'out' on expand_template (#798)
In a lot of cases the name of the generated file is unimportant.
For example in https://github.com/bazel-contrib/rules_oci/pull/534 I wanted to remove 'out' in a bunch of these calls.
2024-03-26 16:57:16 -07:00
Sahin Yort a29dd93c0b
fix: srcs is not mandatory (#786) 2024-03-08 10:47:38 -08:00
Sahin Yort 197b2da974
feat: support location expansion in tar (#774) 2024-03-01 14:51:47 -08:00
Marc Redemske a3d7efe298
feat(list): add `unique` function (#716)
* feat(list): add `unique` function

* Update lists.bzl

* Update lists.bzl

* Update lists.bzl

* Update lists.bzl

---------

Co-authored-by: Alex Eagle <alex@aspect.dev>
2024-02-27 08:25:00 -08:00
Mike Lundy dfcffca8f5
jq: add data file and location expansion support (#757)
This teaches the jq rule about a `data` attribute and adds conditional
support to do bazel location expansion. The expansion is disabled by
default because it likely would cause compat concerns (since jq can take
arbitrary text as input args).
2024-02-26 17:43:56 -08:00
Alex Eagle 1c98ca9f34
chore: make it possible to override run_binary#use_default_shell_env (#762)
Still not documented as public API. We think this leads to non-hermeticity and could cause cache misses, so it must be used with care.

Part of https://github.com/aspect-build/rules_js/issues/1303
2024-02-21 13:37:47 -08:00
Alex Eagle 6d3195f05c
presets: remove eternal test_timeout_filtering (#758)
In practice we've disabled this setting at some clients, because there's not a surrounding workflow to find these targets are being silently dropped from CI, nor run them on another schedule.

We can re-introduce something better when we add Test Selection to Aspect Workflows.
2024-02-16 13:56:38 -08:00
Greg Magolan 1baf14f65c
chore: add example of using write_source_file to merge output tree artifact files with source files that are already in an output directory (#730) 2024-01-22 21:03:31 -08:00
Greg Magolan 5b3b7d7794
feat: allow write_source_file(s) to write source files to bazel packages outside of the target's package (#717) 2024-01-10 15:07:03 -08:00
Greg Magolan 57bcf288bd
chore: fix failing test on arm64 machines (#718) 2024-01-10 11:16:37 -08:00
Greg Magolan c9d08234ce
refactor: remove --enable-runfiles from javascript recommended bazelrc settings (#715) 2024-01-07 21:29:45 -08:00
Greg Magolan 5aaa785b96
chore: test against bazel 7.0.0 (#713) 2024-01-07 16:12:05 -08:00
Greg Magolan d313c8bf75
fix: move flags that should only be set with bazel 6 to bazel6.bazelrc recommended settings (#711) 2024-01-04 08:16:59 -08:00
Sahin Yort ac0055e092
test: fix timeout (#707) 2023-12-22 11:44:44 -08:00
Sahin Yort 4f6b4bd5cb
feat: implement bats test runner (#699) 2023-12-20 13:08:47 -08:00
Tobias Schlatter 8d805e16bf
fix #697: use to_repository_relative_path in mtree_spec (#696)
* Reproduction for mtree_spec behaving different in other repo

* Fix the bug (but not the test)

* Fix the test

* Rename mtree_spec e2e dir to tar

* Fix bzlmod tests

* Remove unnecessary skylib dependency from e2e repos

* Add e2e tests to matrix

* Replace e2e test with a normal test

To do this, we somewhat abuse the skylib dependency, but that's
probalby OK.
2023-12-20 11:22:42 -08:00
Alex Eagle 303779e9ef
fix(tar): propagate testonly attr to mtree_spec (#691) 2023-12-13 15:21:02 -08:00
Alex Eagle f65019be4e
chore: improve docs about mtree mutation (#692) 2023-12-13 15:03:32 -08:00
Greg Magolan b1c342a96f
chore: bazel run //:format (#682) 2023-12-08 00:30:39 -08:00
Derek Cormier 5bd6e5fdd4
fix(ci): fix bzlmod issues and enable on ci (#658) 2023-11-15 15:07:03 -08:00
Greg Magolan a47eebfa65
fix: fix execution requirements for 'build without the bytes' (#639) 2023-10-31 13:38:32 -07:00
Alex Eagle 8cf7e6f995
feat: support treeartifacts (#630) (#631)
Co-authored-by: Sahin Yort <thesayyn@gmail.com>
2023-10-19 15:57:48 -07:00