OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import json |
| 6 import optparse |
| 7 import os |
| 8 import pipes |
| 9 import subprocess |
| 10 import sys |
| 11 |
| 12 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
| 13 from pylib import buildbot_report |
| 14 from pylib import constants |
| 15 |
| 16 |
| 17 TESTING = 'BUILDBOT_TESTING' in os.environ |
| 18 |
| 19 BB_BUILD_DIR = os.path.abspath( |
| 20 os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, |
| 21 os.pardir, os.pardir, os.pardir, os.pardir)) |
| 22 |
| 23 GOMA_DIR = os.path.join(BB_BUILD_DIR, 'goma') |
| 24 |
| 25 |
| 26 class BBOptionParser(optparse.OptionParser): |
| 27 def Error(self, msg): |
| 28 self.print_help() |
| 29 print >> sys.stderr, '\nERROR:', msg |
| 30 return 1 |
| 31 |
| 32 |
| 33 def SpawnCmd(command): |
| 34 """Spawn a process without waiting for termination.""" |
| 35 print '>', ' '.join(map(pipes.quote, command)) |
| 36 sys.stdout.flush() |
| 37 if TESTING: |
| 38 class MockPopen(object): |
| 39 @staticmethod |
| 40 def wait(): |
| 41 return 0 |
| 42 return MockPopen() |
| 43 |
| 44 return subprocess.Popen(command, cwd=constants.CHROME_DIR) |
| 45 |
| 46 |
| 47 def RunCmd(command, flunk_on_failure=True, halt_on_failure=False, |
| 48 retcode_callback=None): |
| 49 """Run a command relative to the chrome source root.""" |
| 50 code = SpawnCmd(command).wait() |
| 51 print '<', ' '.join(map(pipes.quote, command)) |
| 52 if retcode_callback: |
| 53 code, flunk_on_failure, halt_on_failure = retcode_callback(code) |
| 54 if code != 0: |
| 55 print 'ERROR: process exited with code %d' % code |
| 56 if flunk_on_failure: |
| 57 buildbot_report.PrintError() |
| 58 else: |
| 59 buildbot_report.PrintWarning() |
| 60 # Allow steps to have both halting (i.e. 1) and non-halting exit codes. |
| 61 if code != 0 and code != 88 and halt_on_failure: |
| 62 raise OSError() |
| 63 return code |
| 64 |
| 65 |
| 66 def ConvertJson(option, _, value, parser): |
| 67 setattr(parser.values, option.dest, json.loads(value)) |
| 68 |
| 69 |
| 70 def GetParser(): |
| 71 parser = BBOptionParser() |
| 72 parser.add_option('--build-properties', action='callback', |
| 73 callback=ConvertJson, type='string', default={}, |
| 74 help='build properties in JSON format') |
| 75 parser.add_option('--factory-properties', action='callback', |
| 76 callback=ConvertJson, type='string', default={}, |
| 77 help='factory properties in JSON format') |
| 78 parser.add_option('--slave-properties', action='callback', |
| 79 callback=ConvertJson, type='string', default={}, |
| 80 help='Properties set by slave script in JSON format') |
| 81 |
| 82 return parser |
OLD | NEW |