Skip to content

Generate content into build folder #435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ tools/llvmint-2
llvm
build_system/target
config.toml
build
19 changes: 7 additions & 12 deletions build_system/src/clean.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::utils::{remove_file, run_command};

use std::fs::remove_dir_all;
use std::path::Path;

#[derive(Default)]
enum CleanArg {
Expand Down Expand Up @@ -46,12 +47,14 @@ fn clean_all() -> Result<(), String> {
"build_sysroot/sysroot",
"build_sysroot/sysroot_src",
"build_sysroot/target",
"regex",
"simple-raytracer",
];
for dir in dirs_to_remove {
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"];

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

fn clean_ui_tests() -> Result<(), String> {
run_command(
&[
&"find",
&"rust/build/x86_64-unknown-linux-gnu/test/ui/",
&"-name",
&"stamp",
&"-delete",
],
None,
)?;
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)?;
Ok(())
}

Expand Down
19 changes: 9 additions & 10 deletions build_system/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,7 @@ impl ConfigInfo {
}

fn download_gccjit_if_needed(&mut self) -> Result<(), String> {
let output_dir = Path::new(
std::env::var("CARGO_TARGET_DIR")
.as_deref()
.unwrap_or("target"),
)
.join("libgccjit");
let output_dir = Path::new(crate::BUILD_DIR).join("libgccjit");

let commit_hash_file = self.compute_path("libgccjit.version");
let content = fs::read_to_string(&commit_hash_file).map_err(|_| {
Expand Down Expand Up @@ -523,7 +518,11 @@ fn download_gccjit(
&"--retry",
&"3",
&"-SRfL",
if with_progress_bar { &"--progress-bar" } else { &"-s" },
if with_progress_bar {
&"--progress-bar"
} else {
&"-s"
},
&url.as_str(),
],
Some(&output_dir),
Expand All @@ -538,9 +537,9 @@ fn download_gccjit(
&"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;",
&format!(
"(New-Object System.Net.WebClient).DownloadFile('{}', '{}')",
url,
tempfile_name,
).as_str(),
url, tempfile_name,
)
.as_str(),
],
Some(&output_dir),
);
Expand Down
2 changes: 2 additions & 0 deletions build_system/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ mod rustc_info;
mod test;
mod utils;

const BUILD_DIR: &str = "build";

macro_rules! arg_error {
($($err:tt)*) => {{
eprintln!($($err)*);
Expand Down
7 changes: 3 additions & 4 deletions build_system/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ fn clone_and_setup<F>(repo_url: &str, checkout_commit: &str, extra: Option<F>) -
where
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 {
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", &checkout_commit], Some(&repo_path))?;
let filter = format!("-{}-", clone_result.repo_name);
Expand Down Expand Up @@ -219,8 +219,7 @@ impl PrepareArg {
--only-libcore : Only setup libcore and don't clone other repositories
--cross : Apply the patches needed to do cross-compilation
--libgccjit12-patches : Apply patches needed for libgccjit12
--help : Show this help
"#
--help : Show this help"#
)
}
}
Expand Down
75 changes: 42 additions & 33 deletions build_system/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,19 +485,25 @@ fn std_tests(env: &Env, args: &TestArg) -> Result<(), String> {
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!(
"+{channel}-{host}",
channel = get_toolchain()?, // May also include date
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.
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,
Some(env),
);
let rust_dir: Option<&Path> = Some(&rust_dir_path);
run_command(&[&"git", &"checkout", &"--", &"tests/"], rust_dir)?;
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 {
Expand Down Expand Up @@ -561,8 +567,9 @@ fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<(), String> {
String::new()
}
};
let file_path = rust_dir_path.join("config.toml");
std::fs::write(
"rust/config.toml",
&file_path,
&format!(
r#"change-id = 115898

Expand All @@ -587,13 +594,19 @@ download-ci-llvm = false
llvm_filecheck = llvm_filecheck.trim(),
),
)
.map_err(|error| format!("Failed to write into `rust/config.toml`: {:?}", error))?;
Ok(())
.map_err(|error| {
format!(
"Failed to write into `{}`: {:?}",
file_path.display(),
error
)
})?;
Ok(rust_dir_path)
}

fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
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.
println!("[TEST] rustc asm test suite");

Expand Down Expand Up @@ -621,7 +634,7 @@ fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
)
.as_str(),
],
Some(Path::new("rust")),
Some(&rust_dir),
Some(&env),
)?;
Ok(())
Expand Down Expand Up @@ -761,11 +774,11 @@ fn extended_rand_tests(env: &Env, args: &TestArg) -> Result<(), String> {
println!("Not using GCC master branch. Skipping `extended_rand_tests`.");
return Ok(());
}
let path = Path::new("rand");
run_cargo_command(&[&"clean"], Some(path), env, args)?;
let path = Path::new(crate::BUILD_DIR).join("rand");
run_cargo_command(&[&"clean"], Some(&path), env, args)?;
// FIXME: create a function "display_if_not_quiet" or something along the line.
println!("[TEST] rust-random/rand");
run_cargo_command(&[&"test", &"--workspace"], Some(path), env, args)?;
run_cargo_command(&[&"test", &"--workspace"], Some(&path), env, args)?;
Ok(())
}

