Skip to content

Commit

Permalink
rewrite sepcomp-separate to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jul 8, 2024
1 parent a4c72b6 commit 2dda1e3
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 25 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3421,6 +3421,7 @@ dependencies = [
"ar",
"bstr",
"gimli 0.28.1",
"glob",
"object 0.34.0",
"regex",
"similar",
Expand Down
27 changes: 17 additions & 10 deletions src/tools/run-make-support/src/fs_wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs;
use std::path::Path;

/// A wrapper around [`std::fs::remove_file`] which includes the file path in the panic message..
/// A wrapper around [`std::fs::remove_file`] which includes the file path in the panic message.
#[track_caller]
pub fn remove_file<P: AsRef<Path>>(path: P) {
fs::remove_file(path.as_ref())
Expand All @@ -18,21 +18,28 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
));
}

/// A wrapper around [`std::fs::File::create`] which includes the file path in the panic message..
/// A wrapper around [`std::fs::File::create`] which includes the file path in the panic message.
#[track_caller]
pub fn create_file<P: AsRef<Path>>(path: P) {
fs::File::create(path.as_ref())
.expect(&format!("the file in path \"{}\" could not be created", path.as_ref().display()));
}

/// A wrapper around [`std::fs::read`] which includes the file path in the panic message..
/// A wrapper around [`std::fs::File::open`] which includes the file path in the panic message.
#[track_caller]
pub fn open_file<P: AsRef<Path>>(path: P) -> fs::File {
fs::File::open(path.as_ref())
.expect(&format!("the file in path \"{}\" could not be opened", path.as_ref().display()))
}

/// A wrapper around [`std::fs::read`] which includes the file path in the panic message.
#[track_caller]
pub fn read<P: AsRef<Path>>(path: P) -> Vec<u8> {
fs::read(path.as_ref())
.expect(&format!("the file in path \"{}\" could not be read", path.as_ref().display()))
}

/// A wrapper around [`std::fs::read_to_string`] which includes the file path in the panic message..
/// A wrapper around [`std::fs::read_to_string`] which includes the file path in the panic message.
#[track_caller]
pub fn read_to_string<P: AsRef<Path>>(path: P) -> String {
fs::read_to_string(path.as_ref()).expect(&format!(
Expand All @@ -41,14 +48,14 @@ pub fn read_to_string<P: AsRef<Path>>(path: P) -> String {
))
}

/// A wrapper around [`std::fs::read_dir`] which includes the file path in the panic message..
/// A wrapper around [`std::fs::read_dir`] which includes the file path in the panic message.
#[track_caller]
pub fn read_dir<P: AsRef<Path>>(path: P) -> fs::ReadDir {
fs::read_dir(path.as_ref())
.expect(&format!("the directory in path \"{}\" could not be read", path.as_ref().display()))
}

/// A wrapper around [`std::fs::write`] which includes the file path in the panic message..
/// A wrapper around [`std::fs::write`] which includes the file path in the panic message.
#[track_caller]
pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) {
fs::write(path.as_ref(), contents.as_ref()).expect(&format!(
Expand All @@ -57,7 +64,7 @@ pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) {
));
}

