@@ -132,72 +132,46 @@ impl EarlyProps {
132
132
133
133
fn ignore_gdb ( config : & Config , line : & str ) -> bool {
134
134
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
+ } ) ;
137
140
138
141
if start_ver != end_ver {
139
142
panic ! ( "Expected single GDB version" )
140
143
}
141
144
// Ignore if actual version is smaller the minimum required
142
145
// 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
+ } ) ;
146
152
147
153
if max_version < min_version {
148
154
panic ! ( "Malformed GDB version range: max < min" )
149
155
}
150
156
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;
185
158
}
186
- _ => panic ! ( ERROR_MESSAGE ) ,
187
159
}
160
+ false
188
161
}
189
162
190
163
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
+ } ) ;
198
172
// Ignore if actual version is smaller the minimum required
199
173
// version
200
- lldb_version_to_int ( actual_version) < lldb_version_to_int ( min_version)
174
+ actual_version < min_version
201
175
} else if line. starts_with ( "rust-lldb" ) && !config. lldb_native_rust {
202
176
true
203
177
} else {
@@ -212,69 +186,38 @@ impl EarlyProps {
212
186
if config. system_llvm && line. starts_with ( "no-system-llvm" ) {
213
187
return true ;
214
188
}
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 ( ) ;
223
192
// Ignore if actual version is smaller the minimum required
224
193
// 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 ( ) ;
232
199
// Ignore if using system LLVM and actual version
233
200
// 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" )
256
211
}
212
+ // Ignore if version lies inside of range.
213
+ actual_version >= v_min && actual_version <= v_max
257
214
} else {
258
215
false
259
216
}
260
217
} else {
261
218
false
262
219
}
263
220
}
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
- }
278
221
}
279
222
}
280
223
@@ -944,12 +887,6 @@ impl Config {
944
887
}
945
888
}
946
889
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
-
953
890
fn expand_variables ( mut value : String , config : & Config ) -> String {
954
891
const CWD : & ' static str = "{{cwd}}" ;
955
892
const SRC_BASE : & ' static str = "{{src-base}}" ;
@@ -990,3 +927,49 @@ fn parse_normalization_string(line: &mut &str) -> Option<String> {
990
927
* line = & line[ end + 1 ..] ;
991
928
Some ( result)
992
929
}
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
+ }
0 commit comments