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 |
| 24 def CommandToString(command): |
| 25 """Returns quoted command that can be run in bash shell.""" |
| 26 return ' '.join(map(pipes.quote, command)) |
| 27 |
| 28 |
| 29 def SpawnCmd(command): |
| 30 """Spawn a process without waiting for termination.""" |
| 31 print '>', CommandToString(command) |
| 32 sys.stdout.flush() |
| 33 if TESTING: |
| 34 class MockPopen(object): |
| 35 @staticmethod |
| 36 def wait(): |
| 37 return 0 |
| 38 return MockPopen() |
| 39 |
| 40 return subprocess.Popen(command, cwd=constants.DIR_SOURCE_ROOT) |
| 41 |
| 42 |
| 43 def RunCmd(command, flunk_on_failure=True, halt_on_failure=False, |
| 44 warning_code=88): |
| 45 """Run a command relative to the chrome source root.""" |
| 46 code = SpawnCmd(command).wait() |
| 47 print '<', CommandToString(command) |
| 48 if code != 0: |
| 49 print 'ERROR: process exited with code %d' % code |
| 50 if code != warning_code and flunk_on_failure: |
| 51 buildbot_report.PrintError() |
| 52 else: |
| 53 buildbot_report.PrintWarning() |
| 54 # Allow steps to have both halting (i.e. 1) and non-halting exit codes. |
| 55 if code != warning_code and halt_on_failure: |
| 56 raise OSError() |
| 57 return code |
| 58 |
| 59 |
| 60 def GetParser(): |
| 61 def ConvertJson(option, _, value, parser): |
| 62 setattr(parser.values, option.dest, json.loads(value)) |
| 63 parser = optparse.OptionParser() |
| 64 parser.add_option('--build-properties', action='callback', |
| 65 callback=ConvertJson, type='string', default={}, |
| 66 help='build properties in JSON format') |
| 67 parser.add_option('--factory-properties', action='callback', |
| 68 callback=ConvertJson, type='string', default={}, |
| 69 help='factory properties in JSON format') |
| 70 parser.add_option('--slave-properties', action='callback', |
| 71 callback=ConvertJson, type='string', default={}, |
| 72 help='Properties set by slave script in JSON format') |
| 73 |
| 74 return parser |
| 75 |
OLD | NEW |