Skip to content

Commit

Permalink
Bug 795427 - Part 1: Proper exit codes from mach; r=jhammel
Browse files Browse the repository at this point in the history
  • Loading branch information
indygreg committed Oct 5, 2012
1 parent 12894a1 commit f00abf9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mach
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ except ImportError:

# All of the code is in a module because EVERYTHING IS A LIBRARY.
mach = mach.main.Mach(our_dir)
mach.run(sys.argv[1:])
sys.exit(mach.run(sys.argv[1:]))
17 changes: 14 additions & 3 deletions python/mach/mach/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ def __init__(self, cwd):
self.log_manager.register_structured_logger(self.logger)

def run(self, argv):
"""Runs mach with arguments provided from the command line."""
"""Runs mach with arguments provided from the command line.
Returns the integer exit code that should be used. 0 means success. All
other values indicate failure.
"""

# If no encoding is defined, we default to UTF-8 because without this
# Python 2.7 will assume the default encoding of ASCII. This will blow
Expand All @@ -143,7 +147,7 @@ def run(self, argv):
if sys.stderr.encoding is None:
sys.stderr = codecs.getwriter('utf-8')(sys.stderr)

self._run(argv)
return self._run(argv)
finally:
sys.stdin = orig_stdin
sys.stdout = orig_stdout
Expand Down Expand Up @@ -199,7 +203,14 @@ def _run(self, argv):
else:
raise Exception('Dispatch configuration error in module.')

fn(**stripped)
result = fn(**stripped)

if not result:
result = 0

assert isinstance(result, int)

return result

def log(self, level, action, params, format_str):
"""Helper method to record a structured log event."""
Expand Down

0 comments on commit f00abf9

Please sign in to comment.