Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: bin/cbuildbot.py

Issue 3146001: Adding cbuildbot to cros_utils. Leaving old version in repo until buildbot changes over. (Closed) Base URL: ssh://git@chromiumos-git//crosutils.git
Patch Set: patch from issue 1499002 Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bin/cbuildbot ('k') | bin/cbuildbot_config.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2
3 import errno
4 import optparse
5 import os
6 import shutil
7 import subprocess
8
9 from cbuildbot_config import config
10
11 # Utility functions
12
13 def RunCommand(cmd, error_ok=False, error_message=None, exit_code=False,
14 redirect_stdout=False, redirect_stderr=False, cwd=None,
15 input=None):
16 # Useful for debugging:
17 # print >>sys.stderr, "RunCommand:", ' '.join(cmd)
18 if redirect_stdout:
19 stdout = subprocess.PIPE
20 else:
21 stdout = None
22 if redirect_stderr:
23 stderr = subprocess.PIPE
24 else:
25 stderr = None
26 if input:
27 stdin = subprocess.PIPE
28 else:
29 stdin = None
30 proc = subprocess.Popen(cmd, cwd=cwd, stdin=stdin,
31 stdout=stdout, stderr=stderr)
32 (output, error) = proc.communicate(input)
33 if exit_code:
34 return proc.returncode
35 if not error_ok and proc.returncode != 0:
36 raise Exception('Command "%s" failed.\n' % (' '.join(cmd)) +
37 (error_message or error or output or ''))
38 return output
39
40 def MakeDir(path, parents=False):
41 try:
42 os.makedirs(path)
43 except OSError,e:
44 if e.errno == errno.EEXIST and parents:
45 pass
46 else:
47 raise
48
49 # Main functions
50
51 def _FullCheckout(buildroot):
52 MakeDir(buildroot, parents=True)
53 RunCommand(['repo', 'init', '-u', 'http://src.chromium.org/git/manifest'],
54 cwd=buildroot, input='\n\ny\n')
55 RunCommand(['repo', 'sync'], cwd=buildroot)
56 RunCommand(['repo', 'forall', '-c', 'git', 'config',
57 'url.ssh://gitrw.chromium.org.pushinsteadof',
58 'http://src.chromium.org/git'], cwd=buildroot)
59
60 def _IncrementalCheckout(buildroot):
61 RunCommand(['repo', 'sync'], cwd=buildroot)
62
63 def _MakeChroot(buildroot):
64 cwd = os.path.join(buildroot, 'src', 'scripts')
65 RunCommand(['./make_chroot', '--fast'], cwd=cwd)
66
67 def _SetupBoard(buildroot, board='x86-generic'):
68 cwd = os.path.join(buildroot, 'src', 'scripts')
69 RunCommand(['./setup_board', '--fast', '--default', '--board=%s' % board],
70 cwd=cwd)
71
72 def _Build(buildroot):
73 cwd = os.path.join(buildroot, 'src', 'scripts')
74 RunCommand(['./build_packages'], cwd=cwd)
75
76 def _UprevPackages(buildroot):
77 cwd = os.path.join(buildroot, 'src', 'scripts')
78 RunCommand(['./enter_chroot.sh', '--', './cros_mark_all_as_stable',
79 '--tracking_branch="cros/master"'],
80 cwd=cwd)
81
82 def _UprevCleanup(buildroot):
83 cwd = os.path.join(buildroot, 'src', 'scripts')
84 RunCommand(['./cros_mark_as_stable', '--srcroot=..',
85 '--tracking_branch="cros/master"', 'clean'],
86 cwd=cwd)
87
88 def _UprevPush(buildroot):
89 cwd = os.path.join(buildroot, 'src', 'scripts')
90 RunCommand(['./cros_mark_as_stable', '--srcroot=..',
91 '--tracking_branch="cros/master"',
92 '--push_options', '--bypass-hooks -f', 'push'],
93 cwd=cwd)
94
95 def _GetConfig(config_name):
96 default = config['default']
97 buildconfig = {}
98 if config.has_key(config_name):
99 buildconfig = config[config_name]
100 for key in default.iterkeys():
101 if not buildconfig.has_key(key):
102 buildconfig[key] = default[key]
103 return buildconfig
104
105 def main():
106 # Parse options
107 parser = optparse.OptionParser()
108 parser.add_option('-r', '--buildroot',
109 help='root directory where build occurs', default=".")
110 parser.add_option('-n', '--buildnumber',
111 help='build number', type='int', default=0)
112 (options, args) = parser.parse_args()
113
114 buildroot = options.buildroot
115 buildconfig = _GetConfig(args[0])
116
117 try:
118 if not os.path.isdir(buildroot):
119 _FullCheckout(buildroot)
120 else:
121 _IncrementalCheckout(buildroot)
122 chroot_path = os.path.join(buildroot, 'chroot')
123 if not os.path.isdir(chroot_path):
124 _MakeChroot(buildroot)
125 boardpath = os.path.join(chroot_path, 'build', buildconfig['board'])
126 if not os.path.isdir(boardpath):
127 _SetupBoard(buildroot, board=buildconfig['board'])
128 if buildconfig['uprev']:
129 _UprevPackages(buildroot)
130 _Build(buildroot)
131 if buildconfig['uprev']:
132 _UprevPush(buildroot)
133 _UprevCleanup(buildroot)
134 except:
135 # something went wrong, cleanup (being paranoid) for next build
136 RunCommand(['sudo', 'rm', '-rf', buildroot])
137 raise
138
139 if __name__ == '__main__':
140 main()
OLDNEW
« no previous file with comments | « bin/cbuildbot ('k') | bin/cbuildbot_config.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698