Craig Tiller | c2c7921 | 2015-02-16 12:00:01 -0800 | [diff] [blame] | 1 | # Copyright 2015, Google Inc. |
| 2 | # All rights reserved. |
| 3 | # |
| 4 | # Redistribution and use in source and binary forms, with or without |
| 5 | # modification, are permitted provided that the following conditions are |
| 6 | # met: |
| 7 | # |
| 8 | # * Redistributions of source code must retain the above copyright |
| 9 | # notice, this list of conditions and the following disclaimer. |
| 10 | # * Redistributions in binary form must reproduce the above |
| 11 | # copyright notice, this list of conditions and the following disclaimer |
| 12 | # in the documentation and/or other materials provided with the |
| 13 | # distribution. |
| 14 | # * Neither the name of Google Inc. nor the names of its |
| 15 | # contributors may be used to endorse or promote products derived from |
| 16 | # this software without specific prior written permission. |
| 17 | # |
| 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 30 | """Run a group of subprocesses and then finish.""" |
| 31 | |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 32 | import hashlib |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 33 | import multiprocessing |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 34 | import os |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 35 | import platform |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 36 | import random |
Craig Tiller | 336ad50 | 2015-02-24 14:46:02 -0800 | [diff] [blame] | 37 | import signal |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 38 | import subprocess |
| 39 | import sys |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 40 | import tempfile |
| 41 | import time |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 42 | |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 43 | |
ctiller | 94e5dde | 2015-01-09 10:41:59 -0800 | [diff] [blame] | 44 | _DEFAULT_MAX_JOBS = 16 * multiprocessing.cpu_count() |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 45 | |
| 46 | |
Craig Tiller | 336ad50 | 2015-02-24 14:46:02 -0800 | [diff] [blame] | 47 | # setup a signal handler so that signal.pause registers 'something' |
| 48 | # when a child finishes |
| 49 | # not using futures and threading to avoid a dependency on subprocess32 |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 50 | if platform.system() == "Windows": |
| 51 | pass |
| 52 | else: |
| 53 | have_alarm = False |
| 54 | def alarm_handler(unused_signum, unused_frame): |
| 55 | global have_alarm |
| 56 | have_alarm = False |
| 57 | |
| 58 | signal.signal(signal.SIGCHLD, lambda unused_signum, unused_frame: None) |
| 59 | signal.signal(signal.SIGALRM, alarm_handler) |
Craig Tiller | 336ad50 | 2015-02-24 14:46:02 -0800 | [diff] [blame] | 60 | |
| 61 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 62 | def shuffle_iteratable(it): |
| 63 | """Return an iterable that randomly walks it""" |
| 64 | # take a random sampling from the passed in iterable |
| 65 | # we take an element with probablity 1/p and rapidly increase |
| 66 | # p as we take elements - this gives us a somewhat random set of values before |
| 67 | # we've seen all the values, but starts producing values without having to |
| 68 | # compute ALL of them at once, allowing tests to start a little earlier |
| 69 | nextit = [] |
| 70 | p = 1 |
| 71 | for val in it: |
| 72 | if random.randint(0, p) == 0: |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 73 | p = min(p*2, 100) |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 74 | yield val |
| 75 | else: |
| 76 | nextit.append(val) |
| 77 | # after taking a random sampling, we shuffle the rest of the elements and |
| 78 | # yield them |
| 79 | random.shuffle(nextit) |
| 80 | for val in nextit: |
| 81 | yield val |
| 82 | |
| 83 | |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 84 | _SUCCESS = object() |
| 85 | _FAILURE = object() |
| 86 | _RUNNING = object() |
| 87 | _KILLED = object() |
| 88 | |
| 89 | |
Craig Tiller | 3b08306 | 2015-01-12 13:51:28 -0800 | [diff] [blame] | 90 | _COLORS = { |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 91 | 'red': [ 31, 0 ], |
| 92 | 'green': [ 32, 0 ], |
| 93 | 'yellow': [ 33, 0 ], |
| 94 | 'lightgray': [ 37, 0], |
| 95 | 'gray': [ 30, 1 ], |
Craig Tiller | 3b08306 | 2015-01-12 13:51:28 -0800 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
| 99 | _BEGINNING_OF_LINE = '\x1b[0G' |
| 100 | _CLEAR_LINE = '\x1b[2K' |
| 101 | |
| 102 | |
| 103 | _TAG_COLOR = { |
| 104 | 'FAILED': 'red', |
Craig Tiller | e1d0d1c | 2015-02-27 08:54:23 -0800 | [diff] [blame] | 105 | 'TIMEOUT': 'red', |
Craig Tiller | 3b08306 | 2015-01-12 13:51:28 -0800 | [diff] [blame] | 106 | 'PASSED': 'green', |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 107 | 'START': 'gray', |
Craig Tiller | 3b08306 | 2015-01-12 13:51:28 -0800 | [diff] [blame] | 108 | 'WAITING': 'yellow', |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 109 | 'SUCCESS': 'green', |
| 110 | 'IDLE': 'gray', |
Craig Tiller | 3b08306 | 2015-01-12 13:51:28 -0800 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 114 | def message(tag, message, explanatory_text=None, do_newline=False): |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 115 | if platform.system() == 'Windows': |
| 116 | if explanatory_text: |
| 117 | print explanatory_text |
| 118 | print '%s: %s' % (tag, message) |
| 119 | return |
Craig Tiller | 23d2f3f | 2015-02-24 15:23:32 -0800 | [diff] [blame] | 120 | try: |
| 121 | sys.stdout.write('%s%s%s\x1b[%d;%dm%s\x1b[0m: %s%s' % ( |
| 122 | _BEGINNING_OF_LINE, |
| 123 | _CLEAR_LINE, |
| 124 | '\n%s' % explanatory_text if explanatory_text is not None else '', |
| 125 | _COLORS[_TAG_COLOR[tag]][1], |
| 126 | _COLORS[_TAG_COLOR[tag]][0], |
| 127 | tag, |
| 128 | message, |
| 129 | '\n' if do_newline or explanatory_text is not None else '')) |
| 130 | sys.stdout.flush() |
| 131 | except: |
| 132 | pass |
Craig Tiller | 3b08306 | 2015-01-12 13:51:28 -0800 | [diff] [blame] | 133 | |
| 134 | |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 135 | def which(filename): |
| 136 | if '/' in filename: |
| 137 | return filename |
| 138 | for path in os.environ['PATH'].split(os.pathsep): |
| 139 | if os.path.exists(os.path.join(path, filename)): |
| 140 | return os.path.join(path, filename) |
| 141 | raise Exception('%s not found' % filename) |
| 142 | |
| 143 | |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 144 | class JobSpec(object): |
| 145 | """Specifies what to run for a job.""" |
| 146 | |
Jan Tattermusch | e824359 | 2015-04-17 14:14:01 -0700 | [diff] [blame] | 147 | def __init__(self, cmdline, shortname=None, environ=None, hash_targets=None, cwd=None, shell=False): |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 148 | """ |
| 149 | Arguments: |
| 150 | cmdline: a list of arguments to pass as the command line |
| 151 | environ: a dictionary of environment variables to set in the child process |
| 152 | hash_targets: which files to include in the hash representing the jobs version |
| 153 | (or empty, indicating the job should not be hashed) |
| 154 | """ |
murgatroid99 | 132ce6a | 2015-03-04 17:29:14 -0800 | [diff] [blame] | 155 | if environ is None: |
| 156 | environ = {} |
| 157 | if hash_targets is None: |
| 158 | hash_targets = [] |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 159 | self.cmdline = cmdline |
| 160 | self.environ = environ |
| 161 | self.shortname = cmdline[0] if shortname is None else shortname |
| 162 | self.hash_targets = hash_targets or [] |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 163 | self.cwd = cwd |
Jan Tattermusch | e824359 | 2015-04-17 14:14:01 -0700 | [diff] [blame] | 164 | self.shell = shell |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 165 | |
| 166 | def identity(self): |
| 167 | return '%r %r %r' % (self.cmdline, self.environ, self.hash_targets) |
| 168 | |
| 169 | def __hash__(self): |
| 170 | return hash(self.identity()) |
| 171 | |
| 172 | def __cmp__(self, other): |
| 173 | return self.identity() == other.identity() |
| 174 | |
| 175 | |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 176 | class Job(object): |
| 177 | """Manages one job.""" |
| 178 | |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 179 | def __init__(self, spec, bin_hash, newline_on_success, travis): |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 180 | self._spec = spec |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 181 | self._bin_hash = bin_hash |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 182 | self._tempfile = tempfile.TemporaryFile() |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 183 | env = os.environ.copy() |
| 184 | for k, v in spec.environ.iteritems(): |
| 185 | env[k] = v |
Craig Tiller | 9d6139a | 2015-02-26 15:24:43 -0800 | [diff] [blame] | 186 | self._start = time.time() |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 187 | self._process = subprocess.Popen(args=spec.cmdline, |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 188 | stderr=subprocess.STDOUT, |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 189 | stdout=self._tempfile, |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 190 | cwd=spec.cwd, |
Jan Tattermusch | e824359 | 2015-04-17 14:14:01 -0700 | [diff] [blame] | 191 | shell=spec.shell, |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 192 | env=env) |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 193 | self._state = _RUNNING |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 194 | self._newline_on_success = newline_on_success |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 195 | self._travis = travis |
Craig Tiller | b84728d | 2015-02-26 15:40:39 -0800 | [diff] [blame] | 196 | message('START', spec.shortname, do_newline=self._travis) |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 197 | |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 198 | def state(self, update_cache): |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 199 | """Poll current state of the job. Prints messages at completion.""" |
| 200 | if self._state == _RUNNING and self._process.poll() is not None: |
Craig Tiller | 9d6139a | 2015-02-26 15:24:43 -0800 | [diff] [blame] | 201 | elapsed = time.time() - self._start |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 202 | if self._process.returncode != 0: |
| 203 | self._state = _FAILURE |
| 204 | self._tempfile.seek(0) |
| 205 | stdout = self._tempfile.read() |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 206 | message('FAILED', '%s [ret=%d]' % ( |
David Klempner | 559543e | 2015-03-17 20:27:48 -0700 | [diff] [blame] | 207 | self._spec.shortname, self._process.returncode), stdout, do_newline=True) |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 208 | else: |
| 209 | self._state = _SUCCESS |
Craig Tiller | 9d6139a | 2015-02-26 15:24:43 -0800 | [diff] [blame] | 210 | message('PASSED', '%s [time=%.1fsec]' % (self._spec.shortname, elapsed), |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 211 | do_newline=self._newline_on_success or self._travis) |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 212 | if self._bin_hash: |
| 213 | update_cache.finished(self._spec.identity(), self._bin_hash) |
Craig Tiller | 9b3cc74 | 2015-02-26 22:25:03 -0800 | [diff] [blame] | 214 | elif self._state == _RUNNING and time.time() - self._start > 300: |
Craig Tiller | 8421678 | 2015-05-12 09:43:54 -0700 | [diff] [blame^] | 215 | self._tempfile.seek(0) |
| 216 | stdout = self._tempfile.read() |
| 217 | message('TIMEOUT', self._spec.shortname, stdout, do_newline=True) |
Craig Tiller | 9b3cc74 | 2015-02-26 22:25:03 -0800 | [diff] [blame] | 218 | self.kill() |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 219 | return self._state |
| 220 | |
| 221 | def kill(self): |
| 222 | if self._state == _RUNNING: |
| 223 | self._state = _KILLED |
| 224 | self._process.terminate() |
| 225 | |
| 226 | |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 227 | class Jobset(object): |
| 228 | """Manages one run of jobs.""" |
| 229 | |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 230 | def __init__(self, check_cancelled, maxjobs, newline_on_success, travis, cache): |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 231 | self._running = set() |
| 232 | self._check_cancelled = check_cancelled |
| 233 | self._cancelled = False |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 234 | self._failures = 0 |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 235 | self._completed = 0 |
ctiller | 94e5dde | 2015-01-09 10:41:59 -0800 | [diff] [blame] | 236 | self._maxjobs = maxjobs |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 237 | self._newline_on_success = newline_on_success |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 238 | self._travis = travis |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 239 | self._cache = cache |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 240 | |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 241 | def start(self, spec): |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 242 | """Start a job. Return True on success, False on failure.""" |
ctiller | 94e5dde | 2015-01-09 10:41:59 -0800 | [diff] [blame] | 243 | while len(self._running) >= self._maxjobs: |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 244 | if self.cancelled(): return False |
| 245 | self.reap() |
| 246 | if self.cancelled(): return False |
Craig Tiller | 547db2b | 2015-01-30 14:08:39 -0800 | [diff] [blame] | 247 | if spec.hash_targets: |
| 248 | bin_hash = hashlib.sha1() |
| 249 | for fn in spec.hash_targets: |
| 250 | with open(which(fn)) as f: |
| 251 | bin_hash.update(f.read()) |
| 252 | bin_hash = bin_hash.hexdigest() |
| 253 | should_run = self._cache.should_run(spec.identity(), bin_hash) |
| 254 | else: |
| 255 | bin_hash = None |
| 256 | should_run = True |
| 257 | if should_run: |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 258 | try: |
| 259 | self._running.add(Job(spec, |
| 260 | bin_hash, |
| 261 | self._newline_on_success, |
| 262 | self._travis)) |
| 263 | except: |
| 264 | message('FAILED', spec.shortname) |
| 265 | self._cancelled = True |
| 266 | return False |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 267 | return True |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 268 | |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 269 | def reap(self): |
| 270 | """Collect the dead jobs.""" |
| 271 | while self._running: |
| 272 | dead = set() |
| 273 | for job in self._running: |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 274 | st = job.state(self._cache) |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 275 | if st == _RUNNING: continue |
| 276 | if st == _FAILURE: self._failures += 1 |
Craig Tiller | 9b3cc74 | 2015-02-26 22:25:03 -0800 | [diff] [blame] | 277 | if st == _KILLED: self._failures += 1 |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 278 | dead.add(job) |
| 279 | for job in dead: |
Craig Tiller | 738c334 | 2015-01-12 14:28:33 -0800 | [diff] [blame] | 280 | self._completed += 1 |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 281 | self._running.remove(job) |
Craig Tiller | 3b08306 | 2015-01-12 13:51:28 -0800 | [diff] [blame] | 282 | if dead: return |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 283 | if (not self._travis): |
| 284 | message('WAITING', '%d jobs running, %d complete, %d failed' % ( |
| 285 | len(self._running), self._completed, self._failures)) |
Craig Tiller | 5058c69 | 2015-04-08 09:42:04 -0700 | [diff] [blame] | 286 | if platform.system() == 'Windows': |
| 287 | time.sleep(0.1) |
| 288 | else: |
| 289 | global have_alarm |
| 290 | if not have_alarm: |
| 291 | have_alarm = True |
| 292 | signal.alarm(10) |
| 293 | signal.pause() |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 294 | |
| 295 | def cancelled(self): |
| 296 | """Poll for cancellation.""" |
| 297 | if self._cancelled: return True |
| 298 | if not self._check_cancelled(): return False |
| 299 | for job in self._running: |
| 300 | job.kill() |
| 301 | self._cancelled = True |
| 302 | return True |
| 303 | |
| 304 | def finish(self): |
| 305 | while self._running: |
| 306 | if self.cancelled(): pass # poll cancellation |
| 307 | self.reap() |
| 308 | return not self.cancelled() and self._failures == 0 |
Nicolas Noble | ddef246 | 2015-01-06 18:08:25 -0800 | [diff] [blame] | 309 | |
| 310 | |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 311 | def _never_cancelled(): |
| 312 | return False |
| 313 | |
| 314 | |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 315 | # cache class that caches nothing |
| 316 | class NoCache(object): |
| 317 | def should_run(self, cmdline, bin_hash): |
| 318 | return True |
| 319 | |
| 320 | def finished(self, cmdline, bin_hash): |
| 321 | pass |
| 322 | |
| 323 | |
Nicolas Noble | b09078f | 2015-01-14 18:06:05 -0800 | [diff] [blame] | 324 | def run(cmdlines, |
| 325 | check_cancelled=_never_cancelled, |
| 326 | maxjobs=None, |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 327 | newline_on_success=False, |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 328 | travis=False, |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 329 | cache=None): |
ctiller | 94e5dde | 2015-01-09 10:41:59 -0800 | [diff] [blame] | 330 | js = Jobset(check_cancelled, |
Nicolas Noble | 044db74 | 2015-01-14 16:57:24 -0800 | [diff] [blame] | 331 | maxjobs if maxjobs is not None else _DEFAULT_MAX_JOBS, |
Nicolas "Pixel" Noble | a7df3f9 | 2015-02-26 22:07:04 +0100 | [diff] [blame] | 332 | newline_on_success, travis, |
Craig Tiller | 7173518 | 2015-01-15 17:07:13 -0800 | [diff] [blame] | 333 | cache if cache is not None else NoCache()) |
Craig Tiller | b84728d | 2015-02-26 15:40:39 -0800 | [diff] [blame] | 334 | if not travis: |
| 335 | cmdlines = shuffle_iteratable(cmdlines) |
| 336 | else: |
Craig Tiller | 904da8c | 2015-02-26 15:59:15 -0800 | [diff] [blame] | 337 | cmdlines = sorted(cmdlines, key=lambda x: x.shortname) |
Craig Tiller | b84728d | 2015-02-26 15:40:39 -0800 | [diff] [blame] | 338 | for cmdline in cmdlines: |
ctiller | 3040cb7 | 2015-01-07 12:13:17 -0800 | [diff] [blame] | 339 | if not js.start(cmdline): |
| 340 | break |
| 341 | return js.finish() |