[9.x] `--run_under` in platform `flags` splits testonly and non-testonly targets into different output directories

Open
#33,056 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
build-system

Research direction

The issue provides a minimal reproducer in MODULE.bazel, runner.sh, and BUILD.bazel; start by running the shown build on Bazel 9.3.3 and inspect how platform flags and test trimming affect the output directories. The reported fix is in 10.0.0rc4, and commit 5c8f44dd is mentioned as a possible related change. Done means the 9.x build places the generated dependency and testonly output in the same directory.

Written by the indexing model from the issue text.

Description

Description of the bug:

When a platform sets --run_under in its flags, targets that aren't testonly build into <platform>-fastbuild-ST-<hash>, while tests and testonly targets build into <platform>-fastbuild. Test trimming drops --run_under from non-test configurations, and with platform-based flags, the trimmed configuration gets an -ST- hash.

Paths a testonly target derives from its own output directory then miss files generated by its non-testonly deps. For example, a testonly cc_library with includes = ["."] doesn't find a header generated by a genrule: the -I path comes from its ctx.bin_dir, but the header is in the -ST- directory.

--run_under on the command line or --notrim_test_configuration avoids the split. It reproduces in 9.3.3 and is fixed in 10.0.0rc4; could the fix be backported to 9.x? Looking through the commits, 5c8f44dd387d92886c2ef7aabee03152f9143e73 fixed a similar baseline problem for exec configurations, so it might be related, but that's a guess.

We set --run_under in platform flags to run tests on Android devices and iOS simulators, with a runner per platform (as in #22624).

Which category does this issue belong to?

Configurability

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

MODULE.bazel:

module(name = "run_under_repro")

runner.sh (executable):

#!/bin/sh
exec "$@"

BUILD.bazel:

platform(
    name = "device",
    flags = ["--run_under=//:runner.sh"],
)

genrule(
    name = "gen",
    outs = ["gen.txt"],
    cmd = "echo generated > $@",
)

genrule(
    name = "use",
    testonly = True,
    srcs = [":gen"],
    outs = ["use.txt"],
    cmd = "echo \"BINDIR=$(BINDIR) gen=$(location :gen)\" > $@",
)
$ bazel build --platforms=//:device //:use && cat bazel-bin/use.txt
BINDIR=bazel-out/darwin_arm64-fastbuild/bin gen=bazel-out/darwin_arm64-fastbuild-ST-2ca549da6d12/bin/gen.txt

With 10.0.0rc4, both are in bazel-out/device-fastbuild/bin.

Which operating system are you running Bazel on?

macOS 27.2 (arm64)

What is the output of bazel info release?

release 9.3.3

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

Not a regression as far as I know.

Have you found anything relevant by searching the web?

#18480 (test options in the output directory name, from the command line) and #22624 (--run_under with --platforms for on-device tests) are related, but neither covers platform-based flags.

Any other information, logs, or outputs that you want to share?

No response

Dominant language
Java
Stars
26.2k
Forks
4.7k
Avg merge
3d 11h
Merged PRs (30d)
125

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bazelbuild/bazel

All issues in bazelbuild/bazel

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.