From 1570f90fde7a3c6623a1635bbe68f6a028369bf9 Mon Sep 17 00:00:00 2001
From: Denis Davydov <davydden@gmail.com>
Date: Sun, 11 Dec 2016 01:23:39 +0100
Subject: [PATCH] clang: do xcode mockup iff requested by a package (#2544)

* clang: do xcode mockup iff requested by a package

* add a note

* add pkg to setup_custom_environment() and decide whether or not to use mockup XCode there based on the package
---
 lib/spack/spack/build_environment.py           |  2 +-
 lib/spack/spack/compiler.py                    |  2 +-
 lib/spack/spack/compilers/clang.py             | 10 +++++++---
 lib/spack/spack/package.py                     |  4 ++++
 var/spack/repos/builtin/packages/qt/package.py |  2 ++
 5 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py
index 5e99d4552b..619877275d 100644
--- a/lib/spack/spack/build_environment.py
+++ b/lib/spack/spack/build_environment.py
@@ -224,7 +224,7 @@ def set_compiler_environment_variables(pkg, env):
     for mod in compiler.modules:
         load_module(mod)
 
-    compiler.setup_custom_environment(env)
+    compiler.setup_custom_environment(pkg, env)
 
     return env
 
diff --git a/lib/spack/spack/compiler.py b/lib/spack/spack/compiler.py
index 0d9727c69e..92fa1ac4db 100644
--- a/lib/spack/spack/compiler.py
+++ b/lib/spack/spack/compiler.py
@@ -286,7 +286,7 @@ def _find_full_path(self, path):
         """
         return path
 
-    def setup_custom_environment(self, env):
+    def setup_custom_environment(self, pkg, env):
         """Set any environment variables necessary to use the compiler."""
         pass
 
diff --git a/lib/spack/spack/compilers/clang.py b/lib/spack/spack/compilers/clang.py
index b2095defe5..14dc9d6476 100644
--- a/lib/spack/spack/compilers/clang.py
+++ b/lib/spack/spack/compilers/clang.py
@@ -148,7 +148,7 @@ def fc_version(cls, fc):
     def f77_version(cls, f77):
         return cls.fc_version(f77)
 
-    def setup_custom_environment(self, env):
+    def setup_custom_environment(self, pkg, env):
         """Set the DEVELOPER_DIR environment for the Xcode toolchain.
 
         On macOS, not all buildsystems support querying CC and CXX for the
@@ -160,9 +160,13 @@ def setup_custom_environment(self, env):
         the 'DEVELOPER_DIR' environment variables to cause the xcrun and
         related tools to use this Xcode.app.
         """
-        super(Clang, self).setup_custom_environment(env)
+        super(Clang, self).setup_custom_environment(pkg, env)
 
-        if not self.is_apple:
+        if not self.is_apple or not pkg.use_xcode:
+            # if we do it for all packages, we get into big troubles with MPI:
+            # filter_compilers(self) will use mockup XCode compilers on macOS
+            # with Clang. Those point to Spack's compiler wrappers and
+            # consequently render MPI non-functional outside of Spack.
             return
 
         xcode_select = Executable('xcode-select')
diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py
index 9c946844c6..31d08be456 100644
--- a/lib/spack/spack/package.py
+++ b/lib/spack/spack/package.py
@@ -487,6 +487,10 @@ class SomePackage(Package):
     """By default do not run tests within package's install()"""
     run_tests = False
 
+    # FIXME: this is a bad object-oriented design, should be moved to Clang.
+    """By default do not setup mockup XCode on macOS with Clang"""
+    use_xcode = False
+
     """Most packages are NOT extendable. Set to True if you want extensions."""
     extendable = False
 
diff --git a/var/spack/repos/builtin/packages/qt/package.py b/var/spack/repos/builtin/packages/qt/package.py
index 1db651c02b..6e6d4b95f6 100644
--- a/var/spack/repos/builtin/packages/qt/package.py
+++ b/var/spack/repos/builtin/packages/qt/package.py
@@ -92,6 +92,8 @@ class Qt(Package):
     # depends_on("flac", when='+multimedia')
     # depends_on("ogg", when='+multimedia')
 
+    use_xcode = True
+
     def url_for_version(self, version):
         # URL keeps getting more complicated with every release
         url = self.list_url
-- 
GitLab