Merge pull request #17 from catseye/exit-code-1-on-error

Exit with exit code 1 when errors occurred
This commit is contained in:
Michael C. Martin 2013-01-10 22:18:23 -08:00
commit c25047ca66
4 changed files with 15 additions and 8 deletions

View File

@ -1,10 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
from os.path import realpath, dirname, join from os.path import realpath, dirname, join
from sys import argv, path from sys import argv, exit, path
path.insert(0, join(dirname(realpath(argv[0])), '..', 'src')) path.insert(0, join(dirname(realpath(argv[0])), '..', 'src'))
import Ophis.Main import Ophis.Main
Ophis.Main.run_ophis(argv[1:]) exit(Ophis.Main.run_ophis(argv[1:]))

View File

@ -11,7 +11,6 @@
import sys import sys
import Ophis.IR as IR import Ophis.IR as IR
import Ophis.CmdLine as Cmd
import Ophis.Errors as Err import Ophis.Errors as Err
macros = {} macros = {}

View File

@ -20,7 +20,12 @@ import Ophis.Opcodes
def run_all(): def run_all():
"Transforms the source infiles to a binary outfile." """Transforms the source infiles to a binary outfile.
Returns a shell-style exit code: 1 if there were errors, 0 if there
were no errors.
"""
Err.count = 0 Err.count = 0
z = Ophis.Frontend.parse(Ophis.CmdLine.infiles) z = Ophis.Frontend.parse(Ophis.CmdLine.infiles)
env = Ophis.Environment.Environment() env = Ophis.Environment.Environment()
@ -69,7 +74,7 @@ def run_all():
if outfile == '-': if outfile == '-':
output = sys.stdout output = sys.stdout
if sys.platform == "win32": if sys.platform == "win32":
# We can't dump our binary in test mode; that would be # We can't dump our binary in text mode; that would be
# disastrous. So, we'll do some platform-specific # disastrous. So, we'll do some platform-specific
# things here to force our stdout to binary mode. # things here to force our stdout to binary mode.
import msvcrt import msvcrt
@ -82,10 +87,13 @@ def run_all():
output.flush() output.flush()
if outfile != '-': if outfile != '-':
output.close() output.close()
return 0
except IOError: except IOError:
print>>sys.stderr, "Could not write to " + outfile print>>sys.stderr, "Could not write to " + outfile
return 1
else: else:
Err.report() Err.report()
return 1
def run_ophis(args): def run_ophis(args):
@ -98,8 +106,8 @@ def run_ophis(args):
Ophis.Opcodes.opcodes.update(Ophis.Opcodes.c02extensions) Ophis.Opcodes.opcodes.update(Ophis.Opcodes.c02extensions)
Ophis.CorePragmas.reset() Ophis.CorePragmas.reset()
run_all() return run_all()
if __name__ == '__main__': if __name__ == '__main__':
run_ophis(sys.argv[1:]) sys.exit(run_ophis(sys.argv[1:]))

View File

@ -142,7 +142,7 @@ def dump_map(m, prologue=''):
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) > 1: if len(sys.argv) > 1:
chipsets = argv[1:] chipsets = sys.argv[1:]
else: else:
chipsets = ['chipsets.txt'] chipsets = ['chipsets.txt']
archs = [] archs = []