Simplify directory creation
This commit is contained in:
parent
51d27a63b8
commit
9b17b3d184
@ -1,5 +1,5 @@
|
||||
use crate::config::{Channel, ConfigInfo};
|
||||
use crate::utils::{run_command, run_command_with_output_and_env, walk_dir};
|
||||
use crate::utils::{create_dir, run_command, run_command_with_output_and_env, walk_dir};
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::OsStr;
|
||||
use std::fs;
|
||||
@ -103,6 +103,7 @@ fn cleanup_sysroot_previous_build(start_dir: &Path) {
|
||||
|
||||
pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Result<(), String> {
|
||||
let start_dir = Path::new("build_sysroot");
|
||||
|
||||
cleanup_sysroot_previous_build(&start_dir);
|
||||
|
||||
// Builds libs
|
||||
@ -136,13 +137,7 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
|
||||
|
||||
// Copy files to sysroot
|
||||
let sysroot_path = start_dir.join(format!("sysroot/lib/rustlib/{}/lib/", config.target_triple));
|
||||
fs::create_dir_all(&sysroot_path).map_err(|error| {
|
||||
format!(
|
||||
"Failed to create directory `{}`: {:?}",
|
||||
sysroot_path.display(),
|
||||
error
|
||||
)
|
||||
})?;
|
||||
create_dir(&sysroot_path)?;
|
||||
let copier = |dir_to_copy: &Path| {
|
||||
// FIXME: should not use shell command!
|
||||
run_command(&[&"cp", &"-r", &dir_to_copy, &sysroot_path], None).map(|_| ())
|
||||
@ -155,13 +150,7 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
|
||||
|
||||
// Copy the source files to the sysroot (Rust for Linux needs this).
|
||||
let sysroot_src_path = start_dir.join("sysroot/lib/rustlib/src/rust");
|
||||
fs::create_dir_all(&sysroot_src_path).map_err(|error| {
|
||||
format!(
|
||||
"Failed to create directory `{}`: {:?}",
|
||||
sysroot_src_path.display(),
|
||||
error
|
||||
)
|
||||
})?;
|
||||
create_dir(&sysroot_src_path)?;
|
||||
run_command(
|
||||
&[
|
||||
&"cp",
|
||||
@ -216,12 +205,7 @@ fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
|
||||
// We voluntarily ignore the error.
|
||||
let _ = fs::remove_dir_all("target/out");
|
||||
let gccjit_target = "target/out/gccjit";
|
||||
fs::create_dir_all(gccjit_target).map_err(|error| {
|
||||
format!(
|
||||
"Failed to create directory `{}`: {:?}",
|
||||
gccjit_target, error
|
||||
)
|
||||
})?;
|
||||
create_dir(gccjit_target)?;
|
||||
|
||||
println!("[BUILD] sysroot");
|
||||
build_sysroot(&env, &args.config_info)?;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::utils::{
|
||||
create_symlink, get_os_name, run_command_with_output, rustc_version_info, split_args,
|
||||
create_dir, create_symlink, get_os_name, run_command_with_output, rustc_version_info, split_args,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::env as std_env;
|
||||
@ -228,13 +228,7 @@ fn download_gccjit_if_needed(&mut self) -> Result<(), String> {
|
||||
|
||||
let output_dir = output_dir.join(&commit);
|
||||
if !output_dir.is_dir() {
|
||||
std::fs::create_dir_all(&output_dir).map_err(|err| {
|
||||
format!(
|
||||
"failed to create folder `{}`: {:?}",
|
||||
output_dir.display(),
|
||||
err,
|
||||
)
|
||||
})?;
|
||||
create_dir(&output_dir)?;
|
||||
}
|
||||
let output_dir = output_dir.canonicalize().map_err(|err| {
|
||||
format!(
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::rustc_info::get_rustc_path;
|
||||
use crate::utils::{
|
||||
cargo_install, git_clone_root_dir, remove_file, run_command, run_command_with_output, walk_dir,
|
||||
cargo_install, create_dir, git_clone_root_dir, remove_file, run_command, run_command_with_output, walk_dir,
|
||||
};
|
||||
|
||||
use std::fs;
|
||||
@ -41,13 +41,7 @@ fn prepare_libcore(
|
||||
}
|
||||
|
||||
let sysroot_library_dir = sysroot_dir.join("library");
|
||||
fs::create_dir_all(&sysroot_library_dir).map_err(|error| {
|
||||
format!(
|
||||
"Failed to create folder `{}`: {:?}",
|
||||
sysroot_library_dir.display(),
|
||||
error,
|
||||
)
|
||||
})?;
|
||||
create_dir(&sysroot_library_dir)?;
|
||||
|
||||
run_command(
|
||||
&[&"cp", &"-r", &rustlib_dir.join("library"), &sysroot_dir],
|
||||
|
@ -1,13 +1,13 @@
|
||||
use crate::build;
|
||||
use crate::config::{Channel, ConfigInfo};
|
||||
use crate::utils::{
|
||||
get_toolchain, git_clone, git_clone_root_dir, remove_file, run_command, run_command_with_env,
|
||||
create_dir, get_toolchain, git_clone, git_clone_root_dir, remove_file, run_command, run_command_with_env,
|
||||
run_command_with_output_and_env, rustc_version_info, split_args, walk_dir,
|
||||
};
|
||||
|
||||
use std::collections::{BTreeSet, HashMap};
|
||||
use std::ffi::OsStr;
|
||||
use std::fs::{create_dir_all, remove_dir_all, File};
|
||||
use std::fs::{remove_dir_all, File};
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
@ -211,8 +211,7 @@ fn build_if_no_backend(env: &Env, args: &TestArg) -> Result<(), String> {
|
||||
fn clean(_env: &Env, args: &TestArg) -> Result<(), String> {
|
||||
let _ = std::fs::remove_dir_all(&args.config_info.cargo_target_dir);
|
||||
let path = Path::new(&args.config_info.cargo_target_dir).join("gccjit");
|
||||
std::fs::create_dir_all(&path)
|
||||
.map_err(|error| format!("failed to create folder `{}`: {:?}", path.display(), error))
|
||||
create_dir(&path)
|
||||
}
|
||||
|
||||
fn mini_tests(env: &Env, args: &TestArg) -> Result<(), String> {
|
||||
@ -715,8 +714,7 @@ fn test_projects(env: &Env, args: &TestArg) -> Result<(), String> {
|
||||
};
|
||||
|
||||
let projects_path = Path::new("projects");
|
||||
create_dir_all(projects_path)
|
||||
.map_err(|err| format!("Failed to create directory `projects`: {}", err))?;
|
||||
create_dir(projects_path)?;
|
||||
|
||||
let nb_parts = args.nb_parts.unwrap_or(0);
|
||||
if nb_parts > 0 {
|
||||
|
@ -307,6 +307,12 @@ pub fn git_clone(
|
||||
git_clone_inner(to_clone, dest, shallow_clone, repo_name)
|
||||
}
|
||||
|
||||
pub fn create_dir<P: AsRef<Path>>(path: P) -> Result<(), String> {
|
||||
fs::create_dir_all(&path).map_err(|error| {
|
||||
format!("Failed to create directory `{}`: {:?}", path.as_ref().display(), error)
|
||||
})
|
||||
}
|
||||
|
||||
/// This function differs from `git_clone` in how it handles *where* the repository will be cloned.
|
||||
/// In `git_clone`, it is cloned in the provided path. In this function, the path you provide is
|
||||
/// the parent folder. So if you pass "a" as folder and try to clone "b.git", it will be cloned into
|
||||
|
Loading…
Reference in New Issue
Block a user