Skip to content

Commit 483f8d4

Browse files
cclaussBaochengSu
authored andcommitted
build: support py3 for configure.py
PR-URL: nodejs#29106 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Rich Trott <[email protected]> (cherry picked from commit a582c6b)
1 parent 32bfb79 commit 483f8d4

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

configure.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import shlex
88
import subprocess
99
import shutil
10-
import string
1110
from distutils.spawn import find_executable as which
1211

1312
# If not run from node/, cd to node/.
@@ -548,11 +547,14 @@ def warn(msg):
548547

549548
def b(value):
550549
"""Returns the string 'true' if value is truthy, 'false' otherwise."""
551-
if value:
552-
return 'true'
553-
else:
554-
return 'false'
550+
return 'true' if value else 'false'
551+
552+
def B(value):
553+
"""Returns 1 if value is truthy, 0 otherwise."""
554+
return 1 if value else 0
555555

556+
def to_utf8(s):
557+
return s if isinstance(s, str) else s.decode("utf-8")
556558

557559
def pkg_config(pkg):
558560
pkg_config = os.environ.get('PKG_CONFIG', 'pkg-config')
@@ -562,7 +564,7 @@ def pkg_config(pkg):
562564
proc = subprocess.Popen(
563565
shlex.split(pkg_config) + ['--silence-errors', flag, pkg],
564566
stdout=subprocess.PIPE)
565-
val = proc.communicate()[0].strip()
567+
val = to_utf8(proc.communicate()[0]).strip()
566568
except OSError as e:
567569
if e.errno != errno.ENOENT: raise e # Unexpected error.
568570
return (None, None, None) # No pkg-config/pkgconf installed.
@@ -577,10 +579,10 @@ def try_check_compiler(cc, lang):
577579
except OSError:
578580
return (False, False, '', '')
579581

580-
proc.stdin.write('__clang__ __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ '
581-
'__clang_major__ __clang_minor__ __clang_patchlevel__')
582+
proc.stdin.write(b'__clang__ __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ '
583+
b'__clang_major__ __clang_minor__ __clang_patchlevel__')
582584

583-
values = (proc.communicate()[0].split() + ['0'] * 7)[0:7]
585+
values = (to_utf8(proc.communicate()[0]).split() + ['0'] * 7)[0:7]
584586
is_clang = values[0] == '1'
585587
gcc_version = tuple(values[1:1+3])
586588
clang_version = tuple(values[4:4+3])
@@ -607,7 +609,7 @@ def get_version_helper(cc, regexp):
607609
''')
608610
sys.exit()
609611

610-
match = re.search(regexp, proc.communicate()[1])
612+
match = re.search(regexp, to_utf8(proc.communicate()[1]))
611613

612614
if match:
613615
return match.group(2)
@@ -638,8 +640,8 @@ def get_gas_version(cc):
638640
''')
639641
sys.exit()
640642

641-
match = re.match(r"GNU assembler version ([2-9]\.[0-9]+)",
642-
proc.communicate()[1])
643+
gas_ret = to_utf8(proc.communicate()[1])
644+
match = re.match(r"GNU assembler version ([2-9]\.[0-9]+)", gas_ret)
643645

644646
if match:
645647
return match.group(1)
@@ -699,10 +701,8 @@ def cc_macros(cc=None):
699701
''')
700702
sys.exit()
701703

702-
p.stdin.write('\n')
703-
out = p.communicate()[0]
704-
705-
out = str(out).split('\n')
704+
p.stdin.write(b'\n')
705+
out = to_utf8(p.communicate()[0]).split('\n')
706706

707707
k = {}
708708
for line in out:
@@ -1176,7 +1176,7 @@ def write_config(data, name):
11761176
o['variables']['icu_small'] = b(True)
11771177
locs = set(options.with_icu_locales.split(','))
11781178
locs.add('root') # must have root
1179-
o['variables']['icu_locales'] = string.join(locs,',')
1179+
o['variables']['icu_locales'] = ','.join(str(loc) for loc in locs)
11801180
# We will check a bit later if we can use the canned deps/icu-small
11811181
elif with_intl == 'full-icu':
11821182
# full ICU

0 commit comments

Comments
 (0)