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