Skip to content

Commit 6afabce

Browse files
authored
Merge pull request #435 from GuillaumeGomez/clean-up-repo
Generate content into `build` folder
2 parents 7faff65 + 46d6e77 commit 6afabce

File tree

7 files changed

+65
-60
lines changed

7 files changed

+65
-60
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ tools/llvmint-2
2929
llvm
3030
build_system/target
3131
config.toml
32+
build

build_system/src/clean.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::utils::{remove_file, run_command};
22

33
use std::fs::remove_dir_all;
4+
use std::path::Path;
45

56
#[derive(Default)]
67
enum CleanArg {
@@ -46,12 +47,14 @@ fn clean_all() -> Result<(), String> {
4647
"build_sysroot/sysroot",
4748
"build_sysroot/sysroot_src",
4849
"build_sysroot/target",
49-
"regex",
50-
"simple-raytracer",
5150
];
5251
for dir in dirs_to_remove {
5352
let _ = remove_dir_all(dir);
5453
}
54+
let dirs_to_remove = ["regex", "rand", "simple-raytracer"];
55+
for dir in dirs_to_remove {
56+
let _ = remove_dir_all(Path::new(crate::BUILD_DIR).join(dir));
57+
}
5558

5659
let files_to_remove = ["build_sysroot/Cargo.lock", "perf.data", "perf.data.old"];
5760

@@ -64,16 +67,8 @@ fn clean_all() -> Result<(), String> {
6467
}
6568

6669
fn clean_ui_tests() -> Result<(), String> {
67-
run_command(
68-
&[
69-
&"find",
70-
&"rust/build/x86_64-unknown-linux-gnu/test/ui/",
71-
&"-name",
72-
&"stamp",
73-
&"-delete",
74-
],
75-
None,
76-
)?;
70+
let path = Path::new(crate::BUILD_DIR).join("rust/build/x86_64-unknown-linux-gnu/test/ui/");
71+
run_command(&[&"find", &path, &"-name", &"stamp", &"-delete"], None)?;
7772
Ok(())
7873
}
7974

build_system/src/config.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,7 @@ impl ConfigInfo {
191191
}
192192

193193
fn download_gccjit_if_needed(&mut self) -> Result<(), String> {
194-
let output_dir = Path::new(
195-
std::env::var("CARGO_TARGET_DIR")
196-
.as_deref()
197-
.unwrap_or("target"),
198-
)
199-
.join("libgccjit");
194+
let output_dir = Path::new(crate::BUILD_DIR).join("libgccjit");
200195

201196
let commit_hash_file = self.compute_path("libgccjit.version");
202197
let content = fs::read_to_string(&commit_hash_file).map_err(|_| {
@@ -523,7 +518,11 @@ fn download_gccjit(
523518
&"--retry",
524519
&"3",
525520
&"-SRfL",
526-
if with_progress_bar { &"--progress-bar" } else { &"-s" },
521+
if with_progress_bar {
522+
&"--progress-bar"
523+
} else {
524+
&"-s"
525+
},
527526
&url.as_str(),
528527
],
529528
Some(&output_dir),
@@ -538,9 +537,9 @@ fn download_gccjit(
538537
&"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;",
539538
&format!(
540539
"(New-Object System.Net.WebClient).DownloadFile('{}', '{}')",
541-
url,
542-
tempfile_name,
543-
).as_str(),
540+
url, tempfile_name,
541+
)
542+
.as_str(),
544543
],
545544
Some(&output_dir),
546545
);

build_system/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ mod rustc_info;
1111
mod test;
1212
mod utils;
1313

14+
const BUILD_DIR: &str = "build";
15+
1416
macro_rules! arg_error {
1517
($($err:tt)*) => {{
1618
eprintln!($($err)*);

build_system/src/prepare.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ fn clone_and_setup<F>(repo_url: &str, checkout_commit: &str, extra: Option<F>) -
152152
where
153153
F: Fn(&Path) -> Result<(), String>,
154154
{
155-
let clone_result = git_clone(repo_url, None, false)?;
155+
let clone_result = git_clone(repo_url, Some(&Path::new(crate::BUILD_DIR)), false)?;
156156
if !clone_result.ran_clone {
157157
println!("`{}` has already been cloned", clone_result.repo_name);
158158
}
159-
let repo_path = Path::new(&clone_result.repo_name);
159+
let repo_path = Path::new(crate::BUILD_DIR).join(&clone_result.repo_name);
160160
run_command(&[&"git", &"checkout", &"--", &"."], Some(&repo_path))?;
161161
run_command(&[&"git", &"checkout", &checkout_commit], Some(&repo_path))?;
162162
let filter = format!("-{}-", clone_result.repo_name);
@@ -219,8 +219,7 @@ impl PrepareArg {
219219
--only-libcore : Only setup libcore and don't clone other repositories
220220
--cross : Apply the patches needed to do cross-compilation
221221
--libgccjit12-patches : Apply patches needed for libgccjit12
222-
--help : Show this help
223-
"#
222+
--help : Show this help"#
224223
)
225224
}
226225
}

build_system/src/test.rs

+42-33
Original file line numberDiff line numberDiff line change
@@ -485,19 +485,25 @@ fn std_tests(env: &Env, args: &TestArg) -> Result<(), String> {
485485
Ok(())
486486
}
487487

488-
fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<(), String> {
488+
fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<PathBuf, String> {
489489
let toolchain = format!(
490490
"+{channel}-{host}",
491491
channel = get_toolchain()?, // May also include date
492492
host = args.config_info.host_triple
493493
);
494-
let rust_dir = Some(Path::new("rust"));
494+
let rust_dir_path = Path::new(crate::BUILD_DIR).join("rust");
495495
// If the repository was already cloned, command will fail, so doesn't matter.
496496
let _ = run_command_with_output_and_env(
497-
&[&"git", &"clone", &"https://github.com/rust-lang/rust.git"],
497+
&[
498+
&"git",
499+
&"clone",
500+
&"https://github.com/rust-lang/rust.git",
501+
&rust_dir_path,
502+
],
498503
None,
499504
Some(env),
500505
);
506+
let rust_dir: Option<&Path> = Some(&rust_dir_path);
501507
run_command(&[&"git", &"checkout", &"--", &"tests/"], rust_dir)?;
502508
run_command_with_output_and_env(&[&"git", &"fetch"], rust_dir, Some(env))?;
503509
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> {
561567
String::new()
562568
}
563569
};
570+
let file_path = rust_dir_path.join("config.toml");
564571
std::fs::write(
565-
"rust/config.toml",
572+
&file_path,
566573
&format!(
567574
r#"change-id = 115898
568575
@@ -587,13 +594,19 @@ download-ci-llvm = false
587594
llvm_filecheck = llvm_filecheck.trim(),
588595
),
589596
)
590-
.map_err(|error| format!("Failed to write into `rust/config.toml`: {:?}", error))?;
591-
Ok(())
597+
.map_err(|error| {
598+
format!(
599+
"Failed to write into `{}`: {:?}",
600+
file_path.display(),
601+
error
602+
)
603+
})?;
604+
Ok(rust_dir_path)
592605
}
593606

594607
fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
595608
let mut env = env.clone();
596-
setup_rustc(&mut env, args)?;
609+
let rust_dir = setup_rustc(&mut env, args)?;
597610
// FIXME: create a function "display_if_not_quiet" or something along the line.
598611
println!("[TEST] rustc asm test suite");
599612

@@ -621,7 +634,7 @@ fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
621634
)
622635
.as_str(),
623636
],
624-
Some(Path::new("rust")),
637+
Some(&rust_dir),
625638
Some(&env),
626639
)?;
627640
Ok(())
@@ -761,11 +774,11 @@ fn extended_rand_tests(env: &Env, args: &TestArg) -> Result<(), String> {
761774
println!("Not using GCC master branch. Skipping `extended_rand_tests`.");
762775
return Ok(());
763776
}
764-
let path = Path::new("rand");
765-
run_cargo_command(&[&"clean"], Some(path), env, args)?;
777+
let path = Path::new(crate::BUILD_DIR).join("rand");
778+
run_cargo_command(&[&"clean"], Some(&path), env, args)?;
766779
// FIXME: create a function "display_if_not_quiet" or something along the line.
767780
println!("[TEST] rust-random/rand");
768-
run_cargo_command(&[&"test", &"--workspace"], Some(path), env, args)?;
781+
run_cargo_command(&[&"test", &"--workspace"], Some(&path), env, args)?;
769782
Ok(())
770783
}
771784

