Skip to content

Commit 7f4752b

Browse files
committed
compiletest: Rewrite extract_lldb_version function
This makes extract_lldb_version has the same version type like extract_gdb_version. This is technically a breaking change for rustc-dev users. But note that rustc-dev is a nightly component.
1 parent c2dbebd commit 7f4752b

File tree

4 files changed

+50
-76
lines changed

4 files changed

+50
-76
lines changed

src/tools/compiletest/src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ pub struct Config {
268268
pub gdb_native_rust: bool,
269269

270270
/// Version of LLDB
271-
pub lldb_version: Option<String>,
271+
pub lldb_version: Option<u32>,
272272

273273
/// Whether LLDB has native rust support
274274
pub lldb_native_rust: bool,

src/tools/compiletest/src/header.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,17 @@ impl EarlyProps {
188188
}
189189

190190
fn ignore_lldb(config: &Config, line: &str) -> bool {
191-
if let Some(ref actual_version) = config.lldb_version {
192-
if line.starts_with("min-lldb-version") {
193-
let min_version = line
194-
.trim_end()
195-
.rsplit(' ')
196-
.next()
197-
.expect("Malformed lldb version directive");
191+
if let Some(actual_version) = config.lldb_version {
192+
if let Some(min_version) = line.strip_prefix("min-lldb-version:").map(str::trim) {
193+
let min_version = min_version.parse().unwrap_or_else(|e| {
194+
panic!(
195+
"Unexpected format of LLDB version string: {}\n{:?}",
196+
min_version, e
197+
);
198+
});
198199
// Ignore if actual version is smaller the minimum required
199200
// version
200-
lldb_version_to_int(actual_version) < lldb_version_to_int(min_version)
201+
actual_version < min_version
201202
} else if line.starts_with("rust-lldb") && !config.lldb_native_rust {
202203
true
203204
} else {
@@ -943,12 +944,6 @@ impl Config {
943944
}
944945
}
945946

946-
pub fn lldb_version_to_int(version_string: &str) -> isize {
947-
let error_string =
948-
format!("Encountered LLDB version string with unexpected format: {}", version_string);
949-
version_string.parse().expect(&error_string)
950-
}
951-
952947
fn expand_variables(mut value: String, config: &Config) -> String {
953948
const CWD: &'static str = "{{cwd}}";
954949
const SRC_BASE: &'static str = "{{src-base}}";

src/tools/compiletest/src/main.rs

Lines changed: 29 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,12 @@ pub fn parse_config(args: Vec<String>) -> Config {
165165
let cdb = analyze_cdb(matches.opt_str("cdb"), &target);
166166
let (gdb, gdb_version, gdb_native_rust) =
167167
analyze_gdb(matches.opt_str("gdb"), &target, &android_cross_path);
168-
let (lldb_version, lldb_native_rust) = extract_lldb_version(matches.opt_str("lldb-version"));
169-
168+
let (lldb_version, lldb_native_rust) = matches
169+
.opt_str("lldb-version")
170+
.as_deref()
171+
.and_then(extract_lldb_version)
172+
.map(|(v, b)| (Some(v), b))
173+
.unwrap_or((None, false));
170174
let color = match matches.opt_str("color").as_ref().map(|x| &**x) {
171175
Some("auto") | None => ColorConfig::AutoColor,
172176
Some("always") => ColorConfig::AlwaysColor,
@@ -400,17 +404,14 @@ fn configure_lldb(config: &Config) -> Option<Config> {
400404
return None;
401405
}
402406

403-
if let Some(lldb_version) = config.lldb_version.as_ref() {
404-
if lldb_version == "350" {
405-
println!(
406-
"WARNING: The used version of LLDB ({}) has a \
407-
known issue that breaks debuginfo tests. See \
408-
issue #32520 for more information. Skipping all \
409-
LLDB-based tests!",
410-
lldb_version
411-
);
412-
return None;
413-
}
407+
if let Some(350) = config.lldb_version {
408+
println!(
409+
"WARNING: The used version of LLDB (350) has a \
410+
known issue that breaks debuginfo tests. See \
411+
issue #32520 for more information. Skipping all \
412+
LLDB-based tests!",
413+
);
414+
return None;
414415
}
415416

416417
// Some older versions of LLDB seem to have problems with multiple
@@ -908,7 +909,7 @@ fn extract_gdb_version(full_version_line: &str) -> Option<u32> {
908909
}
909910

910911
/// Returns (LLDB version, LLDB is rust-enabled)
911-
fn extract_lldb_version(full_version_line: Option<String>) -> (Option<String>, bool) {
912+
fn extract_lldb_version(full_version_line: &str) -> Option<(u32, bool)> {
912913
// Extract the major LLDB version from the given version string.
913914
// LLDB version strings are different for Apple and non-Apple platforms.
914915
// The Apple variant looks like this:
@@ -917,7 +918,7 @@ fn extract_lldb_version(full_version_line: Option<String>) -> (Option<String>, b
917918
// lldb-300.2.51 (new versions)
918919
//
919920
// We are only interested in the major version number, so this function
920-
// will return `Some("179")` and `Some("300")` respectively.
921+
// will return `Some(179)` and `Some(300)` respectively.
921922
//
922923
// Upstream versions look like:
923924
// lldb version 6.0.1
@@ -929,53 +930,20 @@ fn extract_lldb_version(full_version_line: Option<String>) -> (Option<String>, b
929930
// normally fine because the only non-Apple version we test is
930931
// rust-enabled.
931932

932-
if let Some(ref full_version_line) = full_version_line {
933-
if !full_version_line.trim().is_empty() {
934-
let full_version_line = full_version_line.trim();
935-
936-
for (pos, l) in full_version_line.char_indices() {
937-
if l != 'l' && l != 'L' {
938-
continue;
939-
}
940-
if pos + 5 >= full_version_line.len() {
941-
continue;
942-
}
943-
let l = full_version_line[pos + 1..].chars().next().unwrap();
944-
if l != 'l' && l != 'L' {
945-
continue;
946-
}
947-
let d = full_version_line[pos + 2..].chars().next().unwrap();
948-
if d != 'd' && d != 'D' {
949-
continue;
950-
}
951-
let b = full_version_line[pos + 3..].chars().next().unwrap();
952-
if b != 'b' && b != 'B' {
953-
continue;
954-
}
955-
let dash = full_version_line[pos + 4..].chars().next().unwrap();
956-
if dash != '-' {
957-
continue;
958-
}
959-
960-
let vers = full_version_line[pos + 5..]
961-
.chars()
962-
.take_while(|c| c.is_digit(10))
963-
.collect::<String>();
964-
if !vers.is_empty() {
965-
return (Some(vers), full_version_line.contains("rust-enabled"));
966-
}
967-
}
933+
let full_version_line = full_version_line.trim();
968934

969-
if full_version_line.starts_with("lldb version ") {
970-
let vers = full_version_line[13..]
971-
.chars()
972-
.take_while(|c| c.is_digit(10))
973-
.collect::<String>();
974-
if !vers.is_empty() {
975-
return (Some(vers + "00"), full_version_line.contains("rust-enabled"));
976-
}
977-
}
935+
if let Some(apple_ver) =
936+
full_version_line.strip_prefix("LLDB-").or_else(|| full_version_line.strip_prefix("lldb-"))
937+
{
938+
if let Some(idx) = apple_ver.find(|c: char| !c.is_digit(10)) {
939+
let version: u32 = apple_ver[..idx].parse().unwrap();
940+
return Some((version, full_version_line.contains("rust-enabled")));
941+
}
942+
} else if let Some(lldb_ver) = full_version_line.strip_prefix("lldb version ") {
943+
if let Some(idx) = lldb_ver.find(|c: char| !c.is_digit(10)) {
944+
let version: u32 = lldb_ver[..idx].parse().unwrap();
945+
return Some((version * 100, full_version_line.contains("rust-enabled")));
978946
}
979947
}
980-
(None, false)
948+
None
981949
}

src/tools/compiletest/src/tests.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ fn test_extract_gdb_version() {
4141
}
4242
}
4343

44+
#[test]
45+
fn test_extract_lldb_version() {
46+
// Apple variants
47+
assert_eq!(extract_lldb_version("LLDB-179.5"), Some((179, false)));
48+
assert_eq!(extract_lldb_version("lldb-300.2.51"), Some((300, false)));
49+
50+
// Upstream versions
51+
assert_eq!(extract_lldb_version("lldb version 6.0.1"), Some((600, false)));
52+
assert_eq!(extract_lldb_version("lldb version 9.0.0"), Some((900, false)));
53+
}
54+
4455
#[test]
4556
fn is_test_test() {
4657
assert_eq!(true, is_test(&OsString::from("a_test.rs")));

0 commit comments

Comments
 (0)