From 227272f303a47c55711808c8d21026332299a4dd Mon Sep 17 00:00:00 2001
From: Andre Maroneze <andre.maroneze@cea.fr>
Date: Fri, 30 Oct 2020 08:08:11 +0100
Subject: [PATCH] add Docker-based CI integration with SARIF report artifacts

---
 .gitignore      |  4 ++++
 .gitlab-ci.yml  | 13 +++++++++++++
 Makefile        |  5 +++++
 Makefile.common |  8 ++++++++
 frama-c         |  2 +-
 5 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100644 .gitlab-ci.yml

diff --git a/.gitignore b/.gitignore
index 8dbe798f4..cc96cbea7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,3 +16,7 @@ flamegraph.txt
 
 benchs-value.csv
 bench_clone
+
+# .sarif reports are produced as CI artifacts, but we do not want to version
+# them, due to their size and the redundancy w.r.t. Eva logs.
+*.sarif
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 000000000..ebb62a057
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,13 @@
+default:
+  image: framac/frama-c:dev
+
+build:
+  tags:
+    - docker
+  script:
+    - make -B all >/dev/null
+    - git diff --exit-code
+    - make sarif
+  artifacts:
+    paths:
+    - "*/.frama-c/*.sarif"
diff --git a/Makefile b/Makefile
index 015449b5b..b4891dc2f 100644
--- a/Makefile
+++ b/Makefile
@@ -111,6 +111,11 @@ parse: $(addsuffix .parse,$(TARGETS))
 
 stats: $(addsuffix .stats,$(TARGETS))
 
+%.sarif:
+	$(MAKE) -C $*/.frama-c sarif
+
+sarif: $(addsuffix .sarif,$(TARGETS))
+
 display-targets:
 	@echo $(foreach target,$(TARGETS),\
 	        $(addprefix $(target)/,\
diff --git a/Makefile.common b/Makefile.common
index 4ae62e66d..9bf7b07fe 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -1,3 +1,11 @@
 # Makefile optionally included by each GNUmakefile in the target directories.
 # Note: it must be included at the end of the makefiles,
 # to ensure e.g. TARGETS and other variables are properly defined.
+
+### Extra targets for SARIF report
+# '-noautoload-plugins -load-module eva,markdown_report' minimize loading time
+# of several dozens of calls to Frama-C
+%.sarif: %.eva
+	$(FRAMAC) -no-autoload-plugins -load-module eva,markdown_report -load $^/framac.sav -mdr-gen sarif -mdr-no-print-libc -mdr-sarif-deterministic -mdr-out $@
+
+sarif: $(TARGETS:%.eva=%.sarif)
diff --git a/frama-c b/frama-c
index 292964f37..186247381 160000
--- a/frama-c
+++ b/frama-c
@@ -1 +1 @@
-Subproject commit 292964f3767f94f2e4a45e347aa33fde15a225d1
+Subproject commit 186247381f19703b1572dba997865645cd80d5e9
-- 
GitLab