@@ -4,10 +4,9 @@ use std::fs::File;
4
4
use std:: io:: prelude:: * ;
5
5
use std:: io:: BufReader ;
6
6
use std:: path:: { Path , PathBuf } ;
7
+ use std:: process:: Command ;
7
8
8
- use lazy_static:: lazy_static;
9
- use regex:: Regex ;
10
- use tracing:: * ;
9
+ use tracing:: { self , * } ;
11
10
12
11
use crate :: common:: { CompareMode , Config , Debugger , FailMode , Mode , PanicStrategy , PassMode } ;
13
12
use crate :: util;
@@ -707,35 +706,9 @@ impl Config {
707
706
}
708
707
709
708
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 ( ) ) ;
739
712
740
713
let is_match = name == "test" ||
741
714
target == name || // triple
@@ -763,18 +736,30 @@ impl Config {
763
736
Some ( Debugger :: Gdb ) => name == "gdb" ,
764
737
Some ( Debugger :: Lldb ) => name == "lldb" ,
765
738
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) ;
774
740
775
741
if is_match { EvaluatedProp :: Match } else { EvaluatedProp :: NoMatch }
776
742
}
777
743
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
+
778
763
fn has_prop_prefix ( & self , line : & str , prefix : & str ) -> bool {
779
764
// returns whether this line contains this prefix or not. For prefix
780
765
// "ignore", returns true if line says "ignore-x86_64", "ignore-arch",
0 commit comments