/// A wrapper around [`std::fs::remove_dir_all`] which includes the file path in the panic message..
/// A wrapper around [`std::fs::remove_dir_all`] which includes the file path in the panic message.
#[track_caller]
pub fn remove_dir_all<P: AsRef<Path>>(path: P) {
fs::remove_dir_all(path.as_ref()).expect(&format!(
Expand All @@ -66,7 +73,7 @@ pub fn remove_dir_all<P: AsRef<Path>>(path: P) {
));
}

/// A wrapper around [`std::fs::create_dir`] which includes the file path in the panic message..
/// A wrapper around [`std::fs::create_dir`] which includes the file path in the panic message.
#[track_caller]
pub fn create_dir<P: AsRef<Path>>(path: P) {
fs::create_dir(path.as_ref()).expect(&format!(
Expand All @@ -75,7 +82,7 @@ pub fn create_dir<P: AsRef<Path>>(path: P) {
));
}

/// A wrapper around [`std::fs::create_dir_all`] which includes the file path in the panic message..
/// A wrapper around [`std::fs::create_dir_all`] which includes the file path in the panic message.
#[track_caller]
pub fn create_dir_all<P: AsRef<Path>>(path: P) {
fs::create_dir_all(path.as_ref()).expect(&format!(
Expand All @@ -84,7 +91,7 @@ pub fn create_dir_all<P: AsRef<Path>>(path: P) {
));
}

/// A wrapper around [`std::fs::metadata`] which includes the file path in the panic message..
/// A wrapper around [`std::fs::metadata`] which includes the file path in the panic message.
#[track_caller]
pub fn metadata<P: AsRef<Path>>(path: P) -> fs::Metadata {
fs::metadata(path.as_ref()).expect(&format!(
Expand Down
1 change: 1 addition & 0 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::path::{Path, PathBuf};

pub use bstr;
pub use gimli;
pub use glob;
pub use object;
pub use regex;
pub use wasmparser;
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ run-make/sanitizer-dylib-link/Makefile
run-make/sanitizer-staticlib-link/Makefile
run-make/sepcomp-cci-copies/Makefile
run-make/sepcomp-inlining/Makefile
run-make/sepcomp-separate/Makefile
run-make/share-generics-dylib/Makefile
run-make/silly-file-names/Makefile
run-make/simd-ffi/Makefile
Expand Down
13 changes: 8 additions & 5 deletions tests/run-make/intrinsic-unreachable/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
// See https://github.com/rust-lang/rust/pull/16970

//@ needs-asm-support
//@ ignore-windows-msvc
//@ ignore-windows
// Reason: Because of Windows exception handling, the code is not necessarily any shorter.

use run_make_support::rustc;
use std::io::BufReader;
use std::fs::File;
use run_make_support::{fs_wrapper, rustc};
use std::io::{BufRead, BufReader};

fn main() {
rustc().opt().emit("asm").input("exit-ret.rs").run();
rustc().opt().emit("asm").input("exit-unreachable.rs").run();
assert!(BufReader::new(File::open("exit-unreachable.s")).lines().count() < BufReader::new(File::open("exit-ret.s")).lines().count());
let unreachable_file = fs_wrapper::open_file("exit-unreachable.s");
let ret_file = fs_wrapper::open_file("exit-ret.s");
assert!(
BufReader::new(unreachable_file).lines().count() < BufReader::new(ret_file).lines().count()
);
}
9 changes: 0 additions & 9 deletions tests/run-make/sepcomp-separate/Makefile

This file was deleted.

24 changes: 24 additions & 0 deletions tests/run-make/sepcomp-separate/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Test that separate compilation actually puts code into separate compilation
// units. `foo.rs` defines `magic_fn` in three different modules, which should
// wind up in three different compilation units.
// See https://github.com/rust-lang/rust/pull/16367

use run_make_support::{fs_wrapper, glob, regex, rustc};
use std::io::{BufRead, BufReader};

fn main() {
let mut match_count = 0;
rustc().input("foo.rs").emit("llvm-ir").codegen_units(3).run();
let re = regex::Regex::new(r#"define.*magic_fn"#).unwrap();
let paths = glob::glob("foo.*.ll").unwrap();
paths.filter_map(|entry| entry.ok()).filter(|path| path.is_file()).for_each(|path| {
let file = fs_wrapper::open_file(path);
let reader = BufReader::new(file);
reader
.lines()
.filter_map(|line| line.ok())
.filter(|line| re.is_match(line))
.for_each(|_| match_count += 1);
});
assert_eq!(match_count, 3);
}

0 comments on commit 2dda1e3

Please sign in to comment.