Skip to content

Commit 2c7afc1

Browse files
committed
rewrite obey-crate-type-flag to rmake
1 parent cf9e7a9 commit 2c7afc1

File tree

4 files changed

+53
-15
lines changed

4 files changed

+53
-15
lines changed

src/tools/run-make-support/src/lib.rs

+37
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::path::{Path, PathBuf};
2323

2424
pub use bstr;
2525
pub use gimli;
26+
pub use glob;
2627
pub use object;
2728
pub use regex;
2829
pub use wasmparser;
@@ -223,6 +224,42 @@ pub fn bin_name(name: &str) -> String {
223224
if is_windows() { format!("{name}.exe") } else { name.to_string() }
224225
}
225226

227+
/// Remove all dynamic libraries possessing a name starting with `paths`.
228+
#[track_caller]
229+
pub fn remove_dylibs(paths: &str) {
230+
let paths = format!(r"{paths}*");
231+
remove_glob(dynamic_lib_name(&paths).as_str());
232+
}
233+
234+
/// Remove all rust libraries possessing a name starting with `paths`.
235+
#[track_caller]
236+
pub fn remove_rlibs(paths: &str) {
237+
let paths = format!(r"{paths}*");
238+
remove_glob(rust_lib_name(&paths).as_str());
239+
}
240+
241+
#[track_caller]
242+
fn remove_glob(paths: &str) {
243+
let paths = glob::glob(paths).expect(format!("Glob expression {paths} is not valid.").as_str());
244+
paths
245+
.filter_map(|entry| entry.ok())
246+
.filter(|entry| entry.as_path().is_file())
247+
.for_each(|file| fs_wrapper::remove_file(&file));
248+
}
249+
250+
#[track_caller]
251+
fn count_glob(paths: &str) -> usize {
252+
let paths = glob::glob(paths).expect(format!("Glob expression {paths} is not valid.").as_str());
253+
paths.filter_map(|entry| entry.ok()).filter(|entry| entry.as_path().is_file()).count()
254+
}
255+
256+
/// Count the number of rust libraries possessing a name starting with `paths`.
257+
#[track_caller]
258+
pub fn count_rlibs(paths: &str) -> usize {
259+
let paths = format!(r"{paths}*");
260+
count_glob(rust_lib_name(&paths).as_str())
261+
}
262+
226263
/// Return the current working directory.
227264
#[must_use]
228265
pub fn cwd() -> PathBuf {

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ run-make/native-link-modifier-whole-archive/Makefile
9797
run-make/no-alloc-shim/Makefile
9898
run-make/no-builtins-attribute/Makefile
9999
run-make/no-duplicate-libs/Makefile
100-
run-make/obey-crate-type-flag/Makefile
101100
run-make/panic-abort-eh_frame/Makefile
102101
run-make/pass-linker-flags-flavor/Makefile
103102
run-make/pass-linker-flags-from-dep/Makefile

tests/run-make/obey-crate-type-flag/Makefile

-14
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// test.rs should produce both an rlib and a dylib
2+
// by default. When the crate_type flag is passed and
3+
// forced to dylib, no rlibs should be produced.
4+
// See https://github.com/rust-lang/rust/issues/11573
5+
6+
//@ ignore-cross-compile
7+
8+
use run_make_support::{count_rlibs, remove_dylibs, remove_rlibs, rustc};
9+
10+
fn main() {
11+
rustc().input("test.rs").run();
12+
remove_rlibs("test");
13+
remove_dylibs("test");
14+
rustc().crate_type("dylib").input("test.rs").run();
15+
assert_eq!(count_rlibs("test"), 0);
16+
}

0 commit comments

Comments
 (0)