Skip to content

Commit

Permalink
Improve Python 3 compatibility of build scripts
Browse files Browse the repository at this point in the history
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/+/1527522
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Commit-Queue: Raul Tambre <raul@tambre.ee>
Cr-Commit-Position: refs/heads/master@{#642401}
  • Loading branch information
tambry authored and Commit Bot committed Mar 20, 2019
1 parent e8c12b5 commit 79fbf3c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
7 changes: 1 addition & 6 deletions build/toolchain/win/rc/rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,7 @@ def Preprocess(rc_file_data, flags):
# lines in the file except the preprocessor directives."""
# Thankfully, the Microsoft headers are mostly good about putting everything
# in the system headers behind `if !defined(RC_INVOKED)`, so regular
# preprocessing with RC_INVOKED defined almost works. The one exception
# 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)
# preprocessing with RC_INVOKED defined works.
return preprocessed_output


Expand Down
18 changes: 11 additions & 7 deletions build/toolchain/win/tool_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
is used to set up calls to tools used by the build that need wrappers.
"""

from __future__ import print_function

import os
import re
import shutil
Expand Down Expand Up @@ -154,7 +156,7 @@ def ExecLinkWrapper(self, arch, use_separate_mspdbsrv, *args):
if (not line.startswith(' Creating library ') and
not line.startswith('Generating code') and
not line.startswith('Finished generating code')):
print line,
print(line)
result = link.wait()
if result == 0 and sys.platform == 'win32':
# Flush the file buffers to try to work around a Windows 10 kernel bug,
Expand All @@ -178,7 +180,7 @@ def ExecAsmWrapper(self, arch, *args):
out, _ = popen.communicate()
for line in out.splitlines():
if not line.startswith(' Assembling: '):
print line
print(line)
return popen.returncode

def ExecRcWrapper(self, arch, *args):
Expand Down Expand Up @@ -207,11 +209,13 @@ def ExecRcWrapper(self, arch, *args):
if rc_exe_exit_code == 0:
# 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.
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/linux64/rc.sha1'
print 'Note: including file: ../../build/toolchain/win/rc/mac/rc.sha1'
print 'Note: including file: ../../build/toolchain/win/rc/win/rc.exe.sha1'
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/linux64/rc.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.
if sys.platform == 'win32' and rc_exe_exit_code == 0:
Expand Down
10 changes: 6 additions & 4 deletions build/win/copy_cdb_to_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# 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 glob
import hashlib
import os
Expand Down Expand Up @@ -38,7 +40,7 @@ def _CopyImpl(file_name, target_dir, source_dir, verbose=False):
((not os.path.isfile(target)) or
_HexDigest(source) != _HexDigest(target))):
if verbose:
print 'Copying %s to %s...' % (source, target)
print('Copying %s to %s...' % (source, target))
if os.path.exists(target):
os.unlink(target)
shutil.copy(source, target)
Expand Down Expand Up @@ -69,7 +71,7 @@ def _CopyCDBToOutput(output_dir, target_arch):
elif target_arch in ['x64', 'arm64']:
src_arch = target_arch
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)
# We need to copy multiple files, so cache the computed source directory.
src_dir = os.path.join(win_sdk_dir, 'Debuggers', src_arch)
Expand Down Expand Up @@ -109,8 +111,8 @@ def _CopyCDBToOutput(output_dir, target_arch):

def main():
if len(sys.argv) < 2:
print >>sys.stderr, 'Usage: copy_cdb_to_output.py <output_dir> ' + \
'<target_arch>'
print('Usage: copy_cdb_to_output.py <output_dir> ' + \
'<target_arch>', file=sys.stderr)
return 1
return _CopyCDBToOutput(sys.argv[1], sys.argv[2])

Expand Down
17 changes: 10 additions & 7 deletions build/win/message_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#
# Usage: message_compiler.py <environment_file> [<args to mc.exe>*]

from __future__ import print_function

import difflib
import distutils.dir_util
import filecmp
Expand Down Expand Up @@ -65,7 +67,7 @@ def main():
# we use the 2017 Fall Creator's Update by default.
mc_help = subprocess.check_output(['mc.exe', '/?'], env=env_dict,
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':
return

Expand Down Expand Up @@ -122,20 +124,21 @@ def main():
# in tmp_dir to the checked-in outputs.
diff = filecmp.dircmp(tmp_dir, source)
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,
tmp_dir)
print('mc.exe output different from files in %s, see %s' % (source,
tmp_dir))
diff.report()
for f in diff.diff_files:
if f.endswith('.bin'): continue
fromfile = os.path.join(source, f)
tofile = os.path.join(tmp_dir, f)
print ''.join(difflib.unified_diff(open(fromfile, 'U').readlines(),
open(tofile, 'U').readlines(),
fromfile, tofile))
print(''.join(
difflib.unified_diff(
open(fromfile, 'U').readlines(),
open(tofile, 'U').readlines(), fromfile, tofile)))
delete_tmp_dir = False
sys.exit(1)
except subprocess.CalledProcessError as e:
print e.output
print(e.output)
sys.exit(e.returncode)
finally:
if os.path.exists(tmp_dir) and delete_tmp_dir:
Expand Down

0 comments on commit 79fbf3c

Please sign in to comment.