Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d059935

Browse files
committed
Misc cleanups to the test runner
1 parent c115933 commit d059935

File tree

3 files changed

+50
-59
lines changed

3 files changed

+50
-59
lines changed

build_system/build_backend.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use std::env;
2+
use std::path::{Path, PathBuf};
23
use std::process::Command;
34

45
pub(crate) fn build_backend(
56
channel: &str,
67
host_triple: &str,
78
use_unstable_features: bool,
8-
) {
9+
) -> PathBuf {
910
let mut cmd = Command::new("cargo");
1011
cmd.arg("build").arg("--target").arg(host_triple);
1112

@@ -37,4 +38,6 @@ pub(crate) fn build_backend(
3738

3839
eprintln!("[BUILD] rustc_codegen_cranelift");
3940
super::utils::spawn_and_wait(cmd);
41+
42+
Path::new("target").join(&host_triple).join(&channel)
4043
}

build_system/mod.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::env;
2-
use std::path::{PathBuf, Path};
2+
use std::path::PathBuf;
33
use std::process;
44

55
mod build_backend;
@@ -122,27 +122,28 @@ pub fn main() {
122122
process::exit(1);
123123
}
124124

125-
let cg_clif_build_dir = Path::new("target").join(&host_triple).join(&channel);
125+
let cg_clif_build_dir = build_backend::build_backend(channel, &host_triple, use_unstable_features);
126126

127-
if command == Command::Test {
128-
// TODO: Should we also build_backend here?
129-
tests::run_tests(
130-
channel,
131-
sysroot_kind,
132-
&target_dir,
133-
&cg_clif_build_dir,
134-
&host_triple,
135-
&target_triple,
136-
).expect("Failed to run tests");
137-
} else {
138-
build_backend::build_backend(channel, &host_triple, use_unstable_features);
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-
);
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+
}
147148
}
148149
}

build_system/tests.rs

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use std::fs;
88
use std::path::{Path, PathBuf};
99
use std::process::Command;
1010

