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
3 # found in the LICENSE file.
14 sys
.path
.append(os
.path
.join(os
.path
.dirname(__file__
), '..'))
15 from pylib
import constants
18 TESTING
= 'BUILDBOT_TESTING' in os
.environ
20 BB_BUILD_DIR
= os
.path
.abspath(
21 os
.path
.join(os
.path
.dirname(__file__
), os
.pardir
, os
.pardir
, os
.pardir
,
22 os
.pardir
, os
.pardir
, os
.pardir
, os
.pardir
))
24 CHROME_SRC
= os
.path
.abspath(
25 os
.path
.join(os
.path
.dirname(__file__
), '..', '..', '..'))
27 # TODO: Figure out how to merge this with pylib.cmd_helper.OutDirectory().
28 CHROME_OUT_DIR
= os
.path
.join(CHROME_SRC
, 'out')
30 GOMA_DIR
= os
.environ
.get('GOMA_DIR', os
.path
.join(BB_BUILD_DIR
, 'goma'))
32 GSUTIL_PATH
= os
.path
.join(BB_BUILD_DIR
, 'third_party', 'gsutil', 'gsutil')
34 def CommandToString(command
):
35 """Returns quoted command that can be run in bash shell."""
36 return ' '.join(map(pipes
.quote
, command
))
39 def SpawnCmd(command
, stdout
=None, cwd
=CHROME_SRC
):
40 """Spawn a process without waiting for termination."""
41 print '>', CommandToString(command
)
44 class MockPopen(object):
49 return subprocess
.Popen(command
, cwd
=cwd
, stdout
=stdout
)
52 def RunCmd(command
, flunk_on_failure
=True, halt_on_failure
=False,
53 warning_code
=constants
.WARNING_EXIT_CODE
, stdout
=None,
55 """Run a command relative to the chrome source root."""
56 code
= SpawnCmd(command
, stdout
, cwd
).wait()
57 print '<', CommandToString(command
)
59 print 'ERROR: process exited with code %d' % code
60 if code
!= warning_code
and flunk_on_failure
:
61 bb_annotations
.PrintError()
63 bb_annotations
.PrintWarning()
64 # Allow steps to have both halting (i.e. 1) and non-halting exit codes.
65 if code
!= warning_code
and halt_on_failure
:
66 print 'FATAL %d != %d' % (code
, warning_code
)
72 def ConvertJson(option
, _
, value
, parser
):
73 setattr(parser
.values
, option
.dest
, json
.loads(value
))
74 parser
= optparse
.OptionParser()
75 parser
.add_option('--build-properties', action
='callback',
76 callback
=ConvertJson
, type='string', default
={},
77 help='build properties in JSON format')
78 parser
.add_option('--factory-properties', action
='callback',
79 callback
=ConvertJson
, type='string', default
={},
80 help='factory properties in JSON format')
84 def EncodeProperties(options
):
85 return ['--factory-properties=%s' % json
.dumps(options
.factory_properties
),
86 '--build-properties=%s' % json
.dumps(options
.build_properties
)]
89 def RunSteps(steps
, step_cmds
, options
):
90 unknown_steps
= set(steps
) - set(step
for step
, _
in step_cmds
)
92 print >> sys
.stderr
, 'FATAL: Unknown steps %s' % list(unknown_steps
)
95 for step
, cmd
in step_cmds
: