Merge pull request #435 from GuillaumeGomez/clean-up-repo

Generate content into `build` folder
This commit is contained in:
antoyo 2024-02-13 18:16:24 -05:00 committed by GitHub
commit 6afabceaa6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 65 additions and 60 deletions

1
.gitignore vendored
View File

@ -29,3 +29,4 @@ tools/llvmint-2
llvm llvm
build_system/target build_system/target
config.toml config.toml
build

View File

@ -1,6 +1,7 @@
use crate::utils::{remove_file, run_command}; use crate::utils::{remove_file, run_command};
use std::fs::remove_dir_all; use std::fs::remove_dir_all;
use std::path::Path;
#[derive(Default)] #[derive(Default)]
enum CleanArg { enum CleanArg {
@ -46,12 +47,14 @@ fn clean_all() -> Result<(), String> {
"build_sysroot/sysroot", "build_sysroot/sysroot",
"build_sysroot/sysroot_src", "build_sysroot/sysroot_src",
"build_sysroot/target", "build_sysroot/target",
"regex",
"simple-raytracer",
]; ];
for dir in dirs_to_remove { for dir in dirs_to_remove {
let _ = remove_dir_all(dir); let _ = remove_dir_all(dir);
} }
let dirs_to_remove = ["regex", "rand", "simple-raytracer"];
for dir in dirs_to_remove {
let _ = remove_dir_all(Path::new(crate::BUILD_DIR).join(dir));
}
let files_to_remove = ["build_sysroot/Cargo.lock", "perf.data", "perf.data.old"]; let files_to_remove = ["build_sysroot/Cargo.lock", "perf.data", "perf.data.old"];
@ -64,16 +67,8 @@ fn clean_all() -> Result<(), String> {
} }
fn clean_ui_tests() -> Result<(), String> { fn clean_ui_tests() -> Result<(), String> {
run_command( let path = Path::new(crate::BUILD_DIR).join("rust/build/x86_64-unknown-linux-gnu/test/ui/");
&[ run_command(&[&"find", &path, &"-name", &"stamp", &"-delete"], None)?;
&"find",
&"rust/build/x86_64-unknown-linux-gnu/test/ui/",
&"-name",
&"stamp",
&"-delete",
],
None,
)?;
Ok(()) Ok(())
} }

View File

