Repository: spack/spack

Issue:
new package: wps
depends on #18398
Once WRF has passed the tests and code reviews - I'll update this one accordingly.


Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/wps/package.py b/var/spack/repos/builtin/packages/wps/package.py
new file mode 100644
--- /dev/null
+++ b/var/spack/repos/builtin/packages/wps/package.py
@@ -0,0 +1,102 @@
+# Copyright 2013-2018 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack import *
+
+import glob
+import tempfile
+
+
+class Wps(Package):
+    """The Weather Research and Forecasting Pre-Processing System (WPS)
+    """
+
+    homepage = "https://www.mmm.ucar.edu/weather-research-and-forecasting-model"
+    url      = "https://github.com/wrf-model/WPS/archive/v4.2.tar.gz"
+    maintainers = ['MichaelLaufer']
+
+    version('4.2', sha256='3e175d033355d3e7638be75bc7c0bc0de6da299ebd175a9bbc1b7a121acd0168')
+
+    # Serial variant recommended in WRF/WPS docs
+    variant('build_type', default='serial',
+            values=('serial', 'serial_NO_GRIB2', 'dmpar', 'dmpar_NO_GRIB2'))
+
+    # These patches deal with netcdf & netcdf-fortran being two diff things
+    patch('patches/4.2/arch.Config.pl.patch', when='@4.2')
+    patch('patches/4.2/arch.configure.defaults.patch', when='@4.2')
+    patch('patches/4.2/configure.patch', when='@4.2')
+    patch('patches/4.2/preamble.patch', when='@4.2')
+
+    # According to:
+    # http://www2.mmm.ucar.edu/wrf/users/docs/user_guide_v4/v4.0/users_guide_chap2.html#_Required_Compilers_and_1
+    # Section: "Required/Optional Libraries to Download"
+    depends_on('wrf')
+    depends_on('netcdf-c')
+    depends_on('netcdf-fortran')
+    # build script use csh
+    depends_on('tcsh', type=('build'))
+
+    # this fixes that for csh install scripts
+    depends_on('time', type=('build'))
+    depends_on('m4', type='build')
+    depends_on('libtool', type='build')
+    depends_on('jasper')
+    phases = ['configure', 'build', 'install']
+
+    def setup_build_environment(self, env):
+        env.set('WRF_DIR', self.spec['wrf'].prefix)
+        env.set('NETCDF', self.spec['netcdf-c'].prefix)
+        # This gets used via the applied patch files
+        env.set('NETCDFF', self.spec['netcdf-fortran'].prefix)
+        env.set('JASPERINC', self.spec['jasper'].prefix.include)
+        env.set('JASPERLIB', self.spec['jasper'].prefix.lib)
+
+        if self.spec.satisfies('%gcc@10:'):
+            args = '-w -O2 -fallow-argument-mismatch -fallow-invalid-boz'
+            env.set('FCFLAGS', args)
+            env.set('FFLAGS', args)
+
+    def patch(self):
+        # Let's not assume csh is intalled in bin
+        files = glob.glob('*.csh')
+
+        filter_file('^#!/bin/csh -f', '#!/usr/bin/env csh', *files)
+        filter_file('^#!/bin/csh', '#!/usr/bin/env csh', *files)
+
+    def configure(self, spec, prefix):
+        build_opts = {"gcc":   {"serial": '1',
+                                "serial_NO_GRIB2": '2',
+                                "dmpar":           '3',
+                                "dmpar_NO_GRIB2":  '4'},
+                      "intel": {"serial":          '17',
+                                "serial_NO_GRIB2": '18',
+                                "dmpar":           '19',
+                                "dmpar_NO_GRIB2":  '20'},
+                      "pgi":   {"serial":          '5',
+                                "serial_NO_GRIB2": '6',
+                                "dmpar":           '7',
+                                "dmpar_NO_GRIB2":  '8'},
+                      }
+
+        try:
+            compiler_opts = build_opts[self.spec.compiler.name]
+        except KeyError:
+            raise InstallError("Compiler not recognized nor supported.")
+
+        # Spack already makes sure that the variant value is part of the set.
+        build_type = compiler_opts[spec.variants['build_type'].value]
+
+        with tempfile.TemporaryFile(mode='w') as fp:
+            fp.write(build_type + '\n')
+            fp.seek(0)
+            Executable('./configure')(input=fp)
+
+    def build(self, spec, prefix):
+        csh = which('csh')
+        csh('./compile')
+
+    def install(self, spec, prefix):
+        # Copy all of WPS staging dir to install dir
+        install_tree('.', prefix)
diff --git a/var/spack/repos/builtin/packages/wrf/package.py b/var/spack/repos/builtin/packages/wrf/package.py
--- a/var/spack/repos/builtin/packages/wrf/package.py
+++ b/var/spack/repos/builtin/packages/wrf/package.py
@@ -17,6 +17,7 @@ class Wrf(Package):
 
     homepage = "https://www.mmm.ucar.edu/weather-research-and-forecasting-model"
     url      = "https://github.com/wrf-model/WRF/archive/v4.2.tar.gz"
+    maintainers = ['MichaelLaufer']
 
     version('4.2', sha256='c39a1464fd5c439134bbd39be632f7ce1afd9a82ad726737e37228c6a3d74706')
     version('4.0', sha256='a5b072492746f96a926badda7e6b44cb0af26695afdd6c029a94de5e1e5eec73')
@@ -61,7 +62,7 @@ class Wrf(Package):
     # http://www2.mmm.ucar.edu/wrf/users/docs/user_guide_v4/v4.0/users_guide_chap2.html#_Required_Compilers_and_1
     # Section: "Required/Optional Libraries to Download"
     depends_on('parallel-netcdf', when='+pnetcdf')
-    depends_on('netcdf-c+parallel-netcdf')
+    depends_on('netcdf-c')
     depends_on('netcdf-fortran')
     depends_on('jasper')
     depends_on('libpng')
@@ -74,27 +75,24 @@ class Wrf(Package):
     # time is not installed on all systems b/c bash provides it
     # this fixes that for csh install scripts
     depends_on('time', type=('build'))
-
-    depends_on('autoconf', type='build')
-    depends_on('automake', type='build')
     depends_on('m4', type='build')
     depends_on('libtool', type='build')
     phases = ['configure', 'build', 'install']
 
-    def setup_build_environment(self, spack_env):
-        spack_env.set('NETCDF', self.spec['netcdf-c'].prefix)
+    def setup_build_environment(self, env):
+        env.set('NETCDF', self.spec['netcdf-c'].prefix)
         if '+pnetcdf' in self.spec:
-            spack_env.set('PNETCDF', self.spec['parallel-netcdf'].prefix)
+            env.set('PNETCDF', self.spec['parallel-netcdf'].prefix)
         # This gets used via the applied patch files
-        spack_env.set('NETCDFF', self.spec['netcdf-fortran'].prefix)
-        spack_env.set('PHDF5', self.spec['hdf5'].prefix)
-        spack_env.set('JASPERINC', self.spec['jasper'].prefix.include)
-        spack_env.set('JASPERLIB', self.spec['jasper'].prefix.lib)
+        env.set('NETCDFF', self.spec['netcdf-fortran'].prefix)
+        env.set('PHDF5', self.spec['hdf5'].prefix)
+        env.set('JASPERINC', self.spec['jasper'].prefix.include)
+        env.set('JASPERLIB', self.spec['jasper'].prefix.lib)
 
         if self.spec.satisfies('%gcc@10:'):
             args = '-w -O2 -fallow-argument-mismatch -fallow-invalid-boz'
-            spack_env.set('FCFLAGS', args)
-            spack_env.set('FFLAGS', args)
+            env.set('FCFLAGS', args)
+            env.set('FFLAGS', args)
 
     def patch(self):
         # Let's not assume csh is intalled in bin
@@ -144,7 +142,5 @@ def build(self, spec, prefix):
             spec.variants['compile_type'].value)
 
     def install(self, spec, prefix):
-        mkdir(prefix.bin)
-        install('./main/wrf.exe', prefix.bin)
-        install('./main/ndown.exe', prefix.bin)
-        install('./main/real.exe', prefix.bin)
+        # Save all install files as many are needed for WPS and WRF runs
+        install_tree('.', prefix)


Test patch: