[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # Copyright (c) 2009 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. |
| 5 | |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 6 | import os |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 7 | import re |
[email protected] | c989674 | 2010-09-10 17:26:39 | [diff] [blame] | 8 | import subprocess |
| 9 | import sys |
| 10 | import urllib |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 11 | |
[email protected] | c989674 | 2010-09-10 17:26:39 | [diff] [blame] | 12 | IS_WIN = sys.platform.startswith('win') |
| 13 | BASE_URL = 'http://src.chromium.org/svn/trunk/tools/buildbot/scripts/' |
| 14 | COMPILE_URL = BASE_URL + 'slave/compile.py' |
| 15 | UTILS_URL = BASE_URL + 'common/chromium_utils.py' |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 16 | |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 17 | |
[email protected] | cb2985f | 2010-11-03 14:08:31 | [diff] [blame] | 18 | def Fetch(url, filename): |
| 19 | if not os.path.exists(filename): |
| 20 | urllib.urlretrieve(url, filename) |
[email protected] | c989674 | 2010-09-10 17:26:39 | [diff] [blame] | 21 | |
| 22 | |
| 23 | def GetLastestRevision(): |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 24 | """Returns the revision number of the last build that was archived, or |
| 25 | None on failure.""" |
[email protected] | c989674 | 2010-09-10 17:26:39 | [diff] [blame] | 26 | 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] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 42 | return None |
| 43 | |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 44 | |
| 45 | def DoUpdate(chrome_root): |
| 46 | """gclient sync to the latest build.""" |
[email protected] | c989674 | 2010-09-10 17:26:39 | [diff] [blame] | 47 | 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] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 52 | |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 53 | |
[email protected] | c989674 | 2010-09-10 17:26:39 | [diff] [blame] | 54 | def DoBuild(chrome_root, args): |
| 55 | """Download compile.py and run it.""" |
[email protected] | cb2985f | 2010-11-03 14:08:31 | [diff] [blame] | 56 | compile_path = os.path.join(chrome_root, 'compile.py') |
| 57 | Fetch(COMPILE_URL, compile_path) |
[email protected] | c989674 | 2010-09-10 17:26:39 | [diff] [blame] | 58 | Fetch(UTILS_URL, os.path.join(chrome_root, 'chromium_utils.py')) |
[email protected] | cb2985f | 2010-11-03 14:08:31 | [diff] [blame] | 59 | cmd = ['python', compile_path] + args |
[email protected] | c989674 | 2010-09-10 17:26:39 | [diff] [blame] | 60 | return subprocess.call(cmd, cwd=chrome_root, shell=IS_WIN) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 61 | |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 62 | |
[email protected] | c989674 | 2010-09-10 17:26:39 | [diff] [blame] | 63 | def Main(args): |
| 64 | 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] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 70 | |
[email protected] | c989674 | 2010-09-10 17:26:39 | [diff] [blame] | 71 | chrome_root = args[1] |
[email protected] | f32e8a8 | 2009-06-08 14:04:54 | [diff] [blame] | 72 | if not os.path.isdir(chrome_root): |
[email protected] | c989674 | 2010-09-10 17:26:39 | [diff] [blame] | 73 | print('Path to chrome root (%s) not found.' % chrome_root) |
| 74 | return 1 |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 75 | |
[email protected] | c989674 | 2010-09-10 17:26:39 | [diff] [blame] | 76 | rv = DoUpdate(chrome_root) |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 77 | if rv != 0: |
[email protected] | c989674 | 2010-09-10 17:26:39 | [diff] [blame] | 78 | print('Update Failed. Bailing.') |
| 79 | return rv |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 80 | |
[email protected] | c989674 | 2010-09-10 17:26:39 | [diff] [blame] | 81 | DoBuild(chrome_root, args[2:]) |
| 82 | print('Success!') |
| 83 | return 0 |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 84 | |
[email protected] | fb2b8eb | 2009-04-23 21:03:42 | [diff] [blame] | 85 | |
| 86 | if __name__ == "__main__": |
[email protected] | c989674 | 2010-09-10 17:26:39 | [diff] [blame] | 87 | sys.exit(Main(sys.argv)) |