@ -191,12 +191,7 @@ pub fn rustc_command_vec(&self) -> Vec<&dyn AsRef<OsStr>> {
} }
fn download_gccjit_if_needed(&mut self) -> Result<(), String> { fn download_gccjit_if_needed(&mut self) -> Result<(), String> {
let output_dir = Path::new( let output_dir = Path::new(crate::BUILD_DIR).join("libgccjit");
std::env::var("CARGO_TARGET_DIR")
.as_deref()
.unwrap_or("target"),
)
.join("libgccjit");
let commit_hash_file = self.compute_path("libgccjit.version"); let commit_hash_file = self.compute_path("libgccjit.version");
let content = fs::read_to_string(&commit_hash_file).map_err(|_| { let content = fs::read_to_string(&commit_hash_file).map_err(|_| {
@ -523,7 +518,11 @@ fn download_gccjit(
&"--retry", &"--retry",
&"3", &"3",
&"-SRfL", &"-SRfL",
if with_progress_bar { &"--progress-bar" } else { &"-s" }, if with_progress_bar {
&"--progress-bar"
} else {
&"-s"
},
&url.as_str(), &url.as_str(),
], ],
Some(&output_dir), Some(&output_dir),
@ -538,9 +537,9 @@ fn download_gccjit(
&"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;", &"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;",
&format!( &format!(
"(New-Object System.Net.WebClient).DownloadFile('{}', '{}')", "(New-Object System.Net.WebClient).DownloadFile('{}', '{}')",
url, url, tempfile_name,
tempfile_name, )
).as_str(), .as_str(),
], ],
Some(&output_dir), Some(&output_dir),
); );

View File

@ -11,6 +11,8 @@
mod test; mod test;
mod utils; mod utils;
const BUILD_DIR: &str = "build";
macro_rules! arg_error { macro_rules! arg_error {
($($err:tt)*) => {{ ($($err:tt)*) => {{
eprintln!($($err)*); eprintln!($($err)*);

View File

@ -152,11 +152,11 @@ fn clone_and_setup<F>(repo_url: &str, checkout_commit: &str, extra: Option<F>) -
where where
F: Fn(&Path) -> Result<(), String>, F: Fn(&Path) -> Result<(), String>,
{ {
let clone_result = git_clone(repo_url, None, false)?; let clone_result = git_clone(repo_url, Some(&Path::new(crate::BUILD_DIR)), false)?;
if !clone_result.ran_clone { if !clone_result.ran_clone {
println!("`{}` has already been cloned", clone_result.repo_name); println!("`{}` has already been cloned", clone_result.repo_name);
} }
let repo_path = Path::new(&clone_result.repo_name); let repo_path = Path::new(crate::BUILD_DIR).join(&clone_result.repo_name);
run_command(&[&"git", &"checkout", &"--", &"."], Some(&repo_path))?; run_command(&[&"git", &"checkout", &"--", &"."], Some(&repo_path))?;
run_command(&[&"git", &"checkout", &checkout_commit], Some(&repo_path))?; run_command(&[&"git", &"checkout", &checkout_commit], Some(&repo_path))?;
let filter = format!("-{}-", clone_result.repo_name); let filter = format!("-{}-", clone_result.repo_name);
@ -219,8 +219,7 @@ fn usage() {
--only-libcore : Only setup libcore and don't clone other repositories --only-libcore : Only setup libcore and don't clone other repositories
--cross : Apply the patches needed to do cross-compilation --cross : Apply the patches needed to do cross-compilation
--libgccjit12-patches : Apply patches needed for libgccjit12 --libgccjit12-patches : Apply patches needed for libgccjit12
--help : Show this help --help : Show this help"#
"#
) )
} }
} }

View File

@ -485,19 +485,25 @@ fn std_tests(env: &Env, args: &TestArg) -> Result<(), String> {
Ok(()) Ok(())
} }
fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<(), String> { fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<PathBuf, String> {
let toolchain = format!( let toolchain = format!(
"+{channel}-{host}", "+{channel}-{host}",
channel = get_toolchain()?, // May also include date channel = get_toolchain()?, // May also include date
host = args.config_info.host_triple host = args.config_info.host_triple
); );
let rust_dir = Some(Path::new("rust")); let rust_dir_path = Path::new(crate::BUILD_DIR).join("rust");
// If the repository was already cloned, command will fail, so doesn't matter. // If the repository was already cloned, command will fail, so doesn't matter.
let _ = run_command_with_output_and_env( let _ = run_command_with_output_and_env(
&[&"git", &"clone", &"https://github.com/rust-lang/rust.git"], &[
&"git",
&"clone",
&"https://github.com/rust-lang/rust.git",
&rust_dir_path,
],
None, None,
Some(env), Some(env),
); );
let rust_dir: Option<&Path> = Some(&rust_dir_path);
run_command(&[&"git", &"checkout", &"--", &"tests/"], rust_dir)?; run_command(&[&"git", &"checkout", &"--", &"tests/"], rust_dir)?;
run_command_with_output_and_env(&[&"git", &"fetch"], rust_dir, Some(env))?; run_command_with_output_and_env(&[&"git", &"fetch"], rust_dir, Some(env))?;
let rustc_commit = match rustc_version_info(env.get("RUSTC").map(|s| s.as_str()))?.commit_hash { let rustc_commit = match rustc_version_info(env.get("RUSTC").map(|s| s.as_str()))?.commit_hash {
@ -561,8 +567,9 @@ fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<(), String> {
String::new() String::new()
} }
}; };
let file_path = rust_dir_path.join("config.toml");
std::fs::write( std::fs::write(
"rust/config.toml", &file_path,
&format!( &format!(
r#"change-id = 115898 r#"change-id = 115898
@ -587,13 +594,19 @@ fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<(), String> {
llvm_filecheck = llvm_filecheck.trim(), llvm_filecheck = llvm_filecheck.trim(),
), ),
) )
.map_err(|error| format!("Failed to write into `rust/config.toml`: {:?}", error))?; .map_err(|error| {
Ok(()) format!(
"Failed to write into `{}`: {:?}",
file_path.display(),
error
)
})?;
Ok(rust_dir_path)
} }
fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> { fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
let mut env = env.clone(); let mut env = env.clone();
setup_rustc(&mut env, args)?; let rust_dir = setup_rustc(&mut env, args)?;
// FIXME: create a function "display_if_not_quiet" or something along the line. // FIXME: create a function "display_if_not_quiet" or something along the line.
println!("[TEST] rustc asm test suite"); println!("[TEST] rustc asm test suite");
@ -621,7 +634,7 @@ fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
) )
.as_str(), .as_str(),
], ],
Some(Path::new("rust")), Some(&rust_dir),
Some(&env), Some(&env),
)?; )?;
Ok(()) Ok(())
@ -761,11 +774,11 @@ fn extended_rand_tests(env: &Env, args: &TestArg) -> Result<(), String> {
println!("Not using GCC master branch. Skipping `extended_rand_tests`."); println!("Not using GCC master branch. Skipping `extended_rand_tests`.");
return Ok(()); return Ok(());
} }
let path = Path::new("rand"); let path = Path::new(crate::BUILD_DIR).join("rand");
run_cargo_command(&[&"clean"], Some(path), env, args)?; run_cargo_command(&[&"clean"], Some(&path), env, args)?;
// FIXME: create a function "display_if_not_quiet" or something along the line. // FIXME: create a function "display_if_not_quiet" or something along the line.
println!("[TEST] rust-random/rand"); println!("[TEST] rust-random/rand");
run_cargo_command(&[&"test", &"--workspace"], Some(path), env, args)?; run_cargo_command(&[&"test", &"--workspace"], Some(&path), env, args)?;
Ok(()) Ok(())
} }
@ -774,8 +787,8 @@ fn extended_regex_example_tests(env: &Env, args: &TestArg) -> Result<(), String>
println!("Not using GCC master branch. Skipping `extended_regex_example_tests`."); println!("Not using GCC master branch. Skipping `extended_regex_example_tests`.");
return Ok(()); return Ok(());
} }
let path = Path::new("regex"); let path = Path::new(crate::BUILD_DIR).join("regex");
run_cargo_command(&[&"clean"], Some(path), env, args)?; run_cargo_command(&[&"clean"], Some(&path), env, args)?;
// FIXME: create a function "display_if_not_quiet" or something along the line. // FIXME: create a function "display_if_not_quiet" or something along the line.
println!("[TEST] rust-lang/regex example shootout-regex-dna"); println!("[TEST] rust-lang/regex example shootout-regex-dna");
let mut env = env.clone(); let mut env = env.clone();
@ -788,14 +801,14 @@ fn extended_regex_example_tests(env: &Env, args: &TestArg) -> Result<(), String>
// Make sure `[codegen mono items] start` doesn't poison the diff // Make sure `[codegen mono items] start` doesn't poison the diff
run_cargo_command( run_cargo_command(
&[&"build", &"--example", &"shootout-regex-dna"], &[&"build", &"--example", &"shootout-regex-dna"],
Some(path), Some(&path),
&env, &env,
args, args,
)?; )?;
run_cargo_command_with_callback( run_cargo_command_with_callback(
&[&"run", &"--example", &"shootout-regex-dna"], &[&"run", &"--example", &"shootout-regex-dna"],
Some(path), Some(&path),
&env, &env,
args, args,
|cargo_command, cwd, env| { |cargo_command, cwd, env| {
@ -838,6 +851,7 @@ fn extended_regex_tests(env: &Env, args: &TestArg) -> Result<(), String> {
env.get("RUSTFLAGS").cloned().unwrap_or_default() env.get("RUSTFLAGS").cloned().unwrap_or_default()
); );
env.insert("RUSTFLAGS".to_string(), rustflags); env.insert("RUSTFLAGS".to_string(), rustflags);
let path = Path::new(crate::BUILD_DIR).join("regex");
run_cargo_command( run_cargo_command(
&[ &[
&"test", &"test",
@ -850,7 +864,7 @@ fn extended_regex_tests(env: &Env, args: &TestArg) -> Result<(), String> {
&"-Zunstable-options", &"-Zunstable-options",
&"-q", &"-q",
], ],
Some(Path::new("regex")), Some(&path),
&env, &env,
args, args,
)?; )?;
@ -928,17 +942,15 @@ fn should_remove_test(file_path: &Path) -> Result<bool, String> {
fn test_rustc_inner<F>(env: &Env, args: &TestArg, prepare_files_callback: F) -> Result<(), String> fn test_rustc_inner<F>(env: &Env, args: &TestArg, prepare_files_callback: F) -> Result<(), String>
where where
F: Fn() -> Result<bool, String>, F: Fn(&Path) -> Result<bool, String>,
{ {
// FIXME: create a function "display_if_not_quiet" or something along the line. // FIXME: create a function "display_if_not_quiet" or something along the line.
println!("[TEST] rust-lang/rust"); println!("[TEST] rust-lang/rust");
let mut env = env.clone(); let mut env = env.clone();
setup_rustc(&mut env, args)?; let rust_path = setup_rustc(&mut env, args)?;
let rust_path = Path::new("rust");
walk_dir( walk_dir(
"rust/tests/ui", rust_path.join("tests/ui"),
|dir| { |dir| {
let dir_name = dir.file_name().and_then(|name| name.to_str()).unwrap_or(""); let dir_name = dir.file_name().and_then(|name| name.to_str()).unwrap_or("");
if [ if [
@ -1001,7 +1013,7 @@ fn file_handling(file_path: &Path) -> Result<(), String> {
walk_dir(rust_path.join("tests/ui"), dir_handling, file_handling)?; walk_dir(rust_path.join("tests/ui"), dir_handling, file_handling)?;
if !prepare_files_callback()? { if !prepare_files_callback(&rust_path)? {
// FIXME: create a function "display_if_not_quiet" or something along the line. // FIXME: create a function "display_if_not_quiet" or something along the line.
println!("Keeping all UI tests"); println!("Keeping all UI tests");
} }
@ -1027,7 +1039,7 @@ fn file_handling(file_path: &Path) -> Result<(), String> {
&"-path", &"-path",
&"*/auxiliary/*", &"*/auxiliary/*",
], ],
Some(rust_path), Some(&rust_path),
)? )?
.stdout, .stdout,
) )
@ -1072,18 +1084,18 @@ fn file_handling(file_path: &Path) -> Result<(), String> {
&"--rustc-args", &"--rustc-args",
&rustc_args, &rustc_args,
], ],
Some(rust_path), Some(&rust_path),
Some(&env), Some(&env),
)?; )?;
Ok(()) Ok(())
} }
fn test_rustc(env: &Env, args: &TestArg) -> Result<(), String> { fn test_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
test_rustc_inner(env, args, || Ok(false)) test_rustc_inner(env, args, |_| Ok(false))
} }
fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> { fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
test_rustc_inner(env, args, || { test_rustc_inner(env, args, |rust_path| {
// Removing all tests. // Removing all tests.
run_command( run_command(
&[ &[
@ -1098,7 +1110,7 @@ fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
&"*/auxiliary/*", &"*/auxiliary/*",
&"-delete", &"-delete",
], ],
Some(Path::new("rust")), Some(rust_path),
)?; )?;
// Putting back only the failing ones. // Putting back only the failing ones.
let path = "tests/failing-ui-tests.txt"; let path = "tests/failing-ui-tests.txt";
@ -1108,10 +1120,7 @@ fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
.map(|line| line.trim()) .map(|line| line.trim())
.filter(|line| !line.is_empty()) .filter(|line| !line.is_empty())
{ {
run_command( run_command(&[&"git", &"checkout", &"--", &file], Some(&rust_path))?;
&[&"git", &"checkout", &"--", &file],
Some(Path::new("rust")),
)?;
} }
} else { } else {
println!( println!(
@ -1124,7 +1133,7 @@ fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
} }
fn test_successful_rustc(env: &Env, args: &TestArg) -> Result<(), String> { fn test_successful_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
test_rustc_inner(env, args, || { test_rustc_inner(env, args, |rust_path| {
// Removing the failing tests. // Removing the failing tests.
let path = "tests/failing-ui-tests.txt"; let path = "tests/failing-ui-tests.txt";
if let Ok(files) = std::fs::read_to_string(path) { if let Ok(files) = std::fs::read_to_string(path) {
@ -1133,7 +1142,7 @@ fn test_successful_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
.map(|line| line.trim()) .map(|line| line.trim())
.filter(|line| !line.is_empty()) .filter(|line| !line.is_empty())
{ {
let path = Path::new("rust").join(file); let path = rust_path.join(file);
remove_file(&path)?; remove_file(&path)?;
} }
} else { } else {

View File

@ -28,7 +28,7 @@ pub fn main_inner(profile: Profile) {
} else { } else {
// then we try to retrieve it from the `target` folder. // then we try to retrieve it from the `target` folder.
let commit = include_str!("../libgccjit.version").trim(); let commit = include_str!("../libgccjit.version").trim();
Path::new("target/libgccjit").join(commit) Path::new("build/libgccjit").join(commit)
}; };
let gcc_path = Path::new(&gcc_path) let gcc_path = Path::new(&gcc_path)