Index: build/android/buildbot/bb_utils.py |
diff --git a/build/android/buildbot/bb_utils.py b/build/android/buildbot/bb_utils.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2af87f35894decef8a4a1258ee2b78f9ff556521 |
--- /dev/null |
+++ b/build/android/buildbot/bb_utils.py |
@@ -0,0 +1,61 @@ |
+# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import json |
+import os |
+import pipes |
+import subprocess |
+import sys |
+ |
+sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
+from pylib import buildbot_report |
+from pylib import constants |
+ |
+ |
+TESTING = 'BUILDBOT_TESTING' in os.environ |
+ |
+ |
+def SpawnCmd(command): |
+ """Spawn a process without waiting for termination.""" |
+ print '>', ' '.join(map(pipes.quote, command)) |
+ sys.stdout.flush() |
+ if TESTING: |
+ class MockPopen(object): |
+ @staticmethod |
+ def wait(): |
+ return 0 |
+ return MockPopen() |
+ |
+ return subprocess.Popen(command, cwd=constants.CHROME_DIR) |
+ |
+ |
+def RunCmd(command, flunk_on_failure=True, halt_on_failure=False, |
+ retcode_callback=None): |
+ """Run a command relative to the chrome source root.""" |
+ code = SpawnCmd(command).wait() |
+ print '<', ' '.join(map(pipes.quote, command)) |
+ if retcode_callback: |
+ retcode_callback(code) |
+ return code |
+ if code != 0: |
+ print 'ERROR: process exited with code %d' % code |
+ if flunk_on_failure: |
+ buildbot_report.PrintError() |
+ else: |
+ buildbot_report.PrintWarning() |
+ # Allow steps to have both halting (i.e. 1) and non-halting exit codes. |
+ if code != 0 and code != 88 and halt_on_failure: |
+ raise OSError() |
+ return code |
+ |
+ |
+def OptParserError(parser, msg): |
+ """We avoid parser.error because it calls sys.exit.""" |
+ parser.print_help() |
+ print >> sys.stderr, '\nERROR:', msg |
+ return 1 |
+ |
+ |
+def ConvertJson(option, _, value, parser): |
+ setattr(parser.values, option.dest, json.loads(value)) |