about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2024-06-12 11:24:21 -0400
committerOneirical <manchot@videotron.ca>2024-07-08 10:13:40 -0400
commit2dda1e31bead614a45e7f51c86dc14cf6a4ebe1c (patch)
treec59d91af3d21be4c27edda784e2b2e9108608c6f
parenta4c72b627535c5ed9c58f1efbbe36491a820511a (diff)
downloadrust-2dda1e31bead614a45e7f51c86dc14cf6a4ebe1c.tar.gz
rust-2dda1e31bead614a45e7f51c86dc14cf6a4ebe1c.zip
rewrite sepcomp-separate to rmake
-rw-r--r--Cargo.lock1
-rw-r--r--src/tools/run-make-support/src/fs_wrapper.rs27
-rw-r--r--src/tools/run-make-support/src/lib.rs1
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt1
-rw-r--r--tests/run-make/intrinsic-unreachable/rmake.rs13
-rw-r--r--tests/run-make/sepcomp-separate/Makefile9
-rw-r--r--tests/run-make/sepcomp-separate/rmake.rs24
7 files changed, 51 insertions, 25 deletions
diff --git a/Cargo.lock b/Cargo.lock
index afeb9faec09..05e5685270e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3421,6 +3421,7 @@ dependencies = [
  "ar",
  "bstr",
  "gimli 0.28.1",
+ "glob",
  "object 0.34.0",
  "regex",
  "similar",
diff --git a/src/tools/run-make-support/src/fs_wrapper.rs b/src/tools/run-make-support/src/fs_wrapper.rs
index 8a2bfce8b4a..d65c10b17c9 100644
--- a/src/tools/run-make-support/src/fs_wrapper.rs
+++ b/src/tools/run-make-support/src/fs_wrapper.rs
@@ -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!(
diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs
index f464a109e77..068b022599e 100644
--- a/src/tools/run-make-support/src/lib.rs
+++ b/src/tools/run-make-support/src/lib.rs
@@ -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;
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 1cc414ecdc6..233c2d0b808 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -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
diff --git a/tests/run-make/intrinsic-unreachable/rmake.rs b/tests/run-make/intrinsic-unreachable/rmake.rs
index 6c951147604..5e62a966c54 100644
--- a/tests/run-make/intrinsic-unreachable/rmake.rs
+++ b/tests/run-make/intrinsic-unreachable/rmake.rs
@@ -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()
+    );
 }
diff --git a/tests/run-make/sepcomp-separate/Makefile b/tests/run-make/sepcomp-separate/Makefile
deleted file mode 100644
index 62cf54a88fb..00000000000
--- a/tests/run-make/sepcomp-separate/Makefile
+++ /dev/null
@@ -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" ]
diff --git a/tests/run-make/sepcomp-separate/rmake.rs b/tests/run-make/sepcomp-separate/rmake.rs
new file mode 100644
index 00000000000..d3ef2450a84
--- /dev/null
+++ b/tests/run-make/sepcomp-separate/rmake.rs
@@ -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);
+}