Bug 772186 - Support return values from pymake native commands. r=khuey

If the return value is an integer, treat it like an exit code. Otherwise, if
it is None, treat it like 0. Otherwise treat it as an error. This behaviour is
equivalent to that of sys.exit. Also fix our own sys.exit handling to match
this, and add tests for everything.

--HG--
extra : rebase_source : e36155d8fbe555e76effd182979cd6b1000a6ece
This commit is contained in:
Siddharth Agarwal 2012-07-12 09:52:25 +05:30
parent fd62daa46c
commit fcc673a579
8 changed files with 68 additions and 6 deletions

View File

@ -208,20 +208,26 @@ class PythonJob(Job):
return -127
m = sys.modules[self.module]
if self.method not in m.__dict__:
print >>sys.stderr, "No method named '%s' in module %s" % (method, module)
print >>sys.stderr, "No method named '%s' in module %s" % (self.method, self.module)
return -127
m.__dict__[self.method](self.argv)
rv = m.__dict__[self.method](self.argv)
if rv != 0 and rv is not None:
print >>sys.stderr, (
"Native command '%s %s' returned value '%s'" %
(self.module, self.method, rv))
return (rv if isinstance(rv, int) else 1)
except PythonException, e:
print >>sys.stderr, e
return e.exitcode
except:
e = sys.exc_info()[1]
if isinstance(e, SystemExit) and (e.code == 0 or e.code == '0'):
if isinstance(e, SystemExit) and (e.code == 0 or e.code is None):
pass # sys.exit(0) is not a failure
else:
print >>sys.stderr, e
print >>sys.stderr, traceback.print_exc()
return -127
return (e.code if isinstance(e.code, int) else 1)
finally:
os.environ = oldenv
return 0

View File

@ -0,0 +1,8 @@
#T gmake skip
#T returncode: 2
CMD = %pycmd asplode_return
PYCOMMANDPATH = $(TESTPATH) $(TESTPATH)/subdir
all:
$(CMD) 1

View File

@ -0,0 +1,8 @@
#T gmake skip
#T returncode: 2
CMD = %pycmd asplode_return
PYCOMMANDPATH = $(TESTPATH) $(TESTPATH)/subdir
all:
$(CMD) not-an-integer

View File

@ -0,0 +1,11 @@
#T gmake skip
CMD = %pycmd asplode_return
PYCOMMANDPATH = $(TESTPATH) $(TESTPATH)/subdir
all:
$(CMD) 0
-$(CMD) 1
$(CMD) None
-$(CMD) not-an-integer
@echo TEST-PASS

View File

@ -0,0 +1,8 @@
#T gmake skip
#T returncode: 2
CMD = %pycmd asplode
PYCOMMANDPATH = $(TESTPATH) $(TESTPATH)/subdir
all:
$(CMD) 1

View File

@ -0,0 +1,8 @@
#T gmake skip
#T returncode: 2
CMD = %pycmd asplode
PYCOMMANDPATH = $(TESTPATH) $(TESTPATH)/subdir
all:
$(CMD) not-an-integer

View File

@ -5,4 +5,7 @@ PYCOMMANDPATH = $(TESTPATH) $(TESTPATH)/subdir
all:
$(CMD) 0
-$(CMD) 1
$(CMD) None
-$(CMD) not-an-integer
@echo TEST-PASS

View File

@ -8,6 +8,16 @@ def writeenvtofile(args):
with open(args[0], 'w') as f:
f.write(os.environ[args[1]])
def convertasplode(arg):
try:
return int(arg)
except:
return (None if arg == "None" else arg)
def asplode(args):
sys.exit(0)
return 0
arg0 = convertasplode(args[0])
sys.exit(arg0)
def asplode_return(args):
arg0 = convertasplode(args[0])
return arg0