about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2024-06-14 11:41:54 -0400
committerOneirical <manchot@videotron.ca>2024-07-08 09:59:07 -0400
commit2c7afc114d7ccc9bbc1dce29f1be1dca343e722f (patch)
treebbba24d3995682a156da65117733bae8dfc717a1
parentcf9e7a975d4a64ad60669a9764e64400710c7e67 (diff)
downloadrust-2c7afc114d7ccc9bbc1dce29f1be1dca343e722f.tar.gz
rust-2c7afc114d7ccc9bbc1dce29f1be1dca343e722f.zip
rewrite obey-crate-type-flag to rmake
-rw-r--r--src/tools/run-make-support/src/lib.rs37
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt1
-rw-r--r--tests/run-make/obey-crate-type-flag/Makefile14
-rw-r--r--tests/run-make/obey-crate-type-flag/rmake.rs16
4 files changed, 53 insertions, 15 deletions
diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs
index f464a109e77..721200f77f3 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;
@@ -223,6 +224,42 @@ pub fn bin_name(name: &str) -> String {
     if is_windows() { format!("{name}.exe") } else { name.to_string() }
 }
 
+/// Remove all dynamic libraries possessing a name starting with `paths`.
+#[track_caller]
+pub fn remove_dylibs(paths: &str) {
+    let paths = format!(r"{paths}*");
+    remove_glob(dynamic_lib_name(&paths).as_str());
+}
+
+/// Remove all rust libraries possessing a name starting with `paths`.
+#[track_caller]
+pub fn remove_rlibs(paths: &str) {
+    let paths = format!(r"{paths}*");
+    remove_glob(rust_lib_name(&paths).as_str());
+}
+
+#[track_caller]
+fn remove_glob(paths: &str) {
+    let paths = glob::glob(paths).expect(format!("Glob expression {paths} is not valid.").as_str());
+    paths
+        .filter_map(|entry| entry.ok())
+        .filter(|entry| entry.as_path().is_file())
+        .for_each(|file| fs_wrapper::remove_file(&file));
+}
+
+#[track_caller]
+fn count_glob(paths: &str) -> usize {
+    let paths = glob::glob(paths).expect(format!("Glob expression {paths} is not valid.").as_str());
+    paths.filter_map(|entry| entry.ok()).filter(|entry| entry.as_path().is_file()).count()
+}
+
+/// Count the number of rust libraries possessing a name starting with `paths`.
+#[track_caller]
+pub fn count_rlibs(paths: &str) -> usize {
+    let paths = format!(r"{paths}*");
+    count_glob(rust_lib_name(&paths).as_str())
+}
+
 /// Return the current working directory.
 #[must_use]
 pub fn cwd() -> PathBuf {
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index c527161aa9a..8dc48d42f67 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -97,7 +97,6 @@ run-make/native-link-modifier-whole-archive/Makefile
 run-make/no-alloc-shim/Makefile
 run-make/no-builtins-attribute/Makefile
 run-make/no-duplicate-libs/Makefile
-run-make/obey-crate-type-flag/Makefile
 run-make/panic-abort-eh_frame/Makefile
 run-make/pass-linker-flags-flavor/Makefile
 run-make/pass-linker-flags-from-dep/Makefile
diff --git a/tests/run-make/obey-crate-type-flag/Makefile b/tests/run-make/obey-crate-type-flag/Makefile
deleted file mode 100644
index ecbb2e620ed..00000000000
--- a/tests/run-make/obey-crate-type-flag/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
-# ignore-cross-compile
-include ../tools.mk
-
-# check that rustc builds all crate_type attributes
-# delete rlib
-# delete whatever dylib is made for this system
-# check that rustc only builds --crate-type flags, ignoring attributes
-# fail if an rlib was built
-all:
-	$(RUSTC) test.rs
-	$(call REMOVE_RLIBS,test)
-	$(call REMOVE_DYLIBS,test)
-	$(RUSTC) --crate-type dylib test.rs
-	$(call REMOVE_RLIBS,test) && exit 1 || exit 0
diff --git a/tests/run-make/obey-crate-type-flag/rmake.rs b/tests/run-make/obey-crate-type-flag/rmake.rs
new file mode 100644
index 00000000000..4ae4b6e4eec
--- /dev/null
+++ b/tests/run-make/obey-crate-type-flag/rmake.rs
@@ -0,0 +1,16 @@
+// test.rs should produce both an rlib and a dylib
+// by default. When the crate_type flag is passed and
+// forced to dylib, no rlibs should be produced.
+// See https://github.com/rust-lang/rust/issues/11573
+
+//@ ignore-cross-compile
+
+use run_make_support::{count_rlibs, remove_dylibs, remove_rlibs, rustc};
+
+fn main() {
+    rustc().input("test.rs").run();
+    remove_rlibs("test");
+    remove_dylibs("test");
+    rustc().crate_type("dylib").input("test.rs").run();
+    assert_eq!(count_rlibs("test"), 0);
+}