Repository: spack/spack

Issue:
Installation issue: python %aocc@3.2.0
### Steps to reproduce the issue

Trying to install `python %aocc@3.2.0`, it builds but fails to install.
Tested with both python 3.10.2 and 3.9.10.

```console
$ spack env create -d .
==> Updating view at /home/bc/env/python-aocc/.spack-env/view
==> Created environment in /home/bc/env/python-aocc
==> You can activate this environment with:
==>   spack env activate /home/bc/env/python-aocc
$ spack env activate .
$ spack add python@3.10.2 %aocc@3.2.0
==> Adding python@3.10.2%aocc@3.2.0 to environment /home/bc/env/python-aocc
$ spack concretize
==> Starting concretization
==> Environment concretized in 1.71 seconds.
==> Concretized python@3.10.2%aocc@3.2.0
 -   o74ynhl  python@3.10.2%aocc@3.2.0+bz2+ctypes+dbm~debug+ensurepip+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3~ssl~tix~tkinter~ucs4+uuid+zlib patches=0d98e93,7d40923,f2fd060 arch=linux-rocky8-zen2
[+]  wgogzcx      ^bzip2@1.0.8%aocc@3.2.0~debug~pic+shared arch=linux-rocky8-zen2
[+]  o23a3xl          ^diffutils@3.8%aocc@3.2.0 arch=linux-rocky8-zen2
[+]  uemw5kg              ^libiconv@1.16%aocc@3.2.0 libs=shared,static arch=linux-rocky8-zen2
[+]  sooxcfg      ^expat@2.4.6%aocc@3.2.0+libbsd arch=linux-rocky8-zen2
[+]  4vztj3p          ^libbsd@0.11.5%aocc@3.2.0 arch=linux-rocky8-zen2
[+]  zvzvp2x              ^libmd@1.0.4%aocc@3.2.0 arch=linux-rocky8-zen2
[+]  jlrov7c      ^gdbm@1.23%aocc@3.2.0 arch=linux-rocky8-zen2
[+]  cbqy754          ^readline@8.1%aocc@3.2.0 arch=linux-rocky8-zen2
[+]  bvfbvmm              ^ncurses@6.2%aocc@3.2.0~symlinks+termlib abi=none arch=linux-rocky8-zen2
[+]  j5hsqox                  ^pkgconf@1.8.0%aocc@3.2.0 arch=linux-rocky8-zen2
[+]  2f3jngz      ^gettext@0.21%aocc@3.2.0+bzip2+curses+git~libunistring+libxml2+tar+xz arch=linux-rocky8-zen2
[+]  qplit6u          ^libxml2@2.9.12%aocc@3.2.0~python arch=linux-rocky8-zen2
[+]  dzbxiwp              ^xz@5.2.5%aocc@3.2.0~pic libs=shared,static arch=linux-rocky8-zen2
[+]  32whbbl              ^zlib@1.2.11%aocc@3.2.0+optimize+pic+shared arch=linux-rocky8-zen2
[+]  omm37pb          ^tar@1.34%aocc@3.2.0 arch=linux-rocky8-zen2
[+]  wso5ocb      ^libffi@3.4.2%aocc@3.2.0 arch=linux-rocky8-zen2
[+]  3yiwpk6      ^sqlite@3.37.2%aocc@3.2.0+column_metadata+dynamic_extensions+fts~functions+rtree arch=linux-rocky8-zen2
[+]  oz2etzo      ^util-linux-uuid@2.37.4%aocc@3.2.0 arch=linux-rocky8-zen2

==> Updating view at /home/bc/env/python-aocc/.spack-env/view
$ spack install
```


### Error message

<details><summary>Error message</summary><pre>
==> python: Executing phase: 'install'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j16' 'install'

