2 # Copyright 2013 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.
6 """A script to find a recently-built Chrome, in the likely places.
7 This script is used for automated testing, don't trust it for anything more
16 def FindChrome(src_dir
, configs
, verbose
=False):
17 # List of places that chrome could live.
18 # In theory we should be more careful about what platform we're actually
20 # As currently constructed, this will also hork people who have debug and
21 # release builds sitting side by side who build locally.
24 for config
in configs
:
25 chrome_locations
.extend([
26 'build/%s/chrome.exe' % config
,
27 'chrome/%s/chrome.exe' % config
,
28 # Windows Chromium ninja builder
29 'out/%s/chrome.exe' % config
,
31 'out/%s/chrome' % config
,
32 # Mac Chromium ninja builder
33 'out/%s/Chromium.app/Contents/MacOS/Chromium' % config
,
34 # Mac release ninja builder
35 'out/%s/Google Chrome.app/Contents/MacOS/Google Chrome' % config
,
36 # Mac Chromium xcode builder
37 'xcodebuild/%s/Chromium.app/Contents/MacOS/Chromium' % config
,
38 # Mac release xcode builder
39 'xcodebuild/%s/Google Chrome.app/Contents/MacOS/Google Chrome' % config
,
42 # Pick the one with the newest timestamp.
45 for chrome
in chrome_locations
:
46 chrome_filename
= os
.path
.join(src_dir
, chrome
)
48 print 'Looking for %r...' % chrome_filename
,
49 if os
.path
.exists(chrome_filename
):
52 mtime
= os
.path
.getmtime(chrome_filename
)
53 if mtime
> latest_mtime
:
55 latest_path
= chrome_filename
59 if latest_path
is not None:
61 print 'Most recent is %r.' % latest_path
67 usage
= 'Usage: %prog [options] <src dir>'
69 parser
= optparse
.OptionParser(usage
, description
=description
)
70 parser
.add_option('-c', '--config',
72 help='Which configuration of Chrome to look for. '
73 'One of [Debug, Release]. The default is to try both. '
74 'You can specify this multiple times.')
75 parser
.add_option('-v', '--verbose', action
='store_true',
76 help='Verbose output')
78 options
, args
= parser
.parse_args(args
[1:])
81 parser
.error('Expected source directory as first argument.')
83 if not options
.config
:
84 options
.config
= ['Debug', 'Release']
86 invalid_configs
= set(options
.config
) - set(['Debug', 'Release'])
88 parser
.error('Expected config to be one of [Debug, Release]. '
89 'Got the following invalid configs: %s. ' %
93 chrome_path
= FindChrome(src_dir
, options
.config
, options
.verbose
)
95 sys
.stderr
.write('Error: Cannot find Chrome. '
96 'Run again with -v to see where was searched.\n')
103 if __name__
== '__main__':
104 sys
.exit(main(sys
.argv
))