Commit 79fbf3cf authored by Raul Tambre's avatar Raul Tambre Committed by Commit Bot

Improve Python 3 compatibility of build scripts

These changes allow more of Chromium to be built using Python 3.

The scripts still work with Python 2.
There are no intended behaviour changes.

Bug: 941669
Change-Id: I6897d00ce00ec6aa5d7ca216b9f302e725a21897
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1527522Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Commit-Queue: Raul Tambre <raul@tambre.ee>
Cr-Commit-Position: refs/heads/master@{#642401}
parent e8c12b57
...@@ -141,12 +141,7 @@ def Preprocess(rc_file_data, flags): ...@@ -141,12 +141,7 @@ def Preprocess(rc_file_data, flags):
# lines in the file except the preprocessor directives.""" # lines in the file except the preprocessor directives."""
# Thankfully, the Microsoft headers are mostly good about putting everything # Thankfully, the Microsoft headers are mostly good about putting everything
# in the system headers behind `if !defined(RC_INVOKED)`, so regular # in the system headers behind `if !defined(RC_INVOKED)`, so regular
# preprocessing with RC_INVOKED defined almost works. The one exception # preprocessing with RC_INVOKED defined works.
# is struct tagCRGB in dlgs.h, but that will be fixed in the next major
# SDK release too.
# TODO(thakis): Remove this once an SDK with the fix has been released.
preprocessed_output = re.sub('typedef struct tagCRGB\s*{[^}]*} CRGB;', '',
preprocessed_output)
return preprocessed_output return preprocessed_output
......
...@@ -8,6 +8,8 @@ This file is copied to the build directory as part of toolchain setup and ...@@ -8,6 +8,8 @@ This file is copied to the build directory as part of toolchain setup and
is used to set up calls to tools used by the build that need wrappers. is used to set up calls to tools used by the build that need wrappers.
""" """
from __future__ import print_function
import os import os
import re import re
import shutil import shutil
...@@ -154,7 +156,7 @@ class WinTool(object): ...@@ -154,7 +156,7 @@ class WinTool(object):
if (not line.startswith(' Creating library ') and if (not line.startswith(' Creating library ') and
not line.startswith('Generating code') and not line.startswith('Generating code') and
not line.startswith('Finished generating code')): not line.startswith('Finished generating code')):
print line, print(line)
result = link.wait() result = link.wait()
if result == 0 and sys.platform == 'win32': if result == 0 and sys.platform == 'win32':
# Flush the file buffers to try to work around a Windows 10 kernel bug, # Flush the file buffers to try to work around a Windows 10 kernel bug,
...@@ -178,7 +180,7 @@ class WinTool(object): ...@@ -178,7 +180,7 @@ class WinTool(object):
out, _ = popen.communicate() out, _ = popen.communicate()
for line in out.splitlines(): for line in out.splitlines():
if not line.startswith(' Assembling: '): if not line.startswith(' Assembling: '):
print line print(line)
return popen.returncode return popen.returncode
def ExecRcWrapper(self, arch, *args): def ExecRcWrapper(self, arch, *args):
...@@ -207,11 +209,13 @@ class WinTool(object): ...@@ -207,11 +209,13 @@ class WinTool(object):
if rc_exe_exit_code == 0: if rc_exe_exit_code == 0:
# Since tool("rc") can't have deps, add deps on this script and on rc.py # Since tool("rc") can't have deps, add deps on this script and on rc.py
# and its deps here, so that rc edges become dirty if rc.py changes. # and its deps here, so that rc edges become dirty if rc.py changes.
print 'Note: including file: ../../build/toolchain/win/tool_wrapper.py' print('Note: including file: ../../build/toolchain/win/tool_wrapper.py')
print 'Note: including file: ../../build/toolchain/win/rc/rc.py' print('Note: including file: ../../build/toolchain/win/rc/rc.py')
print 'Note: including file: ../../build/toolchain/win/rc/linux64/rc.sha1' print(
print 'Note: including file: ../../build/toolchain/win/rc/mac/rc.sha1' 'Note: including file: ../../build/toolchain/win/rc/linux64/rc.sha1')
print 'Note: including file: ../../build/toolchain/win/rc/win/rc.exe.sha1' print('Note: including file: ../../build/toolchain/win/rc/mac/rc.sha1')
print(
'Note: including file: ../../build/toolchain/win/rc/win/rc.exe.sha1')
# 2. Run Microsoft rc.exe. # 2. Run Microsoft rc.exe.
if sys.platform == 'win32' and rc_exe_exit_code == 0: if sys.platform == 'win32' and rc_exe_exit_code == 0:
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
from __future__ import print_function
import glob import glob
import hashlib import hashlib
import os import os
...@@ -38,7 +40,7 @@ def _CopyImpl(file_name, target_dir, source_dir, verbose=False): ...@@ -38,7 +40,7 @@ def _CopyImpl(file_name, target_dir, source_dir, verbose=False):
((not os.path.isfile(target)) or ((not os.path.isfile(target)) or
_HexDigest(source) != _HexDigest(target))): _HexDigest(source) != _HexDigest(target))):
if verbose: if verbose:
print 'Copying %s to %s...' % (source, target) print('Copying %s to %s...' % (source, target))
if os.path.exists(target): if os.path.exists(target):
os.unlink(target) os.unlink(target)
shutil.copy(source, target) shutil.copy(source, target)
...@@ -69,7 +71,7 @@ def _CopyCDBToOutput(output_dir, target_arch): ...@@ -69,7 +71,7 @@ def _CopyCDBToOutput(output_dir, target_arch):
elif target_arch in ['x64', 'arm64']: elif target_arch in ['x64', 'arm64']:
src_arch = target_arch src_arch = target_arch
else: else:
print 'copy_cdb_to_output.py: unknown target_arch %s' % target_arch print('copy_cdb_to_output.py: unknown target_arch %s' % target_arch)
sys.exit(1) sys.exit(1)
# We need to copy multiple files, so cache the computed source directory. # We need to copy multiple files, so cache the computed source directory.
src_dir = os.path.join(win_sdk_dir, 'Debuggers', src_arch) src_dir = os.path.join(win_sdk_dir, 'Debuggers', src_arch)
...@@ -109,8 +111,8 @@ def _CopyCDBToOutput(output_dir, target_arch): ...@@ -109,8 +111,8 @@ def _CopyCDBToOutput(output_dir, target_arch):
def main(): def main():
if len(sys.argv) < 2: if len(sys.argv) < 2:
print >>sys.stderr, 'Usage: copy_cdb_to_output.py <output_dir> ' + \ print('Usage: copy_cdb_to_output.py <output_dir> ' + \
'<target_arch>' '<target_arch>', file=sys.stderr)
return 1 return 1
return _CopyCDBToOutput(sys.argv[1], sys.argv[2]) return _CopyCDBToOutput(sys.argv[1], sys.argv[2])
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
# #
# Usage: message_compiler.py <environment_file> [<args to mc.exe>*] # Usage: message_compiler.py <environment_file> [<args to mc.exe>*]
from __future__ import print_function
import difflib import difflib
import distutils.dir_util import distutils.dir_util
import filecmp import filecmp
...@@ -65,7 +67,7 @@ def main(): ...@@ -65,7 +67,7 @@ def main():
# we use the 2017 Fall Creator's Update by default. # we use the 2017 Fall Creator's Update by default.
mc_help = subprocess.check_output(['mc.exe', '/?'], env=env_dict, mc_help = subprocess.check_output(['mc.exe', '/?'], env=env_dict,
stderr=subprocess.STDOUT, shell=True) stderr=subprocess.STDOUT, shell=True)
version = re.search(r'Message Compiler\s+Version (\S+)', mc_help).group(1) version = re.search(b'Message Compiler\s+Version (\S+)', mc_help).group(1)
if version != '10.0.15063': if version != '10.0.15063':
return return
...@@ -122,20 +124,21 @@ def main(): ...@@ -122,20 +124,21 @@ def main():
# in tmp_dir to the checked-in outputs. # in tmp_dir to the checked-in outputs.
diff = filecmp.dircmp(tmp_dir, source) diff = filecmp.dircmp(tmp_dir, source)
if diff.diff_files or set(diff.left_list) != set(diff.right_list): if diff.diff_files or set(diff.left_list) != set(diff.right_list):
print 'mc.exe output different from files in %s, see %s' % (source, print('mc.exe output different from files in %s, see %s' % (source,
tmp_dir) tmp_dir))
diff.report() diff.report()
for f in diff.diff_files: for f in diff.diff_files:
if f.endswith('.bin'): continue if f.endswith('.bin'): continue
fromfile = os.path.join(source, f) fromfile = os.path.join(source, f)
tofile = os.path.join(tmp_dir, f) tofile = os.path.join(tmp_dir, f)
print ''.join(difflib.unified_diff(open(fromfile, 'U').readlines(), print(''.join(
open(tofile, 'U').readlines(), difflib.unified_diff(
fromfile, tofile)) open(fromfile, 'U').readlines(),
open(tofile, 'U').readlines(), fromfile, tofile)))
delete_tmp_dir = False delete_tmp_dir = False
sys.exit(1) sys.exit(1)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
print e.output print(e.output)
sys.exit(e.returncode) sys.exit(e.returncode)
finally: finally:
if os.path.exists(tmp_dir) and delete_tmp_dir: if os.path.exists(tmp_dir) and delete_tmp_dir:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment