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 Jun 14, 2024
1 parent 2752a37 commit 76c7a67
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 25 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3461,6 +3461,7 @@ name = "run_make_support"
version = "0.2.0"
dependencies = [
"gimli 0.28.1",
"glob",
"object 0.34.0",
"regex",
"similar",
Expand Down
1 change: 1 addition & 0 deletions src/tools/run-make-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ similar = "2.5.0"
wasmparser = "0.118.2"
regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace
gimli = "0.28.1"
glob = "0.3.1"
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 @@ -22,6 +22,7 @@ use std::panic;
use std::path::{Path, PathBuf};

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 @@ -208,7 +208,6 @@ run-make/separate-link-fail/Makefile
run-make/separate-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 76c7a67

Please sign in to comment.