Skip to content
Snippets Groups Projects
Unverified Commit d4d852c3 authored by Fabian Meumertzheim's avatar Fabian Meumertzheim Committed by GitHub
Browse files

[7.2.0] Automatically map paths in `Args#map_each` (#22322)

When path mapping is enabled, `File` objects accessed in a user-supplied
callback passed to `Args#map_each` automatically have their paths
mapped.

Automatic rewriting is preferable to e.g. passing a rewriter object into
the callback: All paths emitted into command lines must be rewritten
with path mapping as inputs and outputs are staged at the mapped
locations, so the user would need to manually map all paths - there is
no choice. As an added benefit, the automatic rewriting ensures that
existing rules relying on `map_each` do not need to be modified to use
path mapping.

This is a reland of 955b31e9, which got
rolled back due to a 7% CPU time increase on a benchmark caused by
frequent comparisons of equal but not reference equal
`StarlarkSemantics` used as keys in the `StarlarkClassDescriptor` cache
in `CallUtils`. Instead of overriding `equals` and `hashCode` for
`PathMapper`, this change subclasses `StarlarkSemantics` to provide a
different, reference equal instance as the cache key. This is safe since
the value associated with the `path_mapper` key does not affect the
availability of any Starlark field or method, just the behavior of their
implementations.

Work towards https://github.com/bazelbuild/bazel/issues/6526

Closes #21952.

PiperOrigin-RevId: 629546010
Change-Id: Ib21fa2371a28a02f0c868523b410c5a40c2c6c82

Closes #22221
parent 1d5fdaf3
Showing
with 317 additions and 47 deletions
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment