From 0dba5ac55630357b2ee2e5392b6ba46a066c5c84 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 4 Jul 2024 16:45:48 -0400 Subject: [PATCH 1/2] rewrite extra-filename-with-temp-outputs to rmake --- src/tools/run-make-support/src/lib.rs | 5 ++++ .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../extra-filename-with-temp-outputs/Makefile | 7 ------ .../extra-filename-with-temp-outputs/rmake.rs | 23 +++++++++++++++++++ 4 files changed, 28 insertions(+), 8 deletions(-) delete mode 100644 tests/run-make/extra-filename-with-temp-outputs/Makefile create mode 100644 tests/run-make/extra-filename-with-temp-outputs/rmake.rs diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index af5ae6a8e608c..d547a77e805df 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -295,6 +295,11 @@ pub fn not_contains>(path: P, expected: &str) -> bool { !path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().contains(expected)) } +/// Returns true if the filename at `path` ends with `suffix`. +pub fn has_suffix>(path: P, suffix: &str) -> bool { + path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().ends_with(suffix)) +} + /// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is /// available on the platform! #[track_caller] diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 70c1b055c6e40..96ef2163fd9c4 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -41,7 +41,6 @@ run-make/extern-fn-with-packed-struct/Makefile run-make/extern-fn-with-union/Makefile run-make/extern-multiple-copies/Makefile run-make/extern-multiple-copies2/Makefile -run-make/extra-filename-with-temp-outputs/Makefile run-make/fmt-write-bloat/Makefile run-make/foreign-double-unwind/Makefile run-make/foreign-exceptions/Makefile diff --git a/tests/run-make/extra-filename-with-temp-outputs/Makefile b/tests/run-make/extra-filename-with-temp-outputs/Makefile deleted file mode 100644 index 64745bef5b869..0000000000000 --- a/tests/run-make/extra-filename-with-temp-outputs/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -all: - $(RUSTC) -C extra-filename=bar foo.rs -C save-temps - rm $(TMPDIR)/foobar.foo*0.rcgu.o - rm $(TMPDIR)/$(call BIN,foobar) diff --git a/tests/run-make/extra-filename-with-temp-outputs/rmake.rs b/tests/run-make/extra-filename-with-temp-outputs/rmake.rs new file mode 100644 index 0000000000000..546e462499f9f --- /dev/null +++ b/tests/run-make/extra-filename-with-temp-outputs/rmake.rs @@ -0,0 +1,23 @@ +// In order to prevent temporary files from overwriting each other in parallel +// compilation, rustc was changed to mix an extra filename with temporary +// outputs. However, as this is a similar behavior with the codegen flag +// -C extra-filename, this test checks that the manually passed flag +// is not overwritten by this feature, and that the output files +// are named as expected. +// See https://github.com/rust-lang/rust/pull/15686 + +//FIXME(Oneirical): ignore-cross-compile + +use run_make_support::{ + bin_name, cwd, fs_wrapper, has_prefix, has_suffix, rustc, shallow_find_files, +}; + +fn main() { + rustc().extra_filename("bar").input("foo.rs").arg("-Csave-temps").run(); + let object_files = shallow_find_files(cwd(), |path| { + has_prefix(path, "foobar.foo") && has_suffix(path, "0.rcgu.o") + }); + let object_file = object_files.get(0).unwrap(); + fs_wrapper::remove_file(object_file); + fs_wrapper::remove_file(bin_name("foobar")); +} From b0174d3419b1dcfcd06b44a4bf4b603e1549ad9e Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 4 Jul 2024 17:04:20 -0400 Subject: [PATCH 2/2] rewrite and rename issue-85019-moved-src-dir to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../issue-85019-moved-src-dir/Makefile | 28 ----------- .../main.rs | 0 .../my_lib.rs | 0 .../moved-src-dir-fingerprint-ice/rmake.rs | 48 +++++++++++++++++++ 5 files changed, 48 insertions(+), 29 deletions(-) delete mode 100644 tests/run-make/issue-85019-moved-src-dir/Makefile rename tests/run-make/{issue-85019-moved-src-dir => moved-src-dir-fingerprint-ice}/main.rs (100%) rename tests/run-make/{issue-85019-moved-src-dir => moved-src-dir-fingerprint-ice}/my_lib.rs (100%) create mode 100644 tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 96ef2163fd9c4..afa1c185a661b 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -67,7 +67,6 @@ run-make/issue-69368/Makefile run-make/issue-83045/Makefile run-make/issue-83112-incr-test-moved-file/Makefile run-make/issue-84395-lto-embed-bitcode/Makefile -run-make/issue-85019-moved-src-dir/Makefile run-make/issue-85401-static-mir/Makefile run-make/issue-88756-default-output/Makefile run-make/issue-97463-abi-param-passing/Makefile diff --git a/tests/run-make/issue-85019-moved-src-dir/Makefile b/tests/run-make/issue-85019-moved-src-dir/Makefile deleted file mode 100644 index dec289058f936..0000000000000 --- a/tests/run-make/issue-85019-moved-src-dir/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -include ../tools.mk - -INCR=$(TMPDIR)/incr -FIRST_SRC=$(TMPDIR)/first_src -SECOND_SRC=$(TMPDIR)/second_src - -# ignore-none no-std is not supported -# ignore-nvptx64-nvidia-cuda FIXME: can't find crate for 'std' - -# Tests that we don't get an ICE when the working directory -# (but not the build directory!) changes between compilation -# sessions - -all: - mkdir $(INCR) - # Build from 'FIRST_SRC' - mkdir $(FIRST_SRC) - cp my_lib.rs $(FIRST_SRC)/my_lib.rs - cp main.rs $(FIRST_SRC)/main.rs - cd $(FIRST_SRC) && \ - $(RUSTC) -C incremental=$(INCR) --crate-type lib my_lib.rs --target $(TARGET) && \ - $(RUSTC) -C incremental=$(INCR) --extern my_lib=$(TMPDIR)/libmy_lib.rlib main.rs --target $(TARGET) - # Build from 'SECOND_SRC', keeping the output directory and incremental directory - # the same - mv $(FIRST_SRC) $(SECOND_SRC) - cd $(SECOND_SRC) && \ - $(RUSTC) -C incremental=$(INCR) --crate-type lib my_lib.rs --target $(TARGET) && \ - $(RUSTC) -C incremental=$(INCR) --extern my_lib=$(TMPDIR)/libmy_lib.rlib main.rs --target $(TARGET) diff --git a/tests/run-make/issue-85019-moved-src-dir/main.rs b/tests/run-make/moved-src-dir-fingerprint-ice/main.rs similarity index 100% rename from tests/run-make/issue-85019-moved-src-dir/main.rs rename to tests/run-make/moved-src-dir-fingerprint-ice/main.rs diff --git a/tests/run-make/issue-85019-moved-src-dir/my_lib.rs b/tests/run-make/moved-src-dir-fingerprint-ice/my_lib.rs similarity index 100% rename from tests/run-make/issue-85019-moved-src-dir/my_lib.rs rename to tests/run-make/moved-src-dir-fingerprint-ice/my_lib.rs diff --git a/tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs b/tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs new file mode 100644 index 0000000000000..1fee2591ba9eb --- /dev/null +++ b/tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs @@ -0,0 +1,48 @@ +// A SourceFile created during compilation may have a relative +// path (e.g. if rustc itself is invoked with a relative path). +// When we write out crate metadata, we convert all relative paths +// to absolute paths using the current working directory. +// However, the working directory was previously not included in the crate hash. +// This meant that the crate metadata could change while the crate +// hash remained the same. Among other problems, this could cause a +// fingerprint mismatch ICE, since incremental compilation uses +// the crate metadata hash to determine if a foreign query is green. +// This test checks that we don't get an ICE when the working directory +// (but not the build directory!) changes between compilation +// sessions. +// See https://github.com/rust-lang/rust/issues/85019 + +//@ ignore-none +// Reason: no-std is not supported +//@ ignore-nvptx64-nvidia-cuda +// FIXME: can't find crate for 'std' + +use run_make_support::{fs_wrapper, rust_lib_name, rustc, target}; + +fn main() { + fs_wrapper::create_dir("incr"); + fs_wrapper::create_dir("first_src"); + fs_wrapper::create_dir("output"); + fs_wrapper::rename("my_lib.rs", "first_src/my_lib.rs"); + fs_wrapper::rename("main.rs", "first_src/main.rs"); + // Build from "first_src" + std::env::set_current_dir("first_src").unwrap(); + rustc().input("my_lib.rs").incremental("incr").crate_type("lib").target(target()).run(); + rustc() + .input("main.rs") + .incremental("incr") + .extern_("my_lib", rust_lib_name("my_lib")) + .target(target()) + .run(); + std::env::set_current_dir("..").unwrap(); + fs_wrapper::rename("first_src", "second_src"); + std::env::set_current_dir("second_src").unwrap(); + // Build from "second_src" - the output and incremental directory remain identical + rustc().input("my_lib.rs").incremental("incr").crate_type("lib").target(target()).run(); + rustc() + .input("main.rs") + .incremental("incr") + .extern_("my_lib", rust_lib_name("my_lib")) + .target(target()) + .run(); +}