OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 import errno | 7 import errno |
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 import shutil | 10 import shutil |
11 import subprocess | 11 import subprocess |
12 import sys | 12 import sys |
13 | 13 |
14 from cbuildbot_config import config | 14 from cbuildbot_config import config |
15 | 15 |
16 _DEFAULT_RETRIES=3 | 16 _DEFAULT_RETRIES=3 |
17 | 17 |
18 # Utility functions | 18 # Utility functions |
19 | 19 |
20 def RunCommand(cmd, error_ok=False, error_message=None, exit_code=False, | 20 def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None, |
21 redirect_stdout=False, redirect_stderr=False, cwd=None, | 21 exit_code=False, redirect_stdout=False, redirect_stderr=False, |
22 input=None): | 22 cwd=None, input=None): |
23 # Print out the command before running. | 23 # Print out the command before running. |
24 print >>sys.stderr, "CBUILDBOT -- RunCommand:", ' '.join(cmd) | 24 if print_cmd: |
| 25 print >> sys.stderr, "CBUILDBOT -- RunCommand:", ' '.join(cmd) |
25 if redirect_stdout: | 26 if redirect_stdout: |
26 stdout = subprocess.PIPE | 27 stdout = subprocess.PIPE |
27 else: | 28 else: |
28 stdout = None | 29 stdout = None |
29 if redirect_stderr: | 30 if redirect_stderr: |
30 stderr = subprocess.PIPE | 31 stderr = subprocess.PIPE |
31 else: | 32 else: |
32 stderr = None | 33 stderr = None |
33 if input: | 34 if input: |
34 stdin = subprocess.PIPE | 35 stdin = subprocess.PIPE |
35 else: | 36 else: |
36 stdin = None | 37 stdin = None |
37 proc = subprocess.Popen(cmd, cwd=cwd, stdin=stdin, | 38 proc = subprocess.Popen(cmd, cwd=cwd, stdin=stdin, |
38 stdout=stdout, stderr=stderr) | 39 stdout=stdout, stderr=stderr) |
39 (output, error) = proc.communicate(input) | 40 (output, error) = proc.communicate(input) |
40 if exit_code: | 41 if exit_code: |
41 return proc.returncode | 42 return proc.returncode |
42 if not error_ok and proc.returncode != 0: | 43 if not error_ok and proc.returncode != 0: |
43 raise Exception('Command "%s" failed.\n' % (' '.join(cmd)) + | 44 raise Exception('Command "%s" failed.\n' % (' '.join(cmd)) + |
44 (error_message or error or output or '')) | 45 (error_message or error or output or '')) |
45 return output | 46 return output |
46 | 47 |
47 def MakeDir(path, parents=False): | 48 def MakeDir(path, parents=False): |
48 try: | 49 try: |
49 os.makedirs(path) | 50 os.makedirs(path) |
50 except OSError,e: | 51 except OSError, e: |
51 if e.errno == errno.EEXIST and parents: | 52 if e.errno == errno.EEXIST and parents: |
52 pass | 53 pass |
53 else: | 54 else: |
54 raise | 55 raise |
55 | 56 |
56 def RepoSync(buildroot, retries=_DEFAULT_RETRIES): | 57 def RepoSync(buildroot, retries=_DEFAULT_RETRIES): |
57 while retries > 0: | 58 while retries > 0: |
58 try: | 59 try: |
59 RunCommand(['repo', 'sync'], cwd=buildroot) | 60 RunCommand(['repo', 'sync'], cwd=buildroot) |
60 retries = 0 | 61 retries = 0 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 94 |
94 def _SetupBoard(buildroot, board='x86-generic'): | 95 def _SetupBoard(buildroot, board='x86-generic'): |
95 cwd = os.path.join(buildroot, 'src', 'scripts') | 96 cwd = os.path.join(buildroot, 'src', 'scripts') |
96 RunCommand(['./setup_board', '--fast', '--default', '--board=%s' % board], | 97 RunCommand(['./setup_board', '--fast', '--default', '--board=%s' % board], |
97 cwd=cwd) | 98 cwd=cwd) |
98 | 99 |
99 def _Build(buildroot): | 100 def _Build(buildroot): |
100 cwd = os.path.join(buildroot, 'src', 'scripts') | 101 cwd = os.path.join(buildroot, 'src', 'scripts') |
101 RunCommand(['./build_packages'], cwd=cwd) | 102 RunCommand(['./build_packages'], cwd=cwd) |
102 | 103 |
103 def _UprevPackages(buildroot): | 104 def _UprevAllPackages(buildroot): |
104 cwd = os.path.join(buildroot, 'src', 'scripts') | 105 cwd = os.path.join(buildroot, 'src', 'scripts') |
105 RunCommand(['./enter_chroot.sh', '--', './cros_mark_all_as_stable', | 106 RunCommand(['./enter_chroot.sh', '--', './cros_mark_all_as_stable', |
106 '--tracking_branch="cros/master"'], | 107 '--tracking_branch="cros/master"'], |
107 cwd=cwd) | 108 cwd=cwd) |
108 | 109 |
| 110 def _UprevPackages(buildroot, revisionfile): |
| 111 revisions = None |
| 112 if (revision_file): |
| 113 rev_file = revisionfile.open(revisionfile) |
| 114 revisions = rev_file.read() |
| 115 rev_file.close() |
| 116 |
| 117 # Note: Revisions == "None" indicates a Force Build. |
| 118 if revisions and revisions != 'None': |
| 119 print 'CBUILDBOT - Revision list found %s' % revisions |
| 120 print 'Revision list not yet propagating to build, marking all instead' |
| 121 |
| 122 _UprevAllPackages(buildroot) |
| 123 |
109 def _UprevCleanup(buildroot): | 124 def _UprevCleanup(buildroot): |
110 cwd = os.path.join(buildroot, 'src', 'scripts') | 125 cwd = os.path.join(buildroot, 'src', 'scripts') |
111 RunCommand(['./cros_mark_as_stable', '--srcroot=..', | 126 RunCommand(['./cros_mark_as_stable', '--srcroot=..', |
112 '--tracking_branch="cros/master"', 'clean'], | 127 '--tracking_branch="cros/master"', 'clean'], |
113 cwd=cwd) | 128 cwd=cwd) |
114 | 129 |
115 def _UprevPush(buildroot): | 130 def _UprevPush(buildroot): |
116 cwd = os.path.join(buildroot, 'src', 'scripts') | 131 cwd = os.path.join(buildroot, 'src', 'scripts') |
117 RunCommand(['./cros_mark_as_stable', '--srcroot=..', | 132 RunCommand(['./cros_mark_as_stable', '--srcroot=..', |
118 '--tracking_branch="cros/master"', | 133 '--tracking_branch="cros/master"', |
(...skipping 11 matching lines...) Expand all Loading... |
130 return buildconfig | 145 return buildconfig |
131 | 146 |
132 def main(): | 147 def main(): |
133 # Parse options | 148 # Parse options |
134 usage = "usage: %prog [options] cbuildbot_config" | 149 usage = "usage: %prog [options] cbuildbot_config" |
135 parser = optparse.OptionParser(usage=usage) | 150 parser = optparse.OptionParser(usage=usage) |
136 parser.add_option('-r', '--buildroot', | 151 parser.add_option('-r', '--buildroot', |
137 help='root directory where build occurs', default=".") | 152 help='root directory where build occurs', default=".") |
138 parser.add_option('-n', '--buildnumber', | 153 parser.add_option('-n', '--buildnumber', |
139 help='build number', type='int', default=0) | 154 help='build number', type='int', default=0) |
| 155 parser.add_option('-f', '--revisionfile', |
| 156 help='file where new revisions are stored') |
| 157 parser.add_option('--noclobber', action='store_false', dest='clobber', |
| 158 default=True, |
| 159 help='Disables clobbering the buildroot on failure') |
140 (options, args) = parser.parse_args() | 160 (options, args) = parser.parse_args() |
141 | 161 |
142 buildroot = options.buildroot | 162 buildroot = options.buildroot |
| 163 revisionfile = options.revisionfile |
| 164 clobber = options.clobber |
| 165 |
143 if len(args) == 1: | 166 if len(args) == 1: |
144 buildconfig = _GetConfig(args[0]) | 167 buildconfig = _GetConfig(args[0]) |
145 else: | 168 else: |
146 print >>sys.stderr, "Missing configuration description" | 169 print >> sys.stderr, "Missing configuration description" |
147 parser.print_usage() | 170 parser.print_usage() |
148 sys.exit(1) | 171 sys.exit(1) |
149 try: | 172 try: |
150 if not os.path.isdir(buildroot): | 173 if not os.path.isdir(buildroot): |
151 _FullCheckout(buildroot) | 174 _FullCheckout(buildroot) |
152 else: | 175 else: |
153 _IncrementalCheckout(buildroot) | 176 _IncrementalCheckout(buildroot) |
154 chroot_path = os.path.join(buildroot, 'chroot') | 177 chroot_path = os.path.join(buildroot, 'chroot') |
155 if not os.path.isdir(chroot_path): | 178 if not os.path.isdir(chroot_path): |
156 _MakeChroot(buildroot) | 179 _MakeChroot(buildroot) |
157 boardpath = os.path.join(chroot_path, 'build', buildconfig['board']) | 180 boardpath = os.path.join(chroot_path, 'build', buildconfig['board']) |
158 if not os.path.isdir(boardpath): | 181 if not os.path.isdir(boardpath): |
159 _SetupBoard(buildroot, board=buildconfig['board']) | 182 _SetupBoard(buildroot, board=buildconfig['board']) |
160 if buildconfig['uprev']: | 183 if buildconfig['uprev']: |
161 _UprevPackages(buildroot) | 184 _UprevPackages(buildroot, revisionfile) |
162 _Build(buildroot) | 185 _Build(buildroot) |
163 if buildconfig['uprev']: | 186 if buildconfig['uprev']: |
164 _UprevPush(buildroot) | 187 _UprevPush(buildroot) |
165 _UprevCleanup(buildroot) | 188 _UprevCleanup(buildroot) |
166 except: | 189 except: |
167 # something went wrong, cleanup (being paranoid) for next build | 190 # something went wrong, cleanup (being paranoid) for next build |
168 RunCommand(['sudo', 'rm', '-rf', buildroot]) | 191 if clobber: |
| 192 RunCommand(['sudo', 'rm', '-rf', buildroot], print_cmd=False) |
169 raise | 193 raise |
170 | 194 |
171 if __name__ == '__main__': | 195 if __name__ == '__main__': |
172 main() | 196 main() |
OLD | NEW |