Skip to content

Commit 7cbfbd3

Browse files
committed
compiletest: Introduce "min-cdb-version"
1 parent 81a769f commit 7cbfbd3

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

src/tools/compiletest/src/common.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ pub struct Config {
261261
/// Path to / name of the Microsoft Console Debugger (CDB) executable
262262
pub cdb: Option<OsString>,
263263

264+
/// Version of CDB
265+
pub cdb_version: Option<[u16; 4]>,
266+
264267
/// Path to / name of the GDB executable
265268
pub gdb: Option<String>,
266269

src/tools/compiletest/src/header.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use std::path::{Path, PathBuf};
88
use tracing::*;
99

1010
use crate::common::{CompareMode, Config, Debugger, FailMode, Mode, PassMode};
11-
use crate::extract_gdb_version;
1211
use crate::util;
12+
use crate::{extract_cdb_version, extract_gdb_version};
1313

1414
#[cfg(test)]
1515
mod tests;
@@ -105,6 +105,10 @@ impl EarlyProps {
105105
props.ignore = true;
106106
}
107107

108+
if config.debugger == Some(Debugger::Cdb) && ignore_cdb(config, ln) {
109+
props.ignore = true;
110+
}
111+
108112
if config.debugger == Some(Debugger::Gdb) && ignore_gdb(config, ln) {
109113
props.ignore = true;
110114
}
@@ -131,6 +135,21 @@ impl EarlyProps {
131135

132136
return props;
133137

138+
fn ignore_cdb(config: &Config, line: &str) -> bool {
139+
if let Some(actual_version) = config.cdb_version {
140+
if let Some(min_version) = line.strip_prefix("min-cdb-version:").map(str::trim) {
141+
let min_version = extract_cdb_version(min_version).unwrap_or_else(|| {
142+
panic!("couldn't parse version range: {:?}", min_version);
143+
});
144+
145+
// Ignore if actual version is smaller than the minimum
146+
// required version
147+
return actual_version < min_version;
148+
}
149+
}
150+
false
151+
}
152+
134153
fn ignore_gdb(config: &Config, line: &str) -> bool {
135154
if let Some(actual_version) = config.gdb_version {
136155
if let Some(rest) = line.strip_prefix("min-gdb-version:").map(str::trim) {
@@ -142,8 +161,8 @@ impl EarlyProps {
142161
if start_ver != end_ver {
143162
panic!("Expected single GDB version")
144163
}
145-
// Ignore if actual version is smaller the minimum required
146-
// version
164+
// Ignore if actual version is smaller than the minimum
165+
// required version
147166
return actual_version < start_ver;
148167
} else if let Some(rest) = line.strip_prefix("ignore-gdb-version:").map(str::trim) {
149168
let (min_version, max_version) =

src/tools/compiletest/src/main.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
163163

164164
let target = opt_str2(matches.opt_str("target"));
165165
let android_cross_path = opt_path(matches, "android-cross-path");
166-
let cdb = analyze_cdb(matches.opt_str("cdb"), &target);
166+
let (cdb, cdb_version) = analyze_cdb(matches.opt_str("cdb"), &target);
167167
let (gdb, gdb_version, gdb_native_rust) =
168168
analyze_gdb(matches.opt_str("gdb"), &target, &android_cross_path);
169169
let (lldb_version, lldb_native_rust) = matches
@@ -216,6 +216,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
216216
target,
217217
host: opt_str2(matches.opt_str("host")),
218218
cdb,
219+
cdb_version,
219220
gdb,
220221
gdb_version,
221222
gdb_native_rust,
@@ -773,8 +774,30 @@ fn find_cdb(target: &str) -> Option<OsString> {
773774
}
774775

775776
/// Returns Path to CDB
776-
fn analyze_cdb(cdb: Option<String>, target: &str) -> Option<OsString> {
777-
cdb.map(OsString::from).or_else(|| find_cdb(target))
777+
fn analyze_cdb(cdb: Option<String>, target: &str) -> (Option<OsString>, Option<[u16; 4]>) {
778+
let cdb = cdb.map(OsString::from).or_else(|| find_cdb(target));
779+
780+
let mut version = None;
781+
if let Some(cdb) = cdb.as_ref() {
782+
if let Ok(output) = Command::new(cdb).arg("/version").output() {
783+
if let Some(first_line) = String::from_utf8_lossy(&output.stdout).lines().next() {
784+
version = extract_cdb_version(&first_line);
785+
}
786+
}
787+
}
788+
789+
(cdb, version)
790+
}
791+
792+
fn extract_cdb_version(full_version_line: &str) -> Option<[u16; 4]> {
793+
// Example full_version_line: "cdb version 10.0.18362.1"
794+
let version = full_version_line.rsplit(' ').next()?;
795+
let mut components = version.split('.');
796+
let major: u16 = components.next().unwrap().parse().unwrap();
797+
let minor: u16 = components.next().unwrap().parse().unwrap();
798+
let patch: u16 = components.next().unwrap_or("0").parse().unwrap();
799+
let build: u16 = components.next().unwrap_or("0").parse().unwrap();
800+
Some([major, minor, patch, build])
778801
}
779802

780803
/// Returns (Path to GDB, GDB Version, GDB has Rust Support)

0 commit comments

Comments
 (0)