Skip to content

Commit 5c55b56

Browse files
Add copy_dir_all function to run-make-support
1 parent 21e6de7 commit 5c55b56

File tree

1 file changed

+20
-0
lines changed
  • src/tools/run-make-support/src

1 file changed

+20
-0
lines changed

src/tools/run-make-support/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub mod rustc;
1212
pub mod rustdoc;
1313

1414
use std::env;
15+
use std::fs;
16+
use std::io;
1517
use std::path::{Path, PathBuf};
1618
use std::process::{Command, Output};
1719

@@ -201,6 +203,24 @@ pub fn set_host_rpath(cmd: &mut Command) {
201203
});
202204
}
203205

206+
/// Copy a directory into another.
207+
pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
208+
let dst = dst.as_ref();
209+
if !dst.is_dir() {
210+
fs::create_dir_all(&dst)?;
211+
}
212+
for entry in fs::read_dir(src)? {
213+
let entry = entry?;
214+
let ty = entry.file_type()?;
215+
if ty.is_dir() {
216+
copy_dir_all(entry.path(), dst.join(entry.file_name()))?;
217+
} else {
218+
fs::copy(entry.path(), dst.join(entry.file_name()))?;
219+
}
220+
}
221+
Ok(())
222+
}
223+
204224
/// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
205225
/// containing a `cmd: Command` field and a `output` function. The provided helpers are:
206226
///

0 commit comments

Comments
 (0)