build: support py3 for configure.py

PR-URL: https://github.com/nodejs/node/pull/29106
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
cclauss 2019-08-13 14:53:52 +02:00 committed by Rich Trott
parent affa23bc88
commit a582c6b07c

View File

@ -11,7 +11,6 @@ import re
import shlex import shlex
import subprocess import subprocess
import shutil import shutil
import string
from distutils.spawn import find_executable as which from distutils.spawn import find_executable as which
# If not run from node/, cd to node/. # If not run from node/, cd to node/.
@ -626,18 +625,14 @@ def print_verbose(x):
def b(value): def b(value):
"""Returns the string 'true' if value is truthy, 'false' otherwise.""" """Returns the string 'true' if value is truthy, 'false' otherwise."""
if value: return 'true' if value else 'false'
return 'true'
else:
return 'false'
def B(value): def B(value):
"""Returns 1 if value is truthy, 0 otherwise.""" """Returns 1 if value is truthy, 0 otherwise."""
if value: return 1 if value else 0
return 1
else:
return 0
def to_utf8(s):
return s if isinstance(s, str) else s.decode("utf-8")
def pkg_config(pkg): def pkg_config(pkg):
"""Run pkg-config on the specified package """Run pkg-config on the specified package
@ -652,7 +647,7 @@ def pkg_config(pkg):
try: try:
proc = subprocess.Popen(shlex.split(pkg_config) + args, proc = subprocess.Popen(shlex.split(pkg_config) + args,
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
val = proc.communicate()[0].strip() val = to_utf8(proc.communicate()[0]).strip()
except OSError as e: except OSError as e:
if e.errno != errno.ENOENT: raise e # Unexpected error. if e.errno != errno.ENOENT: raise e # Unexpected error.
return (None, None, None, None) # No pkg-config/pkgconf installed. return (None, None, None, None) # No pkg-config/pkgconf installed.
@ -668,10 +663,10 @@ def try_check_compiler(cc, lang):
except OSError: except OSError:
return (False, False, '', '') return (False, False, '', '')
proc.stdin.write('__clang__ __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ ' proc.stdin.write(b'__clang__ __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ '
'__clang_major__ __clang_minor__ __clang_patchlevel__') b'__clang_major__ __clang_minor__ __clang_patchlevel__')
values = (proc.communicate()[0].split() + ['0'] * 7)[0:7] values = (to_utf8(proc.communicate()[0]).split() + ['0'] * 7)[0:7]
is_clang = values[0] == '1' is_clang = values[0] == '1'
gcc_version = tuple(map(int, values[1:1+3])) gcc_version = tuple(map(int, values[1:1+3]))
clang_version = tuple(map(int, values[4:4+3])) if is_clang else None clang_version = tuple(map(int, values[4:4+3])) if is_clang else None
@ -696,7 +691,7 @@ def get_version_helper(cc, regexp):
consider adjusting the CC environment variable if you installed consider adjusting the CC environment variable if you installed
it in a non-standard prefix.''') it in a non-standard prefix.''')
match = re.search(regexp, proc.communicate()[1]) match = re.search(regexp, to_utf8(proc.communicate()[1]))
if match: if match:
return match.group(2) return match.group(2)
@ -715,7 +710,7 @@ def get_nasm_version(asm):
return '0' return '0'
match = re.match(r"NASM version ([2-9]\.[0-9][0-9]+)", match = re.match(r"NASM version ([2-9]\.[0-9][0-9]+)",
proc.communicate()[0]) to_utf8(proc.communicate()[0]))
if match: if match:
return match.group(1) return match.group(1)
@ -746,7 +741,7 @@ def get_gas_version(cc):
consider adjusting the CC environment variable if you installed consider adjusting the CC environment variable if you installed
it in a non-standard prefix.''') it in a non-standard prefix.''')
gas_ret = proc.communicate()[1] gas_ret = to_utf8(proc.communicate()[1])
match = re.match(r"GNU assembler version ([2-9]\.[0-9]+)", gas_ret) match = re.match(r"GNU assembler version ([2-9]\.[0-9]+)", gas_ret)
if match: if match:
@ -811,10 +806,8 @@ def cc_macros(cc=None):
consider adjusting the CC environment variable if you installed consider adjusting the CC environment variable if you installed
it in a non-standard prefix.''') it in a non-standard prefix.''')
p.stdin.write('\n') p.stdin.write(b'\n')
out = p.communicate()[0] out = to_utf8(p.communicate()[0]).split('\n')
out = str(out).split('\n')
k = {} k = {}
for line in out: for line in out:
@ -1294,7 +1287,7 @@ def glob_to_var(dir_base, dir_sub, patch_dir):
def configure_intl(o): def configure_intl(o):
def icu_download(path): def icu_download(path):
depFile = 'tools/icu/current_ver.dep'; depFile = 'tools/icu/current_ver.dep'
with open(depFile) as f: with open(depFile) as f:
icus = json.load(f) icus = json.load(f)
# download ICU, if needed # download ICU, if needed
@ -1363,7 +1356,7 @@ def configure_intl(o):
o['variables']['icu_small'] = b(True) o['variables']['icu_small'] = b(True)
locs = set(options.with_icu_locales.split(',')) locs = set(options.with_icu_locales.split(','))
locs.add('root') # must have root locs.add('root') # must have root
o['variables']['icu_locales'] = string.join(locs,',') o['variables']['icu_locales'] = ','.join(str(loc) for loc in locs)
# We will check a bit later if we can use the canned deps/icu-small # We will check a bit later if we can use the canned deps/icu-small
elif with_intl == 'full-icu': elif with_intl == 'full-icu':
# full ICU # full ICU
@ -1503,7 +1496,7 @@ def configure_intl(o):
elif int(icu_ver_major) < icu_versions['minimum_icu']: elif int(icu_ver_major) < icu_versions['minimum_icu']:
error('icu4c v%s.x is too old, v%d.x or later is required.' % error('icu4c v%s.x is too old, v%d.x or later is required.' %
(icu_ver_major, icu_versions['minimum_icu'])) (icu_ver_major, icu_versions['minimum_icu']))
icu_endianness = sys.byteorder[0]; icu_endianness = sys.byteorder[0]
o['variables']['icu_ver_major'] = icu_ver_major o['variables']['icu_ver_major'] = icu_ver_major
o['variables']['icu_endianness'] = icu_endianness o['variables']['icu_endianness'] = icu_endianness
icu_data_file_l = 'icudt%s%s.dat' % (icu_ver_major, 'l') icu_data_file_l = 'icudt%s%s.dat' % (icu_ver_major, 'l')