11-
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
12-
1311
struct TestCase {
1412
config: &'static str,
1513
func: &'static dyn Fn(&TestRunner),
@@ -183,18 +181,16 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
183181
runner.run_cargo(["clean"]);
184182

185183
// newer aho_corasick versions throw a deprecation warning
186-
let mut lint_rust_flags = runner.rust_flags.clone();
187-
lint_rust_flags.push("--cap-lints".to_string());
188-
lint_rust_flags.push("warn".to_string());
184+
let lint_rust_flags = format!("{} --cap-lints warn", runner.rust_flags);
189185

190186
let mut build_cmd = runner.cargo_command(["build", "--example", "shootout-regex-dna", "--target", &runner.target_triple]);
191-
build_cmd.env("RUSTFLAGS", lint_rust_flags.join(" "));
187+
build_cmd.env("RUSTFLAGS", lint_rust_flags.clone());
192188

193189
spawn_and_wait(build_cmd);
194190

195191
if runner.host_triple == runner.target_triple {
196192
let mut run_cmd = runner.cargo_command(["run", "--example", "shootout-regex-dna", "--target", &runner.target_triple]);
197-
run_cmd.env("RUSTFLAGS", lint_rust_flags.join(" "));
193+
run_cmd.env("RUSTFLAGS", lint_rust_flags);
198194

199195

200196
let input = fs::read_to_string(PathBuf::from("examples/regexdna-input.txt")).unwrap();
@@ -205,7 +201,6 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
205201
// Make sure `[codegen mono items] start` doesn't poison the diff
206202
let output = output.lines()
207203
.filter(|line| !line.contains("codegen mono items"))
208-
.filter(|line| !line.contains("Spawned thread"))
209204
.chain(Some("")) // This just adds the trailing newline
210205
.collect::<Vec<&str>>()
211206
.join("\r\n");
@@ -267,7 +262,7 @@ pub(crate) fn run_tests(
267262
cg_clif_build_dir: &Path,
268263
host_triple: &str,
269264
target_triple: &str,
270-
) -> Result<()> {
265+
) {
271266
let runner = TestRunner::new(host_triple.to_string(), target_triple.to_string());
272267

273268
if config::get_bool("testsuite.no_sysroot") {
@@ -280,7 +275,7 @@ pub(crate) fn run_tests(
280275
&target_triple,
281276
);
282277

283-
let _ = remove_out_dir();
278+
let _ = fs::remove_dir_all(Path::new("target").join("out"));
284279
runner.run_testsuite(NO_SYSROOT_SUITE);
285280
} else {
286281
eprintln!("[SKIP] no_sysroot tests");
@@ -311,22 +306,16 @@ pub(crate) fn run_tests(
311306
} else {
312307
eprintln!("[SKIP] extended_sysroot tests");
313308
}
314-
315-
Ok(())
316309
}
317310

318311

319-
fn remove_out_dir() -> Result<()> {
320-
let out_dir = Path::new("target").join("out");
321-
Ok(fs::remove_dir_all(out_dir)?)
322-
}
323312

324313
struct TestRunner {
325314
root_dir: PathBuf,
326315
out_dir: PathBuf,
327316
jit_supported: bool,
328-
rust_flags: Vec<String>,
329-
run_wrapper: Vec<String>,
317+
rust_flags: String,
318+
run_wrapper: String,
330319
host_triple: String,
331320
target_triple: String,
332321
}
@@ -342,22 +331,19 @@ impl TestRunner {
342331
let is_native = host_triple == target_triple;
343332
let jit_supported = target_triple.contains("x86_64") && is_native;
344333

345-
let env_rust_flags = env::var("RUSTFLAGS").ok();
346-
let env_run_wrapper = env::var("RUN_WRAPPER").ok();
347-
348-
let mut rust_flags: Vec<&str> = env_rust_flags.iter().map(|s| s.as_str()).collect();
349-
let mut run_wrapper: Vec<&str> = env_run_wrapper.iter().map(|s| s.as_str()).collect();
334+
let mut rust_flags = env::var("RUSTFLAGS").ok().unwrap_or("".to_string());
335+
let mut run_wrapper = String::new();
350336

351337
if !is_native {
352338
match target_triple.as_str() {
353339
"aarch64-unknown-linux-gnu" => {
354340
// We are cross-compiling for aarch64. Use the correct linker and run tests in qemu.
355-
rust_flags.insert(0, "-Clinker=aarch64-linux-gnu-gcc");
356-
run_wrapper.extend(["qemu-aarch64", "-L", "/usr/aarch64-linux-gnu"]);
341+
rust_flags = format!("-Clinker=aarch64-linux-gnu-gcc {}", rust_flags);
342+
run_wrapper = "qemu-aarch64 -L /usr/aarch64-linux-gnu".to_string();
357343
},
358344
"x86_64-pc-windows-gnu" => {
359345
// We are cross-compiling for Windows. Run tests in wine.
360-
run_wrapper.push("wine".into());
346+
run_wrapper = "wine".to_string();
361347
}
362348
_ => {
363349
println!("Unknown non-native platform");
@@ -367,26 +353,25 @@ impl TestRunner {
367353

368354
// FIXME fix `#[linkage = "extern_weak"]` without this
369355
if host_triple.contains("darwin") {
370-
rust_flags.push("-Clink-arg=-undefined");
371-
rust_flags.push("-Clink-arg=dynamic_lookup");
356+
rust_flags = format!("{} -Clink-arg=-undefined -Clink-arg=dynamic_lookup", rust_flags);
372357
}
373358

374359
Self {
375360
root_dir,
376361
out_dir,
377362
jit_supported,
378-
rust_flags: rust_flags.iter().map(|s| s.to_string()).collect(),
379-
run_wrapper: run_wrapper.iter().map(|s| s.to_string()).collect(),
363+
rust_flags,
364+
run_wrapper,
380365
host_triple,
381366
target_triple,
382367
}
383368
}
384369

385370
pub fn run_testsuite(&self, tests: &[TestCase]) {
386371
for &TestCase { config, func } in tests {
387-
let is_jit_test = config.contains("jit");
388372
let (tag, testname) = config.split_once('.').unwrap();
389373
let tag = tag.to_uppercase();
374+
let is_jit_test = tag == "JIT";
390375

391376
if !config::get_bool(config) || (is_jit_test && !self.jit_supported) {
392377
eprintln!("[{tag}] {testname} (skipped)");
@@ -428,14 +413,16 @@ impl TestRunner {
428413
}
429414

430415
let mut cmd = Command::new(rustc_clif);
431-
cmd.args(self.rust_flags.iter());
416+
if !self.rust_flags.is_empty() {
417+
cmd.arg(&self.rust_flags);
418+
}
432419
cmd.arg("-L");
433420
cmd.arg(format!("crate={}", self.out_dir.display()));
434421
cmd.arg("--out-dir");
435422
cmd.arg(format!("{}", self.out_dir.display()));
436423
cmd.arg("-Cdebuginfo=2");
437424
cmd.args(args);
438-
cmd.env("RUSTFLAGS", self.rust_flags.join(" "));
425+
cmd.env("RUSTFLAGS", &self.rust_flags);
439426
cmd
440427
}
441428

@@ -454,8 +441,8 @@ impl TestRunner {
454441
let mut full_cmd = vec![];
455442

456443
// Prepend the RUN_WRAPPER's
457-
for rw in self.run_wrapper.iter() {
458-
full_cmd.push(rw.to_string());
444+
if !self.run_wrapper.is_empty() {
445+
full_cmd.push(self.run_wrapper.clone());
459446
}
460447

461448
full_cmd.push({
@@ -491,7 +478,7 @@ impl TestRunner {
491478

492479
let mut cmd = Command::new(cargo_clif);
493480
cmd.args(args);
494-
cmd.env("RUSTFLAGS", self.rust_flags.join(" "));
481+
cmd.env("RUSTFLAGS", &self.rust_flags);
495482
cmd
496483
}
497484

0 commit comments

Comments
 (0)