Skip to content

Commit

Permalink
gyp: get ready for python 3
Browse files Browse the repository at this point in the history
#1335
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
cclauss authored and rvagg committed Apr 24, 2019
1 parent 788e767 commit abef93d
Show file tree
Hide file tree
Showing 26 changed files with 198 additions and 178 deletions.
21 changes: 11 additions & 10 deletions gyp/pylib/gyp/MSVSSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
The MSBuild schemas were also considered. They are typically found in the
MSBuild install directory, e.g. c:\Program Files (x86)\MSBuild
"""
from __future__ import print_function

import sys
import re
Expand Down Expand Up @@ -400,7 +401,7 @@ def _ValidateExclusionSetting(setting, settings, error_msg, stderr=sys.stderr):

if unrecognized:
# We don't know this setting. Give a warning.
print >> stderr, error_msg
print(error_msg, file=stderr)


def FixVCMacroSlashes(s):
Expand Down Expand Up @@ -461,9 +462,9 @@ def ConvertToMSBuildSettings(msvs_settings, stderr=sys.stderr):
# Invoke the translation function.
try:
msvs_tool[msvs_setting](msvs_value, msbuild_settings)
except ValueError, e:
print >> stderr, ('Warning: while converting %s/%s to MSBuild, '
'%s' % (msvs_tool_name, msvs_setting, e))
except ValueError as e:
print(('Warning: while converting %s/%s to MSBuild, '
'%s' % (msvs_tool_name, msvs_setting, e)), file=stderr)
else:
_ValidateExclusionSetting(msvs_setting,
msvs_tool,
Expand All @@ -472,8 +473,8 @@ def ConvertToMSBuildSettings(msvs_settings, stderr=sys.stderr):
(msvs_tool_name, msvs_setting)),
stderr)
else:
print >> stderr, ('Warning: unrecognized tool %s while converting to '
'MSBuild.' % msvs_tool_name)
print(('Warning: unrecognized tool %s while converting to '
'MSBuild.' % msvs_tool_name), file=stderr)
return msbuild_settings


Expand Down Expand Up @@ -517,9 +518,9 @@ def _ValidateSettings(validators, settings, stderr):
if setting in tool_validators:
try:
tool_validators[setting](value)
except ValueError, e:
print >> stderr, ('Warning: for %s/%s, %s' %
(tool_name, setting, e))
except ValueError as e:
print(('Warning: for %s/%s, %s' %
(tool_name, setting, e)), file=stderr)
else:
_ValidateExclusionSetting(setting,
tool_validators,
Expand All @@ -528,7 +529,7 @@ def _ValidateSettings(validators, settings, stderr):
stderr)

else:
print >> stderr, ('Warning: unrecognized tool %s' % tool_name)
print(('Warning: unrecognized tool %s' % tool_name), file=stderr)


# MSVS and MBuild names of the tools.
Expand Down
2 changes: 1 addition & 1 deletion gyp/pylib/gyp/MSVSVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _RegistryQuery(key, value=None):
text = None
try:
text = _RegistryQueryBase('Sysnative', key, value)
except OSError, e:
except OSError as e:
if e.errno == errno.ENOENT:
text = _RegistryQueryBase('System32', key, value)
else:
Expand Down
17 changes: 9 additions & 8 deletions gyp/pylib/gyp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from __future__ import print_function
import copy
import gyp.input
import optparse
Expand Down Expand Up @@ -34,8 +35,8 @@ def DebugOutput(mode, message, *args):
pass
if args:
message %= args
print '%s:%s:%d:%s %s' % (mode.upper(), os.path.basename(ctx[0]),
ctx[1], ctx[2], message)
print('%s:%s:%d:%s %s' % (mode.upper(), os.path.basename(ctx[0]),
ctx[1], ctx[2], message))

def FindBuildFiles():
extension = '.gyp'
Expand Down Expand Up @@ -226,12 +227,12 @@ def Noop(value):
(action == 'store_false' and not value)):
flags.append(opt)
elif options.use_environment and env_name:
print >>sys.stderr, ('Warning: environment regeneration unimplemented '
print(('Warning: environment regeneration unimplemented '
'for %s flag %r env_name %r' % (action, opt,
env_name))
env_name)), file=sys.stderr)
else:
print >>sys.stderr, ('Warning: regeneration unimplemented for action %r '
'flag %r' % (action, opt))
print(('Warning: regeneration unimplemented for action %r '
'flag %r' % (action, opt)), file=sys.stderr)

return flags

Expand Down Expand Up @@ -475,7 +476,7 @@ def gyp_main(args):
if home_dot_gyp != None:
default_include = os.path.join(home_dot_gyp, 'include.gypi')
if os.path.exists(default_include):
print 'Using overrides found in ' + default_include
print('Using overrides found in ' + default_include)
includes.append(default_include)

# Command-line --include files come after the default include.
Expand Down Expand Up @@ -536,7 +537,7 @@ def gyp_main(args):
def main(args):
try:
return gyp_main(args)
except GypError, e:
except GypError as e:
sys.stderr.write("gyp: %s\n" % e)
return 1

Expand Down
8 changes: 4 additions & 4 deletions gyp/pylib/gyp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def close(self):
same = False
try:
same = filecmp.cmp(self.tmp_path, filename, False)
except OSError, e:
except OSError as e:
if e.errno != errno.ENOENT:
raise

Expand All @@ -382,9 +382,9 @@ def close(self):
#
# No way to get the umask without setting a new one? Set a safe one
# and then set it back to the old value.
umask = os.umask(077)
umask = os.umask(0o77)
os.umask(umask)
os.chmod(self.tmp_path, 0666 & ~umask)
os.chmod(self.tmp_path, 0o666 & ~umask)
if sys.platform == 'win32' and os.path.exists(filename):
# NOTE: on windows (but not cygwin) rename will not replace an
# existing file, so it must be preceded with a remove. Sadly there
Expand Down Expand Up @@ -464,7 +464,7 @@ def CopyTool(flavor, out_path):
''.join([source[0], '# Generated by gyp. Do not edit.\n'] + source[1:]))

# Make file executable.
os.chmod(tool_path, 0755)
os.chmod(tool_path, 0o755)


# From Alex Martelli,
Expand Down
1 change: 1 addition & 0 deletions gyp/pylib/gyp/easy_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import os
import locale
from functools import reduce


def XmlToString(content, encoding='utf-8', pretty=False):
Expand Down
2 changes: 1 addition & 1 deletion gyp/pylib/gyp/flock_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def ExecFlock(self, lockfile, *cmd_list):
# where fcntl.flock(fd, LOCK_EX) always fails
# with EBADF, that's why we use this F_SETLK
# hack instead.
fd = os.open(lockfile, os.O_WRONLY|os.O_NOCTTY|os.O_CREAT, 0666)
fd = os.open(lockfile, os.O_WRONLY|os.O_NOCTTY|os.O_CREAT, 0o666)
if sys.platform.startswith('aix'):
# Python on AIX is compiled with LARGEFILE support, which changes the
# struct size.
Expand Down
Loading

0 comments on commit abef93d

Please sign in to comment.