From aee1eeba3dee5421dd399fa535f2d78df16e5e16 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Mon, 1 Aug 2016 07:20:33 -0700 Subject: [PATCH] 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 --- infer/src/backend/config.ml | 6 +++++ infer/src/backend/config.mli | 1 + infer/src/backend/infer.ml | 2 ++ .../build_systems/build_integration_tests.py | 22 ++++++++++++++++++- .../expected_outputs/pmd-xml_report.json | 7 ++++++ 5 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 infer/tests/build_systems/expected_outputs/pmd-xml_report.json diff --git a/infer/src/backend/config.ml b/infer/src/backend/config.ml index b02ce49b4..690b82996 100644 --- a/infer/src/backend/config.ml +++ b/infer/src/backend/config.ml @@ -852,6 +852,11 @@ and ( mk_option ~deprecated:["skip_translation"] ~long:"skip-translation" "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 *) and 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_skip_translation = !patterns_skip_translation and patterns_modeled_expensive = !patterns_modeled_expensive +and pmd_xml = !pmd_xml and precondition_stats = !precondition_stats and print_builtins = !print_builtins and print_types = !print_types diff --git a/infer/src/backend/config.mli b/infer/src/backend/config.mli index 78ae6bbf4..e5d84d477 100644 --- a/infer/src/backend/config.mli +++ b/infer/src/backend/config.mli @@ -205,6 +205,7 @@ val objc_memory_model_on : bool val only_footprint : bool val optimistic_cast : bool val out_file_cmdline : string +val pmd_xml : bool val precondition_stats : bool val print_builtins : bool val print_types : bool diff --git a/infer/src/backend/infer.ml b/infer/src/backend/infer.ml index 7dec84600..79e8ffed6 100644 --- a/infer/src/backend/infer.ml +++ b/infer/src/backend/infer.ml @@ -82,6 +82,8 @@ let () = (match Config.stacktrace with None -> [] | Some s -> ["--stacktrace"; s]) @ "--multicore" :: (string_of_int Config.jobs) :: + (if not Config.pmd_xml then [] else + ["--pmd-xml"]) @ (if not Config.reactive_mode then [] else ["--reactive"]) @ "--out" :: Config.results_dir :: diff --git a/infer/tests/build_systems/build_integration_tests.py b/infer/tests/build_systems/build_integration_tests.py index b8cf70fd1..d6ebfddf7 100755 --- a/infer/tests/build_systems/build_integration_tests.py +++ b/infer/tests/build_systems/build_integration_tests.py @@ -67,6 +67,7 @@ ALL_TESTS = [ 'make', 'multiclang', 'ndk-build', + 'pmd-xml', 'reactive', 'unknown_ext', 'utf8_in_pwd', @@ -112,7 +113,7 @@ def save_report(reports, filename): 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: 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) found_errors = utils.load_json_from_path(json_path) + extra_check(temp_out_dir) shutil.rmtree(temp_out_dir) os.chdir(SCRIPT_DIR) @@ -224,6 +226,7 @@ def test(name, available=lambda: True, enabled=None, report_fname=None, + extra_check=lambda x: None, preprocess=lambda: None, postprocess=lambda errors: errors): """Run a test. @@ -277,6 +280,7 @@ def test(name, errors = run_analysis( clean_commands, compile_commands, + extra_check=extra_check, env=env) original = os.path.join(EXPECTED_OUTPUTS_DIR, report_fname) do_test(postprocess(errors), original) @@ -469,6 +473,22 @@ class BuildIntegrationTest(unittest.TestCase): [], 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__': # hackish capturing of the arguments after '--' diff --git a/infer/tests/build_systems/expected_outputs/pmd-xml_report.json b/infer/tests/build_systems/expected_outputs/pmd-xml_report.json new file mode 100644 index 000000000..a6ed10eff --- /dev/null +++ b/infer/tests/build_systems/expected_outputs/pmd-xml_report.json @@ -0,0 +1,7 @@ +[ + { + "bug_type": "NULL_DEREFERENCE", + "file": "hello.c", + "procedure": "test" + } +] \ No newline at end of file