Skip to content

Commit

Permalink
miri-script: pass around the relative crate dir, not the absolute pat…
Browse files Browse the repository at this point in the history
…h to the toml file
  • Loading branch information
RalfJung committed Aug 10, 2024
1 parent 116d2de commit 45ec272
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 34 deletions.
32 changes: 15 additions & 17 deletions miri-script/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ impl MiriEnv {
// Sysroot already set, use that.
return Ok(miri_sysroot.into());
}
let manifest_path = path!(self.miri_dir / "cargo-miri" / "Cargo.toml");

// Make sure everything is built. Also Miri itself.
self.build(path!(self.miri_dir / "Cargo.toml"), &[], quiet)?;
self.build(&manifest_path, &[], quiet)?;
self.build(".", &[], quiet)?;
self.build("cargo-miri", &[], quiet)?;

let target_flag = if let Some(target) = &target {
vec![OsStr::new("--target"), target.as_ref()]
Expand All @@ -57,7 +56,7 @@ impl MiriEnv {
}

let mut cmd = self
.cargo_cmd(&manifest_path, "run")
.cargo_cmd("cargo-miri", "run")
.arg("--quiet")
.arg("--")
.args(&["miri", "setup", "--print-sysroot"])
Expand Down Expand Up @@ -429,30 +428,30 @@ impl Command {

fn build(flags: Vec<String>) -> Result<()> {
let e = MiriEnv::new()?;
e.build(path!(e.miri_dir / "Cargo.toml"), &flags, /* quiet */ false)?;
e.build(path!(e.miri_dir / "cargo-miri" / "Cargo.toml"), &flags, /* quiet */ false)?;
e.build(".", &flags, /* quiet */ false)?;
e.build("cargo-miri", &flags, /* quiet */ false)?;
Ok(())
}

fn check(flags: Vec<String>) -> Result<()> {
let e = MiriEnv::new()?;
e.check(path!(e.miri_dir / "Cargo.toml"), &flags)?;
e.check(path!(e.miri_dir / "cargo-miri" / "Cargo.toml"), &flags)?;
e.check(".", &flags)?;
e.check("cargo-miri", &flags)?;
Ok(())
}

fn doc(flags: Vec<String>) -> Result<()> {
let e = MiriEnv::new()?;
e.doc(path!(e.miri_dir / "Cargo.toml"), &flags)?;
e.doc(path!(e.miri_dir / "cargo-miri" / "Cargo.toml"), &flags)?;
e.doc(".", &flags)?;
e.doc("cargo-miri", &flags)?;
Ok(())
}

fn clippy(flags: Vec<String>) -> Result<()> {
let e = MiriEnv::new()?;
e.clippy(path!(e.miri_dir / "Cargo.toml"), &flags)?;
e.clippy(path!(e.miri_dir / "cargo-miri" / "Cargo.toml"), &flags)?;
e.clippy(path!(e.miri_dir / "miri-script" / "Cargo.toml"), &flags)?;
e.clippy(".", &flags)?;
e.clippy("cargo-miri", &flags)?;
e.clippy("miri-script", &flags)?;
Ok(())
}

Expand All @@ -476,7 +475,7 @@ impl Command {

// Then test, and let caller control flags.
// Only in root project as `cargo-miri` has no tests.
e.test(path!(e.miri_dir / "Cargo.toml"), &flags)?;
e.test(".", &flags)?;
Ok(())
}

Expand Down Expand Up @@ -510,7 +509,6 @@ impl Command {
early_flags.push(miri_sysroot.into());

// Compute everything needed to run the actual command. Also add MIRIFLAGS.
let miri_manifest = path!(e.miri_dir / "Cargo.toml");
let miri_flags = e.sh.var("MIRIFLAGS").unwrap_or_default();
let miri_flags = flagsplit(&miri_flags);
let quiet_flag = if verbose { None } else { Some("--quiet") };
Expand All @@ -519,13 +517,13 @@ impl Command {
let run_miri = |e: &MiriEnv, seed_flag: Option<String>| -> Result<()> {
// The basic command that executes the Miri driver.
let mut cmd = if dep {
e.cargo_cmd(&miri_manifest, "test")
e.cargo_cmd(".", "test")
.args(&["--test", "ui"])
.args(quiet_flag)
.arg("--")
.args(&["--miri-run-dep-mode"])
} else {
e.cargo_cmd(&miri_manifest, "run").args(quiet_flag).arg("--")
e.cargo_cmd(".", "run").args(quiet_flag).arg("--")
};
cmd.set_quiet(!verbose);
// Add Miri flags
Expand Down
30 changes: 13 additions & 17 deletions miri-script/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ impl MiriEnv {
Ok(MiriEnv { miri_dir, toolchain, sh, sysroot, cargo_extra_flags })
}

pub fn cargo_cmd(&self, manifest_path: impl AsRef<OsStr>, cmd: &str) -> Cmd<'_> {
pub fn cargo_cmd(&self, crate_dir: impl AsRef<OsStr>, cmd: &str) -> Cmd<'_> {
let MiriEnv { toolchain, cargo_extra_flags, .. } = self;
let manifest_path = Path::new(manifest_path.as_ref());
let manifest_path = path!(self.miri_dir / crate_dir.as_ref() / "Cargo.toml");
cmd!(
self.sh,
"cargo +{toolchain} {cmd} {cargo_extra_flags...} --manifest-path {manifest_path}"
Expand All @@ -117,26 +117,22 @@ impl MiriEnv {
args: impl IntoIterator<Item = impl AsRef<OsStr>>,
) -> Result<()> {
let MiriEnv { sysroot, toolchain, cargo_extra_flags, .. } = self;
let path = path!(self.miri_dir / path.as_ref());
// Install binaries to the miri toolchain's `sysroot` so they do not interact with other toolchains.
// (Not using `cargo_cmd` as `install` is special and doesn't use `--manifest-path`.)
cmd!(self.sh, "cargo +{toolchain} install {cargo_extra_flags...} --path {path} --force --root {sysroot} {args...}").run()?;
Ok(())
}

pub fn build(
&self,
manifest_path: impl AsRef<OsStr>,
args: &[String],
quiet: bool,
) -> Result<()> {
pub fn build(&self, crate_dir: impl AsRef<OsStr>, args: &[String], quiet: bool) -> Result<()> {
let quiet_flag = if quiet { Some("--quiet") } else { None };
// We build the tests as well, (a) to avoid having rebuilds when building the tests later
// and (b) to have more parallelism during the build of Miri and its tests.
// This means `./miri run` without `--dep` will build Miri twice (for the sysroot with
// dev-dependencies, and then for running without dev-dependencies), but the way more common
// `./miri test` will avoid building Miri twice.
let mut cmd = self
.cargo_cmd(manifest_path, "build")
.cargo_cmd(crate_dir, "build")
.args(&["--bins", "--tests"])
.args(quiet_flag)
.args(args);
Expand All @@ -145,23 +141,23 @@ impl MiriEnv {
Ok(())
}

pub fn check(&self, manifest_path: impl AsRef<OsStr>, args: &[String]) -> Result<()> {
self.cargo_cmd(manifest_path, "check").arg("--all-targets").args(args).run()?;
pub fn check(&self, crate_dir: impl AsRef<OsStr>, args: &[String]) -> Result<()> {
self.cargo_cmd(crate_dir, "check").arg("--all-targets").args(args).run()?;
Ok(())
}

pub fn doc(&self, manifest_path: impl AsRef<OsStr>, args: &[String]) -> Result<()> {
self.cargo_cmd(manifest_path, "doc").args(args).run()?;
pub fn doc(&self, crate_dir: impl AsRef<OsStr>, args: &[String]) -> Result<()> {
self.cargo_cmd(crate_dir, "doc").args(args).run()?;
Ok(())
}

pub fn clippy(&self, manifest_path: impl AsRef<OsStr>, args: &[String]) -> Result<()> {
self.cargo_cmd(manifest_path, "clippy").arg("--all-targets").args(args).run()?;
pub fn clippy(&self, crate_dir: impl AsRef<OsStr>, args: &[String]) -> Result<()> {
self.cargo_cmd(crate_dir, "clippy").arg("--all-targets").args(args).run()?;
Ok(())
}

pub fn test(&self, manifest_path: impl AsRef<OsStr>, args: &[String]) -> Result<()> {
self.cargo_cmd(manifest_path, "test").args(args).run()?;
pub fn test(&self, crate_dir: impl AsRef<OsStr>, args: &[String]) -> Result<()> {
self.cargo_cmd(crate_dir, "test").args(args).run()?;
Ok(())
}

Expand Down

0 comments on commit 45ec272

Please sign in to comment.