Skip to content
Snippets Groups Projects
Commit 9cbe7c82 authored by Andre Maroneze's avatar Andre Maroneze
Browse files

[MdR] use Filepath parameters for relevant options

parent 4345d330
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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. \
......
......@@ -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
......
......@@ -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
......@@ -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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment