@@ -579,45 +579,41 @@ def dist_test(self, source, flags):
579
579
return test
580
580
581
581
def dist_info (self ):
582
- """Return a string containing all environment information, required
583
- by the abstract class '_CCompiler' to discovering the platform
584
- environment, also used as a cache factor in order to detect
585
- any changes from outside.
582
+ """
583
+ Return a tuple containing info about (platform, compiler, extra_args),
584
+ required by the abstract class '_CCompiler' for discovering the
585
+ platform environment. This is also used as a cache factor in order
586
+ to detect any changes happening from outside.
586
587
"""
587
588
if hasattr (self , "_dist_info" ):
588
589
return self ._dist_info
589
- # play it safe
590
- cc_info = ""
591
- compiler = getattr (self ._ccompiler , "compiler" , None )
592
- if compiler is not None :
593
- if isinstance (compiler , str ):
594
- cc_info += compiler
595
- elif hasattr (compiler , "__iter__" ):
596
- cc_info += ' ' .join (compiler )
597
- # in case if 'compiler' attribute doesn't provide anything
598
- cc_type = getattr (self ._ccompiler , "compiler_type" , "" )
599
- if cc_type in ("intelem" , "intelemw" , "mingw64" ):
600
- cc_info += "x86_64"
590
+
591
+ cc_type = getattr (self ._ccompiler , "compiler_type" , '' )
592
+ if cc_type in ("intelem" , "intelemw" ):
593
+ platform = "x86_64"
601
594
elif cc_type in ("intel" , "intelw" , "intele" ):
602
- cc_info += "x86"
603
- elif cc_type in ("msvc" , "mingw32" ):
604
- import platform
605
- if platform .architecture ()[0 ] == "32bit" :
606
- cc_info += "x86"
595
+ platform = "x86"
596
+ else :
597
+ from distutils .util import get_platform
598
+ platform = get_platform ()
599
+
600
+ cc_info = getattr (self ._ccompiler , "compiler" , getattr (self ._ccompiler , "compiler_so" , '' ))
601
+ if not cc_type or cc_type == "unix" :
602
+ if hasattr (cc_info , "__iter__" ):
603
+ compiler = cc_info [0 ]
607
604
else :
608
- cc_info += "x86_64"
605
+ compiler = str ( cc_info )
609
606
else :
610
- # the last hope, too bad for cross-compiling
611
- import platform
612
- cc_info += platform .machine ()
607
+ compiler = cc_type
613
608
614
- cc_info += cc_type
615
- cflags = os .environ .get ("CFLAGS" , "" )
616
- if cflags not in cc_info :
617
- cc_info += cflags
609
+ if hasattr (cc_info , "__iter__" ) and len (cc_info ) > 1 :
610
+ extra_args = ' ' .join (cc_info [1 :])
611
+ else :
612
+ extra_args = os .environ .get ("CFLAGS" , "" )
613
+ extra_args += os .environ .get ("CPPFLAGS" , "" )
618
614
619
- self ._dist_info = cc_info
620
- return cc_info
615
+ self ._dist_info = ( platform , compiler , extra_args )
616
+ return self . _dist_info
621
617
622
618
@staticmethod
623
619
def dist_error (* args ):
@@ -893,57 +889,56 @@ class _CCompiler(object):
893
889
def __init__ (self ):
894
890
if hasattr (self , "cc_is_cached" ):
895
891
return
896
- to_detect = (
897
- # attr regex
898
- (
899
- ("cc_on_x64" , "^(x|x86_|amd)64" ),
900
- ("cc_on_x86" , "^(x86|i386|i686)" ),
901
- ("cc_on_ppc64le" , "^(powerpc|ppc)64(el|le)" ),
902
- ("cc_on_ppc64" , "^(powerpc|ppc)64" ),
903
- ("cc_on_armhf" , "^arm" ),
904
- ("cc_on_aarch64" , "^aarch64" ),
905
- # priority is given to first of string
906
- # if it fail we search in the rest, due
907
- # to append platform.machine() at the end,
908
- # check method 'dist_info()' for more clarification.
909
- ("cc_on_x64" , ".*(x|x86_|amd)64.*" ),
910
- ("cc_on_x86" , ".*(x86|i386|i686).*" ),
911
- ("cc_on_ppc64le" , ".*(powerpc|ppc)64(el|le).*" ),
912
- ("cc_on_ppc64" , ".*(powerpc|ppc)64.*" ),
913
- ("cc_on_armhf" , ".*arm.*" ),
914
- ("cc_on_aarch64" , ".*aarch64.*" ),
915
- # undefined platform
916
- ("cc_on_noarch" , "" ),
917
- ),
918
- (
919
- ("cc_is_gcc" , r".*(gcc|gnu\-g).*" ),
920
- ("cc_is_clang" , ".*clang.*" ),
921
- ("cc_is_iccw" , ".*(intelw|intelemw|iccw).*" ), # intel msvc like
922
- ("cc_is_icc" , ".*(intel|icc).*" ), # intel unix like
923
- ("cc_is_msvc" , ".*msvc.*" ),
924
- ("cc_is_nocc" , "" ),
925
- ),
926
- (("cc_has_debug" , ".*(O0|Od|ggdb|coverage|debug:full).*" ),),
927
- (("cc_has_native" , ".*(-march=native|-xHost|/QxHost).*" ),),
928
- # in case if the class run with -DNPY_DISABLE_OPTIMIZATION
929
- (("cc_noopt" , ".*DISABLE_OPT.*" ),),
892
+ # attr regex
893
+ detect_arch = (
894
+ ("cc_on_x64" , ".*(x|x86_|amd)64.*" ),
895
+ ("cc_on_x86" , ".*(win32|x86|i386|i686).*" ),
896
+ ("cc_on_ppc64le" , ".*(powerpc|ppc)64(el|le).*" ),
897
+ ("cc_on_ppc64" , ".*(powerpc|ppc)64.*" ),
898
+ ("cc_on_aarch64" , ".*(aarch64|arm64).*" ),
899
+ ("cc_on_armhf" , ".*arm.*" ),
900
+ # undefined platform
901
+ ("cc_on_noarch" , "" ),
902
+ )
903
+ detect_compiler = (
904
+ ("cc_is_gcc" , r".*(gcc|gnu\-g).*" ),
905
+ ("cc_is_clang" , ".*clang.*" ),
906
+ ("cc_is_iccw" , ".*(intelw|intelemw|iccw).*" ), # intel msvc like
907
+ ("cc_is_icc" , ".*(intel|icc).*" ), # intel unix like
908
+ ("cc_is_msvc" , ".*msvc.*" ),
909
+ # undefined compiler will be treat it as gcc
910
+ ("cc_is_nocc" , "" ),
911
+ )
912
+ detect_args = (
913
+ ("cc_has_debug" , ".*(O0|Od|ggdb|coverage|debug:full).*" ),
914
+ ("cc_has_native" , ".*(-march=native|-xHost|/QxHost).*" ),
915
+ # in case if the class run with -DNPY_DISABLE_OPTIMIZATION
916
+ ("cc_noopt" , ".*DISABLE_OPT.*" ),
930
917
)
931
- for section in to_detect :
932
- for attr , rgex in section :
933
- setattr (self , attr , False )
934
918
935
919
dist_info = self .dist_info ()
936
- for section in to_detect :
920
+ platform , compiler_info , extra_args = dist_info
921
+ # set False to all attrs
922
+ for section in (detect_arch , detect_compiler , detect_args ):
937
923
for attr , rgex in section :
938
- if rgex and not re .match (rgex , dist_info , re .IGNORECASE ):
924
+ setattr (self , attr , False )
925
+
926
+ for detect , searchin in ((detect_arch , platform ), (detect_compiler , compiler_info )):
927
+ for attr , rgex in detect :
928
+ if rgex and not re .match (rgex , searchin , re .IGNORECASE ):
939
929
continue
940
930
setattr (self , attr , True )
941
931
break
942
932
933
+ for attr , rgex in detect_args :
934
+ if rgex and not re .match (rgex , extra_args , re .IGNORECASE ):
935
+ continue
936
+ setattr (self , attr , True )
937
+
943
938
if self .cc_on_noarch :
944
939
self .dist_log (
945
- "unable to detect CPU arch via compiler info, "
946
- "optimization is disabled \n info << %s >> " % dist_info ,
940
+ "unable to detect CPU architecture which lead to disable the optimization. "
941
+ f"check dist_info:<< \n { dist_info } \n >>" ,
947
942
stderr = True
948
943
)
949
944
self .cc_noopt = True
@@ -958,8 +953,9 @@ def __init__(self):
958
953
but still has the same gcc optimization flags.
959
954
"""
960
955
self .dist_log (
961
- "unable to detect compiler name via info <<\n %s\n >> "
962
- "treating it as a gcc" % dist_info ,
956
+ "unable to detect compiler type which leads to treating it as GCC. "
957
+ "this is a normal behavior if you're using gcc-like compiler such as MinGW or IBM/XLC."
958
+ f"check dist_info:<<\n { dist_info } \n >>" ,
963
959
stderr = True
964
960
)
965
961
self .cc_is_gcc = True
@@ -2304,19 +2300,25 @@ def generate_dispatch_header(self, header_path):
2304
2300
2305
2301
def report (self , full = False ):
2306
2302
report = []
2303
+ platform_rows = []
2307
2304
baseline_rows = []
2308
2305
dispatch_rows = []
2306
+ report .append (("Platform" , platform_rows ))
2307
+ report .append (("" , "" ))
2309
2308
report .append (("CPU baseline" , baseline_rows ))
2310
2309
report .append (("" , "" ))
2311
2310
report .append (("CPU dispatch" , dispatch_rows ))
2312
2311
2312
+ ########## platform ##########
2313
+ platform_rows .append (("Architecture" , (
2314
+ "unsupported" if self .cc_on_noarch else self .cc_march )
2315
+ ))
2316
+ platform_rows .append (("Compiler" , (
2317
+ "unix-like" if self .cc_is_nocc else self .cc_name )
2318
+ ))
2313
2319
########## baseline ##########
2314
2320
if self .cc_noopt :
2315
- baseline_rows .append ((
2316
- "Requested" , "optimization disabled %s" % (
2317
- "(unsupported arch)" if self .cc_on_noarch else ""
2318
- )
2319
- ))
2321
+ baseline_rows .append (("Requested" , "optimization disabled" ))
2320
2322
else :
2321
2323
baseline_rows .append (("Requested" , repr (self ._requested_baseline )))
2322
2324
@@ -2337,11 +2339,7 @@ def report(self, full=False):
2337
2339
2338
2340
########## dispatch ##########
2339
2341
if self .cc_noopt :
2340
- dispatch_rows .append ((
2341
- "Requested" , "optimization disabled %s" % (
2342
- "(unsupported arch)" if self .cc_on_noarch else ""
2343
- )
2344
- ))
2342
+ baseline_rows .append (("Requested" , "optimization disabled" ))
2345
2343
else :
2346
2344
dispatch_rows .append (("Requested" , repr (self ._requested_dispatch )))
2347
2345
0 commit comments