xclerc / ocamljava

http://www.ocamljava.org
Other
172 stars 14 forks source link

ocamljava has exit code 0 even on an error #16

Closed xavierleroy closed 9 years ago

xavierleroy commented 9 years ago

ocamljava always exits with code 0 even if an error was detected during compilation. This makes ocamljava hard to use in a build system such as make, where the exit code is what determines success or failure of compilation.

Repro case:

echo "let _ = unbound" > bad.ml ocamljava -c bad.ml echo $?

I'm using openjdk-7 on Linux, if that matters.

There are at least two problems here:

1- The shell scripts in bin/ in the distribution do not propagate the return code of the java invocation. The fix is easy: just change the last command from

"$OCJ_JAVA" -Xss8M -jar ...

to

exec "$OCJ_JAVA" -Xss8M -jar ...

2- Even after the fix above, or if I bypass the shell script and call "java -jar .../ocamljava.jar" directly, the exit code is still 0. So, something else is wrong in the sources of the ocamljava compiler or in the reimplementation of Sys.exit.

xavierleroy commented 9 years ago

PS. Just checking: this is not an issue with openjdk-7 $ cat Exit.java class Exit { public static void main(String[] argv) { System.exit(42); } } $ javac Exit.java $ java Exit $ echo $? 42