Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 216ed3c

Browse files
authoredJul 22, 2020
Rollup merge of #74237 - lzutao:compiletest, r=Mark-Simulacrum
compiletest: Rewrite extract_*_version functions This makes extract_lldb_version has the same version type like extract_gdb_version.
2 parents 8afb305 + 1314d31 commit 216ed3c

File tree

13 files changed

+208
-253
lines changed

13 files changed

+208
-253
lines changed
 

‎src/test/codegen/abi-efiapi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// revisions:x86_64 i686 arm
44

5-
// min-llvm-version 9.0
5+
// min-llvm-version: 9.0
66

77
//[x86_64] compile-flags: --target x86_64-unknown-uefi
88
//[i686] compile-flags: --target i686-unknown-linux-musl

‎src/test/codegen/force-unwind-tables.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// min-llvm-version 8.0
1+
// min-llvm-version: 8.0
22
// compile-flags: -C no-prepopulate-passes -C force-unwind-tables=y
33

44
#![crate_type="lib"]

‎src/test/debuginfo/function-call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This test does not passed with gdb < 8.0. See #53497.
2-
// min-gdb-version 8.0
2+
// min-gdb-version: 8.0
33

44
// compile-flags:-g
55

‎src/test/debuginfo/pretty-huge-vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// ignore-freebsd: gdb package too new
33
// ignore-android: FIXME(#10381)
44
// compile-flags:-g
5-
// min-gdb-version 8.1
5+
// min-gdb-version: 8.1
66
// min-lldb-version: 310
77

88
// === GDB TESTS ===================================================================================

‎src/test/debuginfo/pretty-std-collections.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
// The pretty printers being tested here require the patch from
88
// https://sourceware.org/bugzilla/show_bug.cgi?id=21763
9-
// min-gdb-version 8.1
9+
// min-gdb-version: 8.1
1010

1111
// min-lldb-version: 310
1212

‎src/test/debuginfo/pretty-std.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// only-cdb // "Temporarily" ignored on GDB/LLDB due to debuginfo tests being disabled, see PR 47155
33
// ignore-android: FIXME(#10381)
44
// compile-flags:-g
5-
// min-gdb-version 7.7
5+
// min-gdb-version: 7.7
66
// min-lldb-version: 310
77

88
// === GDB TESTS ===================================================================================

‎src/test/debuginfo/pretty-uninitialized-vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// ignore-freebsd: gdb package too new
33
// ignore-android: FIXME(#10381)
44
// compile-flags:-g
5-
// min-gdb-version 8.1
5+
// min-gdb-version: 8.1
66
// min-lldb-version: 310
77

88
// === GDB TESTS ===================================================================================

‎src/test/ui/sanitize/new-llvm-pass-manager-thin-lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// being run when compiling with new LLVM pass manager and ThinLTO.
33
// Note: The issue occurred only on non-zero opt-level.
44
//
5-
// min-llvm-version 9.0
5+
// min-llvm-version: 9.0
66
// needs-sanitizer-support
77
// needs-sanitizer-address
88
//

‎src/tools/compiletest/src/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,13 @@ pub struct Config {
271271
pub gdb_native_rust: bool,
272272

273273
/// Version of LLDB
274-
pub lldb_version: Option<String>,
274+
pub lldb_version: Option<u32>,
275275

276276
/// Whether LLDB has native rust support
277277
pub lldb_native_rust: bool,
278278

279279
/// Version of LLVM
280-
pub llvm_version: Option<String>,
280+
pub llvm_version: Option<u32>,
281281

282282
/// Is LLVM a system LLVM
283283
pub system_llvm: bool,

‎src/tools/compiletest/src/header.rs

Lines changed: 88 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -132,72 +132,46 @@ impl EarlyProps {
132132

133133
fn ignore_gdb(config: &Config, line: &str) -> bool {
134134
if let Some(actual_version) = config.gdb_version {
135-
if line.starts_with("min-gdb-version") {
136-
let (start_ver, end_ver) = extract_gdb_version_range(line);
135+
if let Some(rest) = line.strip_prefix("min-gdb-version:").map(str::trim) {
136+
let (start_ver, end_ver) = extract_version_range(rest, extract_gdb_version)
137+
.unwrap_or_else(|| {
138+
panic!("couldn't parse version range: {:?}", rest);
139+
});
137140

138141
if start_ver != end_ver {
139142
panic!("Expected single GDB version")
140143
}
141144
// Ignore if actual version is smaller the minimum required
142145
// version
143-
actual_version < start_ver
144-
} else if line.starts_with("ignore-gdb-version") {
145-
let (min_version, max_version) = extract_gdb_version_range(line);
146+
return actual_version < start_ver;
147+
} else if let Some(rest) = line.strip_prefix("ignore-gdb-version:").map(str::trim) {
148+
let (min_version, max_version) =
149+
extract_version_range(rest, extract_gdb_version).unwrap_or_else(|| {
150+
panic!("couldn't parse version range: {:?}", rest);
151+
});
146152

147153
if max_version < min_version {
148154
panic!("Malformed GDB version range: max < min")
149155
}
150156

151-
actual_version >= min_version && actual_version <= max_version
152-
} else {
153-
false
154-
}
155-
} else {
156-
false
157-
}
158-
}
159-
160-
// Takes a directive of the form "ignore-gdb-version <version1> [- <version2>]",
161-
// returns the numeric representation of <version1> and <version2> as
162-
// tuple: (<version1> as u32, <version2> as u32)
163-
// If the <version2> part is omitted, the second component of the tuple
164-
// is the same as <version1>.
165-
fn extract_gdb_version_range(line: &str) -> (u32, u32) {
166-
const ERROR_MESSAGE: &'static str = "Malformed GDB version directive";
167-
168-
let range_components = line
169-
.split(&[' ', '-'][..])
170-
.filter(|word| !word.is_empty())
171-
.map(extract_gdb_version)
172-
.skip_while(Option::is_none)
173-
.take(3) // 3 or more = invalid, so take at most 3.
174-
.collect::<Vec<Option<u32>>>();
175-
176-
match range_components.len() {
177-
1 => {
178-
let v = range_components[0].unwrap();
179-
(v, v)
180-
}
181-
2 => {
182-
let v_min = range_components[0].unwrap();
183-
let v_max = range_components[1].expect(ERROR_MESSAGE);
184-
(v_min, v_max)
157+
return actual_version >= min_version && actual_version <= max_version;
185158
}
186-
_ => panic!(ERROR_MESSAGE),
187159
}
160+
false
188161
}
189162

190163
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");
164+
if let Some(actual_version) = config.lldb_version {
165+
if let Some(min_version) = line.strip_prefix("min-lldb-version:").map(str::trim) {
166+
let min_version = min_version.parse().unwrap_or_else(|e| {
167+
panic!(
168+
"Unexpected format of LLDB version string: {}\n{:?}",
169+
min_version, e
170+
);
171+
});
198172
// Ignore if actual version is smaller the minimum required
199173
// version
200-
lldb_version_to_int(actual_version) < lldb_version_to_int(min_version)
174+
actual_version < min_version
201175
} else if line.starts_with("rust-lldb") && !config.lldb_native_rust {
202176
true
203177
} else {
@@ -212,69 +186,38 @@ impl EarlyProps {
212186
if config.system_llvm && line.starts_with("no-system-llvm") {
213187
return true;
214188
}
215-
if let Some(ref actual_version) = config.llvm_version {
216-
let actual_version = version_to_int(actual_version);
217-
if line.starts_with("min-llvm-version") {
218-
let min_version = line
219-
.trim_end()
220-
.rsplit(' ')
221-
.next()
222-
.expect("Malformed llvm version directive");
189+
if let Some(actual_version) = config.llvm_version {
190+
if let Some(rest) = line.strip_prefix("min-llvm-version:").map(str::trim) {
191+
let min_version = extract_llvm_version(rest).unwrap();
223192
// Ignore if actual version is smaller the minimum required
224193
// version
225-
actual_version < version_to_int(min_version)
226-
} else if line.starts_with("min-system-llvm-version") {
227-
let min_version = line
228-
.trim_end()
229-
.rsplit(' ')
230-
.next()
231-
.expect("Malformed llvm version directive");
194+
actual_version < min_version
195+
} else if let Some(rest) =
196+
line.strip_prefix("min-system-llvm-version:").map(str::trim)
197+
{
198+
let min_version = extract_llvm_version(rest).unwrap();
232199
// Ignore if using system LLVM and actual version
233200
// is smaller the minimum required version
234-
config.system_llvm && actual_version < version_to_int(min_version)
235-
} else if line.starts_with("ignore-llvm-version") {
236-
// Syntax is: "ignore-llvm-version <version1> [- <version2>]"
237-
let range_components = line
238-
.split(' ')
239-
.skip(1) // Skip the directive.
240-
.map(|s| s.trim())
241-
.filter(|word| !word.is_empty() && word != &"-")
242-
.take(3) // 3 or more = invalid, so take at most 3.
243-
.collect::<Vec<&str>>();
244-
match range_components.len() {
245-
1 => actual_version == version_to_int(range_components[0]),
246-
2 => {
247-
let v_min = version_to_int(range_components[0]);
248-
let v_max = version_to_int(range_components[1]);
249-
if v_max < v_min {
250-
panic!("Malformed LLVM version range: max < min")
251-
}
252-
// Ignore if version lies inside of range.
253-
actual_version >= v_min && actual_version <= v_max
254-
}
255-
_ => panic!("Malformed LLVM version directive"),
201+
config.system_llvm && actual_version < min_version
202+
} else if let Some(rest) = line.strip_prefix("ignore-llvm-version:").map(str::trim)
203+
{
204+
// Syntax is: "ignore-llvm-version: <version1> [- <version2>]"
205+
let (v_min, v_max) = extract_version_range(rest, extract_llvm_version)
206+
.unwrap_or_else(|| {
207+
panic!("couldn't parse version range: {:?}", rest);
208+
});
209+
if v_max < v_min {
210+
panic!("Malformed LLVM version range: max < min")
256211
}
212+
// Ignore if version lies inside of range.
213+
actual_version >= v_min && actual_version <= v_max
257214
} else {
258215
false
259216
}
260217
} else {
261218
false
262219
}
263220
}
264-
265-
fn version_to_int(version: &str) -> u32 {
266-
let version_without_suffix = version.trim_end_matches("git").split('-').next().unwrap();
267-
let components: Vec<u32> = version_without_suffix
268-
.split('.')
269-
.map(|s| s.parse().expect("Malformed version component"))
270-
.collect();
271-
match components.len() {
272-
1 => components[0] * 10000,
273-
2 => components[0] * 10000 + components[1] * 100,
274-
3 => components[0] * 10000 + components[1] * 100 + components[2],
275-
_ => panic!("Malformed version"),
276-
}
277-
}
278221
}
279222
}
280223

@@ -944,12 +887,6 @@ impl Config {
944887
}
945888
}
946889

947-
pub fn lldb_version_to_int(version_string: &str) -> isize {
948-
let error_string =
949-
format!("Encountered LLDB version string with unexpected format: {}", version_string);
950-
version_string.parse().expect(&error_string)
951-
}
952-
953890
fn expand_variables(mut value: String, config: &Config) -> String {
954891
const CWD: &'static str = "{{cwd}}";
955892
const SRC_BASE: &'static str = "{{src-base}}";
@@ -990,3 +927,49 @@ fn parse_normalization_string(line: &mut &str) -> Option<String> {
990927
*line = &line[end + 1..];
991928
Some(result)
992929
}
930+
931+
pub fn extract_llvm_version(version: &str) -> Option<u32> {
932+
let version_without_suffix = version.trim_end_matches("git").split('-').next().unwrap();
933+
let components: Vec<u32> = version_without_suffix
934+
.split('.')
935+
.map(|s| s.parse().expect("Malformed version component"))
936+
.collect();
937+
let version = match *components {
938+
[a] => a * 10_000,
939+
[a, b] => a * 10_000 + b * 100,
940+
[a, b, c] => a * 10_000 + b * 100 + c,
941+
_ => panic!("Malformed version"),
942+
};
943+
Some(version)
944+
}
945+
946+
// Takes a directive of the form "<version1> [- <version2>]",
947+
// returns the numeric representation of <version1> and <version2> as
948+
// tuple: (<version1> as u32, <version2> as u32)
949+
// If the <version2> part is omitted, the second component of the tuple
950+
// is the same as <version1>.
951+
fn extract_version_range<F>(line: &str, parse: F) -> Option<(u32, u32)>
952+
where
953+
F: Fn(&str) -> Option<u32>,
954+
{
955+
let mut splits = line.splitn(2, "- ").map(str::trim);
956+
let min = splits.next().unwrap();
957+
if min.ends_with('-') {
958+
return None;
959+
}
960+
961+
let max = splits.next();
962+
963+
if min.is_empty() {
964+
return None;
965+
}
966+
967+
let min = parse(min)?;
968+
let max = match max {
969+
Some(max) if max.is_empty() => return None,
970+
Some(max) => parse(max)?,
971+
_ => min,
972+
};
973+
974+
Some((min, max))
975+
}

‎src/tools/compiletest/src/header/tests.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,17 @@ fn no_system_llvm() {
119119
fn llvm_version() {
120120
let mut config = config();
121121

122-
config.llvm_version = Some("8.1.2-rust".to_owned());
123-
assert!(parse_rs(&config, "// min-llvm-version 9.0").ignore);
122+
config.llvm_version = Some(80102);
123+
assert!(parse_rs(&config, "// min-llvm-version: 9.0").ignore);
124124

125-
config.llvm_version = Some("9.0.1-rust-1.43.0-dev".to_owned());
126-
assert!(parse_rs(&config, "// min-llvm-version 9.2").ignore);
125+
config.llvm_version = Some(90001);
126+
assert!(parse_rs(&config, "// min-llvm-version: 9.2").ignore);
127127

128-
config.llvm_version = Some("9.3.1-rust-1.43.0-dev".to_owned());
129-
assert!(!parse_rs(&config, "// min-llvm-version 9.2").ignore);
128+
config.llvm_version = Some(90301);
129+
assert!(!parse_rs(&config, "// min-llvm-version: 9.2").ignore);
130130

131-
config.llvm_version = Some("10.0.0-rust".to_owned());
132-
assert!(!parse_rs(&config, "// min-llvm-version 9.0").ignore);
131+
config.llvm_version = Some(100000);
132+
assert!(!parse_rs(&config, "// min-llvm-version: 9.0").ignore);
133133
}
134134

135135
#[test]
@@ -220,3 +220,18 @@ fn sanitizers() {
220220
assert!(parse_rs(&config, "// needs-sanitizer-memory").ignore);
221221
assert!(parse_rs(&config, "// needs-sanitizer-thread").ignore);
222222
}
223+
224+
#[test]
225+
fn test_extract_version_range() {
226+
use super::{extract_llvm_version, extract_version_range};
227+
228+
assert_eq!(extract_version_range("1.2.3 - 4.5.6", extract_llvm_version), Some((10203, 40506)));
229+
assert_eq!(extract_version_range("0 - 4.5.6", extract_llvm_version), Some((0, 40506)));
230+
assert_eq!(extract_version_range("1.2.3 -", extract_llvm_version), None);
231+
assert_eq!(extract_version_range("1.2.3 - ", extract_llvm_version), None);
232+
assert_eq!(extract_version_range("- 4.5.6", extract_llvm_version), None);
233+
assert_eq!(extract_version_range("-", extract_llvm_version), None);
234+
assert_eq!(extract_version_range(" - 4.5.6", extract_llvm_version), None);
235+
assert_eq!(extract_version_range(" - 4.5.6", extract_llvm_version), None);
236+
assert_eq!(extract_version_range("0 -", extract_llvm_version), None);
237+
}

‎src/tools/compiletest/src/main.rs

Lines changed: 66 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,20 @@ pub fn parse_config(args: Vec<String>) -> Config {
166166
let cdb = 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);
169-
let (lldb_version, lldb_native_rust) = extract_lldb_version(matches.opt_str("lldb-version"));
170-
171-
let color = match matches.opt_str("color").as_ref().map(|x| &**x) {
169+
let (lldb_version, lldb_native_rust) = matches
170+
.opt_str("lldb-version")
171+
.as_deref()
172+
.and_then(extract_lldb_version)
173+
.map(|(v, b)| (Some(v), b))
174+
.unwrap_or((None, false));
175+
let color = match matches.opt_str("color").as_deref() {
172176
Some("auto") | None => ColorConfig::AutoColor,
173177
Some("always") => ColorConfig::AlwaysColor,
174178
Some("never") => ColorConfig::NeverColor,
175179
Some(x) => panic!("argument for --color must be auto, always, or never, but found `{}`", x),
176180
};
181+
let llvm_version =
182+
matches.opt_str("llvm-version").as_deref().and_then(header::extract_llvm_version);
177183

178184
let src_base = opt_path(matches, "src-base");
179185
let run_ignored = matches.opt_present("ignored");
@@ -215,7 +221,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
215221
gdb_native_rust,
216222
lldb_version,
217223
lldb_native_rust,
218-
llvm_version: matches.opt_str("llvm-version"),
224+
llvm_version,
219225
system_llvm: matches.opt_present("system-llvm"),
220226
android_cross_path,
221227
adb_path: opt_str2(matches.opt_str("adb-path")),
@@ -254,7 +260,7 @@ pub fn log_config(config: &Config) {
254260
logv(c, format!("stage_id: {}", config.stage_id));
255261
logv(c, format!("mode: {}", config.mode));
256262
logv(c, format!("run_ignored: {}", config.run_ignored));
257-
logv(c, format!("filter: {}", opt_str(&config.filter.as_ref().map(|re| re.to_owned()))));
263+
logv(c, format!("filter: {}", opt_str(&config.filter)));
258264
logv(c, format!("filter_exact: {}", config.filter_exact));
259265
logv(
260266
c,
@@ -403,17 +409,14 @@ fn configure_lldb(config: &Config) -> Option<Config> {
403409
return None;
404410
}
405411

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

419422
// Some older versions of LLDB seem to have problems with multiple
@@ -727,9 +730,7 @@ fn make_test_closure(
727730
let config = config.clone();
728731
let testpaths = testpaths.clone();
729732
let revision = revision.cloned();
730-
test::DynTestFn(Box::new(move || {
731-
runtest::run(config, &testpaths, revision.as_ref().map(|s| s.as_str()))
732-
}))
733+
test::DynTestFn(Box::new(move || runtest::run(config, &testpaths, revision.as_deref())))
733734
}
734735

735736
/// Returns `true` if the given target is an Android target for the
@@ -845,75 +846,40 @@ fn extract_gdb_version(full_version_line: &str) -> Option<u32> {
845846
// This particular form is documented in the GNU coding standards:
846847
// https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html#g_t_002d_002dversion
847848

848-
// don't start parsing in the middle of a number
849-
let mut prev_was_digit = false;
850-
let mut in_parens = false;
851-
for (pos, c) in full_version_line.char_indices() {
852-
if in_parens {
853-
if c == ')' {
854-
in_parens = false;
855-
}
856-
continue;
857-
} else if c == '(' {
858-
in_parens = true;
859-
continue;
860-
}
861-
862-
if prev_was_digit || !c.is_digit(10) {
863-
prev_was_digit = c.is_digit(10);
864-
continue;
849+
let mut splits = full_version_line.rsplit(' ');
850+
let version_string = splits.next().unwrap();
851+
852+
let mut splits = version_string.split('.');
853+
let major = splits.next().unwrap();
854+
let minor = splits.next().unwrap();
855+
let patch = splits.next();
856+
857+
let major: u32 = major.parse().unwrap();
858+
let (minor, patch): (u32, u32) = match minor.find(not_a_digit) {
859+
None => {
860+
let minor = minor.parse().unwrap();
861+
let patch: u32 = match patch {
862+
Some(patch) => match patch.find(not_a_digit) {
863+
None => patch.parse().unwrap(),
864+
Some(idx) if idx > 3 => 0,
865+
Some(idx) => patch[..idx].parse().unwrap(),
866+
},
867+
None => 0,
868+
};
869+
(minor, patch)
865870
}
866-
867-
prev_was_digit = true;
868-
869-
let line = &full_version_line[pos..];
870-
871-
let next_split = match line.find(|c: char| !c.is_digit(10)) {
872-
Some(idx) => idx,
873-
None => continue, // no minor version
874-
};
875-
876-
if line.as_bytes()[next_split] != b'.' {
877-
continue; // no minor version
871+
// There is no patch version after minor-date (e.g. "4-2012").
872+
Some(idx) => {
873+
let minor = minor[..idx].parse().unwrap();
874+
(minor, 0)
878875
}
876+
};
879877

880-
let major = &line[..next_split];
881-
let line = &line[next_split + 1..];
882-
883-
let (minor, patch) = match line.find(|c: char| !c.is_digit(10)) {
884-
Some(idx) => {
885-
if line.as_bytes()[idx] == b'.' {
886-
let patch = &line[idx + 1..];
887-
888-
let patch_len =
889-
patch.find(|c: char| !c.is_digit(10)).unwrap_or_else(|| patch.len());
890-
let patch = &patch[..patch_len];
891-
let patch = if patch_len > 3 || patch_len == 0 { None } else { Some(patch) };
892-
893-
(&line[..idx], patch)
894-
} else {
895-
(&line[..idx], None)
896-
}
897-
}
898-
None => (line, None),
899-
};
900-
901-
if minor.is_empty() {
902-
continue;
903-
}
904-
905-
let major: u32 = major.parse().unwrap();
906-
let minor: u32 = minor.parse().unwrap();
907-
let patch: u32 = patch.unwrap_or("0").parse().unwrap();
908-
909-
return Some(((major * 1000) + minor) * 1000 + patch);
910-
}
911-
912-
None
878+
Some(((major * 1000) + minor) * 1000 + patch)
913879
}
914880

915881
/// Returns (LLDB version, LLDB is rust-enabled)
916-
fn extract_lldb_version(full_version_line: Option<String>) -> (Option<String>, bool) {
882+
fn extract_lldb_version(full_version_line: &str) -> Option<(u32, bool)> {
917883
// Extract the major LLDB version from the given version string.
918884
// LLDB version strings are different for Apple and non-Apple platforms.
919885
// The Apple variant looks like this:
@@ -922,7 +888,7 @@ fn extract_lldb_version(full_version_line: Option<String>) -> (Option<String>, b
922888
// lldb-300.2.51 (new versions)
923889
//
924890
// We are only interested in the major version number, so this function
925-
// will return `Some("179")` and `Some("300")` respectively.
891+
// will return `Some(179)` and `Some(300)` respectively.
926892
//
927893
// Upstream versions look like:
928894
// lldb version 6.0.1
@@ -934,53 +900,24 @@ fn extract_lldb_version(full_version_line: Option<String>) -> (Option<String>, b
934900
// normally fine because the only non-Apple version we test is
935901
// rust-enabled.
936902

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

974-
if full_version_line.starts_with("lldb version ") {
975-
let vers = full_version_line[13..]
976-
.chars()
977-
.take_while(|c| c.is_digit(10))
978-
.collect::<String>();
979-
if !vers.is_empty() {
980-
return (Some(vers + "00"), full_version_line.contains("rust-enabled"));
981-
}
982-
}
905+
if let Some(apple_ver) =
906+
full_version_line.strip_prefix("LLDB-").or_else(|| full_version_line.strip_prefix("lldb-"))
907+
{
908+
if let Some(idx) = apple_ver.find(not_a_digit) {
909+
let version: u32 = apple_ver[..idx].parse().unwrap();
910+
return Some((version, full_version_line.contains("rust-enabled")));
911+
}
912+
} else if let Some(lldb_ver) = full_version_line.strip_prefix("lldb version ") {
913+
if let Some(idx) = lldb_ver.find(not_a_digit) {
914+
let version: u32 = lldb_ver[..idx].parse().unwrap();
915+
return Some((version * 100, full_version_line.contains("rust-enabled")));
983916
}
984917
}
985-
(None, false)
918+
None
919+
}
920+
921+
fn not_a_digit(c: char) -> bool {
922+
!c.is_digit(10)
986923
}

‎src/tools/compiletest/src/tests.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use super::header::extract_llvm_version;
12
use super::*;
23

34
#[test]
45
fn test_extract_gdb_version() {
5-
macro_rules! test { ($($expectation:tt: $input:tt,)*) => {{$(
6+
macro_rules! test { ($($expectation:literal: $input:literal,)*) => {{$(
67
assert_eq!(extract_gdb_version($input), Some($expectation));
78
)*}}}
89

@@ -41,6 +42,17 @@ fn test_extract_gdb_version() {
4142
}
4243
}
4344

45+
#[test]
46+
fn test_extract_lldb_version() {
47+
// Apple variants
48+
assert_eq!(extract_lldb_version("LLDB-179.5"), Some((179, false)));
49+
assert_eq!(extract_lldb_version("lldb-300.2.51"), Some((300, false)));
50+
51+
// Upstream versions
52+
assert_eq!(extract_lldb_version("lldb version 6.0.1"), Some((600, false)));
53+
assert_eq!(extract_lldb_version("lldb version 9.0.0"), Some((900, false)));
54+
}
55+
4456
#[test]
4557
fn is_test_test() {
4658
assert_eq!(true, is_test(&OsString::from("a_test.rs")));
@@ -49,3 +61,11 @@ fn is_test_test() {
4961
assert_eq!(false, is_test(&OsString::from("#a_dog_gif")));
5062
assert_eq!(false, is_test(&OsString::from("~a_temp_file")));
5163
}
64+
65+
#[test]
66+
fn test_extract_llvm_version() {
67+
assert_eq!(extract_llvm_version("8.1.2-rust"), Some(80102));
68+
assert_eq!(extract_llvm_version("9.0.1-rust-1.43.0-dev"), Some(90001));
69+
assert_eq!(extract_llvm_version("9.3.1-rust-1.43.0-dev"), Some(90301));
70+
assert_eq!(extract_llvm_version("10.0.0-rust"), Some(100000));
71+
}

0 commit comments

Comments
 (0)
Please sign in to comment.