From 8075ddb98e594f75df45c0103838c61b4d6d747d Mon Sep 17 00:00:00 2001 From: Urgau Date: Wed, 21 Aug 2024 18:56:03 +0200 Subject: Implement RFC3137 trim-paths sysroot changes --- src/tools/compiletest/src/header.rs | 10 ++++++++++ src/tools/compiletest/src/runtest.rs | 12 +++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'src/tools/compiletest') diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index a291ff37112..1fa31181fd5 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -1115,6 +1115,7 @@ fn expand_variables(mut value: String, config: &Config) -> String { const CWD: &str = "{{cwd}}"; const SRC_BASE: &str = "{{src-base}}"; const BUILD_BASE: &str = "{{build-base}}"; + const RUST_SRC_BASE: &str = "{{rust-src-base}}"; const SYSROOT_BASE: &str = "{{sysroot-base}}"; const TARGET_LINKER: &str = "{{target-linker}}"; const TARGET: &str = "{{target}}"; @@ -1144,6 +1145,15 @@ fn expand_variables(mut value: String, config: &Config) -> String { value = value.replace(TARGET, &config.target); } + if value.contains(RUST_SRC_BASE) { + let src_base = config + .sysroot_base + .join("lib/rustlib/src/rust") + .read_link() + .expect("lib/rustlib/src/rust in target is a symlink to checkout root"); + value = value.replace(RUST_SRC_BASE, &src_base.to_string_lossy()); + } + value } diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 25a135aa320..1a1cc86e2de 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2294,7 +2294,7 @@ impl<'test> TestCx<'test> { } let base_dir = Path::new("/rustc/FAKE_PREFIX"); - // Paths into the libstd/libcore + // Fake paths into the libstd/libcore normalize_path(&base_dir.join("library"), "$SRC_DIR"); // `ui-fulldeps` tests can show paths to the compiler source when testing macros from // `rustc_macros` @@ -2310,8 +2310,14 @@ impl<'test> TestCx<'test> { // eg. /home/user/rust/build normalize_path(parent_build_dir, "$BUILD_DIR"); - // Paths into lib directory. - normalize_path(&parent_build_dir.parent().unwrap().join("lib"), "$LIB_DIR"); + // Real paths into the libstd/libcore + let rust_src_dir = &self + .config + .sysroot_base + .join("lib/rustlib/src/rust") + .read_link() + .expect("lib/rustlib/src/rust in target is a symlink to checkout root"); + normalize_path(&rust_src_dir.join("library"), "$SRC_DIR_REAL"); if json { // escaped newlines in json strings should be readable -- cgit 1.4.1-3-g733a5 From 61ef9838dfb5045d00aa5563065a31210dab9460 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 27 Sep 2024 14:05:24 +0200 Subject: compiletest: fallback to the original path if it's not a symlink --- src/tools/compiletest/src/header.rs | 8 +++----- src/tools/compiletest/src/runtest.rs | 9 +++------ 2 files changed, 6 insertions(+), 11 deletions(-) (limited to 'src/tools/compiletest') diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 1fa31181fd5..6a889d27793 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -1146,11 +1146,9 @@ fn expand_variables(mut value: String, config: &Config) -> String { } if value.contains(RUST_SRC_BASE) { - let src_base = config - .sysroot_base - .join("lib/rustlib/src/rust") - .read_link() - .expect("lib/rustlib/src/rust in target is a symlink to checkout root"); + let src_base = config.sysroot_base.join("lib/rustlib/src/rust"); + src_base.try_exists().expect(&*format!("{} should exists", src_base.display())); + let src_base = src_base.read_link().unwrap_or(src_base); value = value.replace(RUST_SRC_BASE, &src_base.to_string_lossy()); } diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 1a1cc86e2de..922492e451f 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2311,12 +2311,9 @@ impl<'test> TestCx<'test> { normalize_path(parent_build_dir, "$BUILD_DIR"); // Real paths into the libstd/libcore - let rust_src_dir = &self - .config - .sysroot_base - .join("lib/rustlib/src/rust") - .read_link() - .expect("lib/rustlib/src/rust in target is a symlink to checkout root"); + let rust_src_dir = &self.config.sysroot_base.join("lib/rustlib/src/rust"); + rust_src_dir.try_exists().expect(&*format!("{} should exists", rust_src_dir.display())); + let rust_src_dir = rust_src_dir.read_link().unwrap_or(rust_src_dir.to_path_buf()); normalize_path(&rust_src_dir.join("library"), "$SRC_DIR_REAL"); if json { -- cgit 1.4.1-3-g733a5 From 37ea27c741f3d04c23033b0c7ec343584b3e7502 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sat, 28 Sep 2024 21:44:44 +0200 Subject: compiletest: normalize to `$SRC_DIR_REAL` before `$TEST_BUILD_DIR` in case the real paths into the libstd/libcore are located inside the the build directory, maybe because it's coming from an extracted dist component in the build dir (cc opt-dist) --- src/tools/compiletest/src/runtest.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/tools/compiletest') diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 922492e451f..456528da21a 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2301,6 +2301,12 @@ impl<'test> TestCx<'test> { // eg. /home/user/rust/compiler normalize_path(&base_dir.join("compiler"), "$COMPILER_DIR"); + // Real paths into the libstd/libcore + let rust_src_dir = &self.config.sysroot_base.join("lib/rustlib/src/rust"); + rust_src_dir.try_exists().expect(&*format!("{} should exists", rust_src_dir.display())); + let rust_src_dir = rust_src_dir.read_link().unwrap_or(rust_src_dir.to_path_buf()); + normalize_path(&rust_src_dir.join("library"), "$SRC_DIR_REAL"); + // Paths into the build directory let test_build_dir = &self.config.build_base; let parent_build_dir = test_build_dir.parent().unwrap().parent().unwrap().parent().unwrap(); @@ -2310,12 +2316,6 @@ impl<'test> TestCx<'test> { // eg. /home/user/rust/build normalize_path(parent_build_dir, "$BUILD_DIR"); - // Real paths into the libstd/libcore - let rust_src_dir = &self.config.sysroot_base.join("lib/rustlib/src/rust"); - rust_src_dir.try_exists().expect(&*format!("{} should exists", rust_src_dir.display())); - let rust_src_dir = rust_src_dir.read_link().unwrap_or(rust_src_dir.to_path_buf()); - normalize_path(&rust_src_dir.join("library"), "$SRC_DIR_REAL"); - if json { // escaped newlines in json strings should be readable // in the stderr files. There's no point int being correct, -- cgit 1.4.1-3-g733a5