Skip to content

Commit d9d7b76

Browse files
committed
Add FileCheck mode
1 parent 9197df0 commit d9d7b76

File tree

4 files changed

+157
-37
lines changed

4 files changed

+157
-37
lines changed

src/main.rs

+9
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ a date (YYYY-MM-DD), git tag name (e.g. 1.58.0) or git commit SHA."
188188
#[arg(long, help = "Script replacement for `cargo build` command")]
189189
script: Option<PathBuf>,
190190

191+
#[arg(
192+
long,
193+
help = "Run in LLVM FileCheck, using the given path for annotations"
194+
)]
195+
filecheck: Option<PathBuf>,
196+
197+
#[arg(long, help = "Path to LLVM FileCheck")]
198+
filecheck_path: Option<PathBuf>,
199+
191200
#[arg(long, help = "Do not install cargo [default: install cargo]")]
192201
without_cargo: bool,
193202

src/toolchains.rs

+84-6
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,24 @@ impl Toolchain {
248248
}
249249
});
250250

251-
let mut cmd = match (script, cfg.args.timeout) {
252-
(Some(script), None) => {
251+
let target_dir = format!("target-{}", self.rustup_name());
252+
// Used in filecheck mode
253+
let llir_path = PathBuf::from(&target_dir)
254+
.join("debug")
255+
.join("deps")
256+
.join("output.ll");
257+
258+
let mut cmd = match (script, cfg.args.timeout, &cfg.args.filecheck) {
259+
(Some(_), _, Some(_)) => {
260+
panic!("incompatbile options `--script` and `--filecheck` used");
261+
}
262+
(Some(script), None, None) => {
253263
let mut cmd = Command::new(script);
254264
cmd.env("RUSTUP_TOOLCHAIN", self.rustup_name());
255265
cmd.args(&cfg.args.command_args);
256266
cmd
257267
}
258-
(None, None) => {
268+
(None, None, None) => {
259269
let mut cmd = Command::new("cargo");
260270
cmd.arg(&format!("+{}", self.rustup_name()));
261271
if cfg.args.command_args.is_empty() {
@@ -265,15 +275,15 @@ impl Toolchain {
265275
}
266276
cmd
267277
}
268-
(Some(script), Some(timeout)) => {
278+
(Some(script), Some(timeout), None) => {
269279
let mut cmd = Command::new("timeout");
270280
cmd.arg(timeout.to_string());
271281
cmd.arg(script);
272282
cmd.args(&cfg.args.command_args);
273283
cmd.env("RUSTUP_TOOLCHAIN", self.rustup_name());
274284
cmd
275285
}
276-
(None, Some(timeout)) => {
286+
(None, Some(timeout), None) => {
277287
let mut cmd = Command::new("timeout");
278288
cmd.arg(timeout.to_string());
279289
cmd.arg("cargo");
@@ -285,9 +295,39 @@ impl Toolchain {
285295
}
286296
cmd
287297
}
298+
(None, None, Some(_)) => {
299+
let mut cmd = Command::new("cargo");
300+
cmd.arg(&format!("+{}", self.rustup_name()));
301+
if cfg.args.command_args.is_empty() {
302+
cmd.arg("rustc")
303+
.arg("--")
304+
.arg("-Copt-level=3")
305+
.arg("-Cdebuginfo=0")
306+
.arg(format!("--emit=llvm-ir={}", llir_path.display()));
307+
} else {
308+
cmd.args(&cfg.args.command_args);
309+
}
310+
cmd
311+
}
312+
(None, Some(timeout), Some(_)) => {
313+
let mut cmd = Command::new("timeout");
314+
cmd.arg(timeout.to_string());
315+
cmd.arg("cargo");
316+
cmd.arg(&format!("+{}", self.rustup_name()));
317+
if cfg.args.command_args.is_empty() {
318+
cmd.arg("rustc")
319+
.arg("--")
320+
.arg("-Copt-level=3")
321+
.arg("-Cdebuginfo=0")
322+
.arg(format!("--emit=llvm-ir={}", llir_path.display()));
323+
} else {
324+
cmd.args(&cfg.args.command_args);
325+
}
326+
cmd
327+
}
288328
};
289329
cmd.current_dir(&cfg.args.test_dir);
290-
cmd.env("CARGO_TARGET_DIR", format!("target-{}", self.rustup_name()));
330+
cmd.env("CARGO_TARGET_DIR", &target_dir);
291331
if let Some(target) = &cfg.args.target {
292332
cmd.env("CARGO_BUILD_TARGET", target);
293333
}
@@ -319,6 +359,44 @@ impl Toolchain {
319359
io::stdout().write_all(&output.stdout).unwrap();
320360
io::stderr().write_all(&output.stderr).unwrap();
321361
}
362+
363+
let Some(check_file) = &cfg.args.filecheck else {
364+
return output;
365+
};
366+
367+
if !output.status.success() {
368+
return output;
369+
}
370+
371+
let filecheck_path = cfg
372+
.args
373+
.filecheck_path
374+
.clone()
375+
.unwrap_or_else(|| PathBuf::from("FileCheck"));
376+
377+
let mut cmd = Command::new(filecheck_path);
378+
cmd.arg("--input-file")
379+
.arg(
380+
PathBuf::from(target_dir)
381+
.join("debug")
382+
.join("deps")
383+
.join("output.ll"),
384+
)
385+
.arg(check_file);
386+
387+
cmd.stdout(default_stdio());
388+
cmd.stderr(default_stdio());
389+
let output = match cmd.output() {
390+
Ok(output) => output,
391+
Err(err) => {
392+
panic!("thiserror::Errored to run {:?}: {:?}", cmd, err);
393+
}
394+
};
395+
if must_capture_output && emit_output {
396+
io::stdout().write_all(&output.stdout).unwrap();
397+
io::stderr().write_all(&output.stderr).unwrap();
398+
}
399+
322400
output
323401
}
324402

tests/cmd/h.stdout

+57-30
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,63 @@ Arguments:
66
[COMMAND_ARGS]... Arguments to pass to cargo or the file specified by --script during tests
77

88
Options:
9-
-a, --alt Download the alt build instead of normal build
10-
--access <ACCESS> How to access Rust git repository [default: github] [possible
11-
values: checkout, github]
12-
--by-commit Bisect via commit artifacts
13-
-c, --component <COMPONENTS> additional components to install
14-
--end <END> Right bound for search (*with* regression). You can use a date
15-
(YYYY-MM-DD), git tag name (e.g. 1.58.0) or git commit SHA.
16-
--force-install Force installation over existing artifacts
17-
-h, --help Print help (see more with '--help')
18-
--host <HOST> Host triple for the compiler [default: [..]]
19-
--install <INSTALL> Install the given artifact
20-
--preserve Preserve the downloaded artifacts
21-
--preserve-target Preserve the target directory used for builds
22-
--prompt Manually evaluate for regression with prompts
23-
--regress <REGRESS> Custom regression definition [default: error] [possible values:
24-
error, success, ice, non-ice, non-error]
25-
--script <SCRIPT> Script replacement for `cargo build` command
26-
--start <START> Left bound for search (*without* regression). You can use a date
27-
(YYYY-MM-DD), git tag name (e.g. 1.58.0) or git commit SHA.
28-
-t, --timeout <TIMEOUT> Assume failure after specified number of seconds (for bisecting
29-
hangs)
30-
--target <TARGET> Cross-compilation target platform
31-
--term-new <TERM_NEW> Text shown when a test does match the condition requested
32-
--term-old <TERM_OLD> Text shown when a test fails to match the condition requested
33-
--test-dir <TEST_DIR> Root directory for tests [default: .]
34-
-v, --verbose...
35-
-V, --version Print version
36-
--with-dev Download rustc-dev [default: no download]
37-
--with-src Download rust-src [default: no download]
38-
--without-cargo Do not install cargo [default: install cargo]
9+
-a, --alt
10+
Download the alt build instead of normal build
11+
--access <ACCESS>
12+
How to access Rust git repository [default: github] [possible values: checkout, github]
13+
--by-commit
14+
Bisect via commit artifacts
15+
-c, --component <COMPONENTS>
16+
additional components to install
17+
--end <END>
18+
Right bound for search (*with* regression). You can use a date (YYYY-MM-DD), git tag name
19+
(e.g. 1.58.0) or git commit SHA.
20+
--filecheck <FILECHECK>
21+
Run in LLVM FileCheck, using the given path for annotations
22+
--filecheck-path <FILECHECK_PATH>
23+
Path to LLVM FileCheck
24+
--force-install
25+
Force installation over existing artifacts
26+
-h, --help
27+
Print help (see more with '--help')
28+
--host <HOST>
29+
Host triple for the compiler [default: x86_64-unknown-linux-gnu]
30+
--install <INSTALL>
31+
Install the given artifact
32+
--preserve
33+
Preserve the downloaded artifacts
34+
--preserve-target
35+
Preserve the target directory used for builds
36+
--prompt
37+
Manually evaluate for regression with prompts
38+
--regress <REGRESS>
39+
Custom regression definition [default: error] [possible values: error, success, ice,
40+
non-ice, non-error]
41+
--script <SCRIPT>
42+
Script replacement for `cargo build` command
43+
--start <START>
44+
Left bound for search (*without* regression). You can use a date (YYYY-MM-DD), git tag
45+
name (e.g. 1.58.0) or git commit SHA.
46+
-t, --timeout <TIMEOUT>
47+
Assume failure after specified number of seconds (for bisecting hangs)
48+
--target <TARGET>
49+
Cross-compilation target platform
50+
--term-new <TERM_NEW>
51+
Text shown when a test does match the condition requested
52+
--term-old <TERM_OLD>
53+
Text shown when a test fails to match the condition requested
54+
--test-dir <TEST_DIR>
55+
Root directory for tests [default: .]
56+
-v, --verbose...
57+
58+
-V, --version
59+
Print version
60+
--with-dev
61+
Download rustc-dev [default: no download]
62+
--with-src
63+
Download rust-src [default: no download]
64+
--without-cargo
65+
Do not install cargo [default: install cargo]
3966

4067
Examples:
4168
Run a fully automatic nightly bisect doing `cargo check`:

tests/cmd/help.stdout

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ Options:
2626
Right bound for search (*with* regression). You can use a date (YYYY-MM-DD), git tag name
2727
(e.g. 1.58.0) or git commit SHA.
2828

29+
--filecheck <FILECHECK>
30+
Run in LLVM FileCheck, using the given path for annotations
31+
32+
--filecheck-path <FILECHECK_PATH>
33+
Path to LLVM FileCheck
34+
2935
--force-install
3036
Force installation over existing artifacts
3137

@@ -35,7 +41,7 @@ Options:
3541
--host <HOST>
3642
Host triple for the compiler
3743

38-
[default: [..]]
44+
[default: x86_64-unknown-linux-gnu]
3945

4046
--install <INSTALL>
4147
Install the given artifact

0 commit comments

Comments
 (0)