Repository: spack/spack

Issue:
Problem installing flang
@junghans 

### Expected Result

`$ spack install flang` completes

### Actual Result

What happened instead
```
<snip>
==> Successfully installed llvm
  Fetch: 24.09s.  Build: 15m 56.54s.  Total: 16m 20.63s.
[+] /scratch/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/llvm-5.0.0-i66qkkvc7d6pnsdx5vjamnxuicye44b6
==> Installing flang
==> Trying to clone git repository: https://github.com/flang-compiler/flang on branch master
==> No checksum needed when fetching with git
==> Already staged flang-develop-i6oboxtz3nbcsdlzxy4jfdo5nchv5o3o in /scratch/spack/var/spack/stage/flang-develop-i6oboxtz3nbcsdlzxy4jfdo5nchv5o3o
==> No patches needed for flang
==> Building flang [CMakePackage]
==> Executing phase: 'cmake'
==> Error: ProcessError: Command exited with status 1:
    'cmake' '/scratch/spack/var/spack/stage/flang-develop-i6oboxtz3nbcsdlzxy4jfdo5nchv5o3o/flang' '-G' 'Unix Makefiles' '-DCMAKE_INSTALL_PREFIX:PATH=/scratch/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/flang-develop-i6oboxtz3nbcsdlzxy4jfdo5nchv5o3o' '-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo' '-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON' '-DCMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL=FALSE' '-DCMAKE_INSTALL_RPATH:STRING=/scratch/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/flang-develop-i6oboxtz3nbcsdlzxy4jfdo5nchv5o3o/lib:/scratch/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/flang-develop-i6oboxtz3nbcsdlzxy4jfdo5nchv5o3o/lib64:/scratch/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/llvm-5.0.0-i66qkkvc7d6pnsdx5vjamnxuicye44b6/lib:/usr/lib' '-DCMAKE_PREFIX_PATH:STRING=/scratch/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/llvm-5.0.0-i66qkkvc7d6pnsdx5vjamnxuicye44b6' '-DWITH_WERROR=OFF' '-DCMAKE_C_COMPILER=/scratch/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/llvm-5.0.0-i66qkkvc7d6pnsdx5vjamnxuicye44b6/bin/clang' '-DCMAKE_CXX_COMPILER=/scratch/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/llvm-5.0.0-i66qkkvc7d6pnsdx5vjamnxuicye44b6/bin/clang++' '-DCMAKE_Fortran_COMPILER=/scratch/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/llvm-5.0.0-i66qkkvc7d6pnsdx5vjamnxuicye44b6/bin/flang' '-DFLANG_LIBOMP=/scratch/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/llvm-5.0.0-i66qkkvc7d6pnsdx5vjamnxuicye44b6/lib/libomp.so'

1 error found in build log:
     [ ... ]
     47    -- Found assembler: /scratch/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/llvm-5.0.0-i66qkkvc7d6pnsdx5vjamnxuicye44b6/bin/clang
     48    -- The Fortran compiler identification is unknown
     49    -- Detecting Fortran compiler ABI info
     50    -- Detecting Fortran compiler ABI info - failed
     51    -- Checking whether /scratch/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/llvm-5.0.0-i66qkkvc7d6pnsdx5vjamnxuicye44b6/bin/flang supports Fortran 90
     52    -- Checking whether /scratch/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/llvm-5.0.0-i66qkkvc7d6pnsdx5vjamnxuicye44b6/bin/flang supports Fortran 90 -- no
  >> 53    CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
     54    Please set them or make sure they are set and tested correctly in the CMake files:
     55    LIBPGMATH
     56        linked by target "flangrti_shared" in directory /scratch/spack/var/spack/stage/flang-develop-i6oboxtz3nbcsdlzxy4jfdo5nchv5o3o/flang/runtime/flangrti
     57    
     58    -- Configuring incomplete, errors occurred!
     59    See also "/tmp/root/spack-stage/spack-stage-Bny4m0/flang/spack-build/CMakeFiles/CMakeOutput.log".

See build log for details:
  /scratch/spack/var/spack/stage/flang-develop-i6oboxtz3nbcsdlzxy4jfdo5nchv5o3o/flang/spack-build.out

```

### Steps to reproduce the issue

