]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_codegen_cranelift/build_system/utils.rs
New upstream version 1.55.0+dfsg1
[rustc.git] / compiler / rustc_codegen_cranelift / build_system / utils.rs
CommitLineData
136023e0
XL
1use std::fs;
2use std::path::Path;
3use std::process::{self, Command};
4
5#[track_caller]
6pub(crate) fn try_hard_link(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
7 let src = src.as_ref();
8 let dst = dst.as_ref();
9 if let Err(_) = fs::hard_link(src, dst) {
10 fs::copy(src, dst).unwrap(); // Fallback to copying if hardlinking failed
11 }
12}
13
14#[track_caller]
15pub(crate) fn spawn_and_wait(mut cmd: Command) {
16 if !cmd.spawn().unwrap().wait().unwrap().success() {
17 process::exit(1);
18 }
19}
20
21pub(crate) fn copy_dir_recursively(from: &Path, to: &Path) {
22 for entry in fs::read_dir(from).unwrap() {
23 let entry = entry.unwrap();
24 let filename = entry.file_name();
25 if filename == "." || filename == ".." {
26 continue;
27 }
28 if entry.metadata().unwrap().is_dir() {
29 fs::create_dir(to.join(&filename)).unwrap();
30 copy_dir_recursively(&from.join(&filename), &to.join(&filename));
31 } else {
32 fs::copy(from.join(&filename), to.join(&filename)).unwrap();
33 }
34 }
35}