mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 22:12:15 +00:00
rewrite sepcomp-separate to rmake
This commit is contained in:
parent
a4c72b6275
commit
2dda1e31be
@ -3421,6 +3421,7 @@ dependencies = [
|
||||
"ar",
|
||||
"bstr",
|
||||
"gimli 0.28.1",
|
||||
"glob",
|
||||
"object 0.34.0",
|
||||
"regex",
|
||||
"similar",
|
||||
|
@ -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())
|
||||
@ -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!(
|
||||
@ -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!(
|
||||
@ -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!(
|
||||
@ -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!(
|
||||
@ -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!(
|
||||
@ -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!(
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
);
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
include ../tools.mk
|
||||
|
||||
# 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.
|
||||
|
||||
all:
|
||||
$(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3
|
||||
[ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ .*magic_fn)" -eq "3" ]
|
24
tests/run-make/sepcomp-separate/rmake.rs
Normal file
24
tests/run-make/sepcomp-separate/rmake.rs
Normal file
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user