diff --git a/tools/gclient_hook.py b/tools/gclient_hook.py index ab79a6741..16389628c 100644 --- a/tools/gclient_hook.py +++ b/tools/gclient_hook.py @@ -3,11 +3,14 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +from __future__ import absolute_import +from __future__ import print_function +from file_util import make_dir, write_file from gclient_util import * from gn_args import GetAllPlatformConfigs, GetConfigFileContents -from file_util import make_dir, write_file -import os, sys import issue_1999 +import os +import sys # The CEF directory is the parent directory of _this_ script. cef_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) @@ -22,21 +25,21 @@ elif sys.platform == 'darwin': elif sys.platform.startswith('linux'): platform = 'linux' else: - print 'Unknown operating system platform' + print('Unknown operating system platform') sys.exit() -print "\nGenerating CEF version header file..." +print("\nGenerating CEF version header file...") cmd = [ - 'python', 'tools/make_version_header.py', '--header', + sys.executable, 'tools/make_version_header.py', '--header', 'include/cef_version.h' ] RunAction(cef_dir, cmd) -print "\nPatching build configuration and source files for CEF..." -cmd = ['python', 'tools/patcher.py'] +print("\nPatching build configuration and source files for CEF...") +cmd = [sys.executable, 'tools/patcher.py'] RunAction(cef_dir, cmd) -print "\nGenerating CEF project files..." +print("\nGenerating CEF project files...") gn_args = {} @@ -133,13 +136,13 @@ for dir, config in configs.items(): if platform == 'windows': issue_1999.apply(out_path) -gn_dir = configs.keys()[0] +gn_dir = list(configs.keys())[0] out_gn_path = os.path.join(src_dir, 'out', gn_dir) gn_path = os.path.join(out_gn_path, 'args.gn') -print "\nGenerating CEF buildinfo header file..." +print("\nGenerating CEF buildinfo header file...") cmd = [ - 'python', 'tools/make_config_header.py', '--header', 'include/cef_config.h', - '--cef_gn_config', gn_path + sys.executable, 'tools/make_config_header.py', '--header', + 'include/cef_config.h', '--cef_gn_config', gn_path ] RunAction(cef_dir, cmd) diff --git a/tools/gclient_util.py b/tools/gclient_util.py index cdc787374..5a6da54ee 100644 --- a/tools/gclient_util.py +++ b/tools/gclient_util.py @@ -3,12 +3,14 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +from __future__ import absolute_import +from __future__ import print_function import os, sys try: # depot_tools may already be in the import path. import gclient_utils -except ImportError, e: +except ImportError as e: # Search the PATH environment variable to find the depot_tools folder. depot_tools = None paths = os.environ.get('PATH').split(os.pathsep) @@ -18,7 +20,7 @@ except ImportError, e: break if depot_tools is None: - print >> sys.stderr, 'Error: could not find depot_tools in PATH.' + print('Error: could not find depot_tools in PATH.', file=sys.stderr) sys.exit(2) # Add depot_tools to import path. @@ -29,18 +31,12 @@ except ImportError, e: # Copied from gclient.py python code. def RunAction(dir, command): """Runs the action.""" - if command[0] == 'python': - # If the hook specified "python" as the first item, the action is a - # Python script. Run it by starting a new copy of the same - # interpreter. - command[0] = sys.executable - try: gclient_utils.CheckCallAndFilter( command, cwd=dir, always_show_header=True, print_stdout=True) - except gclient_utils.Error, e: + except gclient_utils.Error as e: # Use a discrete exit status code of 2 to indicate that a hook action # failed. Users of this script may wish to treat hook action failures # differently from VC failures. - print >> sys.stderr, 'Error: %s' % str(e) + print('Error: %s' % str(e), file=sys.stderr) sys.exit(2) diff --git a/tools/issue_1999.py b/tools/issue_1999.py index 85a1e51d2..6c27d7040 100644 --- a/tools/issue_1999.py +++ b/tools/issue_1999.py @@ -10,6 +10,9 @@ # import issue_1999 # issue_1999.apply(output_path) # +from __future__ import absolute_import +from __future__ import print_function +from io import open import sys import os @@ -82,9 +85,9 @@ def process_line(line): def process_file(path): - print "Applying issue #1999 fix to " + path + print("Applying issue #1999 fix to " + path) - with open(path) as f: + with open(path, 'r', encoding='utf-8') as f: content = f.read().splitlines() result = [] @@ -92,9 +95,14 @@ def process_file(path): for line in content: result.append(process_line(line)) - with open(path, "w") as f: - f.write("\n".join(result)) - f.write("\n") + with open(path, 'w', encoding='utf-8') as fp: + str = "\n".join(result) + "\n" + try: + # Python 2 + fp.write(str.decode('utf-8')) + except Exception as e: + # Python 3 + fp.write(str) def apply(confpath):