Repository: spack/spack

Issue:
gcc v5.4.0 build fails due to mpfr patching problem
There seems to be a patch application issue in the mpfr-3.1.5 build procedure

I was expecting something like my previous build:
```
==> Installing mpfr
==> Fetching file://MIRROR_DIR/mirror/mpfr/mpfr-3.1.5.tar.bz2
==> Staging archive: WORKING_DIR/var/spack/stage/mpfr-3.1.5-rmi7bmi3oaqduvjown2v46snr6ps2zr5/mpfr-3.1.5.tar.bz2
==> Created stage in WORKING_DIR/var/spack/stage/mpfr-3.1.5-rmi7bmi3oaqduvjown2v46snr6ps2zr5
==> Applied patch vasprintf.patch
==> Applied patch strtofr.patch
==> Building mpfr [AutotoolsPackage]
==> Executing phase: 'autoreconf'
==> Executing phase: 'configure'
==> Executing phase: 'build'
==> Executing phase: 'install'
==> Successfully installed mpfr
  Fetch: 0.04s.  Build: 9.54s.  Total: 9.58s.
[+] WORKING_DIR/opt/spack/linux-centos7-x86_64/gcc-4.8.5/mpfr-3.1.5-rmi7bmi3oaqduvjown2v46snr6ps2zr5
```
When I tried to build the gcc compiler yesterday (and again this morning) the results were strange:
```
==> Installing mpfr
1 out of 1 hunk FAILED -- saving rejects to file VERSION.rej
1 out of 1 hunk FAILED -- saving rejects to file src/mpfr.h.rej
1 out of 1 hunk FAILED -- saving rejects to file src/version.c.rej
==> Fetching file://MIRROR_DIR/mirror/mpfr/mpfr-3.1.5.tar.bz2
==> Staging archive: WORKING_DIR/sat/spack/var/spack/stage/mpfr-3.1.5-rmi7bmi3oaqduvjown2v46snr6ps2zr5/mpfr-3.1.5.tar.bz2
==> Created stage in WORKING_DIR/sat/spack/var/spack/stage/mpfr-3.1.5-rmi7bmi3oaqduvjown2v46snr6ps2zr5
==> Patch strtofr.patch failed.
==> Error: ProcessError: Command exited with status 1:
    '/usr/bin/patch' '-s' '-p' '1' '-i' 'WORKING_DIR/sat/spack/var/spack/repos/builtin/packages/mpfr/strtofr.patch' '-d' '.'
==> Error: [Errno 2] No such file or directory: 'WORKING_DIR/sat/spack/var/spack/stage/mpfr-3.1.5-rmi7bmi3oaqduvjown2v46snr6ps2zr5/mpfr-3.1.5/spack-build.out'
```
Not only the error, but the order of the messages seem strange.

A clean clone of the spack repo made no difference
```console
$ spack install gcc@5.4.0
```

Default environment:
```linux-centos7-x86_64/gcc-4.8.5```


Discussion:
Weird, they worked when I added them in #3506, and the checksum hasn't changed. It looks like a new version of `mpfr` has been released. I'll add it.
Figured out what the problem was. `mpfr@3.1.5` has two patches, `vasprintf.patch` and `strtofr.patch`. The first patch changes the version from `3.1.5` to `3.1.5-p1` (among other things), while the second patch changes the version from `3.1.5-p1` to `3.1.5-p2` (among other things). This was working before, but for some reason the order of patches being processed changed. It is no longer done in the order of the lines in `package.py` like it used to be. @alalazo do you know anything about this?

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/mpfr/package.py b/var/spack/repos/builtin/packages/mpfr/package.py
--- a/var/spack/repos/builtin/packages/mpfr/package.py
+++ b/var/spack/repos/builtin/packages/mpfr/package.py
@@ -30,18 +30,33 @@ class Mpfr(AutotoolsPackage):
        floating-point computations with correct rounding."""
 
     homepage = "http://www.mpfr.org"
-    url      = "https://ftp.gnu.org/gnu/mpfr/mpfr-3.1.5.tar.bz2"
+    url      = "https://ftp.gnu.org/gnu/mpfr/mpfr-4.0.1.tar.bz2"
 
+    version('4.0.1', '8c21d8ac7460493b2b9f3ef3cc610454')
+    version('4.0.0', 'ef619f3bb68039e35c4a219e06be72d0')
+    version('3.1.6', '320c28198def956aeacdb240b46b8969')
     version('3.1.5', 'b1d23a55588e3b2a13e3be66bc69fd8d')
     version('3.1.4', 'b8a2f6b0e68bef46e53da2ac439e1cf4')
     version('3.1.3', '5fdfa3cfa5c86514ee4a241a1affa138')
     version('3.1.2', 'ee2c3ac63bf0c2359bf08fc3ee094c19')
 
     # mpir is a drop-in replacement for gmp
-    depends_on('gmp@4.1.0:')  # 4.2.3 or higher is recommended
+    depends_on('gmp@4.1:')  # 4.2.3 or higher is recommended
+    depends_on('gmp@5.0:', when='@4.0.0:')  # http://www.mpfr.org/mpfr-4.0.0/
 
-    patch('vasprintf.patch', when='@3.1.5')
-    patch('strtofr.patch',   when='@3.1.5')
+    # Check the Bugs section of old release pages for patches.
+    # http://www.mpfr.org/mpfr-X.Y.Z/#bugs
+    patches = {
+        '3.1.6': '66a5d58364113a21405fc53f4a48f4e8',
+        '3.1.5': '1dc5fe65feb5607b89fe0f410d53b627',
+        '3.1.4': 'd124381573404fe83654c7d5a79aeabf',
+        '3.1.3': 'ebd1d835e0ae2fd8a9339210ccd1d0a8',
+        '3.1.2': '9f96a5c7cac1d6cd983ed9cf7d997074',
+    }
+
+    for ver, checksum in patches.items():
+        patch('http://www.mpfr.org/mpfr-{0}/allpatches'.format(ver),
+              when='@' + ver, sha256=checksum)
 
     def configure_args(self):
         args = [


Test patch: