From 67f2aded875a8db395ca1c921198c12d51bc6c04 Mon Sep 17 00:00:00 2001
From: Patrick Baudin <patrick.baudin@cea.fr>
Date: Fri, 26 Mar 2021 07:10:00 +0100
Subject: [PATCH] [Ptests] fixes repeated MODULE m

---
 ptests/ptests.ml | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/ptests/ptests.ml b/ptests/ptests.ml
index e2dc772f1c0..8841ebc16cf 100644
--- a/ptests/ptests.ml
+++ b/ptests/ptests.ml
@@ -646,13 +646,15 @@ type cmd = {
   timeout:string
 }
 
+module StringSet = Set.Make (String)
+
 type config =
   { dc_test_regexp: string; (** regexp of test files. *)
     dc_execnow    : execnow list; (** command to be launched before
                                        the toplevel(s)
                                   *)
     dc_load_module: string; (** load module options. *)
-    dc_deps_module: string list; (** modules to compile. *)
+    dc_cmxs_module: StringSet.t; (** compiled modules. *)
     dc_macros: Macros.t; (** existing macros. *)
     dc_default_toplevel   : string;
     (** full path of the default toplevel. *)
@@ -719,7 +721,7 @@ end = struct
       dc_commands = [ { toplevel= !toplevel_path; opts=default_options; macros=Macros.empty; exit_code=None; logs= []; timeout= ""} ];
       dc_dont_run = false;
       dc_load_module = "";
-      dc_deps_module = [];
+      dc_cmxs_module = StringSet.empty;
       dc_framac = true;
       dc_default_log = [];
       dc_timeout = "";
@@ -843,9 +845,11 @@ end = struct
 
   let add_make_modules ~drop ~file dir deps current =
     List.fold_left (fun acc s ->
-        let make_cmd = Macros.expand current.dc_macros "@PTEST_MAKE_MODULE@" in
-        let acc = config_exec ~once:true ~drop ~file dir (make_cmd ^ " " ^ s) acc in
-        { acc with dc_deps_module = s :: acc.dc_deps_module })
+        if StringSet.mem s acc.dc_cmxs_module then acc
+        else
+          let make_cmd = Macros.expand current.dc_macros "@PTEST_MAKE_MODULE@" in
+          let acc = config_exec ~once:true ~drop ~file dir (make_cmd ^ " " ^ s) acc in
+          { acc with dc_cmxs_module = StringSet.add s acc.dc_cmxs_module })
       current deps
 
   let config_module ~drop ~file dir s current =
@@ -854,8 +858,7 @@ end = struct
         (str_split_list s)
     in
     let current = add_make_modules ~drop ~file dir deps current in
-    { current with dc_deps_module = deps @ current.dc_deps_module;
-                   dc_macros = set_load_modules deps current.dc_macros }
+    { current with dc_macros = set_load_modules deps current.dc_macros }
 
   let config_options =
     [ "CMD",
-- 
GitLab