Can just run `docker build` with the following Dockerfile:
```
FROM ubuntu:16.04

ARG NPROC=14

RUN apt-get update && apt-get install -y 
        build-essential \
        gfortran \
        libopenmpi-dev \
        curl \
        cmake \
        git \
        wget \
        vim \
        autoconf \
        lcov \
        valgrind \
        libssl-dev \
        libpng-dev \
        libfreetype6-dev \
        libxft-dev \
        libsqlite3-dev \
        libbz2-dev \
        libatlas-base-dev \
        zlib1g-dev \
        python2.7-dev \
        tmux \
        unzip \
        environment-modules \
        && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* && \
    ln -s /usr/bin/python2.7 /usr/bin/python

ENV PREFIX=/scratch
RUN mkdir -p ${PREFIX} && \
    cd ${PREFIX} && \
    mkdir archive && \
    mkdir source && \
    mkdir build && \
    mkdir install

ENV HOME=/root

ENV SPACK_ROOT=${PREFIX}/spack

# Install Spack (specific hash)
RUN export SPACK_HASH=041aa143db6964575625f1849de639541efb83a5 && \
    export SPACK_URL="https://github.com/spack/spack/archive/${SPACK_HASH}.tar.gz" && \
    export SPACK_INSTALL_DIR="${SPACK_ROOT}" && \
    export SPACK_ARCHIVE="${PREFIX}/archive/spack-${SPACK_HASH}.tar.gz" && \
    wget --quiet ${SPACK_URL} --output-document=${SPACK_ARCHIVE} && \
    mkdir -p ${SPACK_INSTALL_DIR} && \
    tar -xf ${SPACK_ARCHIVE} -C ${SPACK_INSTALL_DIR} --strip-components=1 && \
    rm -rf ${SPACK_ARCHIVE} && \
    mkdir -p ${HOME}/.spack

# Load Spack
ENV PATH="${SPACK_ROOT}/bin:${PATH}"
RUN echo "source $SPACK_ROOT/share/spack/setup-env.sh" >> ${HOME}/.bashrc
RUN echo "source /usr/share/modules/init/bash"         >> ${HOME}/.bashrc

# Install flang
RUN spack spec -I flang && spack install flang && spack clean -a
```

### Information on your system

Ubuntu 16.04 in Docker



Discussion:
@aprokop: Could have a look if llvm actually got patched before build?
@junghans Hmm? Not sure what you mean.
Can you do a verbose install and have a look if it applies a patch in llvm before building?
@junghans Sorry for the delay. I ran `spack install -v flang` (the log is too large to attach). I don't actually see it patching `llvm` (though I may be looking for wrong things), and llvm still shows 
```
$ spack find -v llvm
==> 1 installed packages.
-- linux-ubuntu16.04-x86_64 / gcc@5.4.0 -------------------------
llvm@5.0.0+all_targets build_type=Release +clang+compiler-rt+gold+internal_unwind+libcxx~link_dylib+lld+lldb patches=7f39555783993f78b75c380ca5ef167c1d8b88cc75c6542f6c94e0b6acfb7c5d +polly~python~shared_libs

```
Just to make sure, what would the patching line look like?
same here - @tgamblin @scheibelp are the patched dependencies broken again?
With #8272 I see patch being applied. `flang` installation now seems to be one step further, but still breaks:
```
1 error found in build log:                                                                                │··················································
     47    -- Found assembler: /home/xap/local/opt/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/llvm │··················································
           -5.0.0-ewhqhnhof547bzplwevual4c3m74ukn6/bin/clang                                               │··················································
     48    -- The Fortran compiler identification is unknown                                               │··················································
     49    -- Detecting Fortran compiler ABI info                                                          │··················································
     50    -- Detecting Fortran compiler ABI info - failed                                                 │··················································
     51    -- Checking whether /home/xap/local/opt/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/llvm │··················································
           -5.0.0-ewhqhnhof547bzplwevual4c3m74ukn6/bin/flang supports Fortran 90                           │··················································
     52    -- Checking whether /home/xap/local/opt/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/llvm │··················································
           -5.0.0-ewhqhnhof547bzplwevual4c3m74ukn6/bin/flang supports Fortran 90 -- no                     │··················································
  >> 53    CMake Error: The following variables are used in this project, but they are set to NOTFOUND.    │··················································
     54    Please set them or make sure they are set and tested correctly in the CMake files:              │··················································
     55    LIBPGMATH                                                                                       │··················································
     56        linked by target "flangrti_shared" in directory /home/xap/local/opt/spack/var/spack/stage/f │··················································
           lang-develop-3yxlu57e5j5azd57ipzihmuzdtapbpkk/flang/runtime/flangrti                            │··················································
     57                                                                                                    │··················································
     58    -- Configuring incomplete, errors occurred!                                                     │··················································
     59    See also "/tmp/xap/spack-stage/spack-stage-LMbp7b/flang/spack-build/CMakeFiles/CMakeOutput.log" 
```
It seems that people have experienced that too: flang-compiler/flang#434. Does anybody have a hash of `flang` that used to compile? We may want to add that along with existing `develop` so that we are not dependent on broken upstream.
OK, with the `20180319` release of `flang`, it compiles. I'll do a PR.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/flang/package.py b/var/spack/repos/builtin/packages/flang/package.py
--- a/var/spack/repos/builtin/packages/flang/package.py
+++ b/var/spack/repos/builtin/packages/flang/package.py
@@ -30,9 +30,10 @@
 class Flang(CMakePackage):
     """Flang is a Fortran compiler targeting LLVM."""
     homepage = "https://github.com/flang-compiler/flang"
-    url      = "https://github.com/flang-compiler/flang/flecsi/tarball/v1.0"
+    url      = "https://github.com/flang-compiler/flang/archive/flang_20180319.tar.gz"
 
     version('develop', git='https://github.com/flang-compiler/flang', branch='master')
+    version('20180319', 'e659bad83b791f90af2c5cd672864669')
 
     depends_on(
             "llvm+clang@4.0.1,5.0.0",


Test patch: