Repository: spack/spack

Issue:
Installation issue: swig %nvhpc
There is an unknown switch -ansi error from nvc using nVidia HPC toolkit for Swig.

```console
$ spack install swig %nvhpc

[+] /home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen2/nvhpc-21.2/pcre-8.44-5hfo5uywddrfxnnn7n3kljrvi6azcdun
[+] /home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen2/nvhpc-21.2/pkgconf-1.7.3-wg4ykqnc4ufnzcxpfvush5cmqo7lk5e3
==> Installing swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp
==> No binary for swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp found: installing from source
==> Using cached archive: /home/cessenat/Softs/spack/var/spack/cache/_source-cache/archive/d5/d53be9730d8d58a16bf0cbd1f8ac0c0c3e1090573168bfa151b01eb47fa906fc.tar.gz
==> swig: Executing phase: 'autoreconf'
==> swig: Executing phase: 'configure'
==> swig: Executing phase: 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j8'

6 errors found in build log:
     293    /home/cessenat/Softs/spack/lib/spack/env/nvhpc/nvc -DHAVE_CONFIG_H   -I../Source/Include -I../Source/CParse -I/tmp/cessenat/spack-stag
            e/spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/Source/Include -I/tmp/cessenat/spack-stage/spack-stage-swig-4.0.2-
            twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/Source/DOH -I/tmp/cessenat/spack-stage/spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3q
            ltp/spack-src/Source/CParse -I/tmp/cessenat/spack-stage/spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/Source/Doxyg
            en -I/tmp/cessenat/spack-stage/spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/Source/Preprocessor -I/tmp/cessenat/s
            pack-stage/spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/Source/Swig -I/tmp/cessenat/spack-stage/spack-stage-swig-
            4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/Source/Modules -I/home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen2/nvhpc-21
            .2/pcre-8.44-5hfo5uywddrfxnnn7n3kljrvi6azcdun/include  -g -O2 -Wall -W -ansi -pedantic -c -o CParse/templ.o /tmp/cessenat/spack-stage/
            spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/Source/CParse/templ.c
     294    source='/tmp/cessenat/spack-stage/spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/Source/CParse/util.c' object='CPar
            se/util.o' libtool=no \
     295    DEPDIR=.deps depmode=pgcc /bin/bash /tmp/cessenat/spack-stage/spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/Tools/
            config/depcomp \
     296    /home/cessenat/Softs/spack/lib/spack/env/nvhpc/nvc -DHAVE_CONFIG_H   -I../Source/Include -I../Source/CParse -I/tmp/cessenat/spack-stag
            e/spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/Source/Include -I/tmp/cessenat/spack-stage/spack-stage-swig-4.0.2-
            twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/Source/DOH -I/tmp/cessenat/spack-stage/spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3q
            ltp/spack-src/Source/CParse -I/tmp/cessenat/spack-stage/spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/Source/Doxyg
            en -I/tmp/cessenat/spack-stage/spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/Source/Preprocessor -I/tmp/cessenat/s
            pack-stage/spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/Source/Swig -I/tmp/cessenat/spack-stage/spack-stage-swig-
            4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/Source/Modules -I/home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen2/nvhpc-21
            .2/pcre-8.44-5hfo5uywddrfxnnn7n3kljrvi6azcdun/include  -g -O2 -Wall -W -ansi -pedantic -c -o CParse/util.o /tmp/cessenat/spack-stage/s
            pack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/Source/CParse/util.c
     297    nvc-Error-Unknown switch: -ansi
     298    Makefile:936: recipe for target 'CParse/cscanner.o' failed
  >> 299    make[2]: *** [CParse/cscanner.o] Error 1
     300    make[2]: *** Waiting for unfinished jobs....
     301    nvc-Error-Unknown switch: -ansi
     302    Makefile:936: recipe for target 'CParse/templ.o' failed
  >> 303    make[2]: *** [CParse/templ.o] Error 1
     304    nvc-Error-Unknown switch: -ansi
     305    Makefile:936: recipe for target 'CParse/parser.o' failed
  >> 306    make[2]: *** [CParse/parser.o] Error 1
     307    nvc-Error-Unknown switch: -ansi
     308    Makefile:936: recipe for target 'CParse/util.o' failed
  >> 309    make[2]: *** [CParse/util.o] Error 1
     310    make[2]: Leaving directory '/tmp/cessenat/spack-stage/spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/spack-build/So
            urce'
     311    Makefile:602: recipe for target 'all' failed
  >> 312    make[1]: *** [all] Error 2
     313    make[1]: Leaving directory '/tmp/cessenat/spack-stage/spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/spack-build/So
            urce'
     314    Makefile:37: recipe for target 'source' failed
  >> 315    make: *** [source] Error 2
     316    make: *** Waiting for unfinished jobs....
     317    /home/cessenat/Softs/spack/lib/spack/env/nvhpc/nvc -g -O2 -Wall -W -I.  -o ccache-swig ccache.o mdfour.o hash.o execute.o util.o args.
            o stats.o cleanup.o snprintf.o unify.o -lz
     318    make[1]: Leaving directory '/tmp/cessenat/spack-stage/spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-src/spack-build/CC
            ache'

See build log for details:
  /tmp/cessenat/spack-stage/spack-stage-swig-4.0.2-twowaaahzkwjrxdzci3ap4umaud3qltp/spack-build-out.txt
```

