Skip to content

Commit 371090d

Browse files
kalroveraddaleax
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 <[email protected]> Reviewed-By: Johan Bergström <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent 8c70f79 commit 371090d

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

configure

+36-31
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')
@@ -956,7 +960,7 @@ def configure_static(o):
956960

957961
def write(filename, data):
958962
filename = os.path.join(root_dir, filename)
959-
print 'creating ', filename
963+
print('creating %s' % filename)
960964
f = open(filename, 'w+')
961965
f.write(data)
962966

@@ -976,7 +980,7 @@ def glob_to_var(dir_base, dir_sub, patch_dir):
976980
patchfile = '%s/%s/%s' % (dir_base, patch_dir, file)
977981
if os.path.isfile(patchfile):
978982
srcfile = '%s/%s' % (patch_dir, file)
979-
print 'Using version-specific floating patch %s' % patchfile
983+
print('Using version-specific floating patch %s' % patchfile)
980984
list.append(srcfile)
981985
break
982986
return list
@@ -991,8 +995,8 @@ def configure_intl(o):
991995
def icu_download(path):
992996
# download ICU, if needed
993997
if not os.access(options.download_path, os.W_OK):
994-
print 'Error: cannot write to desired download path. ' \
995-
'Either create it or verify permissions.'
998+
print('Error: cannot write to desired download path. ' \
999+
'Either create it or verify permissions.')
9961000
sys.exit(1)
9971001
for icu in icus:
9981002
url = icu['url']
@@ -1003,16 +1007,16 @@ def configure_intl(o):
10031007
if nodedownload.candownload(auto_downloads, "icu"):
10041008
nodedownload.retrievefile(url, targetfile)
10051009
else:
1006-
print ' Re-using existing %s' % targetfile
1010+
print(' Re-using existing %s' % targetfile)
10071011
if os.path.isfile(targetfile):
10081012
sys.stdout.write(' Checking file integrity with MD5:\r')
10091013
gotmd5 = nodedownload.md5sum(targetfile)
1010-
print ' MD5: %s %s' % (gotmd5, targetfile)
1014+
print(' MD5: %s %s' % (gotmd5, targetfile))
10111015
if (md5 == gotmd5):
10121016
return targetfile
10131017
else:
1014-
print ' Expected: %s *MISMATCH*' % md5
1015-
print '\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile
1018+
print(' Expected: %s *MISMATCH*' % md5)
1019+
print('\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile)
10161020
return None
10171021
icu_config = {
10181022
'variables': {}
@@ -1032,7 +1036,7 @@ def configure_intl(o):
10321036
with_icu_source = options.with_icu_source
10331037
have_icu_path = bool(options.with_icu_path)
10341038
if have_icu_path and with_intl != 'none':
1035-
print 'Error: Cannot specify both --with-icu-path and --with-intl'
1039+
print('Error: Cannot specify both --with-icu-path and --with-intl')
10361040
sys.exit(1)
10371041
elif have_icu_path:
10381042
# Chromium .gyp mode: --with-icu-path
@@ -1061,8 +1065,8 @@ def configure_intl(o):
10611065
o['variables']['v8_enable_i18n_support'] = 1
10621066
pkgicu = pkg_config('icu-i18n')
10631067
if pkgicu[0] is None:
1064-
print 'Error: could not load pkg-config data for "icu-i18n".'
1065-
print 'See above errors or the README.md.'
1068+
print('Error: could not load pkg-config data for "icu-i18n".')
1069+
print('See above errors or the README.md.')
10661070
sys.exit(1)
10671071
(libs, cflags, libpath) = pkgicu
10681072
# libpath provides linker path which may contain spaces
@@ -1115,17 +1119,17 @@ def configure_intl(o):
11151119
# --with-icu-source processing
11161120
# now, check that they didn't pass --with-icu-source=deps/icu
11171121
elif with_icu_source and os.path.abspath(icu_full_path) == os.path.abspath(with_icu_source):
1118-
print 'Ignoring redundant --with-icu-source=%s' % (with_icu_source)
1122+
print('Ignoring redundant --with-icu-source=%s' % with_icu_source)
11191123
with_icu_source = None
11201124
# if with_icu_source is still set, try to use it.
11211125
if with_icu_source:
11221126
if os.path.isdir(icu_full_path):
1123-
print 'Deleting old ICU source: %s' % (icu_full_path)
1127+
print('Deleting old ICU source: %s' % icu_full_path)
11241128
shutil.rmtree(icu_full_path)
11251129
# now, what path was given?
11261130
if os.path.isdir(with_icu_source):
11271131
# it's a path. Copy it.
1128-
print '%s -> %s' % (with_icu_source, icu_full_path)
1132+
print('%s -> %s' % (with_icu_source, icu_full_path))
11291133
shutil.copytree(with_icu_source, icu_full_path)
11301134
else:
11311135
# could be file or URL.
@@ -1149,7 +1153,8 @@ def configure_intl(o):
11491153
os.rename(tmp_icu, icu_full_path)
11501154
shutil.rmtree(icu_tmp_path)
11511155
else:
1152-
print ' Error: --with-icu-source=%s did not result in an "icu" dir.' % with_icu_source
1156+
print(' Error: --with-icu-source=%s did not result in an "icu" dir.' % \
1157+
with_icu_source)
11531158
shutil.rmtree(icu_tmp_path)
11541159
sys.exit(1)
11551160

@@ -1158,22 +1163,22 @@ def configure_intl(o):
11581163
# ICU source dir relative to tools/icu (for .gyp file)
11591164
o['variables']['icu_path'] = icu_full_path
11601165
if not os.path.isdir(icu_full_path):
1161-
print '* ECMA-402 (Intl) support didn\'t find ICU in %s..' % (icu_full_path)
1166+
print('* ECMA-402 (Intl) support didn\'t find ICU in %s..' % icu_full_path)
11621167
# can we download (or find) a zipfile?
11631168
localzip = icu_download(icu_full_path)
11641169
if localzip:
11651170
nodedownload.unpack(localzip, icu_parent_path)
11661171
if not os.path.isdir(icu_full_path):
1167-
print ' Cannot build Intl without ICU in %s.' % (icu_full_path)
1168-
print ' (Fix, or disable with "--with-intl=none" )'
1172+
print(' Cannot build Intl without ICU in %s.' % icu_full_path)
1173+
print(' (Fix, or disable with "--with-intl=none" )')
11691174
sys.exit(1)
11701175
else:
1171-
print '* Using ICU in %s' % (icu_full_path)
1176+
print('* Using ICU in %s' % icu_full_path)
11721177
# Now, what version of ICU is it? We just need the "major", such as 54.
11731178
# uvernum.h contains it as a #define.
11741179
uvernum_h = os.path.join(icu_full_path, 'source/common/unicode/uvernum.h')
11751180
if not os.path.isfile(uvernum_h):
1176-
print ' Error: could not load %s - is ICU installed?' % uvernum_h
1181+
print(' Error: could not load %s - is ICU installed?' % uvernum_h)
11771182
sys.exit(1)
11781183
icu_ver_major = None
11791184
matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
@@ -1183,7 +1188,7 @@ def configure_intl(o):
11831188
if m:
11841189
icu_ver_major = m.group(1)
11851190
if not icu_ver_major:
1186-
print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
1191+
print(' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h)
11871192
sys.exit(1)
11881193
icu_endianness = sys.byteorder[0];
11891194
o['variables']['icu_ver_major'] = icu_ver_major
@@ -1210,8 +1215,8 @@ def configure_intl(o):
12101215
# this is the icudt*.dat file which node will be using (platform endianness)
12111216
o['variables']['icu_data_file'] = icu_data_file
12121217
if not os.path.isfile(icu_data_path):
1213-
print ' Error: ICU prebuilt data file %s does not exist.' % icu_data_path
1214-
print ' See the README.md.'
1218+
print(' Error: ICU prebuilt data file %s does not exist.' % icu_data_path)
1219+
print(' See the README.md.')
12151220
# .. and we're not about to build it from .gyp!
12161221
sys.exit(1)
12171222
# map from variable name to subdirs

0 commit comments

Comments
 (0)