Skip to content

Commit f75571a

Browse files
bazel-iofmeum
andauthored
[7.2.0] Disable path mapping with local or no-{sandbox,remote} tags (#22467)
Targets tagged with `local` or `no-sandbox` and `no-remote` can't successfully use path mapping and thus have it disabled implicitly. Closes #21921. PiperOrigin-RevId: 635832339 Change-Id: Ib5cac0b202cbcd1704410f06fa3cda645581b849 Commit 46dce83 Co-authored-by: Fabian Meumertzheim <[email protected]>
1 parent 87b0a1f commit f75571a

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/main/java/com/google/devtools/build/lib/analysis/actions/PathMappers.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ public static OutputPathsMode getOutputPathsMode(
132132

133133
private static OutputPathsMode getEffectiveOutputPathsMode(
134134
OutputPathsMode outputPathsMode, String mnemonic, Map<String, String> executionInfo) {
135+
if (executionInfo.containsKey(ExecutionRequirements.LOCAL)
136+
|| (executionInfo.containsKey(ExecutionRequirements.NO_SANDBOX)
137+
&& executionInfo.containsKey(ExecutionRequirements.NO_REMOTE))) {
138+
// Path mapping requires sandboxed or remote execution.
139+
return OutputPathsMode.OFF;
140+
}
135141
if (outputPathsMode == OutputPathsMode.STRIP
136142
&& (SUPPORTED_MNEMONICS.contains(mnemonic)
137143
|| executionInfo.containsKey(ExecutionRequirements.SUPPORTS_PATH_MAPPING))) {

src/test/shell/bazel/path_mapping_test.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,43 @@ EOF
286286
expect_log '2 remote[^ ]'
287287
}
288288

289+
function test_path_stripping_disabled_with_tags() {
290+
mkdir pkg
291+
cat > pkg/defs.bzl <<'EOF'
292+
def _my_rule_impl(ctx):
293+
out = ctx.actions.declare_file(ctx.attr.name)
294+
args = ctx.actions.args()
295+
args.add(out)
296+
ctx.actions.run_shell(
297+
outputs = [out],
298+
command = "echo 'Hello, World!' > $1",
299+
arguments = [args],
300+
execution_requirements = {"supports-path-mapping": ""},
301+
)
302+
return [
303+
DefaultInfo(files = depset([out])),
304+
]
305+
306+
my_rule = rule(_my_rule_impl)
307+
EOF
308+
cat > pkg/BUILD << 'EOF'
309+
load(":defs.bzl", "my_rule")
310+
311+
my_rule(
312+
name = "local_target",
313+
tags = ["local"],
314+
)
315+
316+
my_rule(
317+
name = "implicitly_local_target",
318+
tags = [
319+
"no-sandbox",
320+
"no-remote",
321+
],
322+
)
323+
EOF
324+
325+
bazel build --experimental_output_paths=strip //pkg:all &> $TEST_log || fail "build failed unexpectedly"
326+
}
327+
289328
run_suite "path mapping tests"

0 commit comments

Comments
 (0)