2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
13 def reorder_imports(input_dir
, output_dir
, architecture
):
14 """Run swapimports.exe on the initial chrome.exe, and write to the output
15 directory. Also copy over any related files that might be needed
16 (pdbs, manifests etc.).
19 input_image
= os
.path
.join(input_dir
, 'chrome.exe')
20 output_image
= os
.path
.join(output_dir
, 'chrome.exe')
22 # TODO(caitkp): Remove this once swapimport works on x64 builds.
23 if architecture
== 'x64':
24 shutil
.copy(input_image
, output_image
)
26 swap_exe
= os
.path
.join(
28 '..\\..\\..\\third_party\\syzygy\\binaries\\exe\\swapimport.exe')
30 [swap_exe
, '--input-image=%s' % input_image
,
31 '--output-image=%s' % output_image
, '--overwrite', 'chrome_elf.dll'])
33 for fname
in glob
.iglob(os
.path
.join(input_dir
, 'chrome.exe.*')):
34 shutil
.copy(fname
, os
.path
.join(output_dir
, os
.path
.basename(fname
)))
39 usage
= 'reorder_imports.py -i <input_dir> -o <output_dir> -a <target_arch>'
40 parser
= optparse
.OptionParser(usage
=usage
)
41 parser
.add_option('-i', '--input', help='reorder chrome.exe in DIR',
43 parser
.add_option('-o', '--output', help='write new chrome.exe to DIR',
45 parser
.add_option('-a', '--arch', help='architecture of build (optional)',
47 opts
, args
= parser
.parse_args()
49 if not opts
.input or not opts
.output
:
50 parser
.error('Please provide and input and output directory')
51 return reorder_imports(opts
.input, opts
.output
, opts
.arch
)
53 if __name__
== "__main__":
54 sys
.exit(main(sys
.argv
[1:]))