@@ -5,6 +5,8 @@ use std::io::prelude::*;
5
5
use std:: io:: BufReader ;
6
6
use std:: path:: { Path , PathBuf } ;
7
7
8
+ use lazy_static:: lazy_static;
9
+ use regex:: Regex ;
8
10
use tracing:: * ;
9
11
10
12
use crate :: common:: { CompareMode , Config , Debugger , FailMode , Mode , PanicStrategy , PassMode } ;
@@ -669,14 +671,42 @@ impl Config {
669
671
/// Parses a name-value directive which contains config-specific information, e.g., `ignore-x86`
670
672
/// or `normalize-stderr-32bit`.
671
673
fn parse_cfg_name_directive ( & self , line : & str , prefix : & str ) -> ParsedNameDirective {
674
+ // This matches optional whitespace, followed by a group containing a series of word
675
+ // characters (including '_' and '-'), followed optionally by a sequence consisting
676
+ // of a colon, optional whitespace, and another group containing word characters.
677
+ //
678
+ // Matches in full:
679
+ // cfg-target-has-atomic: 128
680
+ // cfg-target-has-atomic:128
681
+ // cfg-target-has-atomic
682
+ //
683
+ // Matches up to the first space (exclusive):
684
+ // ignore-test - This test really shouldn't ever be run
685
+ //
686
+ // Matches up to the second space (exclusive):
687
+ // cfg-target-has-atomic: 128 - this requires fancy newfangled atomics
688
+ //
689
+ // Matches up to the second colon (exclusive)
690
+ // cfg-target-has-atomic:128: I put an extra colon here to confuse other programmers!
691
+ //
692
+ // Does not match:
693
+ // (a line consisting solely of whitespace)
694
+ // &*#$ cfg-target-has-atomic
695
+ //
696
+ lazy_static ! {
697
+ static ref CFG_REGEX : Regex = Regex :: new( r"^\s*([\w-]+)(?::\s*([\w-]+))?" ) . unwrap( ) ;
698
+ }
699
+
672
700
if !line. as_bytes ( ) . starts_with ( prefix. as_bytes ( ) ) {
673
701
return ParsedNameDirective :: NoMatch ;
674
702
}
675
703
if line. as_bytes ( ) . get ( prefix. len ( ) ) != Some ( & b'-' ) {
676
704
return ParsedNameDirective :: NoMatch ;
677
705
}
678
706
679
- let name = line[ prefix. len ( ) + 1 ..] . split ( & [ ':' , ' ' ] [ ..] ) . next ( ) . unwrap ( ) ;
707
+ let captures = CFG_REGEX . captures ( & line[ & prefix. len ( ) + 1 ..] ) . unwrap ( ) ;
708
+ let name = captures. get ( 1 ) . unwrap ( ) . as_str ( ) ;
709
+ let maybe_value = captures. get ( 2 ) . map ( |v| v. as_str ( ) . trim ( ) ) ;
680
710
681
711
let is_match = name == "test" ||
682
712
self . target == name || // triple
@@ -704,6 +734,10 @@ impl Config {
704
734
Some ( Debugger :: Gdb ) => name == "gdb" ,
705
735
Some ( Debugger :: Lldb ) => name == "lldb" ,
706
736
None => false ,
737
+ } ||
738
+ match name. strip_prefix ( "cfg-" ) {
739
+ Some ( rustc_cfg_name) => util:: cfg_has ( & self . target_cfg , rustc_cfg_name, maybe_value) ,
740
+ None => false
707
741
} ;
708
742
709
743
if is_match { ParsedNameDirective :: Match } else { ParsedNameDirective :: NoMatch }
0 commit comments