9
9
import sys
10
10
import sysconfig
11
11
from glob import glob
12
+ from _bootsubprocess import _waitstatus_to_exitcode as waitstatus_to_exitcode
12
13
13
14
14
15
try :
@@ -95,6 +96,11 @@ def get_platform():
95
96
"""
96
97
97
98
99
+ def run_command (cmd ):
100
+ status = os .system (cmd )
101
+ return waitstatus_to_exitcode (status )
102
+
103
+
98
104
# Set common compiler and linker flags derived from the Makefile,
99
105
# reserved for building the interpreter and the stdlib modules.
100
106
# See bpo-21121 and bpo-35257
@@ -176,10 +182,10 @@ def macosx_sdk_root():
176
182
os .unlink (tmpfile )
177
183
except :
178
184
pass
179
- ret = os . system ('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc , tmpfile ))
185
+ ret = run_command ('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc , tmpfile ))
180
186
in_incdirs = False
181
187
try :
182
- if ret >> 8 == 0 :
188
+ if ret == 0 :
183
189
with open (tmpfile ) as fp :
184
190
for line in fp .readlines ():
185
191
if line .startswith ("#include <...>" ):
@@ -595,11 +601,11 @@ def add_multiarch_paths(self):
595
601
tmpfile = os .path .join (self .build_temp , 'multiarch' )
596
602
if not os .path .exists (self .build_temp ):
597
603
os .makedirs (self .build_temp )
598
- ret = os . system (
604
+ ret = run_command (
599
605
'%s -print-multiarch > %s 2> /dev/null' % (cc , tmpfile ))
600
606
multiarch_path_component = ''
601
607
try :
602
- if ret >> 8 == 0 :
608
+ if ret == 0 :
603
609
with open (tmpfile ) as fp :
604
610
multiarch_path_component = fp .readline ().strip ()
605
611
finally :
@@ -620,11 +626,11 @@ def add_multiarch_paths(self):
620
626
tmpfile = os .path .join (self .build_temp , 'multiarch' )
621
627
if not os .path .exists (self .build_temp ):
622
628
os .makedirs (self .build_temp )
623
- ret = os . system (
629
+ ret = run_command (
624
630
'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
625
631
(opt , tmpfile ))
626
632
try :
627
- if ret >> 8 == 0 :
633
+ if ret == 0 :
628
634
with open (tmpfile ) as fp :
629
635
multiarch_path_component = fp .readline ().strip ()
630
636
add_dir_to_list (self .compiler .library_dirs ,
@@ -639,12 +645,12 @@ def add_cross_compiling_paths(self):
639
645
tmpfile = os .path .join (self .build_temp , 'ccpaths' )
640
646
if not os .path .exists (self .build_temp ):
641
647
os .makedirs (self .build_temp )
642
- ret = os . system ('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc , tmpfile ))
648
+ ret = run_command ('%s -E -v - </dev/null 2>%s 1>/dev/null' % (cc , tmpfile ))
643
649
is_gcc = False
644
650
is_clang = False
645
651
in_incdirs = False
646
652
try :
647
- if ret >> 8 == 0 :
653
+ if ret == 0 :
648
654
with open (tmpfile ) as fp :
649
655
for line in fp .readlines ():
650
656
if line .startswith ("gcc version" ):
@@ -932,14 +938,14 @@ def detect_readline_curses(self):
932
938
# Determine if readline is already linked against curses or tinfo.
933
939
if do_readline :
934
940
if CROSS_COMPILING :
935
- ret = os . system ("%s -d %s | grep '(NEEDED)' > %s" \
941
+ ret = run_command ("%s -d %s | grep '(NEEDED)' > %s"
936
942
% (sysconfig .get_config_var ('READELF' ),
937
943
do_readline , tmpfile ))
938
944
elif find_executable ('ldd' ):
939
- ret = os . system ("ldd %s > %s" % (do_readline , tmpfile ))
945
+ ret = run_command ("ldd %s > %s" % (do_readline , tmpfile ))
940
946
else :
941
- ret = 256
942
- if ret >> 8 == 0 :
947
+ ret = 1
948
+ if ret == 0 :
943
949
with open (tmpfile ) as fp :
944
950
for ln in fp :
945
951
if 'curses' in ln :
@@ -1654,9 +1660,9 @@ def detect_expat_elementtree(self):
1654
1660
]
1655
1661
1656
1662
cc = sysconfig .get_config_var ('CC' ).split ()[0 ]
1657
- ret = os . system (
1663
+ ret = run_command (
1658
1664
'"%s" -Werror -Wno-unreachable-code -E -xc /dev/null >/dev/null 2>&1' % cc )
1659
- if ret >> 8 == 0 :
1665
+ if ret == 0 :
1660
1666
extra_compile_args .append ('-Wno-unreachable-code' )
1661
1667
1662
1668
self .add (Extension ('pyexpat' ,
@@ -1859,9 +1865,9 @@ def detect_tkinter_darwin(self):
1859
1865
# Note: cannot use os.popen or subprocess here, that
1860
1866
# requires extensions that are not available here.
1861
1867
if is_macosx_sdk_path (F ):
1862
- os . system ("file %s/Tk.framework/Tk | grep 'for architecture' > %s" % (os .path .join (sysroot , F [1 :]), tmpfile ))
1868
+ run_command ("file %s/Tk.framework/Tk | grep 'for architecture' > %s" % (os .path .join (sysroot , F [1 :]), tmpfile ))
1863
1869
else :
1864
- os . system ("file %s/Tk.framework/Tk | grep 'for architecture' > %s" % (F , tmpfile ))
1870
+ run_command ("file %s/Tk.framework/Tk | grep 'for architecture' > %s" % (F , tmpfile ))
1865
1871
1866
1872
with open (tmpfile ) as fp :
1867
1873
detected_archs = []
0 commit comments