Repository: spack/spack

Issue:
Installation issue: hipsycl
### Steps to reproduce the issue

```console
ulrich@heisenbug:~$ spack spec -I hipsycl@develop%gcc@12.2.0+cuda~ipo build_system=cmake build_type=Release generator=make arch=linux-debian11-zen2
Input spec
--------------------------------
 -   hipsycl@develop%gcc@12.2.0+cuda~ipo build_system=cmake build_type=Release generator=make arch=linux-debian11-zen2

Concretized
--------------------------------
 -   hipsycl@develop%gcc@12.2.0+cuda~ipo build_system=cmake build_type=Release generator=make arch=linux-debian11-zen2
[+]      ^boost@1.69.0%gcc@12.2.0~atomic~chrono~clanglibcpp~container+context~contract~coroutine~date_time~debug~exception+fiber+filesystem~graph~graph_parallel~icu~iostreams~json~locale~log~math~mpi+multithreaded~nowide~numpy~pic~program_options~python~random~regex~serialization+shared~signals~singlethreaded~stacktrace~system~taggedlayout~test~thread~timer~type_erasure~versionedlayout~wave build_system=generic context-impl=fcontext cxxstd=17 patches=3a83d90,5da7ad2,607b077 visibility=hidden arch=linux-debian11-zen2
[+]      ^cmake@3.26.3%gcc@12.2.0~doc+ncurses+ownlibs~qt build_system=generic build_type=Release arch=linux-debian11-zen2
[+]          ^curl@8.1.2%gcc@12.2.0~gssapi~ldap~libidn2~librtmp~libssh~libssh2+nghttp2 build_system=autotools libs=shared,static tls=openssl arch=linux-debian11-zen2
[+]              ^nghttp2@1.52.0%gcc@12.2.0 build_system=autotools arch=linux-debian11-zen2
[+]              ^openssl@3.1.1%gcc@12.2.0~docs~shared build_system=generic certs=mozilla arch=linux-debian11-zen2
[+]                  ^ca-certificates-mozilla@2023-05-30%gcc@12.2.0 build_system=generic arch=linux-debian11-zen2
[+]          ^ncurses@6.4%gcc@12.2.0~symlinks+termlib abi=none build_system=autotools arch=linux-debian11-zen2
[+]          ^zlib@1.2.13%gcc@12.2.0+optimize+pic+shared build_system=makefile arch=linux-debian11-zen2
[+]      ^cuda@12.1.1%gcc@12.2.0~allow-unsupported-compilers~dev build_system=generic arch=linux-debian11-zen2
[+]          ^libxml2@2.10.3%gcc@12.2.0~python build_system=autotools arch=linux-debian11-zen2
[+]              ^libiconv@1.17%gcc@12.2.0 build_system=autotools libs=shared,static arch=linux-debian11-zen2
[+]              ^xz@5.4.1%gcc@12.2.0~pic build_system=autotools libs=shared,static arch=linux-debian11-zen2
[+]      ^gcc-runtime@12.2.0%gcc@12.2.0 build_system=generic arch=linux-debian11-zen2
[+]      ^gmake@4.4.1%gcc@12.2.0~guile build_system=generic arch=linux-debian11-zen2
[+]      ^llvm@16.0.6%gcc@12.2.0+clang~cuda~flang+gold~ipo+libomptarget~libomptarget_debug~link_llvm_dylib+lld+lldb+llvm_dylib~mlir+polly~python~split_dwarf~z3~zstd build_system=cmake build_type=Release compiler-rt=runtime generator=ninja libcxx=runtime libunwind=runtime openmp=runtime shlib_symbol_version=none targets=all version_suffix=none arch=linux-debian11-zen2
[+]          ^binutils@2.40%gcc@12.2.0+gas+gold~gprofng+headers~interwork+ld~libiberty~lto~nls~pgo+plugins build_system=autotools compress_debug_sections=zlib libs=shared,static arch=linux-debian11-zen2
[+]              ^diffutils@3.9%gcc@12.2.0 build_system=autotools arch=linux-debian11-zen2
[+]              ^texinfo@7.0.3%gcc@12.2.0 build_system=autotools arch=linux-debian11-zen2
[+]                  ^gettext@0.21.1%gcc@12.2.0+bzip2+curses+git~libunistring+libxml2+tar+xz build_system=autotools arch=linux-debian11-zen2
[+]                      ^tar@1.34%gcc@12.2.0 build_system=autotools zip=pigz arch=linux-debian11-zen2
[+]                          ^pigz@2.7%gcc@12.2.0 build_system=makefile arch=linux-debian11-zen2
[+]              ^zstd@1.5.5%gcc@12.2.0+programs build_system=makefile compression=none libs=shared,static arch=linux-debian11-zen2
[+]          ^hwloc@2.9.1%gcc@12.2.0~cairo~cuda~gl~libudev+libxml2~netloc~nvml~oneapi-level-zero~opencl+pci~rocm build_system=autotools libs=shared,static arch=linux-debian11-zen2
[+]              ^libpciaccess@0.17%gcc@12.2.0 build_system=autotools arch=linux-debian11-zen2
[+]                  ^libtool@2.4.7%gcc@12.2.0 build_system=autotools arch=linux-debian11-zen2
[+]                      ^m4@1.4.19%gcc@12.2.0+sigsegv build_system=autotools patches=9dc5fbd,bfdffa7 arch=linux-debian11-zen2
[+]                          ^libsigsegv@2.14%gcc@12.2.0 build_system=autotools arch=linux-debian11-zen2
[+]                  ^util-macros@1.19.3%gcc@12.2.0 build_system=autotools arch=linux-debian11-zen2
[+]          ^libedit@3.1-20210216%gcc@12.2.0 build_system=autotools arch=linux-debian11-zen2
[+]          ^libffi@3.4.4%gcc@12.2.0 build_system=autotools arch=linux-debian11-zen2
[+]          ^ninja@1.11.1%gcc@12.2.0+re2c build_system=generic arch=linux-debian11-zen2
[+]              ^re2c@2.2%gcc@12.2.0 build_system=generic arch=linux-debian11-zen2
[+]          ^perl-data-dumper@2.173%gcc@12.2.0 build_system=perl arch=linux-debian11-zen2
[+]              ^perl@5.38.0%gcc@12.2.0+cpanm+opcode+open+shared+threads build_system=generic arch=linux-debian11-zen2
[+]                  ^berkeley-db@18.1.40%gcc@12.2.0+cxx~docs+stl build_system=autotools patches=26090f4,b231fcc arch=linux-debian11-zen2
[+]                  ^bzip2@1.0.8%gcc@12.2.0~debug~pic+shared build_system=generic arch=linux-debian11-zen2
[+]                  ^gdbm@1.23%gcc@12.2.0 build_system=autotools arch=linux-debian11-zen2
[+]                      ^readline@8.2%gcc@12.2.0 build_system=autotools patches=bbf97f1 arch=linux-debian11-zen2
[+]          ^pkgconf@1.9.5%gcc@12.2.0 build_system=autotools arch=linux-debian11-zen2
[e]      ^python@3.9.2%gcc@12.2.0+bz2+crypt+ctypes+dbm~debug+libxml2+lzma+nis~optimizations+pic+pyexpat~pythoncmd+readline+shared+sqlite3+ssl+tix+tkinter+uuid+zlib build_system=generic patches=0d98e93,f2fd060 arch=linux-debian11-zen2
...
```


