@@ -4,10 +4,9 @@ use std::fs::File;
44use std:: io:: prelude:: * ;
55use std:: io:: BufReader ;
66use std:: path:: { Path , PathBuf } ;
7+ use std:: process:: Command ;
78
8- use lazy_static:: lazy_static;
9- use regex:: Regex ;
10- use tracing:: * ;
9+ use tracing:: { self , * } ;
1110
1211use crate :: common:: { CompareMode , Config , Debugger , FailMode , Mode , PanicStrategy , PassMode } ;
1312use crate :: util;
@@ -707,35 +706,9 @@ impl Config {
707706 }
708707
709708 fn evaluate_prop_for_target ( & self , prop : & str , target : & str ) -> EvaluatedProp {
710- // This matches optional whitespace, followed by a group containing a series of word
711- // characters (including '_' and '-'), followed optionally by a sequence consisting
712- // of a colon, optional whitespace, and another group containing word characters.
713- //
714- // Matches in full:
715- // cfg-target-has-atomic: 128
716- // cfg-target-has-atomic:128
717- // cfg-target-has-atomic
718- //
719- // Matches up to the first space (exclusive):
720- // ignore-test - This test really shouldn't ever be run
721- //
722- // Matches up to the second space (exclusive):
723- // cfg-target-has-atomic: 128 - this requires fancy newfangled atomics
724- //
725- // Matches up to the second colon (exclusive)
726- // cfg-target-has-atomic:128: I put an extra colon here to confuse other programmers!
727- //
728- // Does not match:
729- // (a line consisting solely of whitespace)
730- // &*#$ cfg-target-has-atomic
731- //
732- lazy_static ! {
733- static ref CFG_REGEX : Regex = Regex :: new( r"^\s*([\w-]+)(?::\s*([\w-]+))?" ) . unwrap( ) ;
734- }
735-
736- let captures = CFG_REGEX . captures ( & prop) . unwrap ( ) ;
737- let name = captures. get ( 1 ) . unwrap ( ) . as_str ( ) ;
738- let maybe_value = captures. get ( 2 ) . map ( |v| v. as_str ( ) . trim ( ) ) ;
709+ let mut iter = prop. split ( & [ ':' , ' ' ] [ ..] ) ;
710+ let name = iter. next ( ) . unwrap ( ) ;
711+ let maybe_value = iter. find ( |s| !s. is_empty ( ) ) ;
739712
740713 let is_match = name == "test" ||
741714 target == name || // triple
@@ -763,18 +736,30 @@ impl Config {
763736 Some ( Debugger :: Gdb ) => name == "gdb" ,
764737 Some ( Debugger :: Lldb ) => name == "lldb" ,
765738 None => false ,
766- } ||
767- match name. strip_prefix ( "cfg-" ) {
768- Some ( rustc_cfg_name) => {
769- let cfg_data = util:: fetch_cfg_from_rustc_for_target ( & self . rustc_path , target) ;
770- util:: cfg_has ( & cfg_data, rustc_cfg_name, maybe_value)
771- } ,
772- None => false
773- } ;
739+ } || name == "cfg" && self . cfg_matches_for_target ( maybe_value. unwrap ( ) , target) ;
774740
775741 if is_match { EvaluatedProp :: Match } else { EvaluatedProp :: NoMatch }
776742 }
777743
744+ fn cfg_matches_for_target ( & self , value : & str , target : & str ) -> bool {
745+ let whitespace_or_double_quote = |c : char | c. is_whitespace ( ) || c == '"' ;
746+
747+ let value = value. replace ( whitespace_or_double_quote, "" ) ;
748+
749+ let cfg_data = Command :: new ( & self . rustc_path )
750+ . args ( & [ "--target" , & target] )
751+ . args ( & [ "--print" , "cfg" ] )
752+ . output ( )
753+ . unwrap ( )
754+ . stdout ;
755+ let cfg_data = String :: from_utf8 ( cfg_data) . unwrap ( ) ;
756+ let cfg_data = cfg_data. replace ( '"' , "" ) ;
757+
758+ let matches_value = |line : & str | line == value || line. split ( '=' ) . next ( ) . unwrap ( ) == value;
759+
760+ cfg_data. lines ( ) . any ( matches_value)
761+ }
762+
778763 fn has_prop_prefix ( & self , line : & str , prefix : & str ) -> bool {
779764 // returns whether this line contains this prefix or not. For prefix
780765 // "ignore", returns true if line says "ignore-x86_64", "ignore-arch",
0 commit comments