From 70bfa5dc845577728189bac51ff6f23e1880e16d Mon Sep 17 00:00:00 2001 From: Virgile Prevosto <virgile.prevosto@m4x.org> Date: Tue, 20 Oct 2020 11:24:32 +0200 Subject: [PATCH] [MdR] avoid duplicate invocations in SARIF --- src/plugins/markdown-report/sarif_gen.ml | 14 +++++++++++++- .../tests/sarif/oracle/cwe125.sarif | 11 ----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/plugins/markdown-report/sarif_gen.ml b/src/plugins/markdown-report/sarif_gen.ml index fce40cc7d22..3758cd60f88 100644 --- a/src/plugins/markdown-report/sarif_gen.ml +++ b/src/plugins/markdown-report/sarif_gen.ml @@ -60,7 +60,19 @@ module Analysis_cmdline = let command_line () = Array.to_list Sys.argv -let update_cmdline () = Analysis_cmdline.add (command_line()) +let update_cmdline = + let already_updated = ref false in + fun () -> + if not (!already_updated) then begin + (* This function must be run after the loading stage, so that + the Analysis_cmdline state contains the list of previous launches + if any. However, `-then` restart the boot sequence from the loading + included, meaning that the hook will be replayed _also_ after each + `-then`. Using a _non-projectified_ boolean ref ensures that we add + the command line only once per run. *) + already_updated := true; + Analysis_cmdline.add (command_line()) + end let () = Cmdline.run_after_loading_stage update_cmdline diff --git a/src/plugins/markdown-report/tests/sarif/oracle/cwe125.sarif b/src/plugins/markdown-report/tests/sarif/oracle/cwe125.sarif index 3c9e4220598..5855585658f 100644 --- a/src/plugins/markdown-report/tests/sarif/oracle/cwe125.sarif +++ b/src/plugins/markdown-report/tests/sarif/oracle/cwe125.sarif @@ -34,17 +34,6 @@ "exitCode": 0, "executionSuccessful": true }, - { - "commandLine": - "frama-c -check -load tests/sarif/result/cwe125_eva.sav -then -mdr-out tests/sarif/result/cwe125.sarif -mdr-gen sarif -mdr-no-print-libc -mdr-sarif-deterministic", - "arguments": [ - "-check", "-load", "tests/sarif/result/cwe125_eva.sav", "-then", - "-mdr-out", "tests/sarif/result/cwe125.sarif", "-mdr-gen", - "sarif", "-mdr-no-print-libc", "-mdr-sarif-deterministic" - ], - "exitCode": 0, - "executionSuccessful": true - }, { "commandLine": "frama-c -check -load tests/sarif/result/cwe125_eva.sav -then -mdr-out tests/sarif/result/cwe125.sarif -mdr-gen sarif -mdr-no-print-libc -mdr-sarif-deterministic", -- GitLab