### Error message

<details><summary>
installed hipSYCL must provide a unique compiler driver
<pre>
ulrich@heisenbug:~$ spack install -j 60 hipsycl@develop%gcc@12.2.0+cuda~ipo build_system=cmake build_type=Release generator=make arch=linux-debian11-zen2
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/boost-1.69.0-lzqrg4i522c2ag4yzptuog6f23geglli
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/nghttp2-1.52.0-x5wdgxs6fidjw3hc5obqh52sc4ippwcv
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/zlib-1.2.13-qvwbld7rb3usgj6qdbfkaxsjhttscq6w
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/ncurses-6.4-bt2tv43umdlsiaimld2sffxkj3v3okie
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/libiconv-1.17-pztn24l2jxjspbx37yln6u3rn3gpqsih
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/xz-5.4.1-beahnaphmuo7vgwskvdgs3ofnuadanma
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/gcc-runtime-12.2.0-v4wn2t2yiiepamrlyukgaqowtwqbxsek
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/gmake-4.4.1-powg62yawovgnx2caluuvxgtltcams5p
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/zstd-1.5.5-d3iesv2cwmusol4wo3lupvuibjkzcziv
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/libpciaccess-0.17-foegz6xqemti4wzxqyei73l22a7wntvi
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/libffi-3.4.4-2blm5vkebxz6h5kf6nft2ydfttqxcort
[+] /usr (external python-3.9.2-ikw34aobmlm4tu2bmiaehqzldpesoopf)
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/openssl-3.1.1-xydqrfkl7baqzgck7egzrklc4sjz4prz
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/libedit-3.1-20210216-uybrqunp64jnfpfsl4wjcme4oee2p6fk
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/libxml2-2.10.3-6g4ulfn7r5q4pk4fsvk6m5fsntixoedr
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/binutils-2.40-4w6dx7hd3onnb3i4jlfif3qmdgjno64j
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/curl-8.1.2-2s4wrx6to3rvzu2dmpu3zay6jbso4by2
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/hwloc-2.9.1-wjb3zv3maxqu5eock7pvhhm77bwckc5f
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/cuda-12.1.1-v6o3ud5ssbsavqhnwsyqqjkbafl3ld6s
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/cmake-3.26.3-mgfxqwqf5t2h7lpwzuj3uyaotx7rq4md
[+] /import/exception-dump/ulrich/myLibs/spack-packages/linux-debian11-zen2/gcc-12.2.0/llvm-16.0.6-xxtgeagfmiwsasg3otwzvfc5djvpclzt
==> Installing hipsycl-develop-kxqpftef26hqap4jg4xcgffomrffvrt2 [22/22]
==> No binary for hipsycl-develop-kxqpftef26hqap4jg4xcgffomrffvrt2 found: installing from source
==> No patches needed for hipsycl
==> hipsycl: Executing phase: 'cmake'
==> hipsycl: Executing phase: 'build'
==> hipsycl: Executing phase: 'install'
==> Error: InstallError: installed hipSYCL must provide a unique compiler driver configuration file, found: []