7 errors found in build log:
     4170        if not compile_dir(dest, maxlevels, args.ddir,
     4171      File "/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/compileall.py", line 88, in compile_dir
     4172        from concurrent.futures.process import _check_system_limits
     4173      File "/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/concurrent/futures/process.py", line 52, in <module>
     4174        import multiprocessing.connection
     4175    IndexError: string index out of range
  >> 4176    make: [Makefile:1550: libinstall] Error 1 (ignored)
     4177    PYTHONPATH=/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10 LD_LIBRARY_PATH=/tmp/bc/spack-stage/spack-stage-python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/sp
             ack-src/spack-build \
     4178    	./python -E -Wi -O /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/compileall.py \
     4179    	-j0 -d /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10 -f \
     4180    	-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
     4181    	/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10
     4182    Traceback (most recent call last):

     ...

     4186        if not compile_dir(dest, maxlevels, args.ddir,
     4187      File "/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/compileall.py", line 88, in compile_dir
     4188        from concurrent.futures.process import _check_system_limits
     4189      File "/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/concurrent/futures/process.py", line 52, in <module>
     4190        import multiprocessing.connection
     4191    IndexError: string index out of range
  >> 4192    make: [Makefile:1551: libinstall] Error 1 (ignored)
     4193    PYTHONPATH=/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10 LD_LIBRARY_PATH=/tmp/bc/spack-stage/spack-stage-python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/sp
             ack-src/spack-build \
     4194    	./python -E -Wi -OO /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/compileall.py \
     4195    	-j0 -d /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10 -f \
     4196    	-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
     4197    	/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10
     4198    Traceback (most recent call last):

     ...

     4202        if not compile_dir(dest, maxlevels, args.ddir,
     4203      File "/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/compileall.py", line 88, in compile_dir
     4204        from concurrent.futures.process import _check_system_limits
     4205      File "/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/concurrent/futures/process.py", line 52, in <module>
     4206        import multiprocessing.connection
     4207    IndexError: string index out of range
  >> 4208    make: [Makefile:1552: libinstall] Error 1 (ignored)
     4209    PYTHONPATH=/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10 LD_LIBRARY_PATH=/tmp/bc/spack-stage/spack-stage-python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/sp
             ack-src/spack-build \
     4210    	./python -E -Wi /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/compileall.py \
     4211    	-j0 -d /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/site-packages -f \
     4212    	-x badsyntax /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/site-packages
     4213    Traceback (most recent call last):
     4214      File "/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/compileall.py", line 462, in <module>

     ...

     4217        if not compile_dir(dest, maxlevels, args.ddir,
     4218      File "/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/compileall.py", line 88, in compile_dir
     4219        from concurrent.futures.process import _check_system_limits
     4220      File "/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/concurrent/futures/process.py", line 52, in <module>
     4221        import multiprocessing.connection
     4222    IndexError: string index out of range
  >> 4223    make: [Makefile:1553: libinstall] Error 1 (ignored)
     4224    PYTHONPATH=/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10 LD_LIBRARY_PATH=/tmp/bc/spack-stage/spack-stage-python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/sp
             ack-src/spack-build \
     4225    	./python -E -Wi -O /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/compileall.py \
     4226    	-j0 -d /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/site-packages -f \
     4227    	-x badsyntax /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/site-packages
     4228    Traceback (most recent call last):
     4229      File "/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/compileall.py", line 462, in <module>

     ...

     4232        if not compile_dir(dest, maxlevels, args.ddir,
     4233      File "/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/compileall.py", line 88, in compile_dir
     4234        from concurrent.futures.process import _check_system_limits
     4235      File "/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/concurrent/futures/process.py", line 52, in <module>
     4236        import multiprocessing.connection
     4237    IndexError: string index out of range
  >> 4238    make: [Makefile:1554: libinstall] Error 1 (ignored)
     4239    PYTHONPATH=/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10 LD_LIBRARY_PATH=/tmp/bc/spack-stage/spack-stage-python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/sp
             ack-src/spack-build \
     4240    	./python -E -Wi -OO /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/compileall.py \
     4241    	-j0 -d /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/site-packages -f \
     4242    	-x badsyntax /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/site-packages
     4243    Traceback (most recent call last):
     4244      File "/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/compileall.py", line 462, in <module>

     ...

     4247        if not compile_dir(dest, maxlevels, args.ddir,
     4248      File "/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/compileall.py", line 88, in compile_dir
     4249        from concurrent.futures.process import _check_system_limits
     4250      File "/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/concurrent/futures/process.py", line 52, in <module>
     4251        import multiprocessing.connection
     4252    IndexError: string index out of range
  >> 4253    make: [Makefile:1555: libinstall] Error 1 (ignored)
     4254    PYTHONPATH=/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10 LD_LIBRARY_PATH=/tmp/bc/spack-stage/spack-stage-python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/sp
             ack-src/spack-build \
     4255    	./python -E -m lib2to3.pgen2.driver /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/lib2to3/Grammar.txt
     4256    Generating grammar tables from /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/lib2to3/Grammar.txt
     4257    Writing grammar tables to /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/lib2to3/Grammar3.10.2.final.0.pickle
     4258    PYTHONPATH=/home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10 LD_LIBRARY_PATH=/tmp/bc/spack-stage/spack-stage-python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/sp
             ack-src/spack-build \
     4259    	./python -E -m lib2to3.pgen2.driver /home/bc/spack/opt/spack/linux-rocky8-zen2/aocc-3.2.0/python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/lib/python3.10/lib2to3/PatternGrammar.txt

     ...

     4308        return _run_pip([*args, *_PACKAGE_NAMES], additional_paths)
     4309      File "/tmp/bc/spack-stage/spack-stage-python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/spack-src/Lib/ensurepip/__init__.py", line 93, in _run_pip
     4310        return subprocess.run([sys.executable, '-W', 'ignore::DeprecationWarning',
     4311      File "/tmp/bc/spack-stage/spack-stage-python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/spack-src/Lib/subprocess.py", line 524, in run
     4312        raise CalledProcessError(retcode, process.args,
     4313    subprocess.CalledProcessError: Command '['/tmp/bc/spack-stage/spack-stage-python-3.10.2-o74ynhlkzwbmdmwmwozk6aceygiweyjb/spack-src/spack-build/python', '-W', 'ignore::DeprecationWarning', '-c', '\nimport runpy\nimport sys\ns
             ys.path = [\'/tmp/tmp_z9c7nyo/setuptools-58.1.0-py3-none-any.whl\', \'/tmp/tmp_z9c7nyo/pip-21.2.4-py3-none-any.whl\'] + sys.path\nsys.argv[1:] = [\'install\', \'--no-cache-dir\', \'--no-index\', \'--find-links\', \'/tmp/tmp_
             z9c7nyo\', \'--root\', \'/\', \'setuptools\', \'pip\']\nrunpy.run_module("pip", run_name="__main__", alter_sys=True)\n']' returned non-zero exit status 1.
  >> 4314    make: *** [Makefile:1280: install] Error 1
</pre></details>


### Information on your system

```
* **Spack:** 0.17.1-1305-51488dbff5
* **Python:** 3.6.8
* **Platform:** linux-rocky8-zen2
* **Concretizer:** clingo
```

### Additional information

[spack-build-out.txt](https://github.com/spack/spack/files/8112853/spack-build-out.txt)
[spack-build-env.txt](https://github.com/spack/spack/files/8112852/spack-build-env.txt)

@adamjstewart  @scheibelp  @skosukhin  @varioustoxins @amd-toolchain-support



### 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/python/package.py b/var/spack/repos/builtin/packages/python/package.py
--- a/var/spack/repos/builtin/packages/python/package.py
+++ b/var/spack/repos/builtin/packages/python/package.py
@@ -270,9 +270,7 @@ class Python(Package):
     )
     conflicts('+tix', when='~tkinter',
               msg='python+tix requires python+tix+tkinter')
-
     conflicts('%nvhpc')
-
     conflicts('@:2.7', when='platform=darwin target=aarch64:',
               msg='Python 2.7 is too old for Apple Silicon')
 
@@ -455,6 +453,13 @@ def flag_handler(self, name, flags):
             if name == 'cflags':
                 flags.append('-fwrapv')
 
+        # Fix for following issues for python with aocc%3.2.0:
+        # https://github.com/spack/spack/issues/29115
+        # https://github.com/spack/spack/pull/28708
+        if self.spec.satisfies('%aocc@3.2.0', strict=True):
+            if name == 'cflags':
+                flags.extend(['-mllvm', '-disable-indvar-simplify=true'])
+
         # allow flags to be passed through compiler wrapper
         return (flags, None, None)
 


Test patch: