Skip to content

Commit fd31cb3

Browse files
kalroverMylesBorins
authored andcommitted
build: Make configure file parseable on python3
Display python3-compatible error message for some systems use python3 as default. PR-URL: #9657 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
1 parent d03cac8 commit fd31cb3

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

configure

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#!/usr/bin/env python
22

3+
import sys
4+
if sys.version_info[0] != 2 or sys.version_info[1] not in (6, 7):
5+
sys.stdout.write("Please use either Python 2.6 or 2.7\n")
6+
sys.exit(1)
7+
38
import errno
49
import optparse
510
import os
611
import pprint
712
import re
813
import shlex
914
import subprocess
10-
import sys
1115
import shutil
1216
import string
1317

@@ -488,7 +492,7 @@ def pkg_config(pkg):
488492
shlex.split(pkg_config) + ['--silence-errors', flag, pkg],
489493
stdout=subprocess.PIPE)
490494
val = proc.communicate()[0].strip()
491-
except OSError, e:
495+
except OSError as e:
492496
if e.errno != errno.ENOENT: raise e # Unexpected error.
493497
return (None, None, None) # No pkg-config/pkgconf installed.
494498
retval += (val,)
@@ -524,12 +528,12 @@ def get_version_helper(cc, regexp):
524528
proc = subprocess.Popen(shlex.split(cc) + ['-v'], stdin=subprocess.PIPE,
525529
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
526530
except OSError:
527-
print '''Node.js configure error: No acceptable C compiler found!
531+
print('''Node.js configure error: No acceptable C compiler found!
528532
529533
Please make sure you have a C compiler installed on your system and/or
530534
consider adjusting the CC environment variable if you installed
531535
it in a non-standard prefix.
532-
'''
536+
''')
533537
sys.exit()
534538

535539
match = re.search(regexp, proc.communicate()[1])
@@ -555,12 +559,12 @@ def get_gas_version(cc):
555559
stdin=subprocess.PIPE, stderr=subprocess.PIPE,
556560
stdout=subprocess.PIPE)
557561
except OSError:
558-
print '''Node.js configure error: No acceptable C compiler found!
562+
print('''Node.js configure error: No acceptable C compiler found!
559563
560564
Please make sure you have a C compiler installed on your system and/or
561565
consider adjusting the CC environment variable if you installed
562566
it in a non-standard prefix.
563-
'''
567+
''')
564568
sys.exit()
565569

566570
match = re.match(r"GNU assembler version ([2-9]\.[0-9]+)",
@@ -615,12 +619,12 @@ def cc_macros(cc=None):
615619
stdout=subprocess.PIPE,
616620
stderr=subprocess.PIPE)
617621
except OSError:
618-
print '''Node.js configure error: No acceptable C compiler found!
622+
print('''Node.js configure error: No acceptable C compiler found!
619623
620624
Please make sure you have a C compiler installed on your system and/or
621625
consider adjusting the CC environment variable if you installed
622626
it in a non-standard prefix.
623-
'''
627+
''')
624628
sys.exit()
625629

626630
p.stdin.write('\n')
@@ -955,7 +959,7 @@ def configure_static(o):
955959

956960
def write(filename, data):
957961
filename = os.path.join(root_dir, filename)
958-
print 'creating ', filename
962+
print('creating %s' % filename)
959963
f = open(filename, 'w+')
960964
f.write(data)
961965

