From b5545f1b0c28a7acba27d1985a934845a013af1b Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 9 May 2022 04:18:35 +0100 Subject: [PATCH] compiletest: normalize paths from repository root When testing macros from `rustc_macros` in `ui-fulldeps` tests, sometimes paths from the compiler source tree can be shown in error messages - these need to be normalized. Signed-off-by: David Wood --- src/tools/compiletest/src/runtest.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 6d94fe3ebb9..a59a0584d5e 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -3494,22 +3494,21 @@ fn normalize_output(&self, output: &str, custom_rules: &[(String, String)]) -> S normalize_path(parent_dir, "$DIR"); // Paths into the libstd/libcore - let src_dir = self - .config - .src_base - .parent() - .unwrap() - .parent() - .unwrap() - .parent() - .unwrap() - .join("library"); + let base_dir = self.config.src_base.parent().unwrap().parent().unwrap().parent().unwrap(); + let src_dir = base_dir.join("library"); normalize_path(&src_dir, "$SRC_DIR"); + // `ui-fulldeps` tests can show paths to the compiler source when testing macros from + // `rustc_macros` + // eg. /home/user/rust/compiler + let compiler_src_dir = base_dir.join("compiler"); + normalize_path(&compiler_src_dir, "$COMPILER_DIR"); + if let Some(virtual_rust_source_base_dir) = option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").map(PathBuf::from) { normalize_path(&virtual_rust_source_base_dir.join("library"), "$SRC_DIR"); + normalize_path(&virtual_rust_source_base_dir.join("compiler"), "$COMPILER_DIR"); } // Paths into the build directory