Skip to content

Commit fccb239

Browse files
committed
Auto merge of #1008 - RalfJung:sysroot, r=RalfJung
print sysroot without any escaping
2 parents cb932f4 + 324fed3 commit fccb239

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

miri

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ build_sysroot() {
5454
# Build once, for the user to see.
5555
cargo run $CARGO_BUILD_FLAGS --bin cargo-miri -- miri setup "$@"
5656
# Call again, to just set env var.
57-
eval $(cargo run $CARGO_BUILD_FLAGS -q --bin cargo-miri -- miri setup --env "$@")
57+
export MIRI_SYSROOT="$(cargo run $CARGO_BUILD_FLAGS -q --bin cargo-miri -- miri setup --print-sysroot "$@")"
5858
}
5959

6060
# Prepare and set MIRI_SYSROOT. Respects `MIRI_TEST_TARGET` and takes into account

src/bin/cargo-miri.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ path = "lib.rs"
310310
File::create(dir.join("lib.rs")).unwrap();
311311
// Prepare xargo invocation.
312312
let target = get_arg_flag_value("--target");
313-
let print_env = !ask_user && has_arg_flag("--env"); // whether we just print the necessary environment variable
313+
let print_sysroot = !ask_user && has_arg_flag("--print-sysroot"); // whether we just print the sysroot path
314314
let mut command = xargo();
315315
command.arg("build").arg("-q");
316316
command.current_dir(&dir);
@@ -339,13 +339,9 @@ path = "lib.rs"
339339
};
340340
let sysroot = if is_host { dir.join("HOST") } else { PathBuf::from(dir) };
341341
std::env::set_var("MIRI_SYSROOT", &sysroot); // pass the env var to the processes we spawn, which will turn it into "--sysroot" flags
342-
if print_env {
343-
// Escape an arbitrary string for the shell: by wrapping it in `'`, the only special
344-
// character we have to worry about is `'` itself. Everything else is taken literally
345-
// in these strings. `'` is encoded as `'"'"'`: the outer `'` end and being a
346-
// `'`-quoted string, respectively; the `"'"` in the middle represents a single `'`.
347-
// (We could use `'\''` instead of `'"'"'` if we wanted but let's avoid backslashes.)
348-
println!("MIRI_SYSROOT='{}'", sysroot.display().to_string().replace('\'', r#"'"'"'"#));
342+
if print_sysroot {
343+
// Print just the sysroot and nothing else; this way we do not need any escaping.
344+
println!("{}", sysroot.display());
349345
} else if !ask_user {
350346
println!("A libstd for Miri is now available in `{}`.", sysroot.display());
351347
}

0 commit comments

Comments
 (0)