Skip to content

Commit 09b2162

Browse files
committed
remove old remove_and_create_dir_all and use build_helpers remove_and_create_dir_all
1 parent 3164f7d commit 09b2162

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::process::{Child, Command, ExitStatus, Output, Stdio};
99
use std::sync::Arc;
1010
use std::{env, iter, str};
1111

12+
use build_helper::fs::remove_and_create_dir_all;
1213
use camino::{Utf8Path, Utf8PathBuf};
1314
use colored::Colorize;
1415
use regex::{Captures, Regex};
@@ -207,12 +208,6 @@ pub fn compute_stamp_hash(config: &Config) -> String {
207208
format!("{:x}", hash.finish())
208209
}
209210

210-
fn remove_and_create_dir_all(path: &Utf8Path) {
211-
let path = path.as_std_path();
212-
let _ = fs::remove_dir_all(path);
213-
fs::create_dir_all(path).unwrap();
214-
}
215-
216211
#[derive(Copy, Clone, Debug)]
217212
struct TestCx<'test> {
218213
config: &'test Config,
@@ -523,7 +518,8 @@ impl<'test> TestCx<'test> {
523518
let mut rustc = Command::new(&self.config.rustc_path);
524519

525520
let out_dir = self.output_base_name().with_extension("pretty-out");
526-
remove_and_create_dir_all(&out_dir);
521+
remove_and_create_dir_all(&out_dir)
522+
.expect("Failed to remove and recreate output directory");
527523

528524
let target = if self.props.force_host { &*self.config.host } else { &*self.config.target };
529525

@@ -1098,13 +1094,16 @@ impl<'test> TestCx<'test> {
10981094
let aux_dir = self.aux_output_dir_name();
10991095

11001096
if !self.props.aux.builds.is_empty() {
1101-
remove_and_create_dir_all(&aux_dir);
1097+
remove_and_create_dir_all(&aux_dir)
1098+
.expect("Failed to remove and recreate output directory");
11021099
}
11031100

11041101
if !self.props.aux.bins.is_empty() {
11051102
let aux_bin_dir = self.aux_bin_output_dir_name();
1106-
remove_and_create_dir_all(&aux_dir);
1107-
remove_and_create_dir_all(&aux_bin_dir);
1103+
remove_and_create_dir_all(&aux_dir)
1104+
.expect("Failed to remove and recreate output directory");
1105+
remove_and_create_dir_all(&aux_bin_dir)
1106+
.expect("Failed to remove and recreate output directory");
11081107
}
11091108

11101109
aux_dir
@@ -1509,7 +1508,8 @@ impl<'test> TestCx<'test> {
15091508

15101509
let set_mir_dump_dir = |rustc: &mut Command| {
15111510
let mir_dump_dir = self.get_mir_dump_dir();
1512-
remove_and_create_dir_all(&mir_dump_dir);
1511+
remove_and_create_dir_all(&mir_dump_dir)
1512+
.expect("Failed to remove and recreate output directory");
15131513
let mut dir_opt = "-Zdump-mir-dir=".to_string();
15141514
dir_opt.push_str(mir_dump_dir.as_str());
15151515
debug!("dir_opt: {:?}", dir_opt);
@@ -1969,7 +1969,8 @@ impl<'test> TestCx<'test> {
19691969
let suffix =
19701970
self.safe_revision().map_or("nightly".into(), |path| path.to_owned() + "-nightly");
19711971
let compare_dir = output_base_dir(self.config, self.testpaths, Some(&suffix));
1972-
remove_and_create_dir_all(&compare_dir);
1972+
remove_and_create_dir_all(&compare_dir)
1973+
.expect("Failed to remove and recreate output directory");
19731974

19741975
// We need to create a new struct for the lifetimes on `config` to work.
19751976
let new_rustdoc = TestCx {

src/tools/compiletest/src/runtest/rustdoc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ impl TestCx<'_> {
77
assert!(self.revision.is_none(), "revisions not relevant here");
88

99
let out_dir = self.output_base_dir();
10-
remove_and_create_dir_all(&out_dir);
10+
remove_and_create_dir_all(&out_dir)
11+
.expect("Failed to remove and recreate output directory");
1112

1213
let proc_res = self.document(&out_dir, &self.testpaths);
1314
if !proc_res.status.success() {

src/tools/compiletest/src/runtest/rustdoc_json.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ impl TestCx<'_> {
99
assert!(self.revision.is_none(), "revisions not relevant here");
1010

1111
let out_dir = self.output_base_dir();
12-
remove_and_create_dir_all(&out_dir);
12+
remove_and_create_dir_all(&out_dir)
13+
.expect("Failed to remove and recreate output directory");
1314

1415
let proc_res = self.document(&out_dir, &self.testpaths);
1516
if !proc_res.status.success() {

0 commit comments

Comments
 (0)