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?
Should be fixed by #7545.

Resolving patch:
diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py
--- a/lib/spack/spack/package.py
+++ b/lib/spack/spack/package.py
@@ -1162,7 +1162,7 @@ def patches_to_apply(self):
             patch_list
             for spec, patch_list in self.patches.items()
             if self.spec.satisfies(spec))
-        return sorted(patchesToApply, key=lambda p: p.path_or_url)
+        return list(patchesToApply)
 
     def content_hash(self, content=None):
         """Create a hash based on the sources and logic used to build the


Test patch: