|
| 1 | +// A SourceFile created during compilation may have a relative |
| 2 | +// path (e.g. if rustc itself is invoked with a relative path). |
| 3 | +// When we write out crate metadata, we convert all relative paths |
| 4 | +// to absolute paths using the current working directory. |
| 5 | +// However, the working directory was previously not included in the crate hash. |
| 6 | +// This meant that the crate metadata could change while the crate |
| 7 | +// hash remained the same. Among other problems, this could cause a |
| 8 | +// fingerprint mismatch ICE, since incremental compilation uses |
| 9 | +// the crate metadata hash to determine if a foreign query is green. |
| 10 | +// This test checks that we don't get an ICE when the working directory |
| 11 | +// (but not the build directory!) changes between compilation |
| 12 | +// sessions. |
| 13 | +// See https://github.com/rust-lang/rust/issues/85019 |
| 14 | + |
| 15 | +//@ ignore-none |
| 16 | +// Reason: no-std is not supported |
| 17 | +//@ ignore-nvptx64-nvidia-cuda |
| 18 | +// FIXME: can't find crate for 'std' |
| 19 | + |
| 20 | +use run_make_support::{fs_wrapper, rust_lib_name, rustc, target}; |
| 21 | + |
| 22 | +fn main() { |
| 23 | + fs_wrapper::create_dir("incr"); |
| 24 | + fs_wrapper::create_dir("first_src"); |
| 25 | + fs_wrapper::create_dir("output"); |
| 26 | + fs_wrapper::rename("my_lib.rs", "first_src/my_lib.rs"); |
| 27 | + fs_wrapper::rename("main.rs", "first_src/main.rs"); |
| 28 | + // Build from "first_src" |
| 29 | + std::env::set_current_dir("first_src").unwrap(); |
| 30 | + rustc().input("my_lib.rs").incremental("incr").crate_type("lib").target(target()).run(); |
| 31 | + rustc() |
| 32 | + .input("main.rs") |
| 33 | + .incremental("incr") |
| 34 | + .extern_("my_lib", rust_lib_name("my_lib")) |
| 35 | + .target(target()) |
| 36 | + .run(); |
| 37 | + std::env::set_current_dir("..").unwrap(); |
| 38 | + fs_wrapper::rename("first_src", "second_src"); |
| 39 | + std::env::set_current_dir("second_src").unwrap(); |
| 40 | + // Build from "second_src" - the output and incremental directory remain identical |
| 41 | + rustc().input("my_lib.rs").incremental("incr").crate_type("lib").target(target()).run(); |
| 42 | + rustc() |
| 43 | + .input("main.rs") |
| 44 | + .incremental("incr") |
| 45 | + .extern_("my_lib", rust_lib_name("my_lib")) |
| 46 | + .target(target()) |
| 47 | + .run(); |
| 48 | +} |
0 commit comments