Skip to content

Commit

Permalink
simplify llvm helper functions in run_make_support
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jun 11, 2024
1 parent 1239325 commit 0bb84af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
23 changes: 3 additions & 20 deletions src/tools/run-make-support/src/llvm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::fs::File;
use std::io::{BufReader, Read, Write};
use std::path::{Path, PathBuf};

use crate::{env_var, Command};
Expand Down Expand Up @@ -111,18 +109,9 @@ impl LlvmFilecheck {
Self { cmd }
}

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

Expand All @@ -132,9 +121,3 @@ impl LlvmFilecheck {
self
}
}

fn read_bytes<R: Read>(mut reader: R) -> Result<Vec<u8>, std::io::Error> {
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer)?;
Ok(buffer)
}
11 changes: 6 additions & 5 deletions tests/run-make/pgo-branch-weights/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
// (This test has problems generating profdata on mingw. This could use further investigation.)
//@ ignore-windows-gnu

use run_make_support::{llvm_filecheck, llvm_profdata, run_with_args, rustc};
use run_make_support::{fs_wrapper, llvm_filecheck, llvm_profdata, run_with_args, rustc};
use std::fs;
use std::path::Path;

//FIXME(Oneirical): Edit this test to use fs_wrapper and rmake_out_path.

fn main() {
let path_prof_data_dir = Path::new("prof_data_dir");
let path_merged_profdata = path_prof_data_dir.join("merged.profdata");
rustc().input("opaque.rs").run();
fs::create_dir_all(&path_prof_data_dir).unwrap();
fs_wrapper::create_dir_all(&path_prof_data_dir);
rustc()
.input("interesting.rs")
.profile_generate(&path_prof_data_dir)
Expand All @@ -40,5 +38,8 @@ fn main() {
.codegen_units(1)
.emit("llvm-ir")
.run();
llvm_filecheck().patterns("filecheck-patterns.txt").stdin("interesting.ll").run();
llvm_filecheck()
.patterns("filecheck-patterns.txt")
.stdin(fs_wrapper::read("interesting.ll"))
.run();
}

0 comments on commit 0bb84af

Please sign in to comment.