diff --git a/src/plugins/markdown-report/md_gen.ml b/src/plugins/markdown-report/md_gen.ml index dc212069f0d533bf8513d4311ccaf8ef7f9daaa7..eca194f5640fde9bcb9f943f91de4368c42d4d9d 100644 --- a/src/plugins/markdown-report/md_gen.ml +++ b/src/plugins/markdown-report/md_gen.ml @@ -555,12 +555,14 @@ let gen_alarms env = let mk_remarks is_draft = let f = Mdr_params.Remarks.get () in - if f <> "" then Parse_remarks.get_remarks f + if not (Filepath.Normalized.is_unknown f) then + Parse_remarks.get_remarks f else if is_draft then begin let f = Mdr_params.Output.get() in - if Sys.file_exists f then begin + if Sys.file_exists (f:>string) then begin Mdr_params.feedback - "Re-using pre-existing remarks in draft file %s" f; + "Re-using pre-existing remarks in draft file %a" + Filepath.Normalized.pretty f; Parse_remarks.get_remarks f end else Datatype.String.Map.empty end else Datatype.String.Map.empty @@ -609,8 +611,9 @@ let gen_report ~draft:is_draft () = let doc = Markdown.pandoc ~title ~authors ?date elements in let file = Mdr_params.Output.get() in try - Command.print_file file (fun fmt -> Markdown.pp_pandoc fmt doc) ; - Mdr_params.result "Report %s generated" file + Command.print_file (file:>string) (fun fmt -> Markdown.pp_pandoc fmt doc) ; + Mdr_params.result "Report %a generated" Filepath.Normalized.pretty file with Sys_error s -> Mdr_params.warning - "Unable to open %s for writing (%s). No report generated" file s + "Unable to open %a for writing (%s). No report generated" + Filepath.Normalized.pretty file s diff --git a/src/plugins/markdown-report/mdr_params.ml b/src/plugins/markdown-report/mdr_params.ml index 3b799faccaad2e5e4349c5ebe73993683abf2dbb..12d8cfbf603b1ea4f869c8aa011538b5f254462c 100644 --- a/src/plugins/markdown-report/mdr_params.ml +++ b/src/plugins/markdown-report/mdr_params.ml @@ -39,33 +39,36 @@ module Generate = String( none (default), md, draft and sarif" end) -module Output : Parameter_sig.String = +module Output : Parameter_sig.Filepath = struct - include String( + include Filepath( struct let option_name = "-mdr-out" let arg_name = "f" - let default = "report" + let file_kind = "Report" + let existence = Fc_Filepath.Indifferent let help = "sets the name of the output file to <f>. \ If <f> has no extension, it is chosen automatically based on \ the report kind" end) let get () = let s = get () in - if Pervasives_string.contains (Filename.basename s) '.' then s + if Pervasives_string.contains (Filename.basename (s:>string)) '.' then s else let kind = Generate.get () in let ext = if kind = "sarif" then ".sarif" else ".md" in - s ^ ext + Fc_Filepath.Normalized.concat s ext end let () = Generate.set_possible_values [ "none"; "md"; "draft"; "sarif" ] -module Remarks = Empty_string( +module Remarks = Filepath( struct let option_name = "-mdr-remarks" let arg_name = "f" + let file_kind = "Remarks file" + let existence = Fc_Filepath.Must_exist let help = "reads file <f> to add additional remarks to various sections of the report. \ Must be in a format compatible with the file produced by -mdr-gen-draft. \ diff --git a/src/plugins/markdown-report/mdr_params.mli b/src/plugins/markdown-report/mdr_params.mli index b7c5b06901b78d086f8389fa5fe8adf149d07112..f40ba97f1b52665c59872985be6bfd728725fa80 100644 --- a/src/plugins/markdown-report/mdr_params.mli +++ b/src/plugins/markdown-report/mdr_params.mli @@ -23,13 +23,13 @@ include Plugin.S (** Value of [-mdr-out]. *) -module Output: Parameter_sig.String +module Output: Parameter_sig.Filepath (** Value of [-mdr-gen]. *) module Generate: Parameter_sig.String (** Value of [-mdr-remarks]. *) -module Remarks: Parameter_sig.String +module Remarks: Parameter_sig.Filepath (** Value of [-mdr-flamegraph]. *) module FlameGraph: Parameter_sig.String diff --git a/src/plugins/markdown-report/parse_remarks.ml b/src/plugins/markdown-report/parse_remarks.ml index d2e4860e7c455fb1f4fc6b477c3882b2ffc653da..10fc83a0da5af95687e7ec085acff31c9de2337e 100644 --- a/src/plugins/markdown-report/parse_remarks.ml +++ b/src/plugins/markdown-report/parse_remarks.ml @@ -112,13 +112,15 @@ let parse_remarks env chan = env let get_remarks f = - Mdr_params.debug ~dkey "Using remarks file %s" f; + Mdr_params.debug ~dkey "Using remarks file %a" + Filepath.Normalized.pretty f; try - let chan = open_in f in + let chan = open_in (f:>string) in let { remarks } = parse_remarks (empty_env ()) chan in remarks with Sys_error err -> Mdr_params.error - "Unable to open remarks file %s (%s). \ - No additional remarks will be included in the report." f err; + "Unable to open remarks file %a (%s). \ + No additional remarks will be included in the report." + Filepath.Normalized.pretty f err; Datatype.String.Map.empty diff --git a/src/plugins/markdown-report/parse_remarks.mli b/src/plugins/markdown-report/parse_remarks.mli index 2491fe94a4998fe29fed358596b97815f98da233..48728e02729fbad4a37dc3647d8153d729cfdc69 100644 --- a/src/plugins/markdown-report/parse_remarks.mli +++ b/src/plugins/markdown-report/parse_remarks.mli @@ -25,4 +25,4 @@ (** [get_remarks f] retrieves the elements associated to various sections of the report, referenced by their anchor. *) -val get_remarks: string -> Markdown.element list Datatype.String.Map.t +val get_remarks: Filepath.Normalized.t -> Markdown.element list Datatype.String.Map.t diff --git a/src/plugins/markdown-report/sarif_gen.ml b/src/plugins/markdown-report/sarif_gen.ml index 12d64ad6e94bf30041c359bf8bb4d705e75a29f7..a873d605464b41cc128ceada0391dbc2f5c73eb1 100644 --- a/src/plugins/markdown-report/sarif_gen.ml +++ b/src/plugins/markdown-report/sarif_gen.ml @@ -39,7 +39,7 @@ let frama_c_sarif () = let get_remarks () = let f = Mdr_params.Remarks.get () in - if f <> "" then Parse_remarks.get_remarks f + if not (Filepath.Normalized.is_unknown f) then Parse_remarks.get_remarks f else Datatype.String.Map.empty let get_remark remarks label = @@ -274,12 +274,13 @@ let generate () = let runs = [ gen_run remarks ] in let json = Schema.create ~runs () |> Schema.to_yojson in let file = Mdr_params.Output.get () in - if file = "" then + if Filepath.Normalized.is_unknown file then Log.print_on_output (fun fmt -> Yojson.Safe.pretty_print fmt json) else try - Command.write_file file + Command.write_file (file:>string) (fun out -> Yojson.Safe.pretty_to_channel ~std:true out json) ; - Mdr_params.result "Report %s generated" file + Mdr_params.result "Report %a generated" Filepath.Normalized.pretty file with Sys_error s -> - Mdr_params.abort "Unable to generate %s (%s)" file s + Mdr_params.abort "Unable to generate %a (%s)" + Filepath.Normalized.pretty file s