restore --pmd-xml functionality

Summary:
This was lost in the move to OCaml toplevel.

closes #396

Reviewed By: martinoluca

Differential Revision: D3620527

fbshipit-source-id: 4fd4629
master
Jules Villard 9 years ago committed by Facebook Github Bot 2
parent 1f3a3cb373
commit aee1eeba3d

@ -852,6 +852,11 @@ and (
mk_option ~deprecated:["skip_translation"] ~long:"skip-translation" mk_option ~deprecated:["skip_translation"] ~long:"skip-translation"
"Matcher or list of matchers for names of files that should be analyzed at all.") "Matcher or list of matchers for names of files that should be analyzed at all.")
and pmd_xml =
CLOpt.mk_bool ~long:"pmd-xml"
~exes:CLOpt.[Toplevel]
"Output issues in (PMD) XML format"
(** command line flag: if true, print stats about preconditions to standard output *) (** command line flag: if true, print stats about preconditions to standard output *)
and precondition_stats = and precondition_stats =
CLOpt.mk_bool ~deprecated:["precondition_stats"] ~long:"precondition-stats" CLOpt.mk_bool ~deprecated:["precondition_stats"] ~long:"precondition-stats"
@ -1358,6 +1363,7 @@ and out_file_cmdline = !out_file
and patterns_never_returning_null = !patterns_never_returning_null and patterns_never_returning_null = !patterns_never_returning_null
and patterns_skip_translation = !patterns_skip_translation and patterns_skip_translation = !patterns_skip_translation
and patterns_modeled_expensive = !patterns_modeled_expensive and patterns_modeled_expensive = !patterns_modeled_expensive
and pmd_xml = !pmd_xml
and precondition_stats = !precondition_stats and precondition_stats = !precondition_stats
and print_builtins = !print_builtins and print_builtins = !print_builtins
and print_types = !print_types and print_types = !print_types

@ -205,6 +205,7 @@ val objc_memory_model_on : bool
val only_footprint : bool val only_footprint : bool
val optimistic_cast : bool val optimistic_cast : bool
val out_file_cmdline : string val out_file_cmdline : string
val pmd_xml : bool
val precondition_stats : bool val precondition_stats : bool
val print_builtins : bool val print_builtins : bool
val print_types : bool val print_types : bool

@ -82,6 +82,8 @@ let () =
(match Config.stacktrace with None -> [] | Some s -> (match Config.stacktrace with None -> [] | Some s ->
["--stacktrace"; s]) @ ["--stacktrace"; s]) @
"--multicore" :: (string_of_int Config.jobs) :: "--multicore" :: (string_of_int Config.jobs) ::
(if not Config.pmd_xml then [] else
["--pmd-xml"]) @
(if not Config.reactive_mode then [] else (if not Config.reactive_mode then [] else
["--reactive"]) @ ["--reactive"]) @
"--out" :: Config.results_dir :: "--out" :: Config.results_dir ::

@ -67,6 +67,7 @@ ALL_TESTS = [
'make', 'make',
'multiclang', 'multiclang',
'ndk-build', 'ndk-build',
'pmd-xml',
'reactive', 'reactive',
'unknown_ext', 'unknown_ext',
'utf8_in_pwd', 'utf8_in_pwd',
@ -112,7 +113,7 @@ def save_report(reports, filename):
separators=(',', ': '), sort_keys=True) separators=(',', ': '), sort_keys=True)
def run_analysis(clean_cmds, build_cmds, env=None): def run_analysis(clean_cmds, build_cmds, extra_check, env=None):
for clean_cmd in clean_cmds: for clean_cmd in clean_cmds:
subprocess.check_call(clean_cmd, env=env) subprocess.check_call(clean_cmd, env=env)
@ -136,6 +137,7 @@ def run_analysis(clean_cmds, build_cmds, env=None):
json_path = os.path.join(temp_out_dir, REPORT_JSON) json_path = os.path.join(temp_out_dir, REPORT_JSON)
found_errors = utils.load_json_from_path(json_path) found_errors = utils.load_json_from_path(json_path)
extra_check(temp_out_dir)
shutil.rmtree(temp_out_dir) shutil.rmtree(temp_out_dir)
os.chdir(SCRIPT_DIR) os.chdir(SCRIPT_DIR)
@ -224,6 +226,7 @@ def test(name,
available=lambda: True, available=lambda: True,
enabled=None, enabled=None,
report_fname=None, report_fname=None,
extra_check=lambda x: None,
preprocess=lambda: None, preprocess=lambda: None,
postprocess=lambda errors: errors): postprocess=lambda errors: errors):
"""Run a test. """Run a test.
@ -277,6 +280,7 @@ def test(name,
errors = run_analysis( errors = run_analysis(
clean_commands, clean_commands,
compile_commands, compile_commands,
extra_check=extra_check,
env=env) env=env)
original = os.path.join(EXPECTED_OUTPUTS_DIR, report_fname) original = os.path.join(EXPECTED_OUTPUTS_DIR, report_fname)
do_test(postprocess(errors), original) do_test(postprocess(errors), original)
@ -469,6 +473,22 @@ class BuildIntegrationTest(unittest.TestCase):
[], [],
preprocess=preprocess) preprocess=preprocess)
def test_pmd_xml_output(self):
def pmd_check(infer_out):
assert os.path.exists(os.path.join(infer_out, 'report.xml'))
try:
from lxml import etree
has_lxml = True
except ImportError:
has_lxml = False
test('pmd-xml', 'PMD XML output',
CODETOANALYZE_DIR,
[{'compile': ['clang', '-c', 'hello.c'],
'infer_args': ['--pmd-xml']}],
extra_check=pmd_check,
available=lambda: has_lxml)
if __name__ == '__main__': if __name__ == '__main__':
# hackish capturing of the arguments after '--' # hackish capturing of the arguments after '--'

@ -0,0 +1,7 @@
[
{
"bug_type": "NULL_DEREFERENCE",
"file": "hello.c",
"procedure": "test"
}
]
Loading…
Cancel
Save