Skip to content

Commit 6b982c2

Browse files
authored
bpo-40094: Add run_command() to setup.py (GH-19266)
1 parent 16d7567 commit 6b982c2

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

setup.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sys
1010
import sysconfig
1111
from glob import glob
12+
from _bootsubprocess import _waitstatus_to_exitcode as waitstatus_to_exitcode
1213

1314

1415
try:
@@ -95,6 +96,11 @@ def get_platform():
9596
"""
9697

9798

99+
def run_command(cmd):
100+
status = os.system(cmd)
101+
return waitstatus_to_exitcode(status)
102+
103+
98104
# Set common compiler and linker flags derived from the Makefile,
99105
# reserved for building the interpreter and the stdlib modules.
100106
# See bpo-21121 and bpo-35257
@@ -176,10 +182,10 @@ def macosx_sdk_root():
176182
os.unlink(tmpfile)
177183
except:
178184
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))
180186
in_incdirs = False
181187
try:
182-
if ret >> 8 == 0:
188+
if ret == 0:
183189
with open(tmpfile) as fp:
184190
for line in fp.readlines():
185191
if line.startswith("#include <...>"):
@@ -595,11 +601,11 @@ def add_multiarch_paths(self):
595601
tmpfile = os.path.join(self.build_temp, 'multiarch')
596602
if not os.path.exists(self.build_temp):
597603
os.makedirs(self.build_temp)
598-
ret = os.system(
604+
ret = run_command(
599605
'%s -print-multiarch > %s 2> /dev/null' % (cc, tmpfile))
600606
multiarch_path_component = ''
601607
try:
602-
if ret >> 8 == 0:
608+
if ret == 0:
603609
with open(tmpfile) as fp:
604610
multiarch_path_component = fp.readline().strip()
605611
finally:
@@ -620,11 +626,11 @@ def add_multiarch_paths(self):
620626
tmpfile = os.path.join(self.build_temp, 'multiarch')
621627
if not os.path.exists(self.build_temp):
622628
os.makedirs(self.build_temp)
623-
ret = os.system(
629+
ret = run_command(
624630
'dpkg-architecture %s -qDEB_HOST_MULTIARCH > %s 2> /dev/null' %
625631
(opt, tmpfile))
626632
try:
627-
if ret >> 8 == 0:
633+
if ret == 0:
628634
with open(tmpfile) as fp:
629635
multiarch_path_component = fp.readline().strip()
630636
add_dir_to_list(self.compiler.library_dirs,
@@ -639,12 +645,12 @@ def add_cross_compiling_paths(self):
639645
tmpfile = os.path.join(self.build_temp, 'ccpaths')
640646
if not os.path.exists(self.build_temp):
641647
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))
643649
is_gcc = False
644650
is_clang = False
645651
in_incdirs = False
646652
try:
647-
if ret >> 8 == 0:
653+
if ret == 0:
648654
with open(tmpfile) as fp:
649655
for line in fp.readlines():
650656
if line.startswith("gcc version"):
@@ -932,14 +938,14 @@ def detect_readline_curses(self):
932938
# Determine if readline is already linked against curses or tinfo.
933939
if do_readline:
934940
if CROSS_COMPILING:
935-
ret = os.system("%s -d %s | grep '(NEEDED)' > %s" \
941+
ret = run_command("%s -d %s | grep '(NEEDED)' > %s"
936942
% (sysconfig.get_config_var('READELF'),
937943
do_readline, tmpfile))
938944
elif find_executable('ldd'):
939-
ret = os.system("ldd %s > %s" % (do_readline, tmpfile))
945+
ret = run_command("ldd %s > %s" % (do_readline, tmpfile))
940946
else:
941-
ret = 256
942-
if ret >> 8 == 0:
947+
ret = 1
948+
if ret == 0:
943949
with open(tmpfile) as fp:
944950
for ln in fp:
945951
if 'curses' in ln:
@@ -1654,9 +1660,9 @@ def detect_expat_elementtree(self):
16541660
]
16551661

16561662
cc = sysconfig.get_config_var('CC').split()[0]
1657-
ret = os.system(
1663+
ret = run_command(
16581664
'"%s" -Werror -Wno-unreachable-code -E -xc /dev/null >/dev/null 2>&1' % cc)
1659-
if ret >> 8 == 0:
1665+
if ret == 0:
16601666
extra_compile_args.append('-Wno-unreachable-code')
16611667

16621668
self.add(Extension('pyexpat',
@@ -1859,9 +1865,9 @@ def detect_tkinter_darwin(self):
18591865
# Note: cannot use os.popen or subprocess here, that
18601866
# requires extensions that are not available here.
18611867
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))
18631869
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))
18651871

18661872
with open(tmpfile) as fp:
18671873
detected_archs = []

0 commit comments

Comments
 (0)