Repository: spack/spack

Issue:
Spack detects Apple Clang as CCE on macOS
### Steps to reproduce

On a fresh Spack clone on Apple M2 (2022 model), running Monterey,
```shell
$ spack external find --all
```
detects `/usr/bin/cc` as the Cray compiler wrapper `cc`, even though it is really `apple-clang` in disguise. Same goes with `spack compiler find`.

Terminal output of `spack -d external find --all`: [spack-external-find-all.log](https://github.com/spack/spack/files/10006608/spack-external-find-all.log)

Terminal output of `spack -d compiler find`: [spack-compiler-find.log](https://github.com/spack/spack/files/10006660/spack-compiler-find.log)

Of course, it can easily be fixed by `spack compiler rm cce`, so it's not that big of a deal.

(Side note: somehow Spack _correctly_ ignores the fake `/usr/bin/gcc`)

### Error message

```shell
$ /usr/bin/cc --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
```

```shell
$ cat ~/.spack/darwin/compilers.yaml 
compilers:
- compiler:
    spec: apple-clang@14.0.0
    paths:
      cc: /usr/bin/clang
      cxx: /usr/bin/clang++
      f77: null
      fc: null
    flags: {}
    operating_system: monterey
    target: aarch64
    modules: []
    environment: {}
    extra_rpaths: []
- compiler:
    spec: cce@14.0.0
    paths:
      cc: /usr/bin/cc
      cxx: null
      f77: null
      fc: null
    flags: {}
    operating_system: monterey
    target: aarch64
    modules: []
    environment: {}
    extra_rpaths: []
```

### Information on your system

Output of `spack debug report`:
* **Spack:** 0.20.0.dev0 (2913f8b42b27868c0ec021e6fb319ec5b26ab605)
* **Python:** 3.9.6
* **Platform:** darwin-monterey-m2
* **Concretizer:** clingo

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have searched the issues of this repo and believe this is not a duplicate
- [X] I have run the failing commands in debug mode and reported the output


Discussion:
Same problem with macOS 10.15.7 (x86_64), `spack compiler find` detects `/usr/bin/cc` as cce in addition to apple-clang. @becker33 is this related to your recent Cray refactor?
@becker33 you usually fix Cray issues and likely have access to a CCE compiler. Can you make the CCE regex more specific?
@becker33 Looks like Cray has always put their wrappers in `/opt/cray/pe/craype/<version>/bin`, regardless of "old" or "new" Cray as detected by `spack arch`.

Theta - "old" Cray:
```
wyphan@thetalogin4:~$ sw/spack/bin/spack arch
cray-cnl7-haswell
wyphan@thetalogin4:~$ which cc
/opt/cray/pe/craype/2.6.5/bin/cc
```

Polaris - "new" Cray:
```
wyphan@polaris-login-01:~$ sw/spack/bin/spack arch
linux-sles15-zen3
wyphan@polaris-login-01:~$ which cc
/opt/cray/pe/craype/2.7.15/bin/cc
```

Resolving patch:
diff --git a/lib/spack/spack/compilers/cce.py b/lib/spack/spack/compilers/cce.py
--- a/lib/spack/spack/compilers/cce.py
+++ b/lib/spack/spack/compilers/cce.py
@@ -61,7 +61,7 @@ def is_clang_based(self):
         return version >= ver("9.0") and "classic" not in str(version)
 
     version_argument = "--version"
-    version_regex = r"[Vv]ersion.*?(\d+(\.\d+)+)"
+    version_regex = r"[Cc]ray (?:clang|C :|C\+\+ :|Fortran :) [Vv]ersion.*?(\d+(\.\d+)+)"
 
     @property
     def verbose_flag(self):


Test patch:
diff --git a/lib/spack/spack/test/compilers/detection.py b/lib/spack/spack/test/compilers/detection.py
--- a/lib/spack/spack/test/compilers/detection.py
+++ b/lib/spack/spack/test/compilers/detection.py
@@ -58,6 +58,7 @@ def test_arm_version_detection(version_str, expected_version):
     [
         ("Cray C : Version 8.4.6  Mon Apr 15, 2019  12:13:39\n", "8.4.6"),
         ("Cray C++ : Version 8.4.6  Mon Apr 15, 2019  12:13:45\n", "8.4.6"),
+        ("Cray clang Version 8.4.6  Mon Apr 15, 2019  12:13:45\n", "8.4.6"),
         ("Cray Fortran : Version 8.4.6  Mon Apr 15, 2019  12:13:55\n", "8.4.6"),
     ],
 )
@@ -487,3 +488,27 @@ def _module(cmd, *args):
 def test_aocc_version_detection(version_str, expected_version):
     version = spack.compilers.aocc.Aocc.extract_version_from_output(version_str)
     assert version == expected_version
+
+
+@pytest.mark.regression("33901")
+@pytest.mark.parametrize(
+    "version_str",
+    [
+        (
+            "Apple clang version 11.0.0 (clang-1100.0.33.8)\n"
+            "Target: x86_64-apple-darwin18.7.0\n"
+            "Thread model: posix\n"
+            "InstalledDir: "
+            "/Applications/Xcode.app/Contents/Developer/Toolchains/"
+            "XcodeDefault.xctoolchain/usr/bin\n"
+        ),
+        (
+            "Apple LLVM version 7.0.2 (clang-700.1.81)\n"
+            "Target: x86_64-apple-darwin15.2.0\n"
+            "Thread model: posix\n"
+        ),
+    ],
+)
+def test_apple_clang_not_detected_as_cce(version_str):
+    version = spack.compilers.cce.Cce.extract_version_from_output(version_str)
+    assert version == "unknown"