From c3b5aee714b3c7dd0a124f38b84224fbe59e00be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Hermes=29?=
 <stephane.adjemian@univ-lemans.fr>
Date: Thu, 19 May 2016 16:34:47 +0200
Subject: [PATCH] Specialize @dynare macro if one model is processed.

In this case importall is used instead of import.
---
 julia/Dynare.jl                       | 14 ++++++++++----
 tests/julia/rbc/test1.jl              | 16 ++++++++++++++++
 tests/julia/rbc/test2.jl              | 17 +++++++++++++++++
 tests/julia/rbc/{test.jl => test3.jl} |  1 -
 4 files changed, 43 insertions(+), 5 deletions(-)
 create mode 100644 tests/julia/rbc/test1.jl
 create mode 100644 tests/julia/rbc/test2.jl
 rename tests/julia/rbc/{test.jl => test3.jl} (99%)

diff --git a/julia/Dynare.jl b/julia/Dynare.jl
index 0e74023bf8..82efd64f2d 100644
--- a/julia/Dynare.jl
+++ b/julia/Dynare.jl
@@ -34,10 +34,16 @@ end
 
 macro dynare(modfiles...)
     ex = Expr(:toplevel)
-    for modfile in modfiles
-        eval(:(compile($modfile)))
-        basename = split(modfile, ".mod"; keep=false)
-        push!(ex.args, Expr(:import, symbol(basename[1])))
+    if length(modfiles)>1
+        for modfile in modfiles
+            eval(:(compile($modfile)))
+            basename = split(modfile, ".mod"; keep=false)
+            push!(ex.args, Expr(:import, symbol(basename[1])))
+        end
+    else
+        eval(:(compile($modfiles)))
+        basename = split(modfiles[1], ".mod"; keep=false)
+        push!(ex.args, Expr(:importall, symbol(basename[1])))
     end
     return ex
 end
diff --git a/tests/julia/rbc/test1.jl b/tests/julia/rbc/test1.jl
new file mode 100644
index 0000000000..57c6472868
--- /dev/null
+++ b/tests/julia/rbc/test1.jl
@@ -0,0 +1,16 @@
+#clear workspace
+workspace()
+
+# Modification of the path (for packages). Should be done in ~/.juliarc.jl with a fixed path instead.
+if isempty(findin([abspath("../../../julia")], LOAD_PATH))
+    unshift!(LOAD_PATH, abspath("../../../julia"))
+end
+
+# Load Dynare package
+importall Dynare
+
+# Compile the rbc.mod file -> produce a module with the model definition.
+
+@dynare "rbc1.mod"
+
+print(model.fname)
diff --git a/tests/julia/rbc/test2.jl b/tests/julia/rbc/test2.jl
new file mode 100644
index 0000000000..6941d81f26
--- /dev/null
+++ b/tests/julia/rbc/test2.jl
@@ -0,0 +1,17 @@
+#clear workspace
+workspace()
+
+# Modification of the path (for packages). Should be done in ~/.juliarc.jl with a fixed path instead.
+if isempty(findin([abspath("../../../julia")], LOAD_PATH))
+    unshift!(LOAD_PATH, abspath("../../../julia"))
+end
+
+# Load Dynare package
+importall Dynare
+
+# Compile the rbc.mod file -> produce a module with the model definition.
+
+
+@dynare "rbc2.mod"
+
+print(model.fname)
diff --git a/tests/julia/rbc/test.jl b/tests/julia/rbc/test3.jl
similarity index 99%
rename from tests/julia/rbc/test.jl
rename to tests/julia/rbc/test3.jl
index e0857b90e3..fd02a5b46f 100644
--- a/tests/julia/rbc/test.jl
+++ b/tests/julia/rbc/test3.jl
@@ -19,6 +19,5 @@ importall Dynare
 #  @compile "rbc1.mod"
 #  using rbc1
 
-
 print(rbc1.model.fname)
 print(rbc2.model.fname)
-- 
GitLab