summaryrefslogtreecommitdiffstats
path: root/chrome/tools/build
diff options
context:
space:
mode:
authorsiggi@chromium.org <siggi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-28 16:47:29 +0000
committersiggi@chromium.org <siggi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-28 16:47:29 +0000
commit125a48a1d40b94453e9282f71b16127c1b8643af (patch)
tree8bfcccffefdd1ddaf3cf99fa8cd2dd4c76e7c013 /chrome/tools/build
parent413d24d228d77542124d51f2abbabcb7830abf5d (diff)
downloadchromium_src-125a48a1d40b94453e9282f71b16127c1b8643af.zip
chromium_src-125a48a1d40b94453e9282f71b16127c1b8643af.tar.gz
chromium_src-125a48a1d40b94453e9282f71b16127c1b8643af.tar.bz2
Build a Syzygy-reordered mini_installer.exe.
This CL adds an All_syzygy target to the build/all.gyp solution, that builds a Syzygy-reordered chrome.dll and mini_installer. If there there is a chrome.dll-order.json file present in the output directory, chrome.dll will be ordered according to that, otherwise it will be randomized. Moved most of mini_installer.gyp to a common .gypi file for reuse. Review URL: http://codereview.chromium.org/8698009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111710 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/tools/build')
-rwxr-xr-xchrome/tools/build/win/create_installer_archive.py29
-rw-r--r--chrome/tools/build/win/syzygy_reorder.py111
2 files changed, 133 insertions, 7 deletions
diff --git a/chrome/tools/build/win/create_installer_archive.py b/chrome/tools/build/win/create_installer_archive.py
index 5a4e96c..6c42c1c 100755
--- a/chrome/tools/build/win/create_installer_archive.py
+++ b/chrome/tools/build/win/create_installer_archive.py
@@ -115,7 +115,9 @@ def CopySectionFilesToStagingDir(config, section, staging_dir, build_dir):
if not os.path.exists(dst):
os.makedirs(dst)
for file in glob.glob(os.path.join(build_dir, option)):
- shutil.copy(file, dst)
+ dst_file = os.path.join(dst, os.path.basename(file))
+ if not os.path.exists(dst_file):
+ shutil.copy(file, dst)
def GenerateDiffPatch(options, orig_file, new_file, patch_file):
if (options.diff_algorithm == "COURGETTE"):
@@ -186,7 +188,7 @@ def CreateArchiveFile(options, staging_dir, current_version, prev_version):
"""
# First create an uncompressed archive file for the current build (chrome.7z)
lzma_exec = GetLZMAExec(options.build_dir)
- archive_file = os.path.join(options.build_dir,
+ archive_file = os.path.join(options.output_dir,
options.output_name + ARCHIVE_SUFFIX)
cmd = [lzma_exec,
'a',
@@ -220,7 +222,7 @@ def CreateArchiveFile(options, staging_dir, current_version, prev_version):
compressed_archive_file = options.output_name + COMPRESSED_ARCHIVE_SUFFIX
orig_file = archive_file
- compressed_archive_file_path = os.path.join(options.build_dir,
+ compressed_archive_file_path = os.path.join(options.output_dir,
compressed_archive_file)
CompressUsingLZMA(options.build_dir, compressed_archive_file_path, orig_file)
@@ -248,7 +250,7 @@ def PrepareSetupExec(options, staging_dir, current_version, prev_version):
cmd = ['makecab.exe',
'/D', 'CompressionType=LZX',
'/V1',
- '/L', options.build_dir,
+ '/L', options.output_dir,
os.path.join(options.build_dir, SETUP_EXEC),]
RunSystemCommand(cmd)
setup_file = SETUP_EXEC[:-1] + "_"
@@ -316,6 +318,14 @@ def main(options):
prev_version = GetPrevVersion(options.build_dir, temp_dir,
options.last_chrome_installer)
+ # Preferentially copy the files we can find from the output_dir, as
+ # this is where we'll find the Syzygy-optimized executables when
+ # building the optimized mini_installer.
+ if options.build_dir != options.output_dir:
+ CopyAllFilesToStagingDir(config, options.distribution,
+ staging_dir, options.output_dir)
+
+ # Now copy the remainder of the files from the build dir.
CopyAllFilesToStagingDir(config, options.distribution,
staging_dir, options.build_dir)
@@ -341,11 +351,14 @@ def _ParseOptions():
parser = optparse.OptionParser()
parser.add_option('-i', '--input_file',
help='Input file describing which files to archive.')
- parser.add_option('-o', '--build_dir',
+ parser.add_option('-b', '--build_dir',
help='Build directory. The paths in input_file are relative to this.')
parser.add_option('--staging_dir',
help='Staging directory where intermediate files and directories '
'will be created'),
+ parser.add_option('-o', '--output_dir',
+ help='The output directory where the archives will be written. '
+ 'Defaults to the build_dir.')
parser.add_option('--resource_file_path',
help='The path where the resource file will be output. '
'Defaults to %s in the build directory.' %
@@ -368,20 +381,22 @@ def _ParseOptions():
help='Name used to prefix names of generated archives.')
options, args = parser.parse_args()
-
if not options.build_dir:
parser.error('You must provide a build dir.')
if not options.staging_dir:
parser.error('You must provide a staging dir.')
+ if not options.output_dir:
+ options.output_dir = options.build_dir
+
if not options.resource_file_path:
options.options.resource_file_path = os.path.join(options.build_dir,
MINI_INSTALLER_INPUT_FILE)
- print sys.argv
return options
if '__main__' == __name__:
+ print sys.argv
sys.exit(main(_ParseOptions()))
diff --git a/chrome/tools/build/win/syzygy_reorder.py b/chrome/tools/build/win/syzygy_reorder.py
new file mode 100644
index 0000000..a08f8b9
--- /dev/null
+++ b/chrome/tools/build/win/syzygy_reorder.py
@@ -0,0 +1,111 @@
+#!/usr/bin/python
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""A utility script to help building Syzygy-reordered Chrome binaries."""
+
+import logging
+import optparse
+import os
+import subprocess
+import sys
+
+
+# The default relink executable to use to reorder binaries.
+_DEFAULT_RELINKER = os.path.join(
+ os.path.join(os.path.dirname(__file__), '../../../..'),
+ 'third_party/syzygy/binaries/exe/relink.exe')
+
+_LOGGER = logging.getLogger()
+
+# We use the same seed for all random reorderings to get a deterministic build.
+_RANDOM_SEED = 1347344
+
+
+def _Shell(*cmd, **kw):
+ """Shells out to "cmd". Returns a tuple of cmd's stdout, stderr."""
+ _LOGGER.info('Running command "%s".', cmd)
+ prog = subprocess.Popen(cmd, **kw)
+
+ stdout, stderr = prog.communicate()
+ if prog.returncode != 0:
+ raise RuntimeError('Command "%s" returned %d.' % (cmd, prog.returncode))
+
+ return stdout, stderr
+
+
+def _ReorderBinary(relink_exe, executable, symbol, destination_dir):
+ """Reorders the executable found in input_dir, and writes the resultant
+ reordered executable and symbol files to destination_dir.
+
+ If a file named <executable>-order.json exists, imposes that order on the
+ output binaries, otherwise orders them randomly.
+ """
+ cmd = [relink_exe,
+ '--verbose',
+ '--input-dll=%s' % executable,
+ '--input-pdb=%s' % symbol,
+ '--output-dll=%s' % os.path.join(destination_dir,
+ os.path.basename(executable)),
+ '--output-pdb=%s' % os.path.join(destination_dir,
+ os.path.basename(symbol)),]
+
+ # Check whether there's an order file available for the executable.
+ order_file = '%s-order.json' % executable
+ if os.path.exists(order_file):
+ # The ordering file exists, let's use that.
+ _LOGGER.info('Reordering "%s" according to "%s".',
+ os.path.basename(executable),
+ os.path.basename(order_file))
+ cmd.append('--order-file=%s' % order_file)
+ else:
+ # No ordering file, we randomize the output.
+ _LOGGER.info('Randomly reordering "%s"', executable)
+ cmd.append('--seed=%d' % _RANDOM_SEED)
+
+ return _Shell(*cmd)
+
+
+def main(options):
+ logging.basicConfig(level=logging.INFO)
+
+ # Make sure the destination directory exists.
+ if not os.path.isdir(options.destination_dir):
+ _LOGGER.info('Creating destination directory "%s".',
+ options.destination_dir)
+ os.makedirs(options.destination_dir)
+
+ # Reorder the binaries into the destination directory.
+ _ReorderBinary(options.relinker,
+ options.input_executable,
+ options.input_symbol,
+ options.destination_dir)
+
+
+def _ParseOptions():
+ option_parser = optparse.OptionParser()
+ option_parser.add_option('--input_executable',
+ help='The path to the input executable.')
+ option_parser.add_option('--input_symbol',
+ help='The path to the input symbol file.')
+ option_parser.add_option('--relinker', default=_DEFAULT_RELINKER,
+ help='Relinker exectuable to use, defaults to "%s"' % _DEFAULT_RELINKER)
+ option_parser.add_option('-d', '--destination_dir',
+ help='Destination directory for reordered files, defaults to '
+ 'the subdirectory "reordered" in the output_dir.')
+ options, args = option_parser.parse_args()
+
+ if not options.input_executable:
+ option_parser.error('You must provide an input executable.')
+ if not options.input_symbol:
+ option_parser.error('You must provide an input symbol file.')
+
+ if not options.destination_dir:
+ options.destination_dir = os.path.join(options.output_dir, 'reordered')
+
+ return options
+
+
+if '__main__' == __name__:
+ sys.exit(main(_ParseOptions()))