Skip to content

Commit 796da60

Browse files
committed
rewrite archive-duplicate-names to rmake
1 parent 1548218 commit 796da60

File tree

4 files changed

+50
-50
lines changed

4 files changed

+50
-50
lines changed

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

+13-33
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,19 @@ pub fn not_contains<P: AsRef<Path>>(path: P, expected: &str) -> bool {
281281
!path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().contains(expected))
282282
}
283283

284+
/// Returns true if the filename at `path` is not in `expected`.
285+
pub fn filename_not_in_denylist<P: AsRef<Path>, V: AsRef<[String]>>(path: P, expected: V) -> bool {
286+
let expected = expected.as_ref();
287+
path.as_ref()
288+
.file_name()
289+
.is_some_and(|name| !expected.contains(&name.to_str().unwrap().to_owned()))
290+
}
291+
292+
/// Returns true if the filename at `path` ends with `suffix`.
293+
pub fn has_suffix<P: AsRef<Path>>(path: P, suffix: &str) -> bool {
294+
path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().ends_with(suffix))
295+
}
296+
284297
/// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name.
285298
#[track_caller]
286299
pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
@@ -301,19 +314,6 @@ pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
301314
path(lib_path)
302315
}
303316

304-
/// Returns true if the filename at `path` is not in `expected`.
305-
pub fn filename_not_in_denylist<P: AsRef<Path>, V: AsRef<[String]>>(path: P, expected: V) -> bool {
306-
let expected = expected.as_ref();
307-
path.as_ref()
308-
.file_name()
309-
.is_some_and(|name| !expected.contains(&name.to_str().unwrap().to_owned()))
310-
}
311-
312-
/// Returns true if the filename at `path` ends with `suffix`.
313-
pub fn has_suffix<P: AsRef<Path>>(path: P, suffix: &str) -> bool {
314-
path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().ends_with(suffix))
315-
}
316-
317317
/// Gathers all files in the current working directory that have the extension `ext`, and counts
318318
/// the number of lines within that contain a match with the regex pattern `re`.
319319
pub fn count_regex_matches_in_files_with_extension(re: &regex::Regex, ext: &str) -> usize {
@@ -328,26 +328,6 @@ pub fn count_regex_matches_in_files_with_extension(re: &regex::Regex, ext: &str)
328328
count
329329
}
330330

331-
/// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name.
332-
#[track_caller]
333-
pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
334-
let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
335-
let src = format!("{lib_name}.c");
336-
let lib_path = static_lib_name(lib_name);
337-
if is_msvc() {
338-
cc().arg("-c").out_exe(&obj_file).input(src).run();
339-
} else {
340-
cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
341-
};
342-
let mut obj_file = PathBuf::from(format!("{lib_name}.o"));
343-
if is_msvc() {
344-
obj_file.set_extension("");
345-
obj_file.set_extension("obj");
346-
}
347-
llvm_ar().obj_to_ar().output_input(&lib_path, &obj_file).run();
348-
path(lib_path)
349-
}
350-
351331
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
352332
/// available on the platform!
353333
#[track_caller]

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
run-make/archive-duplicate-names/Makefile
21
run-make/atomic-lock-free/Makefile
32
run-make/branch-protection-check-IBT/Makefile
43
run-make/c-dynamic-dylib/Makefile

tests/run-make/archive-duplicate-names/Makefile

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// When two object archives with the same filename are present, an iterator is supposed to
2+
// inspect each object, recognize the duplication and extract each one to a different directory.
3+
// This test checks that this duplicate handling behaviour has not been broken.
4+
// See https://github.com/rust-lang/rust/pull/24439
5+
6+
//@ ignore-cross-compile
7+
// Reason: the compiled binary is executed
8+
9+
use run_make_support::{cc, fs_wrapper, is_msvc, llvm_ar, run, rustc};
10+
11+
fn main() {
12+
fs_wrapper::create_dir("a");
13+
fs_wrapper::create_dir("b");
14+
compile_obj_force_foo("a", "foo");
15+
compile_obj_force_foo("b", "bar");
16+
let mut ar = llvm_ar();
17+
ar.obj_to_ar().arg("libfoo.a");
18+
if is_msvc() {
19+
ar.arg("a/foo.obj").arg("b/foo.obj").run();
20+
} else {
21+
ar.arg("a/foo.o").arg("b/foo.o").run();
22+
}
23+
rustc().input("foo.rs").run();
24+
rustc().input("bar.rs").run();
25+
run("bar");
26+
}
27+
28+
#[track_caller]
29+
pub fn compile_obj_force_foo(dir: &str, lib_name: &str) {
30+
let obj_file = if is_msvc() { format!("{dir}/foo") } else { format!("{dir}/foo.o") };
31+
let src = format!("{lib_name}.c");
32+
if is_msvc() {
33+
cc().arg("-c").out_exe(&obj_file).input(src).run();
34+
} else {
35+
cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
36+
};
37+
}

0 commit comments

Comments
 (0)