-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bce234d
commit 0fdf7c6
Showing
5 changed files
with
74 additions
and
92 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ use crate::utils::{cargo_install, git_clone, run_command, run_command_with_outpu | |
use std::fs; | ||
use std::path::Path; | ||
|
||
fn prepare_libcore() -> Result<(), String> { | ||
fn prepare_libcore(sysroot_path: &Path) -> Result<(), String> { | ||
let rustc_path = match get_rustc_path() { | ||
Some(path) => path, | ||
None => return Err("`rustc` path not found".to_owned()), | ||
|
@@ -15,14 +15,18 @@ fn prepare_libcore() -> Result<(), String> { | |
None => return Err(format!("No parent for `{}`", rustc_path.display())), | ||
}; | ||
|
||
let rustlib_dir = parent.join("../lib/rustlib/src/rust"); | ||
let rustlib_dir = | ||
parent | ||
.join("../lib/rustlib/src/rust") | ||
.canonicalize() | ||
.map_err(|e| format!("Failed to canonicalize path: {e:?}"))?; | ||
if !rustlib_dir.is_dir() { | ||
return Err("Please install `rust-src` component".to_owned()); | ||
} | ||
|
||
let sysroot_dir = Path::new("build_sysroot/sysroot_src"); | ||
let sysroot_dir = sysroot_path.join("sysroot_src"); | ||
if sysroot_dir.is_dir() { | ||
if let Err(e) = fs::remove_dir_all(sysroot_dir) { | ||
if let Err(e) = fs::remove_dir_all(&sysroot_dir) { | ||
return Err(format!("Failed to remove `{}`: {:?}", sysroot_dir.display(), e)); | ||
} | ||
} | ||
|
@@ -34,7 +38,7 @@ fn prepare_libcore() -> Result<(), String> { | |
sysroot_library_dir.display(), | ||
))?; | ||
|
||
run_command(&[&"cp", &"-r", &rustlib_dir, &sysroot_library_dir], None)?; | ||
run_command(&[&"cp", &"-r", &rustlib_dir.join("library"), &sysroot_dir], None)?; | ||
|
||
println!("[GIT] init (cwd): `{}`", sysroot_dir.display()); | ||
run_command_with_output(&[&"git", &"init"], Some(&sysroot_dir))?; | ||
|
@@ -47,8 +51,8 @@ fn prepare_libcore() -> Result<(), String> { | |
// Even using --author is not enough. | ||
run_command(&[&"git", &"config", &"user.email", &"[email protected]"], Some(&sysroot_dir))?; | ||
run_command(&[&"git", &"config", &"user.name", &"None"], Some(&sysroot_dir))?; | ||
run_command(&[&"git", &"config", &"core.autocrlf=false"], Some(&sysroot_dir))?; | ||
run_command(&[&"git", &"config", &"commit.gpgSign=false"], Some(&sysroot_dir))?; | ||
run_command(&[&"git", &"config", &"core.autocrlf", &"false"], Some(&sysroot_dir))?; | ||
run_command(&[&"git", &"config", &"commit.gpgSign", &"false"], Some(&sysroot_dir))?; | ||
run_command(&[&"git", &"commit", &"-m", &"Initial commit", &"-q"], Some(&sysroot_dir))?; | ||
|
||
walk_dir("patches", |_| Ok(()), |file_path: &Path| { | ||
|
@@ -73,27 +77,30 @@ fn build_raytracer(repo_dir: &Path) -> Result<(), String> { | |
Ok(()) | ||
} | ||
|
||
fn clone_and_setup<F>(repo_url: &str, checkout_commit: &str, extra: Option<F>) -> Result<(), String> | ||
fn clone_and_setup<F>(sysroot_path: &Path, repo_url: &str, checkout_commit: &str, extra: Option<F>) -> Result<(), String> | ||
where | ||
F: Fn(&Path) -> Result<(), String>, | ||
{ | ||
let clone_result = git_clone(repo_url, None)?; | ||
let clone_result = git_clone(repo_url, Some(sysroot_path))?; | ||
if !clone_result.ran_clone { | ||
println!("`{}` has already been cloned", clone_result.repo_name); | ||
} | ||
let repo_path = Path::new(&clone_result.repo_name); | ||
run_command(&[&"git", &"checkout", &"--", &"."], Some(repo_path))?; | ||
run_command(&[&"git", &"checkout", &checkout_commit], Some(repo_path))?; | ||
let repo_path = sysroot_path.join(&clone_result.repo_name); | ||
run_command_with_output(&[&"git", &"checkout", &"--", &"."], Some(&repo_path))?; | ||
run_command_with_output(&[&"git", &"checkout", &checkout_commit], Some(&repo_path))?; | ||
let filter = format!("-{}-", clone_result.repo_name); | ||
walk_dir("crate_patches", |_| Ok(()), |file_path| { | ||
let s = file_path.as_os_str().to_str().unwrap(); | ||
if s.contains(&filter) && s.ends_with(".patch") { | ||
run_command(&[&"git", &"am", &s], Some(repo_path))?; | ||
run_command_with_output( | ||
&[&"git", &"am", &file_path.canonicalize().unwrap()], | ||
Some(&repo_path), | ||
)?; | ||
} | ||
Ok(()) | ||
})?; | ||
if let Some(extra) = extra { | ||
extra(repo_path)?; | ||
extra(&repo_path)?; | ||
} | ||
Ok(()) | ||
} | ||
|
@@ -136,7 +143,8 @@ pub fn run() -> Result<(), String> { | |
Some(a) => a, | ||
None => return Ok(()), | ||
}; | ||
prepare_libcore()?; | ||
let sysroot_path = Path::new("build_sysroot"); | ||
prepare_libcore(sysroot_path)?; | ||
|
||
if !args.only_libcore { | ||
cargo_install("hyperfine")?; | ||
|
@@ -148,7 +156,7 @@ pub fn run() -> Result<(), String> { | |
]; | ||
|
||
for (repo_url, checkout_commit, cb) in to_clone { | ||
clone_and_setup(repo_url, checkout_commit, *cb)?; | ||
clone_and_setup(sysroot_path, repo_url, checkout_commit, *cb)?; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters