OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 | |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
4 # Use of this source code is governed by a BSD-style license that can be | |
5 # found in the LICENSE file. | |
6 | |
7 """Pub buildbot steps | |
8 | |
9 Runs tests for pub and the pub packages that are hosted in the main Dart repo. | |
10 This file is heartily inspired by utils/compiler/buildbot.py. | |
11 """ | |
12 | |
13 import optparse | |
14 import os | |
15 from os.path import abspath | |
16 from os.path import dirname | |
17 import re | |
18 import subprocess | |
19 import sys | |
20 | |
21 BUILDER_NAME = 'BUILDBOT_BUILDERNAME' | |
22 BUILDER_CLOBBER = 'BUILDBOT_CLOBBER' | |
23 | |
24 DART_PATH = dirname(dirname(dirname(abspath(__file__)))) | |
25 | |
26 PUB_BUILDER = r'pub-(linux|mac|win)' | |
27 | |
28 NO_COLOR_ENV = dict(os.environ) | |
29 NO_COLOR_ENV['TERM'] = 'nocolor' | |
30 | |
31 | |
32 def GetBuildInfo(): | |
33 """Returns info for the current buildbot based on the name of the builder. | |
34 | |
35 Currently, this is just: | |
36 - mode: always "release" | |
37 - system: "linux", "mac", or "win" | |
38 """ | |
39 | |
40 # For testing the bot locally, allow the user to pass in a buildbot name. | |
Emily Fortuna
2012/10/19 21:35:53
:-D
| |
41 parser = optparse.OptionParser() | |
42 parser.add_option('-n', '--name', dest='name', help='The name of the build' | |
43 'bot you would like to emulate (ex: web-chrome-win7)', default=None) | |
Emily Fortuna
2012/10/19 21:35:53
nit: change the name to a pub-like bot name instea
Bob Nystrom
2012/10/20 01:06:38
Done.
| |
44 args, _ = parser.parse_args() | |
45 | |
46 if args.name: | |
47 builder_name = args.name | |
48 else: | |
49 builder_name = os.environ.get(BUILDER_NAME) | |
50 if not builder_name: | |
51 print 'Use -n $BUILDBOT_NAME for the bot you would like to emulate.' | |
52 sys.exit(1) | |
53 | |
54 pub_pattern = re.match(PUB_BUILDER, builder_name) | |
55 if not pub_pattern: | |
56 print 'Could not handle unfamiliar bot name "$builder_name".' | |
57 sys.exit(1) | |
58 | |
59 system = pub_pattern.group(1) | |
60 if system == 'win': system = 'windows' | |
61 | |
62 return ('release', system) | |
63 | |
64 | |
65 def TestStepName(name, flags): | |
66 # Filter out flags with '=' as this breaks the /stats feature of the | |
67 # build bot. | |
68 flags = [x for x in flags if not '=' in x] | |
69 return ('%s tests %s' % (name, ' '.join(flags))).strip() | |
70 | |
71 | |
72 def TestStep(name, mode, system, compiler, runtime, targets, flags): | |
73 step_name = TestStepName(name, flags) | |
74 print '@@@BUILD_STEP %s@@@' % step_name | |
75 sys.stdout.flush() | |
76 | |
77 cmd = [ | |
78 sys.executable, os.path.join(os.curdir, 'tools', 'test.py'), | |
79 '--step_name=' + step_name, | |
80 '--mode=' + mode, | |
81 '--compiler=' + compiler, | |
82 '--runtime=' + runtime, | |
83 '--progress=buildbot', | |
84 '-v', '--time', '--use-sdk', '--checked', '--report' | |
85 ] | |
86 | |
87 if flags: | |
88 cmd.extend(flags) | |
89 cmd.extend(targets) | |
90 | |
91 print 'Running: %s' % (' '.join(cmd)) | |
92 exit_code = subprocess.call(cmd, env=NO_COLOR_ENV) | |
93 return CheckFailure(exit_code) | |
94 | |
95 | |
96 def BuildSDK(mode, system): | |
Emily Fortuna
2012/10/19 21:35:53
A lot of this is pretty much exactly copied code f
Bob Nystrom
2012/10/20 01:06:38
I don't want to add pub stuff to the original scri
| |
97 """ build the SDK. | |
98 Args: | |
99 - mode: either 'debug' or 'release' | |
100 - system: either 'linux', 'mac', or 'win7' | |
101 """ | |
102 print '@@@BUILD_STEP build sdk@@@' | |
103 args = [sys.executable, './tools/build.py', '--mode=' + mode, 'create_sdk'] | |
104 print 'Building SDK: %s' % (' '.join(args)) | |
105 return subprocess.call(args, env=NO_COLOR_ENV) | |
106 | |
107 | |
108 def ClobberBuilder(mode): | |
109 """ Clobber the builder before we do the build, if appropriate. | |
110 Args: | |
111 - mode: either 'debug' or 'release' | |
112 """ | |
113 if os.environ.get(BUILDER_CLOBBER) != "1": | |
114 return 0 | |
115 | |
116 print '@@@BUILD_STEP Clobber@@@' | |
117 cmd = [sys.executable, | |
118 './tools/clean_output_directory.py', | |
119 '--mode=' + mode] | |
120 print 'Clobbering %s' % (' '.join(cmd)) | |
121 return subprocess.call(cmd, env=NO_COLOR_ENV) | |
122 | |
123 | |
124 def CheckFailure(status): | |
125 """ Prints the appropriate buildbot message if status is a failure code. | |
126 """ | |
127 if status != 0: | |
128 print '@@@STEP_FAILURE@@@' | |
129 | |
130 return status | |
131 | |
132 | |
133 def main(): | |
134 if len(sys.argv) == 0: | |
135 print 'Script pathname not known, giving up.' | |
136 return 1 | |
137 | |
138 (mode, system) = GetBuildInfo() | |
139 | |
140 # Make sure we are in the dart directory | |
141 os.chdir(DART_PATH) | |
142 | |
143 status = ClobberBuilder(mode) | |
144 if CheckFailure(status): return status | |
145 | |
146 status = BuildSDK(mode, system) | |
147 if CheckFailure(status): return status | |
148 | |
149 # TODO(rnystrom): Eventually test other targets here like 'utils'? | |
150 status = TestStep('pub', mode, system, 'none', 'vm', ['pub'], []) | |
151 if CheckFailure(status): return status | |
152 | |
153 if __name__ == '__main__': | |
154 sys.exit(main()) | |
OLD | NEW |