Skip to content

Commit 1a8298f

Browse files
committed
rewrite extra-filename-with-temp-outputs to rmake
1 parent 8a9cccb commit 1a8298f

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,45 @@ pub fn test_while_readonly<P: AsRef<Path>, F: FnOnce() + std::panic::UnwindSafe>
261261
success.unwrap();
262262
}
263263

264+
/// Browse the directory `path` non-recursively and return all files which respect the parameters
265+
/// outlined by `closure`.
266+
#[track_caller]
267+
pub fn shallow_find_files<P: AsRef<Path>, F: Fn(&PathBuf) -> bool>(
268+
path: P,
269+
closure: F,
270+
) -> Vec<PathBuf> {
271+
let mut matching_files = Vec::new();
272+
for entry in fs_wrapper::read_dir(path) {
273+
let entry = entry.expect("failed to read directory entry.");
274+
let path = entry.path();
275+
276+
if path.is_file() && closure(&path) {
277+
matching_files.push(path);
278+
}
279+
}
280+
matching_files
281+
}
282+
283+
/// Returns true if the filename at `path` starts with `prefix`.
284+
pub fn has_prefix<P: AsRef<Path>>(path: P, prefix: &str) -> bool {
285+
path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().starts_with(prefix))
286+
}
287+
288+
/// Returns true if the filename at `path` has the extension `extension`.
289+
pub fn has_extension<P: AsRef<Path>>(path: P, extension: &str) -> bool {
290+
path.as_ref().extension().is_some_and(|ext| ext == extension)
291+
}
292+
293+
/// Returns true if the filename at `path` does not contain `expected`.
294+
pub fn not_contains<P: AsRef<Path>>(path: P, expected: &str) -> bool {
295+
!path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().contains(expected))
296+
}
297+
298+
/// Returns true if the filename at `path` ends with `suffix`.
299+
pub fn has_suffix<P: AsRef<Path>>(path: P, suffix: &str) -> bool {
300+
path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().ends_with(suffix))
301+
}
302+
264303
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
265304
/// available on the platform!
266305
#[track_caller]

src/tools/tidy/src/allowed_run_make_makefiles.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ run-make/extern-fn-with-packed-struct/Makefile
4141
run-make/extern-fn-with-union/Makefile
4242
run-make/extern-multiple-copies/Makefile
4343
run-make/extern-multiple-copies2/Makefile
44-
run-make/extra-filename-with-temp-outputs/Makefile
4544
run-make/fmt-write-bloat/Makefile
4645
run-make/foreign-double-unwind/Makefile
4746
run-make/foreign-exceptions/Makefile

tests/run-make/extra-filename-with-temp-outputs/Makefile

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// In order to prevent temporary files from overwriting each other in parallel
2+
// compilation, rustc was changed to mix an extra filename with temporary
3+
// outputs. However, as this is a similar behavior with the codegen flag
4+
// -C extra-filename, this test checks that the manually passed flag
5+
// is not overwritten by this feature, and that the output files
6+
// are named as expected.
7+
// See https://github.com/rust-lang/rust/pull/15686
8+
9+
//FIXME(Oneirical): ignore-cross-compile
10+
11+
use run_make_support::{
12+
bin_name, cwd, fs_wrapper, has_prefix, has_suffix, rustc, shallow_find_files,
13+
};
14+
15+
fn main() {
16+
rustc().extra_filename("bar").input("foo.rs").arg("-Csave-temps").run();
17+
let object_files = shallow_find_files(cwd(), |path| {
18+
has_prefix(path, "foobar.foo") && has_suffix(path, "0.rcgu.o")
19+
});
20+
let object_file = object_files.get(0).unwrap();
21+
fs_wrapper::remove_file(object_file);
22+
fs_wrapper::remove_file(bin_name("foobar"));
23+
}

0 commit comments

Comments
 (0)