From 92604ed5760cbde70d0d705b5fab0a2682b1eb66 Mon Sep 17 00:00:00 2001
From: Owen Solberg <odoublewen@users.noreply.github.com>
Date: Sat, 18 May 2019 19:00:32 -0700
Subject: [PATCH] intel-tbb: fix patch for old compilers (#11371)

* added patch for intel-tbb@2019.1: with old compilers

* sparately specify when @:2018 and @2019

the reason we can't say @:2019 is that would include @2019.1 where the
patch doesn't work.

* should be possible to list when constraint as @:2019

According to my reading of ["Version ranges" in the Spack
docs](https://spack.readthedocs.io/en/latest/packaging_guide.html#version-ranges),
this should apply to up to `2019` but not `2019.1:`

* @:2019.0 appears to be necessary to specify 2019 but not 2019.1

* specifying 2019.1 2019.2 2019.3 2019.4 separately and explcitly

* flake8 fixes for long lines.

* add comments to explain why so many different patch directives

* remove blank like for flake8

* revert spec %gcc@4.8.0:4.99999 -> %gcc@4.8.0:
---
 .../builtin/packages/intel-tbb/package.py     | 36 ++++++++++++++++---
 .../intel-tbb/tbb_gcc_rtm_key_2019U1.patch    | 11 ++++++
 2 files changed, 42 insertions(+), 5 deletions(-)
 create mode 100644 var/spack/repos/builtin/packages/intel-tbb/tbb_gcc_rtm_key_2019U1.patch

diff --git a/var/spack/repos/builtin/packages/intel-tbb/package.py b/var/spack/repos/builtin/packages/intel-tbb/package.py
index 82a6280c18..c69ac29eb9 100644
--- 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:')
diff --git a/var/spack/repos/builtin/packages/intel-tbb/tbb_gcc_rtm_key_2019U1.patch b/var/spack/repos/builtin/packages/intel-tbb/tbb_gcc_rtm_key_2019U1.patch
new file mode 100644
index 0000000000..5d4fe9aa89
--- /dev/null
+++ b/var/spack/repos/builtin/packages/intel-tbb/tbb_gcc_rtm_key_2019U1.patch
@@ -0,0 +1,11 @@
+--- build/linux.gcc.inc~	2016-09-15 07:00:44.000000000 -0500
++++ build/linux.gcc.inc	2018-06-07 17:32:53.181194974 -0500
+@@ -46,7 +46,7 @@
+ 
+ # gcc 4.8 and later support RTM intrinsics, but require command line switch to enable them
+ ifneq (,$(shell $(CONLY) -dumpversion | egrep  "^(4\.[8-9]|[5-9])"))
+-    RTM_KEY = -mrtm
++    RTM_KEY = # -mrtm
+ endif
+ 
+ ifeq ($(cfg), release)
-- 
GitLab