From 2f0f21f7328e72788c75bbd93dec9d1979935ac1 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Mon, 20 Jan 2020 13:17:40 +0100
Subject: [PATCH] Added parameter --insitu.

---
 ogscm/building_blocks/__init__.py |   1 +
 ogscm/building_blocks/paraview.py | 119 ++++++++++++++++++++++++++++++
 ogscm/cli.py                      |  31 ++++++--
 ogscm/cli_args.py                 |   4 +
 4 files changed, 147 insertions(+), 8 deletions(-)
 create mode 100644 ogscm/building_blocks/paraview.py

diff --git a/ogscm/building_blocks/__init__.py b/ogscm/building_blocks/__init__.py
index 11852c2..57a7b67 100644
--- a/ogscm/building_blocks/__init__.py
+++ b/ogscm/building_blocks/__init__.py
@@ -10,6 +10,7 @@ from ogscm.building_blocks.lmod import lmod
 from ogscm.building_blocks.ogs import ogs
 from ogscm.building_blocks.ogs_base import ogs_base
 from ogscm.building_blocks.osu_benchmarks import osu_benchmarks
+from ogscm.building_blocks.paraview import paraview
 from ogscm.building_blocks.petsc import petsc
 from ogscm.building_blocks.pm_conan import pm_conan
 from ogscm.building_blocks.pm_easybuild import pm_easybuild
diff --git a/ogscm/building_blocks/paraview.py b/ogscm/building_blocks/paraview.py
new file mode 100644
index 0000000..7ce336e
--- /dev/null
+++ b/ogscm/building_blocks/paraview.py
@@ -0,0 +1,119 @@
+# pylint: disable=invalid-name, too-few-public-methods
+# pylint: disable=too-many-instance-attributes
+"""paraview building block"""
+
+from __future__ import absolute_import
+from __future__ import unicode_literals
+from __future__ import print_function
+
+import re
+import os
+import hpccm.templates.wget
+
+from hpccm.building_blocks.base import bb_base
+from hpccm.building_blocks.generic_cmake import generic_cmake
+from hpccm.building_blocks.packages import packages
+from hpccm.primitives.comment import comment
+from hpccm.primitives.copy import copy
+from hpccm.primitives.environment import environment
+from hpccm.toolchain import toolchain
+from hpccm.primitives.shell import shell
+
+
+class paraview(bb_base, hpccm.templates.CMakeBuild, hpccm.templates.ldconfig,
+          hpccm.templates.rm, hpccm.templates.tar, hpccm.templates.wget):
+    """The `paraview` building block downloads and installs the
+    [paraview](https://paraview.org/) component.
+
+    # Parameters
+
+    prefix: The top level installation location.  The default value
+    is `/usr/local/paraview`.
+
+    version: The version of paraview source to download.  The default
+    value is `master`.
+
+    # Examples
+
+    ```python
+    paraview()
+    ```
+
+    """
+    def __init__(self, **kwargs):
+        super(paraview, self).__init__(**kwargs)
+
+        self.__cmake_args = kwargs.get('cmake_args', [])
+        self.__edition = kwargs.get('CANONICAL')
+        self.__ospackages = kwargs.get('ospackages', [])
+        self.__parallel = kwargs.get('parallel', '$(nproc)')
+        self.__prefix = kwargs.get('prefix', '/usr/local/paraview')
+        self.__shared = kwargs.get('shared', True)
+        self.__toolchain = kwargs.get('toolchain', toolchain())
+        self.__version = kwargs.get('version', 'master')
+
+        # TODO:
+        if False:
+            match = re.match(r'(?P<major>\d+)\.(?P<minor>\d+)\.(?P<revision>\d+)',
+                             self.__version)
+            short_version = '{0}.{1}'.format(match.groupdict()['major'],
+                                             match.groupdict()['minor'])
+            self.__baseurl = kwargs.get(
+                'baseurl',
+                'https://www.paraview.org/files/release/{0}'.format(short_version))
+        self.__environment_variables = {}
+
+        self.__instructions()
+
+    def __instructions(self):
+        self += comment('paraview {}'.format(self.__version))
+
+        # if ubuntu:
+        self.__ospackages.append('ninja-build')
+        self += packages(ospackages=self.__ospackages)
+
+        self.__cmake_args.extend([
+            '-G Ninja',
+            '-D CMAKE_BUILD_TYPE=Release',
+            '-D PARAVIEW_BUILD_EDITION={}'.format(self.__edition)])
+        if not self.__shared:
+            self.__cmake_args.append('-D BUILD_SHARED_LIBS=OFF')
+        if self.__toolchain.CC == 'mpicc':
+            self.__cmake_args.append('-D PARAVIEW_USE_MPI=ON')
+
+        # TODO: Install dependencies for rendering editions (ospackages)
+
+        self += generic_cmake(branch = self.__version,
+                              cmake_opts=self.__cmake_args,
+                              directory='paraview-{}'.format(self.__version),
+                              prefix=self.__prefix,
+                              toolchain=self.__toolchain,
+                              recursive=True,
+                              repository='https://gitlab.kitware.com/paraview/paraview.git')
+        self.__environment_variables['ParaView_DIR'] = self.__prefix
+        # Set library path
+        if self.__shared:
+            libpath = os.path.join(self.__prefix, 'lib')
+            if self.ldconfig:
+                self += shell(commands=[self.ldcache_step(directory=libpath)])
+            else:
+                self.__environment_variables[
+                    'LD_LIBRARY_PATH'] = '{}:$LD_LIBRARY_PATH'.format(libpath)
+
+        self += environment(variables=self.__environment_variables)
+
+    def runtime(self, _from='0'):
+        if not self.__shared:
+            return str(comment('ParaView (empty)'))
+        instructions = []
+        instructions.append(comment('ParaView {}'.format(self.__version)))
+        instructions.append(
+            copy(_from=_from, src=self.__prefix, dest=self.__prefix))
+        if self.ldconfig:
+            libpath = os.path.join(self.__prefix, 'lib')
+            instructions.append(
+                shell(commands=[self.ldcache_step(directory=libpath)]))
+
+        instructions.append(
+            environment(variables=self.__environment_variables))
+        return '\n'.join(str(x) for x in instructions)
diff --git a/ogscm/cli.py b/ogscm/cli.py
index b56dacc..2a2980d 100644
--- a/ogscm/cli.py
+++ b/ogscm/cli.py
@@ -31,7 +31,8 @@ from ogscm.config import package_manager
 from ogscm.container_info import container_info
 from ogscm.version import __version__
 from ogscm.building_blocks import ccache, cppcheck, cvode, eigen, iwyy, \
-    jenkins_node, ogs_base, ogs, osu_benchmarks, petsc, pm_conan, vtk, pm_spack
+    jenkins_node, ogs_base, ogs, osu_benchmarks, petsc, pm_conan, vtk, \
+    pm_spack, paraview
 
 
 def main():  # pragma: no cover
@@ -121,6 +122,10 @@ def main():  # pragma: no cover
                                version=args.compiler_version)
             toolchain = compiler.toolchain
             Stage0 += compiler
+            # Upgrade stdc++ lib after installing new compiler
+            # https://stackoverflow.com/a/46613656/80480
+            if args.compiler == 'gcc' and args.compiler_version != None:
+                Stage0 += packages(apt=['libstdc++6'])
             if args.compiler == 'clang':
                 Stage0 += packages(
                     apt=[
@@ -284,13 +289,19 @@ def main():  # pragma: no cover
             Stage0 += boost(version='1.66.0')  # header only?
             Stage0 += environment(variables={'BOOST_ROOT': '/usr/local/boost'})
             Stage0 += eigen()
-            vtk_cmake_args = [
-                '-DVTK_Group_StandAlone=OFF', '-DVTK_Group_Rendering=OFF',
-                '-DModule_vtkIOXML=ON'
-            ]
-            Stage0 += vtk(cmake_args=vtk_cmake_args,
-                          toolchain=toolchain,
-                          ldconfig=True)
+            if args.insitu:
+                Stage0 += paraview(cmake_args=['-D PARAVIEW_USE_PYTHON=ON'],
+                                   edition='CATALYST',
+                                   ldconfig=True,
+                                   toolchain=toolchain)
+            else:
+                vtk_cmake_args = [
+                    '-DVTK_Group_StandAlone=OFF', '-DVTK_Group_Rendering=OFF',
+                    '-DModule_vtkIOXML=ON'
+                ]
+                Stage0 += vtk(cmake_args=vtk_cmake_args,
+                              toolchain=toolchain,
+                              ldconfig=True)
             if ompi != 'off':
                 Stage0 += petsc(version='3.11.3', ldconfig=True)
         if args.cvode:
@@ -319,6 +330,8 @@ def main():  # pragma: no cover
                 cmake_args.append('-DOGS_USE_CVODE=ON')
             if args.gui:
                 cmake_args.append('-DOGS_BUILD_GUI=ON')
+            if args.insitu:
+                cmake_args.append('-DOGS_INSITU=ON')
 
             if not scif_installed:
                 Stage0 += pip(packages=['scif'], pip='pip3')  # SCI-F
@@ -363,6 +376,8 @@ def main():  # pragma: no cover
                                src='/usr/local/bin/mpi_*',
                                dest='/usr/local/bin/')
             Stage1 += Stage0.runtime()
+            if args.compiler == 'gcc' and args.compiler_version != None:
+                Stage1 += packages(apt=['libstdc++6'])
             stages_string += "\n\n" + str(Stage1)
 
         # ---------------------------- recipe end -----------------------------
diff --git a/ogscm/cli_args.py b/ogscm/cli_args.py
index 3bdfb04..f9c8d58 100644
--- a/ogscm/cli_args.py
+++ b/ogscm/cli_args.py
@@ -170,6 +170,10 @@ class Cli_Args(argparse.ArgumentParser):
                                 dest='dev',
                                 action='store_true',
                                 help='Installs development tools (vim, gdb)')
+        switches_g.add_argument('--insitu',
+                                dest='insitu',
+                                action='store_true',
+                                help='Builds with insitu capabilities')
         maint_g = self.add_argument_group('Maintenance')
         maint_g.add_argument(
             '--clean',
-- 
GitLab