Repository: spack/spack

Issue:
Installation issue: intel-tbb
I was stuck with the installation of intel-tbb when going over [Package Creation Tutorial](https://spack.readthedocs.io/en/latest/tutorial_packaging.html#dependencies). 

```console
root@n7459:~$ spack install intel-tbb
==> pkgconf is already installed in $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/pkgconf-1.5.4-ry5yoj2yvm3yl3wfuqmnuzslglleu7aw
==> ncurses is already installed in $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/ncurses-6.1-35xlequxd7hfj36ygbw4umttsdf5pgw4
==> readline is already installed in $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/readline-7.0-r7vc4akeqmhnqtm3vqu255uzntdwjyxv
==> gdbm is already installed in $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/gdbm-1.18.1-7a3bryh6jpoku5yoihcktsjfmac6gspg
==> perl is already installed in $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/perl-5.26.2-p5qgzhl2ucziya2fefq2lvvyowxnzzzf
==> zlib is already installed in $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/zlib-1.2.11-uk4hz57lzsxrg5h7dr5qse3ng6nsrwcj
==> openssl is already installed in $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/openssl-1.1.1-w57qpywb6ceu4r234jnj54cywoakxirj
==> cmake is already installed in $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/cmake-3.13.2-3drpny4v5hxqj23ne7goi6waoewdozxs
==> Installing intel-tbb
==> Searching for binary cache of intel-tbb
==> Warning: No Spack mirrors are currently configured
==> No binary for intel-tbb found: installing from source
==> Using cached archive: $SPACK_ROOT/var/spack/cache/intel-tbb/intel-tbb-2019.2.tar.gz
==> Staging archive: $SPACK_ROOT/var/spack/stage/intel-tbb-2019.2-rezvmbclxhnjg4w24opxrmgeii5zndyj/2019_U2.tar.gz
==> Created stage in $SPACK_ROOT/var/spack/stage/intel-tbb-2019.2-rezvmbclxhnjg4w24opxrmgeii5zndyj
1 out of 1 hunk FAILED -- saving rejects to file build/linux.gcc.inc.rej
==> Patch $SPACK_ROOT/var/spack/repos/builtin/packages/intel-tbb/tbb_gcc_rtm_key.patch failed.
==> Error: ProcessError: Command exited with status 1:
    '/usr/bin/patch' '-s' '-p' '0' '-i' '$SPACK_ROOT/var/spack/repos/builtin/packages/intel-tbb/tbb_gcc_rtm_key.patch' '-d' '.'

```
Please advice. Thanks.


Discussion:
Some additional information: 
When I commented out to simply ignore the `tbb_gcc_rmt_key.patch` it went through well:

```console
root@n52:~$ uname -a
Linux n52 2.6.32-754.9.1.el6.x86_64 #1 SMP Thu Dec 6 08:02:15 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
root@n52:~$ lsb_release -d
Description:	CentOS release 6.10 (Final)
root@n52:~$ cat $SPACK_ROOT/var/spack/repos/builtin/packages/intel-tbb/package.py |grep -n "#patch"
69:    #patch("tbb_gcc_rtm_key.patch", level=0, when='%gcc@4.8.0: os=rhel6')
70:    #patch("tbb_gcc_rtm_key.patch", level=0, when='%gcc@4.8.0: os=scientific6')
71:    #patch("tbb_gcc_rtm_key.patch", level=0, when='%gcc@4.8.0: os=centos6')
root@n52:~$ spack install intel-tbb
==> pkgconf is already installed in $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/pkgconf-1.5.4-ry5yoj2yvm3yl3wfuqmnuzslglleu7aw
==> ncurses is already installed in $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/ncurses-6.1-35xlequxd7hfj36ygbw4umttsdf5pgw4
==> readline is already installed in $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/readline-7.0-r7vc4akeqmhnqtm3vqu255uzntdwjyxv
==> gdbm is already installed in $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/gdbm-1.18.1-7a3bryh6jpoku5yoihcktsjfmac6gspg
==> perl is already installed in $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/perl-5.26.2-p5qgzhl2ucziya2fefq2lvvyowxnzzzf
==> zlib is already installed in $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/zlib-1.2.11-uk4hz57lzsxrg5h7dr5qse3ng6nsrwcj
==> openssl is already installed in $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/openssl-1.1.1-w57qpywb6ceu4r234jnj54cywoakxirj
==> cmake is already installed in $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/cmake-3.13.3-rybuegvkijs6j3uvhuzdvv7lzybmzf5f
==> Installing intel-tbb
==> Searching for binary cache of intel-tbb
==> Warning: No Spack mirrors are currently configured
==> No binary for intel-tbb found: installing from source
==> Using cached archive: $SPACK_ROOT/var/spack/cache/intel-tbb/intel-tbb-2019.2.tar.gz
==> Staging archive: $SPACK_ROOT/var/spack/stage/intel-tbb-2019.2-3lmoloffjyz7jim3vejdlbnr7wjqzsxi/2019_U2.tar.gz
==> Created stage in $SPACK_ROOT/var/spack/stage/intel-tbb-2019.2-3lmoloffjyz7jim3vejdlbnr7wjqzsxi
==> Applied patch $SPACK_ROOT/var/spack/repos/builtin/packages/intel-tbb/tbb_cmakeConfig.patch
==> Building intel-tbb [Package]
==> Executing phase: 'install'
==> Successfully installed intel-tbb
  Fetch: 0.06s.  Build: 51.48s.  Total: 51.54s.
[+] $SPACK_ROOT/opt/spack/linux-centos6-x86_64/gcc-7.2.0/intel-tbb-2019.2-3lmoloffjyz7jim3vejdlbnr7wjqzsxi
```
Any bug-fix for that `tbb_gcc_rmt_key.patch` file? Thanks.
Update: The error was experienced in the "develop" branch. When I check out the "release/v0.12" and repeat the steps, everything is went well as shown in the tutorial. Thanks.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/intel-tbb/package.py b/var/spack/repos/builtin/packages/intel-tbb/package.py
--- a/var/spack/repos/builtin/packages/intel-tbb/package.py
+++ b/var/spack/repos/builtin/packages/intel-tbb/package.py
@@ -67,12 +67,38 @@ class IntelTbb(Package):
     # Build and install CMake config files if we're new enough.
     depends_on('cmake@3.0.0:', type='build', when='@2017.0:')
 
+    # Note: see issues #11371 and #8957 to understand why 2019.x patches are
+    # specified one at a time.  In a nutshell, it is currently impossible
+    # to patch `2019.1` without patching `2019`.  When #8957 is fixed, this
+    # can be simplified.
+
     # Deactivate use of RTM with GCC when on an OS with an elderly assembler.
-    patch("tbb_gcc_rtm_key.patch", level=0, when='%gcc@4.8.0: os=rhel6')
-    patch("tbb_gcc_rtm_key.patch", level=0, when='%gcc@4.8.0: os=scientific6')
-    patch("tbb_gcc_rtm_key.patch", level=0, when='%gcc@4.8.0: os=centos6')
-    patch("gcc_generic-pedantic-4.4.patch", level=1, when='@:2018.99')
-    patch("gcc_generic-pedantic-2019.patch", level=1, when='@2019:')
+    # one patch format for 2019.1 and after...
+    patch("tbb_gcc_rtm_key_2019U1.patch", level=0, when='@2019.4 %gcc@4.8.0: os=rhel6')
+    patch("tbb_gcc_rtm_key_2019U1.patch", level=0, when='@2019.4 %gcc@4.8.0: os=scientific6')
+    patch("tbb_gcc_rtm_key_2019U1.patch", level=0, when='@2019.4 %gcc@4.8.0: os=centos6')
+    patch("tbb_gcc_rtm_key_2019U1.patch", level=0, when='@2019.3 %gcc@4.8.0: os=rhel6')
+    patch("tbb_gcc_rtm_key_2019U1.patch", level=0, when='@2019.3 %gcc@4.8.0: os=scientific6')
+    patch("tbb_gcc_rtm_key_2019U1.patch", level=0, when='@2019.3 %gcc@4.8.0: os=centos6')
+    patch("tbb_gcc_rtm_key_2019U1.patch", level=0, when='@2019.2 %gcc@4.8.0: os=rhel6')
+    patch("tbb_gcc_rtm_key_2019U1.patch", level=0, when='@2019.2 %gcc@4.8.0: os=scientific6')
+    patch("tbb_gcc_rtm_key_2019U1.patch", level=0, when='@2019.2 %gcc@4.8.0: os=centos6')
+    patch("tbb_gcc_rtm_key_2019U1.patch", level=0, when='@2019.1 %gcc@4.8.0: os=rhel6')
+    patch("tbb_gcc_rtm_key_2019U1.patch", level=0, when='@2019.1 %gcc@4.8.0: os=scientific6')
+    patch("tbb_gcc_rtm_key_2019U1.patch", level=0, when='@2019.1 %gcc@4.8.0: os=centos6')
+    # ...another patch file for 2019 and before
+    patch("tbb_gcc_rtm_key.patch", level=0, when='@:2019.0 %gcc@4.8.0: os=rhel6')
+    patch("tbb_gcc_rtm_key.patch", level=0, when='@:2019.0 %gcc@4.8.0: os=scientific6')
+    patch("tbb_gcc_rtm_key.patch", level=0, when='@:2019.0 %gcc@4.8.0: os=centos6')
+
+    # patch for pedantic warnings (#10836)
+    # one patch file for 2019.1 and after...
+    patch("gcc_generic-pedantic-2019.patch", level=1, when='@2019.4')
+    patch("gcc_generic-pedantic-2019.patch", level=1, when='@2019.3')
+    patch("gcc_generic-pedantic-2019.patch", level=1, when='@2019.2')
+    patch("gcc_generic-pedantic-2019.patch", level=1, when='@2019.1')
+    # ...another patch file for 2019 and before
+    patch("gcc_generic-pedantic-4.4.patch", level=1, when='@:2019.0')
 
     # Patch cmakeConfig.cmake.in to find the libraries where we install them.
     patch("tbb_cmakeConfig.patch", level=0, when='@2017.0:')


Test patch: