Skip to content

Commit

Permalink
no need to forward all env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 2, 2023
1 parent 0640ae9 commit 751cfa8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/tools/miri/miri-script/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::ops::Not;
use anyhow::{anyhow, bail, Context, Result};
use path_macro::path;
use walkdir::WalkDir;
use xshell::cmd;
use xshell::{cmd, Shell};

use crate::util::*;
use crate::Command;
Expand Down Expand Up @@ -91,7 +91,7 @@ impl Command {
// Make sure rustup-toolchain-install-master is installed.
which::which("rustup-toolchain-install-master")
.context("Please install rustup-toolchain-install-master by running 'cargo install rustup-toolchain-install-master'")?;
let sh = shell()?;
let sh = Shell::new()?;
sh.change_dir(miri_dir()?);
let new_commit = Some(sh.read_file("rust-version")?.trim().to_owned());
let current_commit = {
Expand Down Expand Up @@ -130,7 +130,7 @@ impl Command {
}

fn rustc_pull(commit: Option<String>) -> Result<()> {
let sh = shell()?;
let sh = Shell::new()?;
sh.change_dir(miri_dir()?);
let commit = commit.map(Result::Ok).unwrap_or_else(|| {
let rust_repo_head =
Expand Down Expand Up @@ -177,7 +177,7 @@ impl Command {
}

fn rustc_push(github_user: String, branch: String) -> Result<()> {
let sh = shell()?;
let sh = Shell::new()?;
sh.change_dir(miri_dir()?);
let base = sh.read_file("rust-version")?.trim().to_owned();
// Make sure the repo is clean.
Expand Down Expand Up @@ -265,7 +265,7 @@ impl Command {
let Some((command_name, trailing_args)) = command.split_first() else {
bail!("expected many-seeds command to be non-empty");
};
let sh = shell()?;
let sh = Shell::new()?;
for seed in seed_start..seed_end {
println!("Trying seed: {seed}");
let mut miriflags = env::var_os("MIRIFLAGS").unwrap_or_default();
Expand Down Expand Up @@ -293,7 +293,7 @@ impl Command {
// Make sure we have an up-to-date Miri installed and selected the right toolchain.
Self::install(vec![])?;

let sh = shell()?;
let sh = Shell::new()?;
sh.change_dir(miri_dir()?);
let benches_dir = "bench-cargo-miri";
let benches = if benches.is_empty() {
Expand Down
13 changes: 2 additions & 11 deletions src/tools/miri/miri-script/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,12 @@ pub fn miri_dir() -> std::io::Result<PathBuf> {

/// Queries the active toolchain for the Miri dir.
pub fn active_toolchain() -> Result<String> {
let sh = shell()?;
let sh = Shell::new()?;
sh.change_dir(miri_dir()?);
let stdout = cmd!(sh, "rustup show active-toolchain").read()?;
Ok(stdout.split_whitespace().next().context("Could not obtain active Rust toolchain")?.into())
}

pub fn shell() -> Result<Shell> {
let sh = Shell::new()?;
// xshell does not propagate parent's env variables by default.
for (k, v) in std::env::vars_os() {
sh.set_var(k, v);
}
Ok(sh)
}

pub fn flagsplit(flags: &str) -> Vec<String> {
// This code is taken from `RUSTFLAGS` handling in cargo.
flags.split(' ').map(str::trim).filter(|s| !s.is_empty()).map(str::to_string).collect()
Expand All @@ -50,7 +41,7 @@ pub struct MiriEnv {
impl MiriEnv {
pub fn new() -> Result<Self> {
let toolchain = active_toolchain()?;
let sh = shell()?; // we are preserving the current_dir on this one, so paths resolve properly!
let sh = Shell::new()?; // we are preserving the current_dir on this one, so paths resolve properly!
let miri_dir = miri_dir()?;

let sysroot = cmd!(sh, "rustc +{toolchain} --print sysroot").read()?.into();
Expand Down

0 comments on commit 751cfa8

Please sign in to comment.