Skip to content

Commit ce35f8e

Browse files
committed
remap-cwd-prefix
1 parent 69c4aa2 commit ce35f8e

File tree

5 files changed

+70
-3
lines changed

5 files changed

+70
-3
lines changed

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ fn test_debugging_options_tracking_hash() {
753753
tracked!(profiler_runtime, "abc".to_string());
754754
tracked!(relax_elf_relocations, Some(true));
755755
tracked!(relro_level, Some(RelroLevel::Full));
756+
tracked!(remap_cwd_prefix, Some(PathBuf::from("abc")));
756757
tracked!(simulate_remapped_rust_src_base, Some(PathBuf::from("/rustc/abc")));
757758
tracked!(report_delayed_bugs, true);
758759
tracked!(sanitizer, SanitizerSet::ADDRESS);

compiler/rustc_session/src/config.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,9 +1920,10 @@ fn parse_extern_dep_specs(
19201920

19211921
fn parse_remap_path_prefix(
19221922
matches: &getopts::Matches,
1923+
debugging_opts: &DebuggingOptions,
19231924
error_format: ErrorOutputType,
19241925
) -> Vec<(PathBuf, PathBuf)> {
1925-
matches
1926+
let mut mapping: Vec<(PathBuf, PathBuf)> = matches
19261927
.opt_strs("remap-path-prefix")
19271928
.into_iter()
19281929
.map(|remap| match remap.rsplit_once('=') {
@@ -1932,7 +1933,15 @@ fn parse_remap_path_prefix(
19321933
),
19331934
Some((from, to)) => (PathBuf::from(from), PathBuf::from(to)),
19341935
})
1935-
.collect()
1936+
.collect();
1937+
match &debugging_opts.remap_cwd_prefix {
1938+
Some(to) => match std::env::current_dir() {
1939+
Ok(cwd) => mapping.push((cwd, to.clone())),
1940+
Err(_) => (),
1941+
},
1942+
None => (),
1943+
};
1944+
mapping
19361945
}
19371946

19381947
pub fn build_session_options(matches: &getopts::Matches) -> Options {
@@ -2077,7 +2086,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
20772086

20782087
let crate_name = matches.opt_str("crate-name");
20792088

2080-
let remap_path_prefix = parse_remap_path_prefix(matches, error_format);
2089+
let remap_path_prefix = parse_remap_path_prefix(matches, &debugging_opts, error_format);
20812090

20822091
let pretty = parse_pretty(&debugging_opts, error_format);
20832092

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,8 @@ options! {
12361236
"whether ELF relocations can be relaxed"),
12371237
relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
12381238
"choose which RELRO level to use"),
1239+
remap_cwd_prefix: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
1240+
"remap paths under the current working directory to this path prefix"),
12391241
simulate_remapped_rust_src_base: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
12401242
"simulate the effect of remap-debuginfo = true at bootstrapping by remapping path \
12411243
to rust's source base directory. only meant for testing purposes"),

src/doc/rustc/src/command-line-arguments.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,19 @@ replacement is purely textual, with no consideration of the current system's
345345
pathname syntax. For example `--remap-path-prefix foo=bar` will match
346346
`foo/lib.rs` but not `./foo/lib.rs`.
347347

348+
<a id="option-remap-cwd-prefix"></a>
349+
## `--remap-cwd-prefix`: remap paths under the cwd in output
350+
351+
Remap all absolute paths that are rooted under the current working directory to
352+
be under the given value instead. The given value may be absolute or relative,
353+
or empty. This switch takes precidence over `--remap-path-prefix` in case they
354+
would both match a given path.
355+
356+
This flag allows the command line to be universally reproducible, such that the
357+
same execution will work on all machines, regardless of build environment.
358+
359+
This is an unstable option. Use `-Z remap-cwd-prefix=val` to specify a value.
360+
348361
<a id="option-json"></a>
349362
## `--json`: configure json messages printed by the compiler
350363

src/test/run-make-fulldeps/reproducible-build/Makefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ all: \
1010
link_paths \
1111
remap_paths \
1212
different_source_dirs \
13+
remap_cwd_bin \
14+
remap_cwd_rlib \
15+
remap_cwd_to_empty \
1316
extern_flags
1417

1518
smoke:
@@ -64,6 +67,45 @@ different_source_dirs:
6467
--crate-type rlib)
6568
cmp "$(TMPDIR)/libreproducible_build.rlib" "$(TMPDIR)/libfoo.rlib" || exit 1
6669

70+
remap_cwd_bin:
71+
rm -rf $(TMPDIR) && mkdir $(TMPDIR)
72+
$(RUSTC) reproducible-build-aux.rs
73+
mkdir $(TMPDIR)/test
74+
cp reproducible-build.rs $(TMPDIR)/test
75+
$(RUSTC) reproducible-build.rs --crate-type bin -C debuginfo=2 \
76+
-Z remap-cwd-prefix=.
77+
cp $(TMPDIR)/reproducible-build $(TMPDIR)/first
78+
(cd $(TMPDIR)/test && \
79+
$(RUSTC) reproducible-build.rs --crate-type bin -C debuginfo=2 \
80+
-Z remap-cwd-prefix=.)
81+
cmp "$(TMPDIR)/first" "$(TMPDIR)/reproducible-build" || exit 1
82+
83+
remap_cwd_rlib:
84+
rm -rf $(TMPDIR) && mkdir $(TMPDIR)
85+
$(RUSTC) reproducible-build-aux.rs
86+
mkdir $(TMPDIR)/test
87+
cp reproducible-build.rs $(TMPDIR)/test
88+
$(RUSTC) reproducible-build.rs --crate-type rlib -C debuginfo=2 \
89+
-Z remap-cwd-prefix=.
90+
cp $(TMPDIR)/libreproducible_build.rlib $(TMPDIR)/libfirst.rlib
91+
(cd $(TMPDIR)/test && \
92+
$(RUSTC) reproducible-build.rs --crate-type rlib -C debuginfo=2 \
93+
-Z remap-cwd-prefix=.)
94+
cmp "$(TMPDIR)/libfirst.rlib" "$(TMPDIR)/libreproducible_build.rlib" || exit 1
95+
96+
remap_cwd_to_empty:
97+
rm -rf $(TMPDIR) && mkdir $(TMPDIR)
98+
$(RUSTC) reproducible-build-aux.rs
99+
mkdir $(TMPDIR)/test
100+
cp reproducible-build.rs $(TMPDIR)/test
101+
$(RUSTC) reproducible-build.rs --crate-type rlib -C debuginfo=2 \
102+
-Z remap-cwd-prefix=
103+
cp $(TMPDIR)/libreproducible_build.rlib $(TMPDIR)/libfirst.rlib
104+
(cd $(TMPDIR)/test && \
105+
$(RUSTC) reproducible-build.rs --crate-type rlib -C debuginfo=2 \
106+
-Z remap-cwd-prefix=)
107+
cmp "$(TMPDIR)/libfirst.rlib" "$(TMPDIR)/libreproducible_build.rlib" || exit 1
108+
67109
extern_flags:
68110
rm -rf $(TMPDIR) && mkdir $(TMPDIR)
69111
$(RUSTC) reproducible-build-aux.rs

0 commit comments

Comments
 (0)