@@ -975,7 +979,7 @@ def glob_to_var(dir_base, dir_sub, patch_dir):
975979
patchfile = '%s/%s/%s' % (dir_base, patch_dir, file)
976980
if os.path.isfile(patchfile):
977981
srcfile = '%s/%s' % (patch_dir, file)
978-
print 'Using version-specific floating patch %s' % patchfile
982+
print('Using version-specific floating patch %s' % patchfile)
979983
list.append(srcfile)
980984
break
981985
return list
@@ -990,8 +994,8 @@ def configure_intl(o):
990994
def icu_download(path):
991995
# download ICU, if needed
992996
if not os.access(options.download_path, os.W_OK):
993-
print 'Error: cannot write to desired download path. ' \
994-
'Either create it or verify permissions.'
997+
print('Error: cannot write to desired download path. ' \
998+
'Either create it or verify permissions.')
995999
sys.exit(1)
9961000
for icu in icus:
9971001
url = icu['url']
@@ -1002,16 +1006,16 @@ def configure_intl(o):
10021006
if nodedownload.candownload(auto_downloads, "icu"):
10031007
nodedownload.retrievefile(url, targetfile)
10041008
else:
1005-
print ' Re-using existing %s' % targetfile
1009+
print(' Re-using existing %s' % targetfile)
10061010
if os.path.isfile(targetfile):
10071011
sys.stdout.write(' Checking file integrity with MD5:\r')
10081012
gotmd5 = nodedownload.md5sum(targetfile)
1009-
print ' MD5: %s %s' % (gotmd5, targetfile)
1013+
print(' MD5: %s %s' % (gotmd5, targetfile))
10101014
if (md5 == gotmd5):
10111015
return targetfile
10121016
else:
1013-
print ' Expected: %s *MISMATCH*' % md5
1014-
print '\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile
1017+
print(' Expected: %s *MISMATCH*' % md5)
1018+
print('\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile)
10151019
return None
10161020
icu_config = {
10171021
'variables': {}
@@ -1031,7 +1035,7 @@ def configure_intl(o):
10311035
with_icu_source = options.with_icu_source
10321036
have_icu_path = bool(options.with_icu_path)
10331037
if have_icu_path and with_intl != 'none':
1034-
print 'Error: Cannot specify both --with-icu-path and --with-intl'
1038+
print('Error: Cannot specify both --with-icu-path and --with-intl')
10351039
sys.exit(1)
10361040
elif have_icu_path:
10371041
# Chromium .gyp mode: --with-icu-path
@@ -1060,8 +1064,8 @@ def configure_intl(o):
10601064
o['variables']['v8_enable_i18n_support'] = 1
10611065
pkgicu = pkg_config('icu-i18n')
10621066
if pkgicu[0] is None:
1063-
print 'Error: could not load pkg-config data for "icu-i18n".'
1064-
print 'See above errors or the README.md.'
1067+
print('Error: could not load pkg-config data for "icu-i18n".')
1068+
print('See above errors or the README.md.')
10651069
sys.exit(1)
10661070
(libs, cflags, libpath) = pkgicu
10671071
# libpath provides linker path which may contain spaces
@@ -1114,17 +1118,17 @@ def configure_intl(o):
11141118
# --with-icu-source processing
11151119
# now, check that they didn't pass --with-icu-source=deps/icu
11161120
elif with_icu_source and os.path.abspath(icu_full_path) == os.path.abspath(with_icu_source):
1117-
print 'Ignoring redundant --with-icu-source=%s' % (with_icu_source)
1121+
print('Ignoring redundant --with-icu-source=%s' % with_icu_source)
11181122
with_icu_source = None
11191123
# if with_icu_source is still set, try to use it.
11201124
if with_icu_source:
11211125
if os.path.isdir(icu_full_path):
1122-
print 'Deleting old ICU source: %s' % (icu_full_path)
1126+
print('Deleting old ICU source: %s' % icu_full_path)
11231127
shutil.rmtree(icu_full_path)
11241128
# now, what path was given?
11251129
if os.path.isdir(with_icu_source):
11261130
# it's a path. Copy it.
1127-
print '%s -> %s' % (with_icu_source, icu_full_path)
1131+
print('%s -> %s' % (with_icu_source, icu_full_path))
11281132
shutil.copytree(with_icu_source, icu_full_path)
11291133
else:
11301134
# could be file or URL.
@@ -1148,7 +1152,8 @@ def configure_intl(o):
11481152
os.rename(tmp_icu, icu_full_path)
11491153
shutil.rmtree(icu_tmp_path)
11501154
else:
1151-
print ' Error: --with-icu-source=%s did not result in an "icu" dir.' % with_icu_source
1155+
print(' Error: --with-icu-source=%s did not result in an "icu" dir.' % \
1156+
with_icu_source)
11521157
shutil.rmtree(icu_tmp_path)
11531158
sys.exit(1)
11541159

@@ -1157,22 +1162,22 @@ def configure_intl(o):
11571162
# ICU source dir relative to tools/icu (for .gyp file)
11581163
o['variables']['icu_path'] = icu_full_path
11591164
if not os.path.isdir(icu_full_path):
1160-
print '* ECMA-402 (Intl) support didn\'t find ICU in %s..' % (icu_full_path)
1165+
print('* ECMA-402 (Intl) support didn\'t find ICU in %s..' % icu_full_path)
11611166
# can we download (or find) a zipfile?
11621167
localzip = icu_download(icu_full_path)
11631168
if localzip:
11641169
nodedownload.unpack(localzip, icu_parent_path)
11651170
if not os.path.isdir(icu_full_path):
1166-
print ' Cannot build Intl without ICU in %s.' % (icu_full_path)
1167-
print ' (Fix, or disable with "--with-intl=none" )'
1171+
print(' Cannot build Intl without ICU in %s.' % icu_full_path)
1172+
print(' (Fix, or disable with "--with-intl=none" )')
11681173
sys.exit(1)
11691174
else:
1170-
print '* Using ICU in %s' % (icu_full_path)
1175+
print('* Using ICU in %s' % icu_full_path)
11711176
# Now, what version of ICU is it? We just need the "major", such as 54.
11721177
# uvernum.h contains it as a #define.
11731178
uvernum_h = os.path.join(icu_full_path, 'source/common/unicode/uvernum.h')
11741179
if not os.path.isfile(uvernum_h):
1175-
print ' Error: could not load %s - is ICU installed?' % uvernum_h
1180+
print(' Error: could not load %s - is ICU installed?' % uvernum_h)
11761181
sys.exit(1)
11771182
icu_ver_major = None
11781183
matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
@@ -1182,7 +1187,7 @@ def configure_intl(o):
11821187
if m:
11831188
icu_ver_major = m.group(1)
11841189
if not icu_ver_major:
1185-
print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
1190+
print(' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h)
11861191
sys.exit(1)
11871192
icu_endianness = sys.byteorder[0];
11881193
o['variables']['icu_ver_major'] = icu_ver_major
@@ -1209,8 +1214,8 @@ def configure_intl(o):
12091214
# this is the icudt*.dat file which node will be using (platform endianness)
12101215
o['variables']['icu_data_file'] = icu_data_file
12111216
if not os.path.isfile(icu_data_path):
1212-
print ' Error: ICU prebuilt data file %s does not exist.' % icu_data_path
1213-
print ' See the README.md.'
1217+
print(' Error: ICU prebuilt data file %s does not exist.' % icu_data_path)
1218+
print(' See the README.md.')
12141219
# .. and we're not about to build it from .gyp!
12151220
sys.exit(1)
12161221
# map from variable name to subdirs

0 commit comments

Comments
 (0)