[infer][java] stop swallowing errors coming from compilation failures

Summary:
No longer swallow compilation failures for javac. Before this diff, the compilation failures where raised:

  > infer -- javac Test.java
  Test.java:5: error: ';' expected
    static String str = "Hello"
                               ^
  1 error

but the exit code was incorrect:

  > echo $?
  0

With this diff, the failing command is printed in standard error:

  > infer -- javac Test.java
  Javac compilation error with:

  ['javac', '-g', 'Test.java', '-J-Duser.language=en']

and the exit code is different from 0.

  > echo $?
  1
master
jrm 10 years ago
parent 4b241266df
commit 7e00a845d8

@ -69,8 +69,6 @@ class VersionAction(argparse._VersionAction):
option_string) option_string)
base_parser = argparse.ArgumentParser(add_help=False) base_parser = argparse.ArgumentParser(add_help=False)
base_group = base_parser.add_argument_group('global arguments') base_group = base_parser.add_argument_group('global arguments')
base_group.add_argument('-o', '--out', metavar='<directory>', base_group.add_argument('-o', '--out', metavar='<directory>',

@ -7,10 +7,10 @@
# of patent rights can be found in the PATENTS file in the same directory. # of patent rights can be found in the PATENTS file in the same directory.
import argparse import argparse
import logging
import tempfile
import os import os
import tempfile
import subprocess import subprocess
import utils
# javac options # javac options
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
@ -44,14 +44,13 @@ class CompilerCall:
prefix='javac_', prefix='javac_',
delete=False) as file_out: delete=False) as file_out:
self.verbose_out = file_out.name self.verbose_out = file_out.name
try: try:
subprocess.check_call(javac_cmd, stderr=file_out) subprocess.check_call(javac_cmd, stderr=file_out)
return os.EX_OK except subprocess.CalledProcessError:
except subprocess.CalledProcessError as exc:
error_msg = 'Javac compilation error with: \n\n{}\n' error_msg = 'Javac compilation error with: \n\n{}\n'
failing_cmd = [arg for arg in javac_cmd failing_cmd = [arg for arg in javac_cmd
if arg != '-verbose'] if arg != '-verbose']
logging.error(error_msg.format(failing_cmd)) utils.error(error_msg.format(failing_cmd))
os.system(' '.join(failing_cmd)) subprocess.check_call(failing_cmd)
return exc.returncode
return os.EX_OK

Loading…
Cancel
Save