Skip to content

Commit 0bb84af

Browse files
committed
simplify llvm helper functions in run_make_support
1 parent 1239325 commit 0bb84af

File tree

2 files changed

+9
-25
lines changed
  • src/tools/run-make-support/src
  • tests/run-make/pgo-branch-weights

2 files changed

+9
-25
lines changed

src/tools/run-make-support/src/llvm.rs

+3-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::fs::File;
2-
use std::io::{BufReader, Read, Write};
31
use std::path::{Path, PathBuf};
42

53
use crate::{env_var, Command};
@@ -111,18 +109,9 @@ impl LlvmFilecheck {
111109
Self { cmd }
112110
}
113111

114-
/// Pipe a file into standard input containing patterns that will be matched against the .patterns(path) call.
115-
pub fn stdin<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
116-
let file = File::open(path).unwrap();
117-
let reader = BufReader::new(file);
118-
let byte_vec = read_bytes(reader).expect("failed to read bytes of standard input");
119-
let byte_slice = byte_vec.as_slice();
120-
self.cmd.stdin(std::process::Stdio::piped());
121-
let mut child = self.cmd.spawn().unwrap();
122-
let mut stdin = child.stdin.take().unwrap();
123-
stdin.write_all(byte_slice).unwrap();
124-
stdin.flush().unwrap();
125-
child.wait_with_output().unwrap();
112+
/// Pipe a read file into standard input containing patterns that will be matched against the .patterns(path) call.
113+
pub fn stdin<I: AsRef<[u8]>>(&mut self, input: I) -> &mut Self {
114+
self.cmd.set_stdin(input.as_ref().to_vec().into_boxed_slice());
126115
self
127116
}
128117

@@ -132,9 +121,3 @@ impl LlvmFilecheck {
132121
self
133122
}
134123
}
135-
136-
fn read_bytes<R: Read>(mut reader: R) -> Result<Vec<u8>, std::io::Error> {
137-
let mut buffer = Vec::new();
138-
reader.read_to_end(&mut buffer)?;
139-
Ok(buffer)
140-
}

tests/run-make/pgo-branch-weights/rmake.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@
1313
// (This test has problems generating profdata on mingw. This could use further investigation.)
1414
//@ ignore-windows-gnu
1515

16-
use run_make_support::{llvm_filecheck, llvm_profdata, run_with_args, rustc};
16+
use run_make_support::{fs_wrapper, llvm_filecheck, llvm_profdata, run_with_args, rustc};
1717
use std::fs;
1818
use std::path::Path;
1919

20-
//FIXME(Oneirical): Edit this test to use fs_wrapper and rmake_out_path.
21-
2220
fn main() {
2321
let path_prof_data_dir = Path::new("prof_data_dir");
2422
let path_merged_profdata = path_prof_data_dir.join("merged.profdata");
2523
rustc().input("opaque.rs").run();
26-
fs::create_dir_all(&path_prof_data_dir).unwrap();
24+
fs_wrapper::create_dir_all(&path_prof_data_dir);
2725
rustc()
2826
.input("interesting.rs")
2927
.profile_generate(&path_prof_data_dir)
@@ -40,5 +38,8 @@ fn main() {
4038
.codegen_units(1)
4139
.emit("llvm-ir")
4240
.run();
43-
llvm_filecheck().patterns("filecheck-patterns.txt").stdin("interesting.ll").run();
41+
llvm_filecheck()
42+
.patterns("filecheck-patterns.txt")
43+
.stdin(fs_wrapper::read("interesting.ll"))
44+
.run();
4445
}

0 commit comments

Comments
 (0)