Skip to content

Commit eecf0b7

Browse files
committed
Fix ordering of --remap-path-prefix flags.
These flags are interpreted in reverse order (see rust-lang/rust#82108), and if we have a set of flags like: ``` --remap-path-prefix=/a/b/c/d=. --remap-path-prefix=/a/b=. ``` then the first flag will never apply, because the path will be first rewritten as ./c/d. In this case, output_base is the outermost directory, so we need to make sure it's remapped last.
1 parent 7b31777 commit eecf0b7

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

rust/private/rustc.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,9 +1116,13 @@ def construct_arguments(
11161116

11171117
# For determinism to help with build distribution and such
11181118
if remap_path_prefix != None:
1119+
# `--remap-path-prefix` flags are applied in reverse order. We need to
1120+
# specify the outermost directory (output_base) first, so that it's
1121+
# remapped last. Otherwise we can end up with a partial rewrite where
1122+
# "/path/to/output_base/execroot" becomes "./execroot" rather than ".".
1123+
rustc_flags.add("--remap-path-prefix=${{output_base}}={}".format(remap_path_prefix))
11191124
rustc_flags.add("--remap-path-prefix=${{pwd}}={}".format(remap_path_prefix))
11201125
rustc_flags.add("--remap-path-prefix=${{exec_root}}={}".format(remap_path_prefix))
1121-
rustc_flags.add("--remap-path-prefix=${{output_base}}={}".format(remap_path_prefix))
11221126

11231127
emit_without_paths = []
11241128
for kind in emit:

test/unit/remap_path_prefix/remap_path_prefix_test.bzl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ def _remap_path_prefix_test_impl(ctx):
1717
action = target.actions[0]
1818
assert_action_mnemonic(env, action, "Rustc")
1919

20-
assert_argv_contains(env, action, "--remap-path-prefix=${pwd}=.")
21-
assert_argv_contains(env, action, "--remap-path-prefix=${exec_root}=.")
22-
assert_argv_contains(env, action, "--remap-path-prefix=${output_base}=.")
20+
assert_list_contains_adjacent_elements(env, action.argv, [
21+
"--remap-path-prefix=${output_base}=.",
22+
"--remap-path-prefix=${pwd}=.",
23+
"--remap-path-prefix=${exec_root}=.",
24+
])
2325

2426
return analysistest.end(env)
2527

0 commit comments

Comments
 (0)