From 726be74cce3d35c496d89e082a82c9af6551af88 Mon Sep 17 00:00:00 2001 From: Virgile Prevosto <virgile.prevosto@m4x.org> Date: Fri, 28 Aug 2020 08:32:56 +0200 Subject: [PATCH] sample program results passes Sarif 2.1.0 validation --- src/plugins/markdown-report/sarif.ml | 66 ++++++++++++------------ src/plugins/markdown-report/sarif_gen.ml | 10 ++-- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/plugins/markdown-report/sarif.ml b/src/plugins/markdown-report/sarif.ml index 32c557b9c6e..e50d9262a43 100644 --- a/src/plugins/markdown-report/sarif.ml +++ b/src/plugins/markdown-report/sarif.ml @@ -87,37 +87,6 @@ struct let v2_1_0 = "2.1.0" end -module Message = struct - type t = { - text: (string [@default ""]); - messageId: (string [@default ""]); - richText: (string [@default ""]); - richMessageId: (string [@default ""]); - arguments: (string list [@default []]); - }[@@deriving yojson] - - let create - ?(text="") - ?(messageId="") - ?(richText="") - ?(richMessageId="") - ?(arguments=[]) - () - = - { text; messageId; richText; richMessageId; arguments } - - let plain_text ~text ?id:messageId ?arguments () = - create ~text ?messageId ?arguments () - - let markdown ~markdown ?id:richMessageId ?arguments () = - let pp fmt = Markdown.pp_elements fmt in - let richText = String.trim (Format.asprintf "@[%a@]" pp markdown) - in - create ~richText ?richMessageId ?arguments () - - let default = create () -end - module ArtifactLocation = struct type t = { uri: string; @@ -177,6 +146,37 @@ module Properties = struct | _ -> `Assoc (("tags", tags_to_yojson tags)::additional_properties) end +module Message = struct + type t = { + text: (string [@default ""]); + id: (string [@default ""]); + markdown: (string [@default ""]); + arguments: (string list [@default []]); + properties: (Properties.t [@default Properties.default]); + }[@@deriving yojson] + + let create + ?(text="") + ?(id="") + ?(markdown="") + ?(arguments=[]) + ?(properties=Properties.default) + () + = + { text; id; markdown; arguments; properties } + + let plain_text ~text ?id ?arguments () = + create ~text ?id ?arguments () + + let markdown ~markdown ?id ?arguments () = + let pp fmt = Markdown.pp_elements fmt in + let markdown = String.trim (Format.asprintf "@[%a@]" pp markdown) + in + create ~markdown ?id ?arguments () + + let default = create () +end + module MultiformatMessageString = struct type t = { text: string; @@ -1019,7 +1019,7 @@ module Sarif_result = struct }[@@deriving yojson] let create - ?(ruleId = "") + ~ruleId ?(kind=Result_kind.pass) ?(level=Result_level.none) ?(message=Message.default) @@ -1420,7 +1420,7 @@ end module Schema = struct type t = { - schema: (Uri.t [@default Uri.sarif_github]) [@key "$schema"]; + schema: Uri.t [@key "$schema"]; version: Version.t; runs: Run.t list } [@@deriving yojson] diff --git a/src/plugins/markdown-report/sarif_gen.ml b/src/plugins/markdown-report/sarif_gen.ml index d3633e8e8aa..278073346ff 100644 --- a/src/plugins/markdown-report/sarif_gen.ml +++ b/src/plugins/markdown-report/sarif_gen.ml @@ -101,11 +101,11 @@ let make_message alarm annot remark = | [] -> summary :: gen_remark alarm | _ -> summary :: remark in - let richText = + let markdown = String.trim (Format.asprintf "@[%a@]" (Markdown.pp_elements ~page:"") markdown) in - Message.create ~text ~richText () + Message.create ~text ~markdown () let opt_physical_location_of_loc loc = if loc = Cil_datatype.Location.unknown then [] @@ -142,12 +142,14 @@ let make_ip_message ip = let text = Format.asprintf "@[%a.@]" Property.short_pretty ip in Message.plain_text ~text () +let user_annot_id = "user-spec" + let gen_status ip = let status = Property_status.Feedback.get ip in let level = level_of_status status in let locations = opt_physical_location_of_loc (Property.location ip) in let message = make_ip_message ip in - Sarif_result.create ~level ~locations ~message () + Sarif_result.create ~ruleId:user_annot_id ~level ~locations ~message () let gen_statuses () = let f ip content = @@ -184,7 +186,7 @@ let gen_run remarks = | [] -> rules | _ -> Datatype.String.Map.add - "user-spec" "User-written ACSL specification" rules + user_annot_id "User-written ACSL specification" rules in let rules = make_taxonomies rules in let taxonomies = [ToolComponent.create ~name ~rules ()] in -- GitLab