|
14 | 14 | //@ ignore-windows-gnu
|
15 | 15 | //@ ignore-cross-compile
|
16 | 16 |
|
17 |
| -use run_make_support::{llvm_profdata, rustc, rustdoc, target, tmp_dir}; |
| 17 | +use run_make_support::{llvm_profdata, rustc, rustdoc, stdin_command, target, tmp_dir}; |
18 | 18 | use std::io::{self, Write};
|
19 | 19 | use std::process::Command;
|
20 | 20 |
|
21 | 21 | fn main() {
|
22 | 22 | // For some very small programs GNU ld seems to not properly handle
|
23 | 23 | // instrumentation sections correctly. Neither Gold nor LLD have that
|
24 | 24 | // problem.
|
25 |
| - let common_flags = if cfg!(target_os = "linux") && target().contains("x86") { |
26 |
| - "-Clink-args=-fuse-ld=gold" |
27 |
| - } else { |
28 |
| - "" |
29 |
| - }; |
| 25 | + let link_args = (cfg!(target_os = "linux") && target().contains("x86")).then_some("-Clink-args=-fuse-ld=gold"); |
| 26 | + |
30 | 27 | let path_prof_data_dir = tmp_dir().join("prof_data_dir");
|
31 | 28 | let path_merged_profdata = path_prof_data_dir.join("merged.profdata");
|
32 |
| - rustc().arg(common_flags).input("opaque.rs").run(); |
| 29 | + let invoc = rustc().input("opaque.rs"); |
| 30 | + if let Some(link_args) = link_args { |
| 31 | + invoc.arg(link_args); |
| 32 | + } |
| 33 | + invoc.run(); |
33 | 34 | fs::create_dir_all(&path_prof_data_dir);
|
34 |
| - rustc().arg(common_flags) |
35 |
| - .input("interesting.rs") |
| 35 | + let invoc = rustc().input("interesting.rs") |
36 | 36 | .profile_generate(&path_prof_data_dir)
|
37 | 37 | .opt()
|
38 |
| - .codegen_units(1) |
39 |
| - .run(); |
40 |
| - rustc().arg(common_flags) |
41 |
| - .input("main.rs") |
| 38 | + .codegen_units(1); |
| 39 | + if let Some(link_args) = link_args { |
| 40 | + invoc.arg(link_args); |
| 41 | + } |
| 42 | + invoc.run(); |
| 43 | + let invoc = rustc().input("main.rs") |
42 | 44 | .profile_generate(&path_prof_data_dir)
|
43 |
| - .opt() |
44 |
| - .run(); |
| 45 | + .opt(); |
| 46 | + if let Some(link_args) = link_args { |
| 47 | + invoc.arg(link_args); |
| 48 | + } |
| 49 | + invoc.run(); |
45 | 50 | run("main");
|
46 | 51 | llvm_profdata().merge().output(&path_merged_profdata).input(path_prof_data_dir).command_output();
|
47 |
| - rustc().arg(common_flags) |
48 |
| - .input("interesting.rs") |
| 52 | + let invoc = rustc().input("interesting.rs") |
49 | 53 | .profile_use(path_merged_profdata)
|
50 | 54 | .opt()
|
51 | 55 | .codegen_units(1)
|
52 |
| - .emit("llvm-ir") |
53 |
| - .run(); |
54 |
| - |
55 |
| - // FIXME This part below is a rough attempt |
| 56 | + .emit("llvm-ir"); |
| 57 | + if let Some(link_args) = link_args { |
| 58 | + invoc.arg(link_args); |
| 59 | + } |
| 60 | + invoc.run(); |
56 | 61 |
|
57 | 62 | let interesting_ll = tmp_dir().join("interesting.ll");
|
58 |
| - let file_interesting_ll = File::open(interesting_ll)?; |
59 |
| - let reader = BufReader::new(file_interesting_ll); |
60 |
| - |
61 |
| - let mut child = Command::new("llvm-filecheck") |
62 |
| - .stdin(std::process::Stdio::piped()) |
63 |
| - .stdout(std::process::Stdio::piped()) |
64 |
| - .stderr(std::process::Stdio::piped()) |
65 |
| - .arg("filecheck-patterns.txt") |
66 |
| - .spawn() |
67 |
| - .unwrap(); |
68 |
| - |
69 |
| - let mut child_stdin = child.stdin.take().unwrap(); |
70 |
| - child_stdin.write_all(reader.bytes().collect::<Vec<_>>().as_slice()).unwrap(); |
71 |
| - child_stdin.flush().unwrap(); |
72 |
| - |
73 |
| - let output = child.wait_with_output().unwrap(); |
| 63 | + stdin_command("llvm-filecheck", interesting_ll, "filecheck-patterns.txt"); |
74 | 64 | }
|
0 commit comments