<!-- Please include the output of `spack debug report` -->
spack debug report
* **Spack:** 0.16.0-1079-af988fc32d
* **Python:** 3.6.9
* **Platform:** linux-ubuntu18.04-zen2
* **Concretizer:** original

<!-- If you have any relevant configuration detail (custom `packages.yaml` or `modules.yaml`, etc.) you can add that here as well. -->
packages.yaml:
  nvhpc:
    externals:
    - spec: nvhpc@21.2+mpi+blas+lapack
      prefix: /opt/nvidia/hpc_sdk
      modules:
        - nvhpc/21.2
    - spec: nvhpc@21.2~mpi+blas+lapack
      prefix: /opt/nvidia/hpc_sdk


linux/compilers.yaml:
- compiler:
    spec: nvhpc@21.2
    paths:
      cc: /opt/nvidia/hpc_sdk/Linux_x86_64/21.2/compilers/bin/nvc
      cxx: /opt/nvidia/hpc_sdk/Linux_x86_64/21.2/compilers/bin/nvc++
      f77: /opt/nvidia/hpc_sdk/Linux_x86_64/21.2/compilers/bin/nvfortran
      fc: /opt/nvidia/hpc_sdk/Linux_x86_64/21.2/compilers/bin/nvfortran
    flags: {}
    operating_system: ubuntu18.04
    target: x86_64
    modules: [nvhpc/21.2]
    extra_rpaths: []


<!-- Please upload the following files. They should be present in the stage directory of the failing build. Also upload any config.log or similar file if one exists. -->
* [spack-build-out.txt](
[spack-build-out.txt](https://github.com/spack/spack/files/6170596/spack-build-out.txt)
)
* [spack-build-env.txt](
[spack-build-env.txt](https://github.com/spack/spack/files/6170597/spack-build-env.txt)
)

<!-- Some packages have maintainers who have volunteered to debug build failures. Run `spack maintainers <name-of-the-package>` and @mention them here if they exist. -->

### General information

<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [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:
Maybe @sethrj would know what to do about it.
Same pb with nvhpc@21.3 and
$ spack debug report
* **Spack:** 0.16.0-2228-facb72f17e
* **Python:** 3.6.9
* **Platform:** linux-ubuntu18.04-zen2
* **Concretizer:** original

@cessenat SWIG uses a pretty outdated build system, including some wacky hardcoded flags meant for older GCC versions. However, since SWIG is just used for *generating* code, and the code it generates is pretty compiler-independent (and does *not* depend on the compiler used to build SWIG) I strongly recommend just building it with your GCC core compiler.

If you *really* want to build with ~~cray~~ nvhpc I think I saw a recent commit on SWIG that removes the useless `-ansi`  flag -- so you could try building `@master` (if you don't need Fortran support).
A "big hammer" solution is to create `$HOME/.mynvcrc` with the content:
```
set NOSWITCHERROR=1;
```

The more robust solution would be to figure out which Makefile is adding `-ansi` and modify the `swig` package to filter out that option when using `nvhpc`.  See the `libxml2` package for an example.
Thanks ! @sethrj worked fine !
I failed to properly use the hammer @samcmill, but never mind since the master build passed.
Cheers

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/swig/package.py b/var/spack/repos/builtin/packages/swig/package.py
--- a/var/spack/repos/builtin/packages/swig/package.py
+++ b/var/spack/repos/builtin/packages/swig/package.py
@@ -21,6 +21,7 @@ class Swig(AutotoolsPackage, SourceforgePackage):
 
     homepage = "http://www.swig.org"
     sourceforge_mirror_path = "swig/swig-3.0.12.tar.gz"
+    maintainers = ['sethrj']
 
     version('master', git='https://github.com/swig/swig.git')
     version('4.0.2', sha256='d53be9730d8d58a16bf0cbd1f8ac0c0c3e1090573168bfa151b01eb47fa906fc',
@@ -57,6 +58,8 @@ class Swig(AutotoolsPackage, SourceforgePackage):
 
     build_directory = 'spack-build'
 
+    conflicts('%nvhpc', when='@:4.0.2')
+
     @run_after('install')
     def create_symlink(self):
         # CMake compatibility: see https://github.com/spack/spack/pull/6240


Test patch: