Skip to content

Commit e0c4d65

Browse files
authored
Merge pull request #384 from GuillaumeGomez/rustify-test
Rustify test.sh
2 parents db49437 + 8e870c7 commit e0c4d65

16 files changed

+1633
-824
lines changed

.github/workflows/ci.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,19 @@ jobs:
124124
- name: Run tests
125125
run: |
126126
# TODO: remove --features master when it is back to the default.
127-
./test.sh --features master --release --clean --build-sysroot ${{ matrix.commands }}
127+
./y.sh test --features master --release --clean --build-sysroot ${{ matrix.commands }}
128128
129129
duplicates:
130130
runs-on: ubuntu-latest
131131
steps:
132132
- uses: actions/checkout@v3
133133
- run: python tools/check_intrinsics_duplicates.py
134+
135+
build_system:
136+
runs-on: ubuntu-latest
137+
steps:
138+
- uses: actions/checkout@v3
139+
- name: Test build system
140+
run: |
141+
cd build_system
142+
cargo test

.github/workflows/failures.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,5 @@ jobs:
128128
- name: Run tests
129129
id: tests
130130
run: |
131-
${{ matrix.libgccjit_version.env_extra }} ./test.sh --release --clean --build-sysroot --test-failing-rustc ${{ matrix.libgccjit_version.extra }} | tee output_log
131+
${{ matrix.libgccjit_version.env_extra }} ./y.sh test --release --clean --build-sysroot --test-failing-rustc ${{ matrix.libgccjit_version.extra }} | tee output_log
132132
rg --text "test result" output_log >> $GITHUB_STEP_SUMMARY

.github/workflows/gcc12.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ jobs:
2828
# FIXME: re-enable asm tests when GCC can emit in the right syntax.
2929
# "--asm-tests",
3030
"--test-libcore",
31-
"--extended-rand-tests",
32-
"--extended-regex-example-tests",
33-
"--extended-regex-tests",
3431
"--test-successful-rustc --nb-parts 2 --current-part 0",
3532
"--test-successful-rustc --nb-parts 2 --current-part 1",
3633
]
@@ -112,4 +109,4 @@ jobs:
112109

113110
- name: Run tests
114111
run: |
115-
./test.sh --release --clean --build-sysroot ${{ matrix.commands }} --no-default-features
112+
./y.sh test --release --clean --build-sysroot ${{ matrix.commands }} --no-default-features

.github/workflows/m68k.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,4 @@ jobs:
139139
- name: Run tests
140140
run: |
141141
# TODO: remove --features master when it is back to the default.
142-
./test.sh --release --features master --clean --build-sysroot ${{ matrix.commands }}
142+
./y.sh test --release --features master --clean --build-sysroot ${{ matrix.commands }}

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ jobs:
105105
- name: Run tests
106106
run: |
107107
# TODO: remove --features master when it is back to the default.
108-
EMBED_LTO_BITCODE=1 ./test.sh --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }} --features master
108+
EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }} --features master

.github/workflows/stdarch.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ jobs:
120120
if: ${{ !matrix.cargo_runner }}
121121
run: |
122122
# TODO: remove `--features master` when it is back to the default.
123-
./test.sh --release --clean --release-sysroot --build-sysroot --mini-tests --std-tests --test-libcore --features master
123+
./y.sh test --release --clean --release-sysroot --build-sysroot --mini-tests --std-tests --test-libcore --features master
124124
125125
- name: Run stdarch tests
126126
if: ${{ !matrix.cargo_runner }}

.rustfmt.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
disable_all_formatting = true
1+
ignore = ["/src", "/tests"]

Readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ $ LIBRARY_PATH=$(cat gcc_path) LD_LIBRARY_PATH=$(cat gcc_path) ./y.sh build --re
6565
To run the tests:
6666

6767
```bash
68-
$ ./test.sh --release --features master
68+
$ ./y.sh test --release --features master
6969
```
7070

7171
## Usage
@@ -82,7 +82,7 @@ export CG_GCCJIT_DIR=[the full path to rustc_codegen_gcc]
8282
$ CHANNEL="release" $CG_GCCJIT_DIR/cargo.sh run
8383
```
8484

85-
If you compiled cg_gccjit in debug mode (aka you didn't pass `--release` to `./test.sh`) you should use `CHANNEL="debug"` instead or omit `CHANNEL="release"` completely.
85+
If you compiled cg_gccjit in debug mode (aka you didn't pass `--release` to `./y.sh test`) you should use `CHANNEL="debug"` instead or omit `CHANNEL="release"` completely.
8686

8787
### LTO
8888

build_system/src/build.rs

+63-85
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
use crate::config::{set_config, ConfigInfo};
2-
use crate::utils::{
3-
get_gcc_path, run_command, run_command_with_output_and_env, walk_dir,
4-
};
1+
use crate::config::{Channel, ConfigInfo};
2+
use crate::utils::{get_gcc_path, run_command, run_command_with_output_and_env, walk_dir};
53
use std::collections::HashMap;
64
use std::ffi::OsStr;
75
use std::fs;
86
use std::path::Path;
97

108
#[derive(Default)]
119
struct BuildArg {
12-
codegen_release_channel: bool,
13-
sysroot_release_channel: bool,
14-
sysroot_panic_abort: bool,
1510
flags: Vec<String>,
1611
gcc_path: String,
12+
config_info: ConfigInfo,
1713
}
1814

1915
impl BuildArg {
@@ -28,14 +24,9 @@ impl BuildArg {
2824

2925
while let Some(arg) = args.next() {
3026
match arg.as_str() {
31-
"--release" => build_arg.codegen_release_channel = true,
32-
"--release-sysroot" => build_arg.sysroot_release_channel = true,
3327
"--no-default-features" => {
3428
build_arg.flags.push("--no-default-features".to_string());
3529
}
36-
"--sysroot-panic-abort" => {
37-
build_arg.sysroot_panic_abort = true;
38-
},
3930
"--features" => {
4031
if let Some(arg) = args.next() {
4132
build_arg.flags.push("--features".to_string());
@@ -50,25 +41,11 @@ impl BuildArg {
5041
Self::usage();
5142
return Ok(None);
5243
}
53-
"--target-triple" => {
54-
if args.next().is_some() {
55-
// Handled in config.rs.
56-
} else {
57-
return Err(
58-
"Expected a value after `--target-triple`, found nothing".to_string()
59-
);
60-
}
61-
}
62-
"--target" => {
63-
if args.next().is_some() {
64-
// Handled in config.rs.
65-
} else {
66-
return Err(
67-
"Expected a value after `--target`, found nothing".to_string()
68-
);
44+
arg => {
45+
if !build_arg.config_info.parse_argument(arg, &mut args)? {
46+
return Err(format!("Unknown argument `{}`", arg));
6947
}
7048
}
71-
arg => return Err(format!("Unknown argument `{}`", arg)),
7249
}
7350
}
7451
Ok(Some(build_arg))
@@ -79,29 +56,20 @@ impl BuildArg {
7956
r#"
8057
`build` command help:
8158
82-
--release : Build codegen in release mode
83-
--release-sysroot : Build sysroot in release mode
84-
--sysroot-panic-abort : Build the sysroot without unwinding support.
8559
--no-default-features : Add `--no-default-features` flag
86-
--features [arg] : Add a new feature [arg]
87-
--target-triple [arg] : Set the target triple to [arg]
88-
--help : Show this help
89-
"#
90-
)
60+
--features [arg] : Add a new feature [arg]"#
61+
);
62+
ConfigInfo::show_usage();
63+
println!(" --help : Show this help");
9164
}
9265
}
9366

94-
fn build_sysroot(
95-
env: &mut HashMap<String, String>,
96-
args: &BuildArg,
97-
config: &ConfigInfo,
98-
) -> Result<(), String> {
99-
std::env::set_current_dir("build_sysroot")
100-
.map_err(|error| format!("Failed to go to `build_sysroot` directory: {:?}", error))?;
67+
pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Result<(), String> {
68+
let start_dir = Path::new("build_sysroot");
10169
// Cleanup for previous run
10270
// Clean target dir except for build scripts and incremental cache
10371
let _ = walk_dir(
104-
"target",
72+
start_dir.join("target"),
10573
|dir: &Path| {
10674
for top in &["debug", "release"] {
10775
let _ = fs::remove_dir_all(dir.join(top).join("build"));
@@ -138,79 +106,93 @@ fn build_sysroot(
138106
|_| Ok(()),
139107
);
140108

141-
let _ = fs::remove_file("Cargo.lock");
142-
let _ = fs::remove_file("test_target/Cargo.lock");
143-
let _ = fs::remove_dir_all("sysroot");
109+
let _ = fs::remove_file(start_dir.join("Cargo.lock"));
110+
let _ = fs::remove_file(start_dir.join("test_target/Cargo.lock"));
111+
let _ = fs::remove_dir_all(start_dir.join("sysroot"));
144112

145113
// Builds libs
146-
let mut rustflags = env
147-
.get("RUSTFLAGS")
148-
.cloned()
149-
.unwrap_or_default();
150-
if args.sysroot_panic_abort {
114+
let mut rustflags = env.get("RUSTFLAGS").cloned().unwrap_or_default();
115+
if config.sysroot_panic_abort {
151116
rustflags.push_str(" -Cpanic=abort -Zpanic-abort-tests");
152117
}
153-
env.insert(
154-
"RUSTFLAGS".to_string(),
155-
format!("{} -Zmir-opt-level=3", rustflags),
156-
);
157-
let channel = if args.sysroot_release_channel {
118+
rustflags.push_str(" -Z force-unstable-if-unmarked");
119+
let mut env = env.clone();
120+
let channel = if config.sysroot_release_channel {
121+
env.insert(
122+
"RUSTFLAGS".to_string(),
123+
format!("{} -Zmir-opt-level=3", rustflags),
124+
);
158125
run_command_with_output_and_env(
159126
&[
160127
&"cargo",
161128
&"build",
129+
&"--release",
162130
&"--target",
163131
&config.target,
164-
&"--release",
165132
],
166-
None,
133+
Some(start_dir),
167134
Some(&env),
168135
)?;
169136
"release"
170137
} else {
138+
env.insert("RUSTFLAGS".to_string(), rustflags);
139+
171140
run_command_with_output_and_env(
172-
&[
173-
&"cargo",
174-
&"build",
175-
&"--target",
176-
&config.target,
177-
],
178-
None,
179-
Some(env),
141+
&[&"cargo", &"build", &"--target", &config.target],
142+
Some(start_dir),
143+
Some(&env),
180144
)?;
181145
"debug"
182146
};
183147

184148
// Copy files to sysroot
185-
let sysroot_path = format!("sysroot/lib/rustlib/{}/lib/", config.target_triple);
186-
fs::create_dir_all(&sysroot_path)
187-
.map_err(|error| format!("Failed to create directory `{}`: {:?}", sysroot_path, error))?;
149+
let sysroot_path = start_dir.join(format!("sysroot/lib/rustlib/{}/lib/", config.target_triple));
150+
fs::create_dir_all(&sysroot_path).map_err(|error| {
151+
format!(
152+
"Failed to create directory `{}`: {:?}",
153+
sysroot_path.display(),
154+
error
155+
)
156+
})?;
188157
let copier = |dir_to_copy: &Path| {
158+
// FIXME: should not use shell command!
189159
run_command(&[&"cp", &"-r", &dir_to_copy, &sysroot_path], None).map(|_| ())
190160
};
191161
walk_dir(
192-
&format!("target/{}/{}/deps", config.target_triple, channel),
162+
start_dir.join(&format!("target/{}/{}/deps", config.target_triple, channel)),
193163
copier,
194164
copier,
195165
)?;
196166

197167
// Copy the source files to the sysroot (Rust for Linux needs this).
198168
let sysroot_src_path = "sysroot/lib/rustlib/src/rust";
199-
fs::create_dir_all(&sysroot_src_path)
200-
.map_err(|error| format!("Failed to create directory `{}`: {:?}", sysroot_src_path, error))?;
201-
run_command(&[&"cp", &"-r", &"sysroot_src/library/", &sysroot_src_path], None)?;
169+
fs::create_dir_all(&sysroot_src_path).map_err(|error| {
170+
format!(
171+
"Failed to create directory `{}`: {:?}",
172+
sysroot_src_path, error
173+
)
174+
})?;
175+
run_command(
176+
&[
177+
&"cp",
178+
&"-r",
179+
&start_dir.join("sysroot_src/library/"),
180+
&sysroot_src_path,
181+
],
182+
None,
183+
)?;
202184

203185
Ok(())
204186
}
205187

206-
fn build_codegen(args: &BuildArg) -> Result<(), String> {
188+
fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
207189
let mut env = HashMap::new();
208190

209191
env.insert("LD_LIBRARY_PATH".to_string(), args.gcc_path.clone());
210192
env.insert("LIBRARY_PATH".to_string(), args.gcc_path.clone());
211193

212194
let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"rustc"];
213-
if args.codegen_release_channel {
195+
if args.config_info.channel == Channel::Release {
214196
command.push(&"--release");
215197
env.insert("CHANNEL".to_string(), "release".to_string());
216198
env.insert("CARGO_INCREMENTAL".to_string(), "1".to_string());
@@ -223,7 +205,7 @@ fn build_codegen(args: &BuildArg) -> Result<(), String> {
223205
}
224206
run_command_with_output_and_env(&command, None, Some(&env))?;
225207

226-
let config = set_config(&mut env, &[], Some(&args.gcc_path))?;
208+
args.config_info.setup(&mut env, Some(&args.gcc_path))?;
227209

228210
// We voluntarily ignore the error.
229211
let _ = fs::remove_dir_all("target/out");
@@ -236,19 +218,15 @@ fn build_codegen(args: &BuildArg) -> Result<(), String> {
236218
})?;
237219

238220
println!("[BUILD] sysroot");
239-
build_sysroot(
240-
&mut env,
241-
args,
242-
&config,
243-
)?;
221+
build_sysroot(&env, &args.config_info)?;
244222
Ok(())
245223
}
246224

247225
pub fn run() -> Result<(), String> {
248-
let args = match BuildArg::new()? {
226+
let mut args = match BuildArg::new()? {
249227
Some(args) => args,
250228
None => return Ok(()),
251229
};
252-
build_codegen(&args)?;
230+
build_codegen(&mut args)?;
253231
Ok(())
254232
}

0 commit comments

Comments
 (0)