Skip to content

Commit a323b98

Browse files
Merge pull request #23 from anp/preserve-toolchain-for-prompts
Make retrying prompt mode work with uninstalls correctly.
2 parents 36d7b26 + f4adfca commit a323b98

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/main.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ struct Opts {
9999
#[structopt(long = "preserve", help = "Preserve the downloaded artifacts")]
100100
preserve: bool,
101101

102+
#[structopt(long = "preserve-target", help = "Preserve the target directory used for builds")]
103+
preserve_target: bool,
104+
102105
#[structopt(
103106
long = "with-cargo", help = "Download cargo, by default the installed cargo is used"
104107
)]
@@ -459,9 +462,9 @@ impl Toolchain {
459462
}
460463

461464
fn test(&self, cfg: &Config, dl_spec: &DownloadParams) -> TestOutcome {
462-
if cfg.args.prompt {
465+
let outcome = if cfg.args.prompt {
463466
loop {
464-
let status = self.run_test(cfg, dl_spec);
467+
let status = self.run_test(cfg);
465468

466469
eprintln!("\n\n{} finished with exit code {:?}.", self, status.code());
467470
eprintln!("please select an action to take:");
@@ -479,20 +482,28 @@ impl Toolchain {
479482
}
480483
}
481484
} else {
482-
if self.run_test(cfg, dl_spec).success() {
485+
if self.run_test(cfg).success() {
483486
TestOutcome::Baseline
484487
} else {
485488
TestOutcome::Regressed
486489
}
490+
};
491+
492+
if !cfg.args.preserve {
493+
let _ = self.remove(dl_spec);
487494
}
495+
496+
outcome
488497
}
489498

490-
fn run_test(&self, cfg: &Config, dl_spec: &DownloadParams) -> process::ExitStatus {
491-
let _ = fs::remove_dir_all(
492-
cfg.args
493-
.test_dir
494-
.join(&format!("target-{}", self.rustup_name())),
495-
);
499+
fn run_test(&self, cfg: &Config) -> process::ExitStatus {
500+
if !cfg.args.preserve_target {
501+
let _ = fs::remove_dir_all(
502+
cfg.args
503+
.test_dir
504+
.join(&format!("target-{}", self.rustup_name())),
505+
);
506+
}
496507
let mut cmd = match cfg.args.script {
497508
Some(ref script) => {
498509
let mut cmd = Command::new(script);
@@ -525,9 +536,6 @@ impl Toolchain {
525536
panic!("failed to run {:?}: {:?}", cmd, err);
526537
}
527538
};
528-
if !cfg.args.preserve {
529-
let _ = self.remove(dl_spec);
530-
}
531539

532540
status
533541
}

0 commit comments

Comments
 (0)