summaryrefslogtreecommitdiffstats
path: root/src/bootstrap/util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bootstrap/util.rs')
-rw-r--r--src/bootstrap/util.rs42
1 files changed, 17 insertions, 25 deletions
diff --git a/src/bootstrap/util.rs b/src/bootstrap/util.rs
index b291584b3..3c4a21434 100644
--- a/src/bootstrap/util.rs
+++ b/src/bootstrap/util.rs
@@ -46,9 +46,9 @@ pub use t;
/// executable for a particular target.
pub fn exe(name: &str, target: TargetSelection) -> String {
if target.contains("windows") {
- format!("{}.exe", name)
+ format!("{name}.exe")
} else if target.contains("uefi") {
- format!("{}.efi", name)
+ format!("{name}.efi")
} else {
name.to_string()
}
@@ -153,16 +153,6 @@ pub fn symlink_dir(config: &Config, original: &Path, link: &Path) -> io::Result<
}
}
-/// The CI environment rustbuild is running in. This mainly affects how the logs
-/// are printed.
-#[derive(Copy, Clone, PartialEq, Eq, Debug)]
-pub enum CiEnv {
- /// Not a CI environment.
- None,
- /// The GitHub Actions environment, for Linux (including Docker), Windows and macOS builds.
- GitHubActions,
-}
-
pub fn forcing_clang_based_tests() -> bool {
if let Some(var) = env::var_os("RUSTBUILD_FORCE_CLANG_BASED_TESTS") {
match &var.to_string_lossy().to_lowercase()[..] {
@@ -171,9 +161,8 @@ pub fn forcing_clang_based_tests() -> bool {
other => {
// Let's make sure typos don't go unnoticed
panic!(
- "Unrecognized option '{}' set in \
- RUSTBUILD_FORCE_CLANG_BASED_TESTS",
- other
+ "Unrecognized option '{other}' set in \
+ RUSTBUILD_FORCE_CLANG_BASED_TESTS"
)
}
}
@@ -229,7 +218,7 @@ pub fn is_valid_test_suite_arg<'a, P: AsRef<Path>>(
pub fn run(cmd: &mut Command, print_cmd_on_fail: bool) {
if try_run(cmd, print_cmd_on_fail).is_err() {
- crate::detail_exit_macro!(1);
+ crate::exit!(1);
}
}
@@ -237,15 +226,14 @@ pub fn check_run(cmd: &mut Command, print_cmd_on_fail: bool) -> bool {
let status = match cmd.status() {
Ok(status) => status,
Err(e) => {
- println!("failed to execute command: {:?}\nerror: {}", cmd, e);
+ println!("failed to execute command: {cmd:?}\nerror: {e}");
return false;
}
};
if !status.success() && print_cmd_on_fail {
println!(
- "\n\ncommand did not execute successfully: {:?}\n\
- expected success, got: {}\n\n",
- cmd, status
+ "\n\ncommand did not execute successfully: {cmd:?}\n\
+ expected success, got: {status}\n\n"
);
}
status.success()
@@ -253,14 +241,14 @@ pub fn check_run(cmd: &mut Command, print_cmd_on_fail: bool) -> bool {
pub fn run_suppressed(cmd: &mut Command) {
if !try_run_suppressed(cmd) {
- crate::detail_exit_macro!(1);
+ crate::exit!(1);
}
}
pub fn try_run_suppressed(cmd: &mut Command) -> bool {
let output = match cmd.output() {
Ok(status) => status,
- Err(e) => fail(&format!("failed to execute command: {:?}\nerror: {}", cmd, e)),
+ Err(e) => fail(&format!("failed to execute command: {cmd:?}\nerror: {e}")),
};
if !output.status.success() {
println!(
@@ -293,7 +281,7 @@ pub fn make(host: &str) -> PathBuf {
pub fn output(cmd: &mut Command) -> String {
let output = match cmd.stderr(Stdio::inherit()).output() {
Ok(status) => status,
- Err(e) => fail(&format!("failed to execute command: {:?}\nerror: {}", cmd, e)),
+ Err(e) => fail(&format!("failed to execute command: {cmd:?}\nerror: {e}")),
};
if !output.status.success() {
panic!(
@@ -308,7 +296,7 @@ pub fn output(cmd: &mut Command) -> String {
pub fn output_result(cmd: &mut Command) -> Result<String, String> {
let output = match cmd.stderr(Stdio::inherit()).output() {
Ok(status) => status,
- Err(e) => return Err(format!("failed to run command: {:?}: {}", cmd, e)),
+ Err(e) => return Err(format!("failed to run command: {cmd:?}: {e}")),
};
if !output.status.success() {
return Err(format!(
@@ -338,7 +326,7 @@ pub fn up_to_date(src: &Path, dst: &Path) -> bool {
let threshold = mtime(dst);
let meta = match fs::metadata(src) {
Ok(meta) => meta,
- Err(e) => panic!("source {:?} failed to get metadata: {}", src, e),
+ Err(e) => panic!("source {src:?} failed to get metadata: {e}"),
};
if meta.is_dir() {
dir_up_to_date(src, threshold)
@@ -503,3 +491,7 @@ pub fn lld_flag_no_threads(is_windows: bool) -> &'static str {
});
if is_windows { windows } else { other }
}
+
+pub fn dir_is_empty(dir: &Path) -> bool {
+ t!(std::fs::read_dir(dir)).next().is_none()
+}