Repository: spack/spack

Issue:
pgmath fails to build on Ubuntu (16.04 and maybe later)
@junghans @tinlun 

I tried installing `flang` in a Docker container based on Ubuntu 16.04. I tried that using both `gcc-7` and `gcc-8`. The `pgmath` dependency fails to build with segfault.


### Steps to reproduce the issue

```console
$ spack install pgmath # On Ubuntu 16.04
```

### Error Message

```
==> Building pgmath [CMakePackage]                                                                                                                [1532/30305]
==> Executing phase: 'cmake'
==> Executing phase: 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j32'

4 errors found in build log:
  >> 357    Segmentation fault (core dumped)
     358    lib/common/CMakeFiles/mth_z2yy.dir/build.make:63: recipe for target 'lib/common/mth_z2yy.c' failed
  >> 359    make[2]: *** [lib/common/mth_z2yy.c] Error 139
     360    make[2]: *** Deleting file 'lib/common/mth_z2yy.c'
     361    make[2]: Leaving directory '/tmp/root/spack-stage/spack-stage-TbIWzt/flang-flang_20180612/spack-build'
     362    CMakeFiles/Makefile2:1044: recipe for target 'lib/common/CMakeFiles/mth_z2yy.dir/all' failed
  >> 363    make[1]: *** [lib/common/CMakeFiles/mth_z2yy.dir/all] Error 2
     364    make[1]: *** Waiting for unfinished jobs....
```
that activate the full debug output. 


### Information on your system

Ubuntu 16.04

### Reason

The default for `awk` in Ubuntu is `mawk`. If I read it right, `pgmath` uses `awk` to generate some of its own source code. `mawk` simply segfaults when running that `awk` command. Using `gawk` to run that awk command seems to be OK.


Discussion:
This is known, see https://github.com/flang-compiler/flang/issues/434#issuecomment-378159723 and reported upstream https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=901477.

A possible solution would be to add a `depend_on("awk")`.
@junghans Thanks, I somehow missed those issues.

> A possible solution would be to add a `depend_on("awk")`.

How does that work? There is no `awk` package in Spack, only `gawk` and `mawk`. How does it choose one?
`awk` is a virtual dependency, much like `mpi`, and can be satisfied by either `gawk` or `mawk`. The default provider is `gawk`.
If it's a virtual dependency, and can be satisfied by either, than the code should be
```
depends_on("gawk")
```
as `mawk` cannot be used.
As I said in https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=901477, the latest version of mawk works, just the ancient version coming with ubuntu is broken!
@junghans OK. Sorry for possibly stupid question, but how would you then specify the condition: depends on awk, but make sure that whatever awk it is resolved to is not the ancient mawk version?
That isn't currently possible, unless awk has its own versioning system, like how MPI has version 2.0, 3.0, etc. However, Spack will always default to the latest version of a package, so it shouldn't use an old mawk unless someone configures packages.yaml that way.
How about we only include non-buggy version of mawk in spack? Or conflict on the buggy version of mawk?
> How about we only include non-buggy version of mawk in spack

Would be nice. Quick grep in Spack shows that no package depends on mawk explicitly. But this does not solve the problem if user specifies `mawk` in `packages.yaml`.

> Or conflict on the buggy version of mawk?

I'm missing something here. If you do
```python
depens_on("awk")
conflict("mawk@:version")
```
would not spack simply ignore the later as this is not an explicit depends of `pgmath`?
With the next version of `mawk` in spack adding `depens_on("awk")` should fix most cases.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/pgmath/package.py b/var/spack/repos/builtin/packages/pgmath/package.py
--- a/var/spack/repos/builtin/packages/pgmath/package.py
+++ b/var/spack/repos/builtin/packages/pgmath/package.py
@@ -17,6 +17,7 @@ class Pgmath(CMakePackage):
     version('develop', branch='master')
     version('20180612', '62284e26214eaaff261a922c67f6878c')
 
+    depends_on("awk", type="build")
     conflicts("%gcc@:7.1.9999")
 
     root_cmakelists_dir = 'runtime/libpgmath'


Test patch: