Skip to content

Commit 6ea85e6

Browse files
committed
rewrite obey-crate-type-flag to rmake
1 parent 592a94f commit 6ea85e6

File tree

10 files changed

+59
-21
lines changed

10 files changed

+59
-21
lines changed

src/doc/reference

src/tools/cargo

Submodule cargo updated 155 files

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

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

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

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

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ run-make/native-link-modifier-whole-archive/Makefile
111111
run-make/no-alloc-shim/Makefile
112112
run-make/no-builtins-attribute/Makefile
113113
run-make/no-duplicate-libs/Makefile
114-
run-make/obey-crate-type-flag/Makefile
115114
run-make/optimization-remarks-dir-pgo/Makefile
116115
run-make/optimization-remarks-dir/Makefile
117116
run-make/output-type-permutations/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)