mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
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:
parent
fd62daa46c
commit
fcc673a579
@ -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
|
||||
|
8
build/pymake/tests/native-command-return-fail1.mk
Normal file
8
build/pymake/tests/native-command-return-fail1.mk
Normal file
@ -0,0 +1,8 @@
|
||||
#T gmake skip
|
||||
#T returncode: 2
|
||||
|
||||
CMD = %pycmd asplode_return
|
||||
PYCOMMANDPATH = $(TESTPATH) $(TESTPATH)/subdir
|
||||
|
||||
all:
|
||||
$(CMD) 1
|
8
build/pymake/tests/native-command-return-fail2.mk
Normal file
8
build/pymake/tests/native-command-return-fail2.mk
Normal file
@ -0,0 +1,8 @@
|
||||
#T gmake skip
|
||||
#T returncode: 2
|
||||
|
||||
CMD = %pycmd asplode_return
|
||||
PYCOMMANDPATH = $(TESTPATH) $(TESTPATH)/subdir
|
||||
|
||||
all:
|
||||
$(CMD) not-an-integer
|
11
build/pymake/tests/native-command-return.mk
Normal file
11
build/pymake/tests/native-command-return.mk
Normal 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
|
8
build/pymake/tests/native-command-sys-exit-fail1.mk
Normal file
8
build/pymake/tests/native-command-sys-exit-fail1.mk
Normal file
@ -0,0 +1,8 @@
|
||||
#T gmake skip
|
||||
#T returncode: 2
|
||||
|
||||
CMD = %pycmd asplode
|
||||
PYCOMMANDPATH = $(TESTPATH) $(TESTPATH)/subdir
|
||||
|
||||
all:
|
||||
$(CMD) 1
|
8
build/pymake/tests/native-command-sys-exit-fail2.mk
Normal file
8
build/pymake/tests/native-command-sys-exit-fail2.mk
Normal file
@ -0,0 +1,8 @@
|
||||
#T gmake skip
|
||||
#T returncode: 2
|
||||
|
||||
CMD = %pycmd asplode
|
||||
PYCOMMANDPATH = $(TESTPATH) $(TESTPATH)/subdir
|
||||
|
||||
all:
|
||||
$(CMD) not-an-integer
|
@ -5,4 +5,7 @@ PYCOMMANDPATH = $(TESTPATH) $(TESTPATH)/subdir
|
||||
|
||||
all:
|
||||
$(CMD) 0
|
||||
-$(CMD) 1
|
||||
$(CMD) None
|
||||
-$(CMD) not-an-integer
|
||||
@echo TEST-PASS
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user