Skip to content

Support output path mapping and multiplex worker sandboxing - #175

Open
06393993 wants to merge 3 commits into
Bencodes:mainfrom
06393993:t1-upstream-pr
Open

06393993 wants to merge 3 commits into
Bencodes:mainfrom
06393993:t1-upstream-pr

Conversation

@06393993

@06393993 06393993 commented Dec 3, 2026

Copy link
Copy Markdown

Summary

Enable Bazel output path mapping (--experimental_output_paths=strip) and multiplex worker sandboxing (--experimental_worker_multiplex_sandboxing) for AndroidLint actions:

  1. Pass AAR paths to lint as File objects (rules/impl.bzl, authored by Jasmine Tang): replaces "%s:%s" % (aar.path, aar_dir.path) with args.add_joined("--classpath-aar", [aar, aar_dir], join_with = ":", expand_directories = False) so Bazel's path mapper rewrites both paths while keeping the aar_dir tree artifact as a single directory path.
  2. Support WorkRequest.sandbox_dir in the persistent worker (src/worker/, src/cli/):
    • Resolve the @flagfile and all path arguments (inputs, --output, --android-home, --jdk-home, <root dir>, --path-variables PWD=...) against the request's execution root (workingDirectory.resolve(request.sandboxDir).normalize()).
    • Guard PWD lookup against stale inherited PWD values.
    • Load cached AndroidLintCliInvoker URLClassLoaders from jar.toRealPath() (matching the cache key) so the shared classloader and UastEnvironment survive after Bazel deletes the first request's sandbox symlink.
    • Route per-request error stack traces to WorkRequestHandler's per-request PrintWriter instead of shared System.err, and convert checked callback exceptions into failed WorkResponses so requests never hang unanswered.
    • Initialize user.home once per worker process (thread-safely) rather than mutating the JVM-global property per request.
  3. Declare execution requirements on AndroidLint (rules/impl.bzl): adds supports-multiplex-sandboxing and supports-path-mapping to AndroidLint (leaving ExtractLintAar excluded).

Testing

  • Unit tests in //tests/src/worker:WorkerTest, //tests/src/cli:AndroidLintActionTest, //tests/src/cli:AndroidLintActionArgsTest, and //tests/src/cli:AndroidLintCliInvokerCacheTest covering concurrent multiplex sandboxes, per-request output isolation, checked exception handling, PWD handling, and classloader reuse after sandbox deletion.
  • Analysis tests in //tests/rules:tests verifying execution requirements and confirming every bazel-out/ path on the AndroidLint command line (including both halves of --classpath-aar) maps to bazel-out/cfg/ under --experimental_output_paths=strip.
  • bazel test //... passes (30/30) on both Bazel 8.x and Bazel 9.x with --strategy=AndroidLint=worker, --strategy=AndroidLint=local, and --strategy=AndroidLint=worker --experimental_output_paths=strip --experimental_worker_multiplex_sandboxing, plus //.github/workflows:buildifier.check.

badumbatish and others added 3 commits December 3, 2026 15:27
The --classpath-aar argument was built by formatting aar.path and
aar_dir.path into a string, so Bazel could not recognize the paths. With
--experimental_output_paths=strip the inputs are staged under
bazel-out/cfg while the argument kept the original configuration
directory, and lint failed because the AARs did not exist there.

Pass the Files to add_joined so that path mapping rewrites them, keeping
the tree artifact as a single path.
With multiplex sandboxing, Bazel stages each work request's inputs under
the request's WorkRequest.sandbox_dir, relative to the worker's working
directory. The worker resolved the @flagfile and every path argument
against its own working directory, and took the lint root directory,
--path-variables PWD and --sdk-home from $PWD, so a sandboxed request
could not find its inputs or write its report.

Resolve the flagfile and every path argument against the request's
execution root: its sandbox directory when Bazel sets one, otherwise the
worker's working directory. The project XML, --xml, --sdk-home,
--jdk-home and the root directory now all use absolute paths under it.
The worker's working directory comes from $PWD only when it names the
current directory, so a stale inherited $PWD can't misplace paths.

AndroidLintCliInvokerCache keys on the lint jar's real path, so requests
in different sandboxes still share one lint classloader. It now also
loads the jar from that real path: the sandbox symlink the first request
staged it through is deleted after that request, while the classloader
keeps serving later ones.

Write each request's error output to the PrintWriter whose contents
WorkRequestHandler returns in that request's WorkResponse. It went to
System.err, which WorkRequestHandler captures into one buffer shared by
every in-flight request, so concurrent requests could report each
other's errors. Lint's own console output still goes through that
buffer. Also report checked exceptions as failed requests:
WorkRequestHandler only answers RuntimeExceptions and
InterruptedExceptions, so any other checked exception left the request
without a response.

Set user.home once per worker process, to a temporary directory that
lives as long as the worker. Each request used to set the JVM-global
property to a directory in its own working directory, which raced
between concurrent requests and was deleted while lint, which caches
the locations it derives from user.home per classloader, kept using it.
Declare supports-path-mapping and supports-multiplex-sandboxing on the
AndroidLint action, so it shares remote cache entries across
configurations under --experimental_output_paths=strip and keeps running
as a multiplex worker under --experimental_worker_multiplex_sandboxing,
instead of falling back to sandboxed singleplex workers.

Every bazel-out path reaches the command line as a File, so path mapping
can rewrite it, and the worker resolves every path against the
request's sandbox. --android-home and --jdk-home pass toolchain roots,
which live outside bazel-out and so don't change under path mapping.
ExtractLintAar still formats paths into its shell command, so it
doesn't declare supports-path-mapping.

A new analysis test analyzes the lint action under
--experimental_output_paths=strip and checks that every bazel-out path on
its command line, including both halves of a joined --classpath-aar
argument, moves to bazel-out/cfg.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants