Skip to content

Commit 7802429

Browse files
Merge pull request #19 from ehuss/script
Add --script to specify an arbitrary script.
2 parents be6b64a + 75fcc34 commit 7802429

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

src/main.rs

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ struct Opts {
138138

139139
#[structopt(long = "force-install", help = "force installation over existing artifacts")]
140140
force_install: bool,
141+
142+
#[structopt(
143+
long = "script",
144+
help = "script to run instead of cargo to test for regression",
145+
parse(from_os_str)
146+
)]
147+
script: Option<PathBuf>,
141148
}
142149

143150
#[derive(Clone, Debug)]
@@ -443,7 +450,7 @@ impl Toolchain {
443450
fn test(&self, cfg: &Config, dl_spec: &DownloadParams) -> TestOutcome {
444451
if cfg.args.prompt {
445452
loop {
446-
let status = self.run_cargo(cfg, dl_spec);
453+
let status = self.run_test(cfg, dl_spec);
447454

448455
eprintln!("\n\n{} finished with exit code {:?}.", self, status.code());
449456
eprintln!("please select an action to take:");
@@ -461,42 +468,50 @@ impl Toolchain {
461468
}
462469
}
463470
} else {
464-
if self.run_cargo(cfg, dl_spec).success() {
471+
if self.run_test(cfg, dl_spec).success() {
465472
TestOutcome::Baseline
466473
} else {
467474
TestOutcome::Regressed
468475
}
469476
}
470477
}
471478

472-
fn run_cargo(&self, cfg: &Config, dl_spec: &DownloadParams) -> process::ExitStatus {
473-
// do things with this toolchain
474-
let mut cargo = Command::new("cargo");
475-
cargo.arg(&format!("+{}", self.rustup_name()));
476-
cargo.current_dir(&cfg.args.test_dir);
479+
fn run_test(&self, cfg: &Config, dl_spec: &DownloadParams) -> process::ExitStatus {
477480
let _ = fs::remove_dir_all(
478481
cfg.args
479482
.test_dir
480483
.join(&format!("target-{}", self.rustup_name())),
481484
);
482-
cargo.env("CARGO_TARGET_DIR", format!("target-{}", self.rustup_name()));
483-
484-
if cfg.args.cargo_args.is_empty() {
485-
cargo.arg("build");
486-
} else {
487-
cargo.args(&cfg.args.cargo_args);
488-
}
485+
let mut cmd = match cfg.args.script {
486+
Some(ref script) => {
487+
let mut cmd = Command::new(script);
488+
cmd.env("RUSTUP_TOOLCHAIN", self.rustup_name());
489+
cmd
490+
}
491+
None => {
492+
let mut cmd = Command::new("cargo");
493+
cmd.arg(&format!("+{}", self.rustup_name()));
494+
if cfg.args.cargo_args.is_empty() {
495+
cmd.arg("build");
496+
} else {
497+
cmd.args(&cfg.args.cargo_args);
498+
}
499+
cmd
500+
}
501+
};
502+
cmd.current_dir(&cfg.args.test_dir);
503+
cmd.env("CARGO_TARGET_DIR", format!("target-{}", self.rustup_name()));
489504
if cfg.args.emit_cargo_output() || cfg.args.prompt {
490-
cargo.stdout(Stdio::inherit());
491-
cargo.stderr(Stdio::inherit());
505+
cmd.stdout(Stdio::inherit());
506+
cmd.stderr(Stdio::inherit());
492507
} else {
493-
cargo.stdout(Stdio::null());
494-
cargo.stderr(Stdio::null());
508+
cmd.stdout(Stdio::null());
509+
cmd.stderr(Stdio::null());
495510
}
496-
let status = match cargo.status() {
511+
let status = match cmd.status() {
497512
Ok(status) => status,
498513
Err(err) => {
499-
panic!("failed to run {:?}: {:?}", cargo, err);
514+
panic!("failed to run {:?}: {:?}", cmd, err);
500515
}
501516
};
502517
if !cfg.args.preserve {

0 commit comments

Comments
 (0)