From 83982656387798ff2b98db7f487ff784b67793f0 Mon Sep 17 00:00:00 2001
From: Alicia Klinvex <64440832+amklinv-nnl@users.noreply.github.com>
Date: Thu, 13 Aug 2020 16:35:00 -0400
Subject: [PATCH] Add support for pFUnit version 4 (#17683)

* pFUnit: Added support for version 4

pFUnit v4 uses submodules, so we must fetch from the repo rather
than grabbing the tarball (see #11642).

* pFUnit: Added conflicts

pFUnit 4 causes an internal compiler error with gcc 7.2.0, and
several pFUnit versions are incompatible with shared libraries.

* pFUnit: Added conflicts for version 4

Verson 4 uses Fortran 2008 features and cannot be built with gcc
compilers prior to 8.4.

* pFUnit: Fixed conflicts/dependencies as suggested

* pFUnit: Version 4 no longer fetches from git

Checksummable files are fetched instead.

* pFUnit: Simplify major version check

Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>

* pFUnit: Removed unnecessary patch for v4

The patch is still applied to v3.

* pFUnit: Modified MPI flag for v4

pFUnit v3 and v4 use different CMake flags to enable/disable MPI
support. Also added a conflict for v3 with MPI enabled using
gfortran 10, since newer gfortran is more finicky about datatypes.

* pFUnit: Rearranged mpi logic

* pFUnit: changed m4 to a build dependency

Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>

* pFUnit: Added URL back

I did not realize it was needed by "spack versions" and
"spack checksum". Thanks @adamjstewart!

Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
---
 .../repos/builtin/packages/pfunit/package.py  | 35 ++++++++++++++-----
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/var/spack/repos/builtin/packages/pfunit/package.py b/var/spack/repos/builtin/packages/pfunit/package.py
index ab6bc53d2c..3c6f8576b7 100644
--- a/var/spack/repos/builtin/packages/pfunit/package.py
+++ b/var/spack/repos/builtin/packages/pfunit/package.py
@@ -13,13 +13,12 @@ class Pfunit(CMakePackage):
     serial and MPI-parallel software written in Fortran."""
 
     homepage = "http://pfunit.sourceforge.net/"
-    url      = "https://github.com/Goddard-Fortran-Ecosystem/pFUnit/archive/3.2.9.tar.gz"
+    url = "https://github.com/Goddard-Fortran-Ecosystem/pFUnit/releases/download/v4.1.10/pFUnit-4.1.10.tar"
 
     maintainers = ['citibeth']
 
-    # Currently investigating build fails for v 4.0.0.
-    # See discussion in PR #11642.
-    # version('4.0.0',  sha256='b8b6470f2b1e2b19c164c244c10e803bd69c8da9a6a5a65ba7c479fb8b92a1e1') # noqa: E501
+    version('4.1.11', sha256='16160bac223aaa3ed2b27e30287d25fdaec3cf6f2c570ebd8d61196e6aa6180f')
+    version('4.1.10', sha256='051c35ad9678002943f4a4f2ab532a6b44de86ca414751616f93e69f393f5373')
     version('3.3.3',  sha256='9f673b58d20ad23148040a100227b4f876458a9d9aee0f0d84a5f0eef209ced5')
     version('3.3.2',  sha256='b1cc2e109ba602ea71bccefaa3c4a06e7ab1330db9ce6c08db89cfde497b8ab8')
     version('3.3.1',  sha256='f8f4bea7de991a518a0371b4c70b19e492aa9a0d3e6715eff9437f420b0cdb45')
@@ -40,9 +39,15 @@ class Pfunit(CMakePackage):
 
     depends_on('python@2.7:', type=('build', 'run'))  # python3 too!
     depends_on('mpi', when='+mpi')
+    depends_on('m4', when='@4.1.5:', type='build')
 
+    conflicts("%gcc@:8.3.9", when="@4.0.0:", msg='Older versions of GCC do '
+              'not support the Fortran 2008 features required by new pFUnit.')
+    # See https://github.com/Goddard-Fortran-Ecosystem/pFUnit/pull/179
+    conflicts("+shared", when="@4.0.0:")
     conflicts("use_comm_world", when="~mpi")
-    patch("mpi-test.patch", when="+use_comm_world")
+    conflicts('+mpi', when='@:3.99.99 %gcc@10.0.0:')
+    patch("mpi-test.patch", when="@:3.99.99 +use_comm_world")
 
     def patch(self):
         # The package tries to put .mod files in directory ./mod;
@@ -50,6 +55,16 @@ def patch(self):
         for file in glob.glob('*/CMakeLists.txt'):
             filter_file(r'.*/mod($|[^\w].*)', '', file)
 
+    def url_for_version(self, version):
+        # Version 4 uses a different URL syntax than previous versions
+        url_base = "https://github.com/Goddard-Fortran-Ecosystem/pFUnit"
+        if version >= Version('4'):
+            url = url_base + "/releases/download/v{0}/pFUnit-{0}.tar"
+        else:
+            url = url_base + "/archive/{0}.tar.gz"
+
+        return url.format(version.dotted)
+
     def cmake_args(self):
         spec = self.spec
         args = [
@@ -60,11 +75,15 @@ def cmake_args(self):
             '-DOPENMP=%s' % ('YES' if '+openmp' in spec else 'NO'),
             '-DMAX_RANK=%s' % spec.variants['max_array_rank'].value]
 
+        if spec.satisfies('@4.0.0:'):
+            args.append('-DSKIP_MPI=%s' % ('YES' if '~mpi' in spec else 'NO'))
+        else:
+            args.append('-DMPI=%s' % ('YES' if '+mpi' in spec else 'NO'))
+
         if spec.satisfies('+mpi'):
-            args.extend(['-DMPI=YES', '-DMPI_USE_MPIEXEC=YES',
+            args.extend(['-DMPI_USE_MPIEXEC=YES',
                          '-DCMAKE_Fortran_COMPILER=%s' % spec['mpi'].mpifc])
-        else:
-            args.append('-DMPI=NO')
+
         return args
 
     def check(self):
-- 
GitLab