Skip to content

Commit 216ed3c

Browse files
authored
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

13 files changed

+208
-253
lines changed

src/test/codegen/abi-efiapi.rs

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+88-105
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

+23-8
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+
}

0 commit comments

Comments
 (0)