/import/exception-dump/ulrich/spack/var/spack/repos/builtin/packages/hipsycl/package.py:125, in filter_config_file:
        122    def filter_config_file(self):
        123        config_file_paths = filesystem.find(self.prefix, "syclcc.json")
        124        if len(config_file_paths) != 1:
  >>    125            raise InstallError(
        126                "installed hipSYCL must provide a unique compiler driver "
        127                "configuration file, found: {0}".format(config_file_paths)
        128            )

See build log for details:

</pre></details>


### Information on your system

* **Spack:** 0.22.0.dev0 (922a1983f3878c99c63c4f31d1cce7e84f83d1ab)
* **Python:** 3.9.2
* **Platform:** linux-debian11-zen2
* **Concretizer:** clingo


### Additional information

[spack-build-out.txt](https://github.com/spack/spack/files/14123533/spack-build-out.txt)
[spack-build-env.txt](https://github.com/spack/spack/files/14123534/spack-build-env.txt)

@nazavode

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have run `spack maintainers <name-of-the-package>` and **@mentioned** any maintainers
- [X] I have uploaded the build log and environment files
- [X] I have searched the issues of this repo and believe this is not a duplicate


Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/hipsycl/package.py b/var/spack/repos/builtin/packages/hipsycl/package.py
--- a/var/spack/repos/builtin/packages/hipsycl/package.py
+++ b/var/spack/repos/builtin/packages/hipsycl/package.py
@@ -26,6 +26,8 @@ class Hipsycl(CMakePackage):
     license("BSD-2-Clause")
 
     version("stable", branch="stable", submodules=True)
+    version("23.10.0", commit="3952b468c9da89edad9dff953cdcab0a3c3bf78c", submodules=True)
+    version("0.9.4", commit="99d9e24d462b35e815e0e59c1b611936c70464ae", submodules=True)
     version("0.9.4", commit="99d9e24d462b35e815e0e59c1b611936c70464ae", submodules=True)
     version("0.9.3", commit="51507bad524c33afe8b124804091b10fa25618dc", submodules=True)
     version("0.9.2", commit="49fd02499841ae884c61c738610e58c27ab51fdb", submodules=True)
@@ -120,42 +122,65 @@ def cmake_args(self):
 
     @run_after("install")
     def filter_config_file(self):
-        config_file_paths = filesystem.find(self.prefix, "syclcc.json")
-        if len(config_file_paths) != 1:
-            raise InstallError(
-                "installed hipSYCL must provide a unique compiler driver "
-                "configuration file, found: {0}".format(config_file_paths)
-            )
-        config_file_path = config_file_paths[0]
-        with open(config_file_path) as f:
-            config = json.load(f)
-        # 1. Fix compiler: use the real one in place of the Spack wrapper
-        config["default-cpu-cxx"] = self.compiler.cxx
-        # 2. Fix stdlib: we need to make sure cuda-enabled binaries find
-        #    the libc++.so and libc++abi.so dyn linked to the sycl
-        #    ptx backend
-        rpaths = set()
-        so_paths = filesystem.find_libraries(
-            "libc++", self.spec["llvm"].prefix, shared=True, recursive=True
-        )
-        if len(so_paths) != 1:
-            raise InstallError(
-                "concretized llvm dependency must provide a "
-                "unique directory containing libc++.so, "
-                "found: {0}".format(so_paths)
+        def edit_config(filename, editor):
+            config_file_paths = filesystem.find(self.prefix, filename)
+            if len(config_file_paths) != 1:
+                raise InstallError(
+                    "installed hipSYCL must provide a unique compiler driver"
+                    "configuration file ({0}), found: {1}".format(filename, config_file_paths)
+                )
+            config_file_path = config_file_paths[0]
+            with open(config_file_path) as f:
+                config = json.load(f)
+
+            config_modified = editor(config)
+
+            with open(config_file_path, "w") as f:
+                json.dump(config_modified, f, indent=2)
+
+        if self.spec.satisfies("@:23.10.0"):
+            configfiles = {"core": "syclcc.json", "cuda": "syclcc.json"}
+        else:
+            configfiles = {"core": "acpp-core.json", "cuda": "acpp-cuda.json"}
+
+        def adjust_core_config(config):
+            config["default-cpu-cxx"] = self.compiler.cxx
+            return config
+
+        edit_config(configfiles["core"], adjust_core_config)
+
+        if self.spec.satisfies("+cuda"):
+            # 1. Fix compiler: use the real one in place of the Spack wrapper
+
+            # 2. Fix stdlib: we need to make sure cuda-enabled binaries find
+            #    the libc++.so and libc++abi.so dyn linked to the sycl
+            #    ptx backend
+            rpaths = set()
+            so_paths = filesystem.find_libraries(
+                "libc++", self.spec["llvm"].prefix, shared=True, recursive=True
             )
-        rpaths.add(path.dirname(so_paths[0]))
-        so_paths = filesystem.find_libraries(
-            "libc++abi", self.spec["llvm"].prefix, shared=True, recursive=True
-        )
-        if len(so_paths) != 1:
-            raise InstallError(
-                "concretized llvm dependency must provide a "
-                "unique directory containing libc++abi, "
-                "found: {0}".format(so_paths)
+            if len(so_paths) != 1:
+                raise InstallError(
+                    "concretized llvm dependency must provide a "
+                    "unique directory containing libc++.so, "
+                    "found: {0}".format(so_paths)
+                )
+            rpaths.add(path.dirname(so_paths[0]))
+            so_paths = filesystem.find_libraries(
+                "libc++abi", self.spec["llvm"].prefix, shared=True, recursive=True
             )
-        rpaths.add(path.dirname(so_paths[0]))
-        config["default-cuda-link-line"] += " " + " ".join("-rpath {0}".format(p) for p in rpaths)
-        # Replace the installed config file
-        with open(config_file_path, "w") as f:
-            json.dump(config, f, indent=2)
+            if len(so_paths) != 1:
+                raise InstallError(
+                    "concretized llvm dependency must provide a "
+                    "unique directory containing libc++abi, "
+                    "found: {0}".format(so_paths)
+                )
+            rpaths.add(path.dirname(so_paths[0]))
+
+            def adjust_cuda_config(config):
+                config["default-cuda-link-line"] += " " + " ".join(
+                    "-rpath {0}".format(p) for p in rpaths
+                )
+                return config
+
+            edit_config(configfiles["cuda"], adjust_cuda_config)


Test patch: