Repository: spack/spack

Issue:
papi: add additional variants
This PR adds variants to the Papi package for additional configuration options. Specifically, explicitly enabling static building, shared building, and building shlib-tools is now supported.


Discussion:
After looking more at the configure process for papi, it seems like it will always fail if you try to configure "--with-static-lib=no".  See line 5449 of the configure script.  I will bring this up with the papi dev team. 

Therefore, it seems like this makes +static required in all cases.
I also see that "--without-shlib" is not a papi configure option. You should pass either "--with-static-tools" or "--with-shlib-tools" based on the variant "shlib_tools".  It will also need a conflict() to make sure that you are building the shared library if you request "--with-shlib-tools".
It does not seem like papi uses the shared library with tools and utilities even when you configure "--with-shlib-tools". I will also have to discuss this with the papi team.  

Since there are a number of issues that we will have to resolve, would it be OK if I discuss these with the papi team and then make a pull request with the needed changes at that time?

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/papi/package.py b/var/spack/repos/builtin/packages/papi/package.py
--- a/var/spack/repos/builtin/packages/papi/package.py
+++ b/var/spack/repos/builtin/packages/papi/package.py
@@ -2,6 +2,7 @@
 # Spack Project Developers. See the top-level COPYRIGHT file for details.
 #
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
 import glob
 import os
 import sys
@@ -38,10 +39,20 @@ class Papi(AutotoolsPackage):
     variant('lmsensors', default=False, description='Enable lm_sensors support')
     variant('sde', default=False, description='Enable software defined events')
 
+    variant('shared', default=True, description='Build shared libraries')
+    # PAPI requires building static libraries, so there is no "static" variant
+    variant('static_tools', default=False, description='Statically link the PAPI tools')
+    # The PAPI configure option "--with-shlib-tools" is deprecated
+    # and therefore not implemented here
+
     depends_on('lm-sensors', when='+lmsensors')
 
     conflicts('%gcc@8:', when='@5.3.0', msg='Requires GCC version less than 8.0')
 
+    # This is the only way to match exactly version 6.0.0 without also
+    # including version 6.0.0.1 due to spack version matching logic
+    conflicts('@5.9.99999:6.0.0.a', when='+static_tools', msg='Static tools cannot build on version 6.0.0')
+
     # Does not build with newer versions of gcc, see
     # https://bitbucket.org/icl/papi/issues/46/cannot-compile-on-arch-linux
     patch('https://bitbucket.org/icl/papi/commits/53de184a162b8a7edff48fed01a15980664e15b1/raw', sha256='64c57b3ad4026255238cc495df6abfacc41de391a0af497c27d0ac819444a1f8', when='@5.4.0:5.6.99%gcc@8:')
@@ -55,15 +66,24 @@ def setup_build_environment(self, env):
     setup_run_environment = setup_build_environment
 
     def configure_args(self):
+        spec = self.spec
         # PAPI uses MPI if MPI is present; since we don't require
         # an MPI package, we ensure that all attempts to use MPI
         # fail, so that PAPI does not get confused
         options = ['MPICC=:']
-        # Build a list of activated variants (optional PAPI components)
-        variants = filter(lambda x: self.spec.variants[x].value is True,
-                          self.spec.variants)
-        if variants:
-            options.append('--with-components={0}'.format(' '.join(variants)))
+        # Build a list of PAPI components
+        components = filter(
+            lambda x: spec.variants[x].value,
+            ['example', 'infiniband', 'powercap', 'rapl', 'lmsensors', 'sde'])
+        if components:
+            options.append('--with-components=' + ' '.join(components))
+
+        build_shared = 'yes' if '+shared' in spec else 'no'
+        options.append('--with-shared-lib=' + build_shared)
+
+        if '+static_tools' in spec:
+            options.append('--with-static-tools')
+
         return options
 
     @run_before('configure')


Test patch: