From 97784ac90bfc4b3a6eeecec70fd89e41a6df8d8a Mon Sep 17 00:00:00 2001
From: Virgile Prevosto <virgile.prevosto@m4x.org>
Date: Mon, 17 Dec 2018 11:36:51 +0100
Subject: [PATCH] [sarif] generate information about input files

---
 src/plugins/markdown-report/sarif.ml     | 19 +++++++++++++++++++
 src/plugins/markdown-report/sarif_gen.ml | 13 ++++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/plugins/markdown-report/sarif.ml b/src/plugins/markdown-report/sarif.ml
index e6c489fd59b..6d64ba13288 100644
--- a/src/plugins/markdown-report/sarif.ml
+++ b/src/plugins/markdown-report/sarif.ml
@@ -644,6 +644,25 @@ module File = struct
     lastModifiedTime: (string [@default ""]);
     properties: (Properties.t [@default Properties.default]);
   }[@@deriving yojson]
+
+  let create
+    ?(fileLocation = FileLocation.default)
+    ?(parentKey = "")
+    ?(offset = 0)
+    ?(length = 0)
+    ?(roles = [])
+    ?(mimeType = "")
+    ?(contents = FileContent.default)
+    ?(encoding = "")
+    ?(hashes = [])
+    ?(lastModifiedTime = "")
+    ?(properties = Properties.default)
+    ()
+    =
+    {
+      fileLocation; parentKey; offset; length; roles; mimeType; contents;
+      encoding; hashes; lastModifiedTime; properties
+    }
 end
 
 module FileChange = struct
diff --git a/src/plugins/markdown-report/sarif_gen.ml b/src/plugins/markdown-report/sarif_gen.ml
index 2309c2ff85c..72ae96507c2 100644
--- a/src/plugins/markdown-report/sarif_gen.ml
+++ b/src/plugins/markdown-report/sarif_gen.ml
@@ -50,11 +50,22 @@ let gen_results remarks =
   let _, content = Alarms.fold treat_alarm (0, []) in
   List.rev content
 
+let gen_files () =
+  let add_src_file f =
+    let key = Filename.chop_extension (Filename.basename f) in
+    let fileLocation = FileLocation.create ~uri:(Filepath.normalize f) () in
+    let roles = [ Role.analysisTarget ] in
+    let mimeType = "text/x-csrc" in
+    key, File.create ~fileLocation ~roles ~mimeType ()
+  in
+  List.map add_src_file (Kernel.Files.get ())
+
 let gen_run remarks =
   let tool = frama_c_sarif in
   let invocations = [gen_invocation ()] in
   let results = gen_results remarks in
-  Run.create ~tool ~invocations ~results ()
+  let files = gen_files () in
+  Run.create ~tool ~invocations ~results ~files ()
 
 let generate () =
   let remarks = get_remarks () in
-- 
GitLab