From 8c1b25abb1c0d946bebbfa20e3f1df36c79430f4 Mon Sep 17 00:00:00 2001 From: Virgile Prevosto <virgile.prevosto@m4x.org> Date: Mon, 10 Dec 2018 10:48:13 +0100 Subject: [PATCH] Refactor cmdline options that decide what kind of output should be generated --- src/plugins/markdown-report/Makefile | 3 ++- .../markdown-report/Report_markdown.mli | 5 +---- src/plugins/markdown-report/md_gen.ml | 22 +++++++++---------- src/plugins/markdown-report/mdr_params.ml | 17 +++++++------- src/plugins/markdown-report/mdr_params.mli | 5 +---- src/plugins/markdown-report/sarif_gen.ml | 1 + src/plugins/markdown-report/sarif_gen.mli | 2 ++ 7 files changed, 26 insertions(+), 29 deletions(-) create mode 100644 src/plugins/markdown-report/sarif_gen.ml create mode 100644 src/plugins/markdown-report/sarif_gen.mli diff --git a/src/plugins/markdown-report/Makefile b/src/plugins/markdown-report/Makefile index abecbdebfb5..cd82c36f341 100644 --- a/src/plugins/markdown-report/Makefile +++ b/src/plugins/markdown-report/Makefile @@ -3,7 +3,8 @@ ifndef FRAMAC_SHARE endif PLUGIN_NAME:=Report_markdown -PLUGIN_CMO:=markdown sarif mdr_params parse_remarks eva_coverage md_gen +PLUGIN_CMO:=\ + markdown sarif mdr_params parse_remarks eva_coverage sarif_gen md_gen PLUGIN_NO_TEST:=true PLUGIN_REQUIRES:=ppx_deriving ppx_deriving_yojson yojson PLUGIN_DISTRIB_EXTERNAL:=share/acsl.xml diff --git a/src/plugins/markdown-report/Report_markdown.mli b/src/plugins/markdown-report/Report_markdown.mli index 24a5713e2e2..f76e4200aa3 100644 --- a/src/plugins/markdown-report/Report_markdown.mli +++ b/src/plugins/markdown-report/Report_markdown.mli @@ -5,10 +5,7 @@ include Plugin.S module Output: Parameter_sig.String (** Value of [-mdr-gen]. *) -module Generate: Parameter_sig.Bool - -(** Value of [-mdr-gen-draft]. *) -module Gen_draft: Parameter_sig.Bool +module Generate: Parameter_sig.String (** Value of [-mdr-remarks]. *) module Remarks: Parameter_sig.String diff --git a/src/plugins/markdown-report/md_gen.ml b/src/plugins/markdown-report/md_gen.ml index 3fe132bcf7d..c2c784b2b04 100644 --- a/src/plugins/markdown-report/md_gen.ml +++ b/src/plugins/markdown-report/md_gen.ml @@ -582,10 +582,10 @@ let mk_date () = (Printf.sprintf "%d-%02d-%02d" (1900 + tm.Unix.tm_year) (1 + tm.Unix.tm_mon) tm.Unix.tm_mday) -let mk_remarks () = +let mk_remarks is_draft = let f = Mdr_params.Remarks.get () in if f <> "" then Parse_remarks.get_remarks f - else if Mdr_params.Gen_draft.get () then begin + else if is_draft then begin let f = Mdr_params.Output.get() in if Sys.file_exists f then begin Mdr_params.feedback @@ -595,7 +595,7 @@ let mk_remarks () = end else Datatype.String.Map.empty let gen_report is_draft = - let remarks = mk_remarks () in + let remarks = mk_remarks is_draft in let env = { remarks; is_draft } in let context = gen_context env in let coverage = gen_coverage env in @@ -645,13 +645,13 @@ let gen_report is_draft = (Mdr_params.Output.get()) s let main () = - if Mdr_params.Gen_draft.get () then begin - if Mdr_params.Generate.get () then - Mdr_params.warning - "-mdr-gen and -mdr-gen-draft cannot be activated at the \ - same time. Only draft will be generated"; - gen_report true - end - else if Mdr_params.Generate.get () then gen_report false + match Mdr_params.Generate.get () with + | "none" -> () + | "md" -> gen_report false + | "draft" -> gen_report true + | "sarif" -> Sarif_gen.generate () + | s -> + Mdr_params.fatal "Unexpected value for option %s: %s" + Mdr_params.Generate.option_name s let () = Db.Main.extend main diff --git a/src/plugins/markdown-report/mdr_params.ml b/src/plugins/markdown-report/mdr_params.ml index 188830f2ac9..be8ef4d1c14 100644 --- a/src/plugins/markdown-report/mdr_params.ml +++ b/src/plugins/markdown-report/mdr_params.ml @@ -13,19 +13,18 @@ struct let help = "sets the name of the output file to <f>" end) -module Generate = False( +module Generate = String( struct let option_name = "-mdr-gen" - let help = "generates an analysis report on the current project" + let arg_name = "kind" + let default = "none" + let help = + "select the <kind> of report to generate among: \ + none (default), md, draft and sarif" end) -module Gen_draft = False( - struct - let option_name = "-mdr-gen-draft" - let help = - "instead of a full report, generates an empty draft \ - in a format suitable for -mdr-remarks" - end) +let () = + Generate.set_possible_values [ "none"; "md"; "draft"; "sarif" ] module Remarks = Empty_string( struct diff --git a/src/plugins/markdown-report/mdr_params.mli b/src/plugins/markdown-report/mdr_params.mli index 993fcafd394..4affc377045 100644 --- a/src/plugins/markdown-report/mdr_params.mli +++ b/src/plugins/markdown-report/mdr_params.mli @@ -4,10 +4,7 @@ include Plugin.S module Output: Parameter_sig.String (** Value of [-mdr-gen]. *) -module Generate: Parameter_sig.Bool - -(** Value of [-mdr-gen-draft]. *) -module Gen_draft: Parameter_sig.Bool +module Generate: Parameter_sig.String (** Value of [-mdr-remarks]. *) module Remarks: Parameter_sig.String diff --git a/src/plugins/markdown-report/sarif_gen.ml b/src/plugins/markdown-report/sarif_gen.ml new file mode 100644 index 00000000000..d68842c4d75 --- /dev/null +++ b/src/plugins/markdown-report/sarif_gen.ml @@ -0,0 +1 @@ +let generate () = Mdr_params.not_yet_implemented "Sarif_gen.generate" diff --git a/src/plugins/markdown-report/sarif_gen.mli b/src/plugins/markdown-report/sarif_gen.mli new file mode 100644 index 00000000000..a3bd7165f7d --- /dev/null +++ b/src/plugins/markdown-report/sarif_gen.mli @@ -0,0 +1,2 @@ +(** generate a sarif json object. *) +val generate: unit -> unit -- GitLab