From e03fc173377581db4a42679438e7457de7d4334b Mon Sep 17 00:00:00 2001
From: Virgile Prevosto <virgile.prevosto@m4x.org>
Date: Wed, 21 Nov 2018 19:13:44 +0100
Subject: [PATCH] [GUI] Dgraph compatibility: use fake Dgraph module in gtk3
 mode

---
 .gitignore                    |  3 +++
 Makefile                      | 23 ++++++++++++++++++++++-
 src/plugins/gui/dgraph.ml.in  | 14 ++++++++++++++
 src/plugins/gui/dgraph.mli.in | 14 ++++++++++++++
 4 files changed, 53 insertions(+), 1 deletion(-)
 create mode 100644 src/plugins/gui/dgraph.ml.in
 create mode 100644 src/plugins/gui/dgraph.mli.in

diff --git a/.gitignore b/.gitignore
index ddbe6066a1e..7bb9b259fc6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -198,3 +198,6 @@ hello-*.tar.gz
 # should remain empty #
 #######################
 /src/plugins/gui/GSourceView2.mli
+/src/plugins/gui/GSourceView2.ml
+/src/plugins/gui/dgraph.ml
+/src/plugins/gui/dgraph.mli
diff --git a/Makefile b/Makefile
index 24819a4a472..e39c957906a 100644
--- a/Makefile
+++ b/Makefile
@@ -684,15 +684,31 @@ SOURCEVIEWCOMPAT:=
 ifeq ($(strip $(GTKSOURCEVIEW)),lablgtk2.sourceview3)
 SOURCEVIEWCOMPAT:=GSourceView2
 
-src/plugins/gui/GSourceView2.ml%: src/plugins/gui/GSourceView2.ml%.in
+src/plugins/gui/GSourceView2.ml: src/plugins/gui/GSourceView2.ml.in
 	$(CP) $< $@
 	$(CHMOD_RO) $@
 
+src/plugins/gui/GSourceView2.mli: src/plugins/gui/GSourceView2.mli.in
+	$(CP) $< $@
+	$(CHMOD_RO) $@
+
+endif
+
+DGRAPHCOMPAT:=
+ifeq ($(HAS_GNOMECANVAS),no)
+DGRAPHCOMPAT:=dgraph
+src/plugins/gui/dgraph.ml: src/plugins/gui/dgraph.ml.in
+	$(CP) $< $@
+	$(CHMOD_RO) $@
+src/plugins/gui/dgraph.mli: src/plugins/gui/dgraph.mli.in
+	$(CP) $< $@
+	$(CHMOD_RO) $@
 endif
 
 SINGLE_GUI_CMO:= \
 	$(WTOOLKIT) \
 	$(SOURCEVIEWCOMPAT) \
+	$(DGRAPHCOMPAT) \
 	gui_parameters \
 	gtk_helper gtk_form \
 	source_viewer pretty_source source_manager book_manager \
@@ -745,7 +761,12 @@ PLUGIN_NAME:=Callgraph
 PLUGIN_DISTRIBUTED:=yes
 PLUGIN_DIR:=src/plugins/callgraph
 PLUGIN_CMO:= options journalize subgraph cg services uses register
+#GTK3: no DGraph available.
+ifeq ($(HAS_GNOMECANVAS),yes)
 PLUGIN_GUI_CMO:=cg_viewer
+else
+PLUGIN_GUI_CMO:=
+endif
 PLUGIN_CMI:= callgraph_api
 PLUGIN_INTERNAL_TEST:=yes
 PLUGIN_TESTS_DIRS:=callgraph
diff --git a/src/plugins/gui/dgraph.ml.in b/src/plugins/gui/dgraph.ml.in
new file mode 100644
index 00000000000..85cffffb27e
--- /dev/null
+++ b/src/plugins/gui/dgraph.ml.in
@@ -0,0 +1,14 @@
+(* dgraph module that always generates an error: Dgraph is not available
+   with gtk3
+*)
+
+module DGraphModel = struct
+  exception DotError of string
+end
+
+module DGraphContainer = struct
+  module Dot = struct
+    let from_dot_with_commands ?packing:_ _ =
+      raise (DGraphModel.DotError "DGraph is unsupported in GTK3")
+  end
+end
diff --git a/src/plugins/gui/dgraph.mli.in b/src/plugins/gui/dgraph.mli.in
new file mode 100644
index 00000000000..ce84948c30d
--- /dev/null
+++ b/src/plugins/gui/dgraph.mli.in
@@ -0,0 +1,14 @@
+(* dgraph module that always generates an error: Dgraph is not available
+   with gtk3
+*)
+
+module DGraphModel: sig
+  exception DotError of string
+end
+
+module DGraphContainer: sig
+  module Dot: sig
+    val from_dot_with_commands: ?packing:(GObj.widget ->unit) -> string ->
+        GPack.table * <adapt_zoom: unit -> unit>
+  end
+end
-- 
GitLab