Skip to content

Commit 231f7c6

Browse files
authored
Merge pull request rust-lang#1252 from afonso360/tests-rs
Move test script to y.rs
2 parents 49e7731 + 0db9094 commit 231f7c6

File tree

12 files changed

+730
-238
lines changed

12 files changed

+730
-238
lines changed

.cirrus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ task:
2222
- # Reduce amount of benchmark runs as they are slow
2323
- export COMPILE_RUNS=2
2424
- export RUN_RUNS=2
25-
- ./test.sh
25+
- ./y.rs test

.github/workflows/main.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
# Enable extra checks
104104
export CG_CLIF_ENABLE_VERIFIER=1
105105
106-
./test.sh
106+
./y.rs test
107107
108108
- name: Package prebuilt cg_clif
109109
run: tar cvfJ cg_clif.tar.xz build
@@ -162,14 +162,14 @@ jobs:
162162
#name: Test
163163
run: |
164164
# Enable backtraces for easier debugging
165-
#export RUST_BACKTRACE=1
165+
#$Env:RUST_BACKTRACE=1
166166
167167
# Reduce amount of benchmark runs as they are slow
168-
#export COMPILE_RUNS=2
169-
#export RUN_RUNS=2
168+
#$Env:COMPILE_RUNS=2
169+
#$Env:RUN_RUNS=2
170170
171171
# Enable extra checks
172-
#export CG_CLIF_ENABLE_VERIFIER=1
172+
#$Env:CG_CLIF_ENABLE_VERIFIER=1
173173
174174
./y.exe build
175175

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ perf.data.old
88
*.string*
99
/y.bin
1010
/y.bin.dSYM
11+
/y.exe
12+
/y.pdb
1113
/build
1214
/build_sysroot/sysroot_src
1315
/build_sysroot/compiler-builtins

build_system/build_sysroot.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ use std::fs;
22
use std::path::{Path, PathBuf};
33
use std::process::{self, Command};
44

5-
use super::rustc_info::{get_file_name, get_rustc_version};
5+
use super::rustc_info::{get_file_name, get_rustc_version, get_wrapper_file_name};
66
use super::utils::{spawn_and_wait, try_hard_link};
77
use super::SysrootKind;
88

99
pub(crate) fn build_sysroot(
1010
channel: &str,
1111
sysroot_kind: SysrootKind,
1212
target_dir: &Path,
13-
cg_clif_build_dir: PathBuf,
13+
cg_clif_build_dir: &Path,
1414
host_triple: &str,
1515
target_triple: &str,
1616
) {
17+
eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
18+
1719
if target_dir.exists() {
1820
fs::remove_dir_all(target_dir).unwrap();
1921
}
@@ -35,11 +37,13 @@ pub(crate) fn build_sysroot(
3537

3638
// Build and copy rustc and cargo wrappers
3739
for wrapper in ["rustc-clif", "cargo-clif"] {
40+
let wrapper_name = get_wrapper_file_name(wrapper, "bin");
41+
3842
let mut build_cargo_wrapper_cmd = Command::new("rustc");
3943
build_cargo_wrapper_cmd
4044
.arg(PathBuf::from("scripts").join(format!("{wrapper}.rs")))
4145
.arg("-o")
42-
.arg(target_dir.join(wrapper))
46+
.arg(target_dir.join(wrapper_name))
4347
.arg("-g");
4448
spawn_and_wait(build_cargo_wrapper_cmd);
4549
}

build_system/mod.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod build_sysroot;
77
mod config;
88
mod prepare;
99
mod rustc_info;
10+
mod tests;
1011
mod utils;
1112

1213
fn usage() {
@@ -15,6 +16,9 @@ fn usage() {
1516
eprintln!(
1617
" ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
1718
);
19+
eprintln!(
20+
" ./y.rs test [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
21+
);
1822
}
1923

2024
macro_rules! arg_error {
@@ -25,11 +29,13 @@ macro_rules! arg_error {
2529
}};
2630
}
2731

32+
#[derive(PartialEq, Debug)]
2833
enum Command {
2934
Build,
35+
Test,
3036
}
3137

32-
#[derive(Copy, Clone)]
38+
#[derive(Copy, Clone, Debug)]
3339
pub(crate) enum SysrootKind {
3440
None,
3541
Clif,
@@ -46,12 +52,13 @@ pub fn main() {
4652
let command = match args.next().as_deref() {
4753
Some("prepare") => {
4854
if args.next().is_some() {
49-
arg_error!("./x.rs prepare doesn't expect arguments");
55+
arg_error!("./y.rs prepare doesn't expect arguments");
5056
}
5157
prepare::prepare();
5258
process::exit(0);
5359
}
5460
Some("build") => Command::Build,
61+
Some("test") => Command::Test,
5562
Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
5663
Some(command) => arg_error!("Unknown command {}", command),
5764
None => {
@@ -117,12 +124,26 @@ pub fn main() {
117124

118125
let cg_clif_build_dir =
119126
build_backend::build_backend(channel, &host_triple, use_unstable_features);
120-
build_sysroot::build_sysroot(
121-
channel,
122-
sysroot_kind,
123-
&target_dir,
124-
cg_clif_build_dir,
125-
&host_triple,
126-
&target_triple,
127-
);
127+
match command {
128+
Command::Test => {
129+
tests::run_tests(
130+
channel,
131+
sysroot_kind,
132+
&target_dir,
133+
&cg_clif_build_dir,
134+
&host_triple,
135+
&target_triple,
136+
);
137+
}
138+
Command::Build => {
139+
build_sysroot::build_sysroot(
140+
channel,
141+
sysroot_kind,
142+
&target_dir,
143+
&cg_clif_build_dir,
144+
&host_triple,
145+
&target_triple,
146+
);
147+
}
148+
}
128149
}

build_system/prepare.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ pub(crate) fn prepare() {
5050
spawn_and_wait(build_cmd);
5151
fs::copy(
5252
Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin")),
53-
// FIXME use get_file_name here too once testing is migrated to rust
54-
"simple-raytracer/raytracer_cg_llvm",
53+
Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin")),
5554
)
5655
.unwrap();
5756
}

build_system/rustc_info.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,12 @@ pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String {
6363
assert!(file_name.contains(crate_name));
6464
file_name
6565
}
66+
67+
/// Similar to `get_file_name`, but converts any dashes (`-`) in the `crate_name` to
68+
/// underscores (`_`). This is specially made for the the rustc and cargo wrappers
69+
/// which have a dash in the name, and that is not allowed in a crate name.
70+
pub(crate) fn get_wrapper_file_name(crate_name: &str, crate_type: &str) -> String {
71+
let crate_name = crate_name.replace('-', "_");
72+
let wrapper_name = get_file_name(&crate_name, crate_type);
73+
wrapper_name.replace('_', "-")
74+
}

0 commit comments

Comments
 (0)