Expand All @@ -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`.");
return Ok(());
}
let path = Path::new("regex");
run_cargo_command(&[&"clean"], Some(path), env, args)?;
let path = Path::new(crate::BUILD_DIR).join("regex");
run_cargo_command(&[&"clean"], Some(&path), env, args)?;
// FIXME: create a function "display_if_not_quiet" or something along the line.
println!("[TEST] rust-lang/regex example shootout-regex-dna");
let mut env = env.clone();
Expand All @@ -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
run_cargo_command(
&[&"build", &"--example", &"shootout-regex-dna"],
Some(path),
Some(&path),
&env,
args,
)?;

run_cargo_command_with_callback(
&[&"run", &"--example", &"shootout-regex-dna"],
Some(path),
Some(&path),
&env,
args,
|cargo_command, cwd, env| {
Expand Down Expand Up @@ -838,6 +851,7 @@ fn extended_regex_tests(env: &Env, args: &TestArg) -> Result<(), String> {
env.get("RUSTFLAGS").cloned().unwrap_or_default()
);
env.insert("RUSTFLAGS".to_string(), rustflags);
let path = Path::new(crate::BUILD_DIR).join("regex");
run_cargo_command(
&[
&"test",
Expand All @@ -850,7 +864,7 @@ fn extended_regex_tests(env: &Env, args: &TestArg) -> Result<(), String> {
&"-Zunstable-options",
&"-q",
],
Some(Path::new("regex")),
Some(&path),
&env,
args,
)?;
Expand Down Expand Up @@ -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>
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.
println!("[TEST] rust-lang/rust");
let mut env = env.clone();
setup_rustc(&mut env, args)?;

let rust_path = Path::new("rust");
let rust_path = setup_rustc(&mut env, args)?;

walk_dir(
"rust/tests/ui",
rust_path.join("tests/ui"),
|dir| {
let dir_name = dir.file_name().and_then(|name| name.to_str()).unwrap_or("");
if [
Expand Down Expand Up @@ -1001,7 +1013,7 @@ where

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.
println!("Keeping all UI tests");
}
Expand All @@ -1027,7 +1039,7 @@ where
&"-path",
&"*/auxiliary/*",
],
Some(rust_path),
Some(&rust_path),
)?
.stdout,
)
Expand Down Expand Up @@ -1072,18 +1084,18 @@ where
&"--rustc-args",
&rustc_args,
],
Some(rust_path),
Some(&rust_path),
Some(&env),
)?;
Ok(())
}

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> {
test_rustc_inner(env, args, || {
test_rustc_inner(env, args, |rust_path| {
// Removing all tests.
run_command(
&[
Expand All @@ -1098,7 +1110,7 @@ fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
&"*/auxiliary/*",
&"-delete",
],
Some(Path::new("rust")),
Some(rust_path),
)?;
// Putting back only the failing ones.
let path = "tests/failing-ui-tests.txt";
Expand All @@ -1108,10 +1120,7 @@ fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
.map(|line| line.trim())
.filter(|line| !line.is_empty())
{
run_command(
&[&"git", &"checkout", &"--", &file],
Some(Path::new("rust")),
)?;
run_command(&[&"git", &"checkout", &"--", &file], Some(&rust_path))?;
}
} else {
println!(
Expand All @@ -1124,7 +1133,7 @@ fn test_failing_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.
let path = "tests/failing-ui-tests.txt";
if let Ok(files) = std::fs::read_to_string(path) {
Expand All @@ -1133,7 +1142,7 @@ fn test_successful_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
.map(|line| line.trim())
.filter(|line| !line.is_empty())
{
let path = Path::new("rust").join(file);
let path = rust_path.join(file);
remove_file(&path)?;
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/lang_tests_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn main_inner(profile: Profile) {
} else {
// then we try to retrieve it from the `target` folder.
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)
Expand Down