Skip to content

Commit 29fdb9b

Browse files
committed
Add --script to specify an arbitrary script.
Fixes #11
1 parent be6b64a commit 29fdb9b

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

src/main.rs

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

139139
#[structopt(long = "force-install", help = "force installation over existing artifacts")]
140140
force_install: bool,
141+
142+
#[structopt(long = "script", help = "script to run instead of cargo to test for regression")]
143+
script: Option<String>,
141144
}
142145

143146
#[derive(Clone, Debug)]
@@ -443,7 +446,7 @@ impl Toolchain {
443446
fn test(&self, cfg: &Config, dl_spec: &DownloadParams) -> TestOutcome {
444447
if cfg.args.prompt {
445448
loop {
446-
let status = self.run_cargo(cfg, dl_spec);
449+
let status = self.run_test(cfg, dl_spec);
447450

448451
eprintln!("\n\n{} finished with exit code {:?}.", self, status.code());
449452
eprintln!("please select an action to take:");
@@ -461,42 +464,50 @@ impl Toolchain {
461464
}
462465
}
463466
} else {
464-
if self.run_cargo(cfg, dl_spec).success() {
467+
if self.run_test(cfg, dl_spec).success() {
465468
TestOutcome::Baseline
466469
} else {
467470
TestOutcome::Regressed
468471
}
469472
}
470473
}
471474

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);
475+
fn run_test(&self, cfg: &Config, dl_spec: &DownloadParams) -> process::ExitStatus {
477476
let _ = fs::remove_dir_all(
478477
cfg.args
479478
.test_dir
480479
.join(&format!("target-{}", self.rustup_name())),
481480
);
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-
}
481+
let mut cmd = match cfg.args.script {
482+
Some(ref script) => {
483+
let mut cmd = Command::new(script);
484+
cmd.env("RUSTUP_TOOLCHAIN", self.rustup_name());
485+
cmd
486+
}
487+
None => {
488+
let mut cmd = Command::new("cargo");
489+
cmd.arg(&format!("+{}", self.rustup_name()));
490+
if cfg.args.cargo_args.is_empty() {
491+
cmd.arg("build");
492+
} else {
493+
cmd.args(&cfg.args.cargo_args);
494+
}
495+
cmd
496+
}
497+
};
498+
cmd.current_dir(&cfg.args.test_dir);
499+
cmd.env("CARGO_TARGET_DIR", format!("target-{}", self.rustup_name()));
489500
if cfg.args.emit_cargo_output() || cfg.args.prompt {
490-
cargo.stdout(Stdio::inherit());
491-
cargo.stderr(Stdio::inherit());
501+
cmd.stdout(Stdio::inherit());
502+
cmd.stderr(Stdio::inherit());
492503
} else {
493-
cargo.stdout(Stdio::null());
494-
cargo.stderr(Stdio::null());
504+
cmd.stdout(Stdio::null());
505+
cmd.stderr(Stdio::null());
495506
}
496-
let status = match cargo.status() {
507+
let status = match cmd.status() {
497508
Ok(status) => status,
498509
Err(err) => {
499-
panic!("failed to run {:?}: {:?}", cargo, err);
510+
panic!("failed to run {:?}: {:?}", cmd, err);
500511
}
501512
};
502513
if !cfg.args.preserve {

0 commit comments

Comments
 (0)