@@ -774,8 +787,8 @@ fn extended_regex_example_tests(env: &Env, args: &TestArg) -> Result<(), String>
774787
println!("Not using GCC master branch. Skipping `extended_regex_example_tests`.");
775788
return Ok(());
776789
}
777-
let path = Path::new("regex");
778-
run_cargo_command(&[&"clean"], Some(path), env, args)?;
790+
let path = Path::new(crate::BUILD_DIR).join("regex");
791+
run_cargo_command(&[&"clean"], Some(&path), env, args)?;
779792
// FIXME: create a function "display_if_not_quiet" or something along the line.
780793
println!("[TEST] rust-lang/regex example shootout-regex-dna");
781794
let mut env = env.clone();
@@ -788,14 +801,14 @@ fn extended_regex_example_tests(env: &Env, args: &TestArg) -> Result<(), String>
788801
// Make sure `[codegen mono items] start` doesn't poison the diff
789802
run_cargo_command(
790803
&[&"build", &"--example", &"shootout-regex-dna"],
791-
Some(path),
804+
Some(&path),
792805
&env,
793806
args,
794807
)?;
795808

796809
run_cargo_command_with_callback(
797810
&[&"run", &"--example", &"shootout-regex-dna"],
798-
Some(path),
811+
Some(&path),
799812
&env,
800813
args,
801814
|cargo_command, cwd, env| {
@@ -838,6 +851,7 @@ fn extended_regex_tests(env: &Env, args: &TestArg) -> Result<(), String> {
838851
env.get("RUSTFLAGS").cloned().unwrap_or_default()
839852
);
840853
env.insert("RUSTFLAGS".to_string(), rustflags);
854+
let path = Path::new(crate::BUILD_DIR).join("regex");
841855
run_cargo_command(
842856
&[
843857
&"test",
@@ -850,7 +864,7 @@ fn extended_regex_tests(env: &Env, args: &TestArg) -> Result<(), String> {
850864
&"-Zunstable-options",
851865
&"-q",
852866
],
853-
Some(Path::new("regex")),
867+
Some(&path),
854868
&env,
855869
args,
856870
)?;
@@ -928,17 +942,15 @@ fn should_remove_test(file_path: &Path) -> Result<bool, String> {
928942

929943
fn test_rustc_inner<F>(env: &Env, args: &TestArg, prepare_files_callback: F) -> Result<(), String>
930944
where
931-
F: Fn() -> Result<bool, String>,
945+
F: Fn(&Path) -> Result<bool, String>,
932946
{
933947
// FIXME: create a function "display_if_not_quiet" or something along the line.
934948
println!("[TEST] rust-lang/rust");
935949
let mut env = env.clone();
936-
setup_rustc(&mut env, args)?;
937-
938-
let rust_path = Path::new("rust");
950+
let rust_path = setup_rustc(&mut env, args)?;
939951

940952
walk_dir(
941-
"rust/tests/ui",
953+
rust_path.join("tests/ui"),
942954
|dir| {
943955
let dir_name = dir.file_name().and_then(|name| name.to_str()).unwrap_or("");
944956
if [
@@ -1001,7 +1013,7 @@ where
10011013

10021014
walk_dir(rust_path.join("tests/ui"), dir_handling, file_handling)?;
10031015

1004-
if !prepare_files_callback()? {
1016+
if !prepare_files_callback(&rust_path)? {
10051017
// FIXME: create a function "display_if_not_quiet" or something along the line.
10061018
println!("Keeping all UI tests");
10071019
}
@@ -1027,7 +1039,7 @@ where
10271039
&"-path",
10281040
&"*/auxiliary/*",
10291041
],
1030-
Some(rust_path),
1042+
Some(&rust_path),
10311043
)?
10321044
.stdout,
10331045
)
@@ -1072,18 +1084,18 @@ where
10721084
&"--rustc-args",
10731085
&rustc_args,
10741086
],
1075-
Some(rust_path),
1087+
Some(&rust_path),
10761088
Some(&env),
10771089
)?;
10781090
Ok(())
10791091
}
10801092

10811093
fn test_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
1082-
test_rustc_inner(env, args, || Ok(false))
1094+
test_rustc_inner(env, args, |_| Ok(false))
10831095
}
10841096

10851097
fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
1086-
test_rustc_inner(env, args, || {
1098+
test_rustc_inner(env, args, |rust_path| {
10871099
// Removing all tests.
10881100
run_command(
10891101
&[
@@ -1098,7 +1110,7 @@ fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
10981110
&"*/auxiliary/*",
10991111
&"-delete",
11001112
],
1101-
Some(Path::new("rust")),
1113+
Some(rust_path),
11021114
)?;
11031115
// Putting back only the failing ones.
11041116
let path = "tests/failing-ui-tests.txt";
@@ -1108,10 +1120,7 @@ fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
11081120
.map(|line| line.trim())
11091121
.filter(|line| !line.is_empty())
11101122
{
1111-
run_command(
1112-
&[&"git", &"checkout", &"--", &file],
1113-
Some(Path::new("rust")),
1114-
)?;
1123+
run_command(&[&"git", &"checkout", &"--", &file], Some(&rust_path))?;
11151124
}
11161125
} else {
11171126
println!(
@@ -1124,7 +1133,7 @@ fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
11241133
}
11251134

11261135
fn test_successful_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
1127-
test_rustc_inner(env, args, || {
1136+
test_rustc_inner(env, args, |rust_path| {
11281137
// Removing the failing tests.
11291138
let path = "tests/failing-ui-tests.txt";
11301139
if let Ok(files) = std::fs::read_to_string(path) {
@@ -1133,7 +1142,7 @@ fn test_successful_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
11331142
.map(|line| line.trim())
11341143
.filter(|line| !line.is_empty())
11351144
{
1136-
let path = Path::new("rust").join(file);
1145+
let path = rust_path.join(file);
11371146
remove_file(&path)?;
11381147
}
11391148
} else {

tests/lang_tests_common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn main_inner(profile: Profile) {
2828
} else {
2929
// then we try to retrieve it from the `target` folder.
3030
let commit = include_str!("../libgccjit.version").trim();
31-
Path::new("target/libgccjit").join(commit)
31+
Path::new("build/libgccjit").join(commit)
3232
};
3333

3434
let gcc_path = Path::new(&gcc_path)

0 commit comments

Comments
 (0)