summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAdam J. Stewart <ajstewart426@gmail.com>2023-07-31 12:24:04 -0500
committerGitHub <noreply@github.com>2023-07-31 10:24:04 -0700
commit9394fa403e72fed833a74a38a8c8819b56875896 (patch)
tree23b980d9f3fe21a40625c9eb3046119d8d558784 /lib
parent679c6a606d37e8bea1ed2114677007981fe4bf46 (diff)
downloadspack-9394fa403e72fed833a74a38a8c8819b56875896.tar.gz
spack-9394fa403e72fed833a74a38a8c8819b56875896.tar.bz2
spack-9394fa403e72fed833a74a38a8c8819b56875896.tar.xz
spack-9394fa403e72fed833a74a38a8c8819b56875896.zip
Remove Xcode mock-up (#39020)
* Remove Xcode mock-up * Remove unused imports
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/compilers/apple_clang.py109
-rw-r--r--lib/spack/spack/package_base.py4
-rw-r--r--lib/spack/spack/test/compilers/basics.py114
3 files changed, 0 insertions, 227 deletions
diff --git a/lib/spack/spack/compilers/apple_clang.py b/lib/spack/spack/compilers/apple_clang.py
index 1373ac0bf2..e81703b2d2 100644
--- a/lib/spack/spack/compilers/apple_clang.py
+++ b/lib/spack/spack/compilers/apple_clang.py
@@ -2,13 +2,9 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
-import os.path
import re
-import shutil
import llnl.util.lang
-import llnl.util.tty as tty
-from llnl.util.symlink import symlink
import spack.compiler
import spack.compilers.clang
@@ -119,108 +115,3 @@ class AppleClang(spack.compilers.clang.Clang):
self, "the C23 standard", "c23_flag", "< 11.0.3"
)
return "-std=c2x"
-
- 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
- compilers to use and instead query the Xcode toolchain for what
- compiler to run. This side-steps the spack wrappers. In order to inject
- spack into this setup, we need to copy (a subset of) Xcode.app and
- replace the compiler executables with symlinks to the spack wrapper.
- Currently, the stage is used to store the Xcode.app copies. We then set
- the 'DEVELOPER_DIR' environment variables to cause the xcrun and
- related tools to use this Xcode.app.
- """
- super().setup_custom_environment(pkg, env)
-
- if 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
-
- # Use special XCode versions of compiler wrappers when using XCode
- # Overwrites build_environment's setting of SPACK_CC and SPACK_CXX
- xcrun = spack.util.executable.Executable("xcrun")
- xcode_clang = xcrun("-f", "clang", output=str).strip()
- xcode_clangpp = xcrun("-f", "clang++", output=str).strip()
- env.set("SPACK_CC", xcode_clang, force=True)
- env.set("SPACK_CXX", xcode_clangpp, force=True)
-
- xcode_select = spack.util.executable.Executable("xcode-select")
-
- # Get the path of the active developer directory
- real_root = xcode_select("--print-path", output=str).strip()
-
- # The path name can be used to determine whether the full Xcode suite
- # or just the command-line tools are installed
- if real_root.endswith("Developer"):
- # The full Xcode suite is installed
- pass
- else:
- if real_root.endswith("CommandLineTools"):
- # Only the command-line tools are installed
- msg = "It appears that you have the Xcode command-line tools "
- msg += "but not the full Xcode suite installed.\n"
-
- else:
- # Xcode is not installed
- msg = "It appears that you do not have Xcode installed.\n"
-
- msg += "In order to use Spack to build the requested application, "
- msg += "you need the full Xcode suite. It can be installed "
- msg += "through the App Store. Make sure you launch the "
- msg += "application and accept the license agreement.\n"
-
- raise OSError(msg)
-
- real_root = os.path.dirname(os.path.dirname(real_root))
- developer_root = os.path.join(
- spack.stage.get_stage_root(), "xcode-select", self.name, str(self.version)
- )
- xcode_link = os.path.join(developer_root, "Xcode.app")
-
- if not os.path.exists(developer_root):
- tty.warn(
- "Copying Xcode from %s to %s in order to add spack "
- "wrappers to it. Please do not interrupt." % (real_root, developer_root)
- )
-
- # We need to make a new Xcode.app instance, but with symlinks to
- # the spack wrappers for the compilers it ships. This is necessary
- # because some projects insist on just asking xcrun and related
- # tools where the compiler runs. These tools are very hard to trick
- # as they do realpath and end up ignoring the symlinks in a
- # "softer" tree of nothing but symlinks in the right places.
- shutil.copytree(
- real_root,
- developer_root,
- symlinks=True,
- ignore=shutil.ignore_patterns(
- "AppleTV*.platform",
- "Watch*.platform",
- "iPhone*.platform",
- "Documentation",
- "swift*",
- ),
- )
-
- real_dirs = ["Toolchains/XcodeDefault.xctoolchain/usr/bin", "usr/bin"]
-
- bins = ["c++", "c89", "c99", "cc", "clang", "clang++", "cpp"]
-
- for real_dir in real_dirs:
- dev_dir = os.path.join(developer_root, "Contents", "Developer", real_dir)
- for fname in os.listdir(dev_dir):
- if fname in bins:
- os.unlink(os.path.join(dev_dir, fname))
- symlink(
- os.path.join(spack.paths.build_env_path, "cc"),
- os.path.join(dev_dir, fname),
- )
-
- symlink(developer_root, xcode_link)
-
- env.set("DEVELOPER_DIR", xcode_link)
diff --git a/lib/spack/spack/package_base.py b/lib/spack/spack/package_base.py
index bbeeef1923..617950c743 100644
--- a/lib/spack/spack/package_base.py
+++ b/lib/spack/spack/package_base.py
@@ -528,10 +528,6 @@ class PackageBase(WindowsRPath, PackageViewMixin, metaclass=PackageMeta):
#: 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
-
#: Keep -Werror flags, matches config:flags:keep_werror to override config
# NOTE: should be type Optional[Literal['all', 'specific', 'none']] in 3.8+
keep_werror: Optional[str] = None
diff --git a/lib/spack/spack/test/compilers/basics.py b/lib/spack/spack/test/compilers/basics.py
index 76c4c82084..60079ee92e 100644
--- a/lib/spack/spack/test/compilers/basics.py
+++ b/lib/spack/spack/test/compilers/basics.py
@@ -4,7 +4,6 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
"""Test basic behavior of compilers in Spack"""
import os
-import shutil
import sys
from copy import copy
@@ -832,119 +831,6 @@ echo "4.4.4"
assert flag == "-std=c++0x"
-@pytest.mark.skipif(sys.platform == "win32", reason="Apple Clang and XCode unsupported on Windows")
-def test_apple_clang_setup_environment(mock_executable, monkeypatch):
- """Test a code path that is taken only if the package uses
- Xcode on MacOS.
- """
-
- class MockPackage:
- use_xcode = False
-
- apple_clang_cls = spack.compilers.class_for_compiler_name("apple-clang")
- compiler = apple_clang_cls(
- spack.spec.CompilerSpec("apple-clang@=11.0.0"),
- "catalina",
- "x86_64",
- ["/usr/bin/clang", "/usr/bin/clang++", None, None],
- )
- env = spack.util.environment.EnvironmentModifications()
- # Check a package that doesn't use xcode and ensure we don't add changes
- # to the environment
- pkg = MockPackage()
- compiler.setup_custom_environment(pkg, env)
- assert not env
-
- # Prepare mock executables to fake the Xcode environment
- xcrun = mock_executable(
- "xcrun",
- """
-if [[ "$2" == "clang" ]] ; then
- echo "/Library/Developer/CommandLineTools/usr/bin/clang"
-fi
-if [[ "$2" == "clang++" ]] ; then
- echo "/Library/Developer/CommandLineTools/usr/bin/clang++"
-fi
-""",
- )
- mock_executable(
- "xcode-select",
- """
-echo "/Library/Developer"
-""",
- )
- bin_dir = os.path.dirname(xcrun)
- monkeypatch.setenv("PATH", bin_dir, prepend=os.pathsep)
-
- def noop(*args, **kwargs):
- pass
-
- real_listdir = os.listdir
-
- def _listdir(path):
- if not os.path.exists(path):
- return []
- return real_listdir(path)
-
- # Set a few operations to noop
- monkeypatch.setattr(shutil, "copytree", noop)
- monkeypatch.setattr(os, "unlink", noop)
- monkeypatch.setattr(os, "symlink", noop)
- monkeypatch.setattr(os, "listdir", _listdir)
-
- # Qt is so far the only package that uses this code path, change
- # introduced in https://github.com/spack/spack/pull/1832
- pkg.use_xcode = True
- compiler.setup_custom_environment(pkg, env)
- assert len(env) == 3
- assert env.env_modifications[0].name == "SPACK_CC"
- assert env.env_modifications[1].name == "SPACK_CXX"
- assert env.env_modifications[2].name == "DEVELOPER_DIR"
-
-
-@pytest.mark.skipif(sys.platform == "win32", reason="Not supported on Windows (yet)")
-@pytest.mark.parametrize("xcode_select_output", ["", "/Library/Developer/CommandLineTools"])
-def test_xcode_not_available(xcode_select_output, mock_executable, monkeypatch):
- # Prepare mock executables to fake the Xcode environment
- xcrun = mock_executable(
- "xcrun",
- """
- if [[ "$2" == "clang" ]] ; then
- echo "/Library/Developer/CommandLineTools/usr/bin/clang"
- fi
- if [[ "$2" == "clang++" ]] ; then
- echo "/Library/Developer/CommandLineTools/usr/bin/clang++"
- fi
- """,
- )
- mock_executable(
- "xcode-select",
- """
- echo "{0}"
- """.format(
- xcode_select_output
- ),
- )
- bin_dir = os.path.dirname(xcrun)
- monkeypatch.setenv("PATH", bin_dir, prepend=os.pathsep)
- # Prepare compiler
- apple_clang_cls = spack.compilers.class_for_compiler_name("apple-clang")
- compiler = apple_clang_cls(
- spack.spec.CompilerSpec("apple-clang@11.0.0"),
- "catalina",
- "x86_64",
- ["/usr/bin/clang", "/usr/bin/clang++", None, None],
- )
- env = spack.util.environment.EnvironmentModifications()
-
- class MockPackage:
- use_xcode = True
-
- pkg = MockPackage()
- with pytest.raises(OSError):
- compiler.setup_custom_environment(pkg, env)
-
-
@pytest.mark.enable_compiler_verification
def test_compiler_executable_verification_raises(tmpdir):
compiler = MockCompiler()