Skip to content

Commit c020eda

Browse files
committed
compiletest: avoid invoking rustc with absolute paths.
1 parent 9cb358c commit c020eda

28 files changed

+86
-58
lines changed

crates/rustc_codegen_spirv/src/codegen_cx/mod.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::maybe_pqp_cg_ssa as rustc_codegen_ssa;
1515

1616
use itertools::Itertools as _;
1717
use rspirv::dr::{Module, Operand};
18-
use rspirv::spirv::{Decoration, LinkageType, Op, Word};
18+
use rspirv::spirv::{Decoration, LinkageType, Word};
1919
use rustc_abi::{AddressSpace, HasDataLayout, TargetDataLayout};
2020
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
2121
use rustc_codegen_ssa::mir::debuginfo::{FunctionDebugContext, VariableKind};
@@ -37,7 +37,7 @@ use rustc_target::spec::{HasTargetSpec, Target, TargetTuple};
3737
use std::cell::RefCell;
3838
use std::collections::BTreeSet;
3939
use std::iter::once;
40-
use std::path::{Path, PathBuf};
40+
use std::path::PathBuf;
4141
use std::rc::Rc;
4242
use std::str::FromStr;
4343

@@ -767,25 +767,6 @@ impl CodegenArgs {
767767

768768
if self.disassemble_globals {
769769
for inst in module.global_inst_iter() {
770-
// HACK: On Windows, paths are printed like `OpString "D:\\dir\\blah"`.
771-
// Unfortunately, compiletest will only normalize `D:\dir\blah` to `$DIR/blah` -
772-
// one backslash, not two. So, when disassembling for compiletest, check if the
773-
// argument to OpString can be parsed as an absolute path, and if it is, replace it
774-
// with just the filename component of the path.
775-
if inst.class.opcode == Op::String {
776-
let path = Path::new(inst.operands[0].unwrap_literal_string());
777-
if path.is_absolute()
778-
&& let Some(file_name) = path.file_name()
779-
{
780-
let mut inst = inst.clone();
781-
inst.operands[0] = Operand::LiteralString(format!(
782-
"$OPSTRING_FILENAME/{}",
783-
file_name.to_string_lossy(),
784-
));
785-
eprintln!("{}", inst.disassemble());
786-
continue;
787-
}
788-
}
789770
eprintln!("{}", inst.disassemble());
790771
}
791772
}

tests/compiletests/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ fn main() {
6565
let deps_target_dir = original_target_dir.join("compiletest-deps");
6666
let compiletest_build_dir = original_target_dir.join("compiletest-results");
6767

68+
// HACK(eddyb) force `compiletest` to pass `ui/...` relative paths to `rustc`,
69+
// which should always end up being the same regardless of the path that the
70+
// Rust-GPU repo is checked out at (among other things, this avoids harcoded
71+
// `compiletest` limits being hit by e.g. users with slightly longer paths).
72+
std::env::set_current_dir(tests_dir).unwrap();
73+
let tests_dir = PathBuf::from("");
74+
6875
// Pull in rustc_codegen_spirv as a dynamic library in the same way
6976
// spirv-builder does.
7077
let codegen_backend_path = find_rustc_codegen_spirv();

tests/compiletests/ui/dis/asm_op_decorate.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
99
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"
1010

11+
// HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows.
12+
// normalize-stderr-test "ui/dis/" -> "$$DIR/"
13+
1114
// FIXME(eddyb) this should use revisions to track both the `vulkan1.2` output
1215
// and the pre-`vulkan1.2` output, but per-revisions `{only,ignore}-*` directives
1316
// are not supported in `compiletest-rs`.

tests/compiletests/ui/dis/asm_op_decorate.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ OpExtension "SPV_EXT_descriptor_indexing"
44
OpMemoryModel Logical Simple
55
OpEntryPoint Fragment %1 "main"
66
OpExecutionMode %1 OriginUpperLeft
7-
%2 = OpString "$OPSTRING_FILENAME/asm_op_decorate.rs"
7+
%2 = OpString "$DIR/asm_op_decorate.rs"
88
OpName %3 "asm_op_decorate::main"
99
OpName %4 "asm_op_decorate::add_decorate"
1010
OpDecorate %5 Binding 0

tests/compiletests/ui/dis/const-float-cast-optimized.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
99
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"
1010

11+
// HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows.
12+
// normalize-stderr-test "ui/dis/" -> "$$DIR/"
13+
1114
use spirv_std::spirv;
1215

1316
#[spirv(fragment)]

tests/compiletests/ui/dis/const-float-cast-optimized.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ OpCapability Float64
33
OpMemoryModel Logical Simple
44
OpEntryPoint Fragment %1 "main" %2
55
OpExecutionMode %1 OriginUpperLeft
6-
%3 = OpString "$OPSTRING_FILENAME/const-float-cast-optimized.rs"
6+
%3 = OpString "$DIR/const-float-cast-optimized.rs"
77
OpName %2 "output"
88
OpDecorate %2 Location 0
99
%4 = OpTypeFloat 64

tests/compiletests/ui/dis/const-float-cast.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
88
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"
99

10+
// HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows.
11+
// normalize-stderr-test "ui/dis/" -> "$$DIR/"
12+
1013
use spirv_std::spirv;
1114

1215
#[spirv(fragment)]

tests/compiletests/ui/dis/const-float-cast.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ OpCapability Float64
33
OpMemoryModel Logical Simple
44
OpEntryPoint Fragment %1 "main" %2
55
OpExecutionMode %1 OriginUpperLeft
6-
%3 = OpString "$OPSTRING_FILENAME/const-float-cast.rs"
6+
%3 = OpString "$DIR/const-float-cast.rs"
77
OpName %2 "output"
88
OpDecorate %2 Location 0
99
%4 = OpTypeFloat 32

tests/compiletests/ui/dis/const-from-cast.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
99
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"
1010

11+
// HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows.
12+
// normalize-stderr-test "ui/dis/" -> "$$DIR/"
13+
1114
use spirv_std::spirv;
1215

1316
const K: u8 = 42;

tests/compiletests/ui/dis/const-from-cast.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ OpCapability Shader
22
OpMemoryModel Logical Simple
33
OpEntryPoint Fragment %1 "main" %2
44
OpExecutionMode %1 OriginUpperLeft
5-
%3 = OpString "$OPSTRING_FILENAME/const-from-cast.rs"
5+
%3 = OpString "$DIR/const-from-cast.rs"
66
OpName %2 "output"
77
OpDecorate %2 Location 0
88
%4 = OpTypeInt 32 0

0 commit comments

Comments
 (0)