@@ -181,69 +181,35 @@ impl EarlyProps {
181181 if config. system_llvm && line. starts_with ( "no-system-llvm" ) {
182182 return true ;
183183 }
184- if let Some ( ref actual_version) = config. llvm_version {
185- let actual_version = version_to_int ( actual_version) ;
186- if line. starts_with ( "min-llvm-version" ) {
187- let min_version = line
188- . trim_end ( )
189- . rsplit ( ' ' )
190- . next ( )
191- . expect ( "Malformed llvm version directive" ) ;
184+ if let Some ( actual_version) = config. llvm_version {
185+ if let Some ( rest) = line. strip_prefix ( "min-llvm-version:" ) . map ( str:: trim) {
186+ let min_version = extract_llvm_version ( rest) . unwrap ( ) ;
192187 // Ignore if actual version is smaller the minimum required
193188 // version
194- actual_version < version_to_int ( min_version)
195- } else if line. starts_with ( "min-system-llvm-version" ) {
196- let min_version = line
197- . trim_end ( )
198- . rsplit ( ' ' )
199- . next ( )
200- . expect ( "Malformed llvm version directive" ) ;
189+ actual_version < min_version
190+ } else if let Some ( rest) =
191+ line. strip_prefix ( "min-system-llvm-version:" ) . map ( str:: trim)
192+ {
193+ let min_version = extract_llvm_version ( rest) . unwrap ( ) ;
201194 // Ignore if using system LLVM and actual version
202195 // is smaller the minimum required version
203- config. system_llvm && actual_version < version_to_int ( min_version)
204- } else if line. starts_with ( "ignore-llvm-version" ) {
205- // Syntax is: "ignore-llvm-version <version1> [- <version2>]"
206- let range_components = line
207- . split ( ' ' )
208- . skip ( 1 ) // Skip the directive.
209- . map ( |s| s. trim ( ) )
210- . filter ( |word| !word. is_empty ( ) && word != & "-" )
211- . take ( 3 ) // 3 or more = invalid, so take at most 3.
212- . collect :: < Vec < & str > > ( ) ;
213- match range_components. len ( ) {
214- 1 => actual_version == version_to_int ( range_components[ 0 ] ) ,
215- 2 => {
216- let v_min = version_to_int ( range_components[ 0 ] ) ;
217- let v_max = version_to_int ( range_components[ 1 ] ) ;
218- if v_max < v_min {
219- panic ! ( "Malformed LLVM version range: max < min" )
220- }
221- // Ignore if version lies inside of range.
222- actual_version >= v_min && actual_version <= v_max
223- }
224- _ => panic ! ( "Malformed LLVM version directive" ) ,
196+ config. system_llvm && actual_version < min_version
197+ } else if let Some ( rest) = line. strip_prefix ( "ignore-llvm-version:" ) . map ( str:: trim)
198+ {
199+ // Syntax is: "ignore-llvm-version: <version1> [- <version2>]"
200+ let ( v_min, v_max) = extract_version_range ( rest, extract_llvm_version) ;
201+ if v_max < v_min {
202+ panic ! ( "Malformed LLVM version range: max < min" )
225203 }
204+ // Ignore if version lies inside of range.
205+ actual_version >= v_min && actual_version <= v_max
226206 } else {
227207 false
228208 }
229209 } else {
230210 false
231211 }
232212 }
233-
234- fn version_to_int ( version : & str ) -> u32 {
235- let version_without_suffix = version. trim_end_matches ( "git" ) . split ( '-' ) . next ( ) . unwrap ( ) ;
236- let components: Vec < u32 > = version_without_suffix
237- . split ( '.' )
238- . map ( |s| s. parse ( ) . expect ( "Malformed version component" ) )
239- . collect ( ) ;
240- match components. len ( ) {
241- 1 => components[ 0 ] * 10000 ,
242- 2 => components[ 0 ] * 10000 + components[ 1 ] * 100 ,
243- 3 => components[ 0 ] * 10000 + components[ 1 ] * 100 + components[ 2 ] ,
244- _ => panic ! ( "Malformed version" ) ,
245- }
246- }
247213 }
248214}
249215
@@ -954,6 +920,21 @@ fn parse_normalization_string(line: &mut &str) -> Option<String> {
954920 Some ( result)
955921}
956922
923+ pub fn extract_llvm_version ( version : & str ) -> Option < u32 > {
924+ let version_without_suffix = version. trim_end_matches ( "git" ) . split ( '-' ) . next ( ) . unwrap ( ) ;
925+ let components: Vec < u32 > = version_without_suffix
926+ . split ( '.' )
927+ . map ( |s| s. parse ( ) . expect ( "Malformed version component" ) )
928+ . collect ( ) ;
929+ let version = match * components {
930+ [ a] => a * 10_000 ,
931+ [ a, b] => a * 10_000 + b * 100 ,
932+ [ a, b, c] => a * 10_000 + b * 100 + c,
933+ _ => panic ! ( "Malformed version" ) ,
934+ } ;
935+ Some ( version)
936+ }
937+
957938// Takes a directive of the form "<version1> [- <version2>]",
958939// returns the numeric representation of <version1> and <version2> as
959940// tuple: (<version1> as u32, <version2> as u32)
0 commit comments