blob: 4fb11e5aba2578d2b99d146d1c171942264a0d54 [file] [log] [blame]
[email protected]725f1c32011-04-01 20:24:541#!/usr/bin/env python
2# Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]fb2b8eb2009-04-23 21:03:423# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
[email protected]fb2b8eb2009-04-23 21:03:426import os
[email protected]fb2b8eb2009-04-23 21:03:427import re
[email protected]c9896742010-09-10 17:26:398import subprocess
9import sys
10import urllib
[email protected]fb2b8eb2009-04-23 21:03:4211
[email protected]c9896742010-09-10 17:26:3912IS_WIN = sys.platform.startswith('win')
13BASE_URL = 'http://src.chromium.org/svn/trunk/tools/buildbot/scripts/'
14COMPILE_URL = BASE_URL + 'slave/compile.py'
15UTILS_URL = BASE_URL + 'common/chromium_utils.py'
[email protected]fb2b8eb2009-04-23 21:03:4216
[email protected]fb2b8eb2009-04-23 21:03:4217
[email protected]cb2985f2010-11-03 14:08:3118def Fetch(url, filename):
19 if not os.path.exists(filename):
20 urllib.urlretrieve(url, filename)
[email protected]c9896742010-09-10 17:26:3921
22
23def GetLastestRevision():
[email protected]fb2b8eb2009-04-23 21:03:4224 """Returns the revision number of the last build that was archived, or
25 None on failure."""
[email protected]c9896742010-09-10 17:26:3926 url = 'http://build.chromium.org/buildbot/continuous/'
27 if sys.platform.startswith('win'):
28 url += 'win/'
29 elif sys.platform.startswith('linux'):
30 url += 'linux/'
31 elif sys.platform.startswith('darwin'):
32 url += 'mac/'
33 else:
34 # This path is actually win.
35 pass
36 url += 'LATEST/REVISION'
37 text = urllib.urlopen(url).read()
38 if text:
39 match = re.search(r"(\d+)", text)
40 if match:
41 return int(match.group(1))
[email protected]fb2b8eb2009-04-23 21:03:4242 return None
43
[email protected]fb2b8eb2009-04-23 21:03:4244
45def DoUpdate(chrome_root):
46 """gclient sync to the latest build."""
[email protected]c9896742010-09-10 17:26:3947 cmd = ["gclient", "sync"]
48 rev = GetLastestRevision()
49 if rev:
50 cmd.extend(['--revision', 'src@%d' % rev])
51 return subprocess.call(cmd, cwd=chrome_root, shell=IS_WIN)
[email protected]fb2b8eb2009-04-23 21:03:4252
[email protected]fb2b8eb2009-04-23 21:03:4253
[email protected]c9896742010-09-10 17:26:3954def DoBuild(chrome_root, args):
55 """Download compile.py and run it."""
[email protected]cb2985f2010-11-03 14:08:3156 compile_path = os.path.join(chrome_root, 'compile.py')
57 Fetch(COMPILE_URL, compile_path)
[email protected]c9896742010-09-10 17:26:3958 Fetch(UTILS_URL, os.path.join(chrome_root, 'chromium_utils.py'))
[email protected]cb2985f2010-11-03 14:08:3159 cmd = ['python', compile_path] + args
[email protected]c9896742010-09-10 17:26:3960 return subprocess.call(cmd, cwd=chrome_root, shell=IS_WIN)
[email protected]fb2b8eb2009-04-23 21:03:4261
[email protected]fb2b8eb2009-04-23 21:03:4262
[email protected]013731e2015-02-26 18:28:4363def main(args):
[email protected]c9896742010-09-10 17:26:3964 if len(args) < 3:
65 print('Usage: chrome-update.py <path> [options]')
66 print('See options from compile.py at')
67 print(' %s' % COMPILE_URL)
68 print('\nFor more example, see the compile steps on the waterfall')
69 return 1
[email protected]fb2b8eb2009-04-23 21:03:4270
[email protected]c9896742010-09-10 17:26:3971 chrome_root = args[1]
[email protected]f32e8a82009-06-08 14:04:5472 if not os.path.isdir(chrome_root):
[email protected]c9896742010-09-10 17:26:3973 print('Path to chrome root (%s) not found.' % chrome_root)
74 return 1
[email protected]fb2b8eb2009-04-23 21:03:4275
[email protected]c9896742010-09-10 17:26:3976 rv = DoUpdate(chrome_root)
[email protected]fb2b8eb2009-04-23 21:03:4277 if rv != 0:
[email protected]c9896742010-09-10 17:26:3978 print('Update Failed. Bailing.')
79 return rv
[email protected]fb2b8eb2009-04-23 21:03:4280
[email protected]c9896742010-09-10 17:26:3981 DoBuild(chrome_root, args[2:])
82 print('Success!')
83 return 0
[email protected]fb2b8eb2009-04-23 21:03:4284
[email protected]fb2b8eb2009-04-23 21:03:4285
86if __name__ == "__main__":
[email protected]013731e2015-02-26 18:28:4387 try:
88 sys.exit(main(sys.argv))
89 except KeyboardInterrupt:
90 sys.stderr.write('interrupted\n')
91 sys.exit(1)