From 47a0123e0101d36a80e8b96b45cf0555fedc6641 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Oriol=20Tint=C3=B3?= <oriol.tinto@lmu.de>
Date: Mon, 17 Apr 2023 14:14:20 +0200
Subject: [PATCH] Change +lmu for +source=lmu, allowing also dkrz (default) and
 dkrz_https

---
 spack_repo/packages/icon-nwp/package.py | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/spack_repo/packages/icon-nwp/package.py b/spack_repo/packages/icon-nwp/package.py
index 40a2848..bb8acee 100644
--- a/spack_repo/packages/icon-nwp/package.py
+++ b/spack_repo/packages/icon-nwp/package.py
@@ -27,7 +27,15 @@ class IconNwp(Package):
     version("plexrt", branch="icon-nwp/icon-nwp-plexrt")
     version("master", branch="master")
 
-    variant("lmu", default=False, description="if git.url and submodules should be patched to use the LMU mirrors")
+    # FIXME: Workaround to deal with different sources. The default is using dkrz's through ssh.
+    variant("source", values=('dkrz', 'dkrz_https', 'lmu'), default='dkrz',
+            description='Select the source of the ICON: dkrz (ssh), dkrz_https, lmu (ssh)')
+    custom_fetchers = {
+        "dkrz": "ssh://git@gitlab.dkrz.de/icon/icon-nwp.git",
+        "dkrz_https": "https://gitlab.dkrz.de/icon/icon-nwp.git",
+        "lmu": "ssh://git@gitlab.physik.uni-muenchen.de/w2w/icon.git",
+    }
+
     variant("plexrt", default=False, description="add 3D radiation support with TenStream")
     variant("petsc", default=False, description="add PETSc support")
 
@@ -57,14 +65,16 @@ class IconNwp(Package):
     phases = ["configure", "build", "install"]
 
     def do_fetch(self, mirror_only=False):
-        if "+lmu" in self.spec:
-            self.fetcher[0].url = self.git = "ssh://git@gitlab.physik.uni-muenchen.de/w2w/icon.git"
+        # FIXME: Using the custom_fetchers workaround
+        source = self.spec.variants['source'].value
+        self.fetcher[0].url = self.git = self.custom_fetchers[source]
+
         super(IconNwp, self).do_fetch(mirror_only)
 
     def patch(self):
         # Run git submodule update
         git = which("git")
-        if "+lmu" in self.spec:
+        if self.spec.variants['source'].value == 'lmu':
             self.patch_submodules()
         git("submodule", "update", "--init", "--recursive")
 
-- 
GitLab