Skip to content

Commit b68c29b

Browse files
Auto merge of #149987 - Zalathar:ambient-cdb, r=<try>
Move ambient cdb discovery from compiletest to bootstrap try-job: x86_64-msvc-1 try-job: i686-msvc-1 try-job: aarch64-msvc-1 try-job: x86_64-mingw-1
2 parents 08de25c + 5e42f8b commit b68c29b

File tree

5 files changed

+49
-47
lines changed

5 files changed

+49
-47
lines changed

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,6 +2181,10 @@ Please disable assertions with `rust.debug-assertions = false`.
21812181
}
21822182

21832183
if mode == CompiletestMode::Debuginfo {
2184+
if let Some(debuggers::Cdb { cdb }) = debuggers::discover_cdb(target) {
2185+
cmd.arg("--cdb").arg(cdb);
2186+
}
2187+
21842188
if let Some(debuggers::Gdb { gdb }) = debuggers::discover_gdb(builder, android.as_ref())
21852189
{
21862190
cmd.arg("--gdb").arg(gdb.as_ref());
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use std::env;
2+
use std::path::PathBuf;
3+
4+
use crate::core::config::TargetSelection;
5+
6+
pub(crate) struct Cdb {
7+
pub(crate) cdb: PathBuf,
8+
}
9+
10+
/// FIXME: This CDB discovery code was very questionable when it was in
11+
/// compiletest, and it's just as questionable now that it's in bootstrap.
12+
pub(crate) fn discover_cdb(target: TargetSelection) -> Option<Cdb> {
13+
if !cfg!(windows) || !target.ends_with("-pc-windows-msvc") {
14+
return None;
15+
}
16+
17+
let pf86 =
18+
PathBuf::from(env::var_os("ProgramFiles(x86)").or_else(|| env::var_os("ProgramFiles"))?);
19+
let cdb_arch = if cfg!(target_arch = "x86") {
20+
"x86"
21+
} else if cfg!(target_arch = "x86_64") {
22+
"x64"
23+
} else if cfg!(target_arch = "aarch64") {
24+
"arm64"
25+
} else if cfg!(target_arch = "arm") {
26+
"arm"
27+
} else {
28+
return None; // No compatible CDB.exe in the Windows 10 SDK
29+
};
30+
31+
let mut path = pf86;
32+
path.push(r"Windows Kits\10\Debuggers"); // We could check 8.1 etc. too?
33+
path.push(cdb_arch);
34+
path.push(r"cdb.exe");
35+
36+
if !path.exists() {
37+
return None;
38+
}
39+
40+
Some(Cdb { cdb: path })
41+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
//! Code for discovering debuggers and debugger-related configuration, so that
22
//! it can be passed to compiletest when running debuginfo tests.
33
4+
pub(crate) use self::cdb::{Cdb, discover_cdb};
45
pub(crate) use self::gdb::{Gdb, discover_gdb};
56
pub(crate) use self::lldb::{Lldb, discover_lldb};
67

8+
mod cdb;
79
mod gdb;
810
mod lldb;

src/tools/compiletest/src/debuggers.rs

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::env;
22
use std::process::Command;
33
use std::sync::Arc;
44

5-
use camino::{Utf8Path, Utf8PathBuf};
5+
use camino::Utf8Path;
66

77
use crate::common::{Config, Debugger};
88

@@ -54,51 +54,6 @@ pub(crate) fn configure_lldb(config: &Config) -> Option<Arc<Config>> {
5454
Some(Arc::new(Config { debugger: Some(Debugger::Lldb), ..config.clone() }))
5555
}
5656

57-
/// Returns `true` if the given target is a MSVC target for the purposes of CDB testing.
58-
fn is_pc_windows_msvc_target(target: &str) -> bool {
59-
target.ends_with("-pc-windows-msvc")
60-
}
61-
62-
/// FIXME: this is very questionable...
63-
fn find_cdb(target: &str) -> Option<Utf8PathBuf> {
64-
if !(cfg!(windows) && is_pc_windows_msvc_target(target)) {
65-
return None;
66-
}
67-
68-
let pf86 = Utf8PathBuf::from_path_buf(
69-
env::var_os("ProgramFiles(x86)").or_else(|| env::var_os("ProgramFiles"))?.into(),
70-
)
71-
.unwrap();
72-
let cdb_arch = if cfg!(target_arch = "x86") {
73-
"x86"
74-
} else if cfg!(target_arch = "x86_64") {
75-
"x64"
76-
} else if cfg!(target_arch = "aarch64") {
77-
"arm64"
78-
} else if cfg!(target_arch = "arm") {
79-
"arm"
80-
} else {
81-
return None; // No compatible CDB.exe in the Windows 10 SDK
82-
};
83-
84-
let mut path = pf86;
85-
path.push(r"Windows Kits\10\Debuggers"); // We could check 8.1 etc. too?
86-
path.push(cdb_arch);
87-
path.push(r"cdb.exe");
88-
89-
if !path.exists() {
90-
return None;
91-
}
92-
93-
Some(path)
94-
}
95-
96-
/// Returns Path to CDB
97-
pub(crate) fn discover_cdb(cdb: Option<String>, target: &str) -> Option<Utf8PathBuf> {
98-
let cdb = cdb.map(Utf8PathBuf::from).or_else(|| find_cdb(target));
99-
cdb
100-
}
101-
10257
pub(crate) fn query_cdb_version(cdb: &Utf8Path) -> Option<[u16; 4]> {
10358
let mut version = None;
10459
if let Ok(output) = Command::new(cdb).arg("/version").output() {

src/tools/compiletest/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ fn parse_config(args: Vec<String>) -> Config {
263263
let adb_device_status = target.contains("android") && adb_test_dir.is_some();
264264

265265
// FIXME: `cdb_version` is *derived* from cdb, but it's *not* technically a config!
266-
let cdb = debuggers::discover_cdb(matches.opt_str("cdb"), &target);
266+
let cdb = matches.opt_str("cdb").map(Utf8PathBuf::from);
267267
let cdb_version = cdb.as_deref().and_then(debuggers::query_cdb_version);
268268
// FIXME: `gdb_version` is *derived* from gdb, but it's *not* technically a config!
269269
let gdb = matches.opt_str("gdb").map(Utf8PathBuf::from);

0 commit comments

Comments
 (0)