summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAdam J. Stewart <ajstewart426@gmail.com>2020-09-03 17:30:39 -0500
committerGitHub <noreply@github.com>2020-09-03 17:30:39 -0500
commit7728b0737bf408758f9e70d4a128ee4e1c478994 (patch)
tree06216d16015be45202168297ba5fc6144b369f26 /lib
parentfab2622a71e5729fdd9fa90d5702250696bc9407 (diff)
downloadspack-7728b0737bf408758f9e70d4a128ee4e1c478994.tar.gz
spack-7728b0737bf408758f9e70d4a128ee4e1c478994.tar.bz2
spack-7728b0737bf408758f9e70d4a128ee4e1c478994.tar.xz
spack-7728b0737bf408758f9e70d4a128ee4e1c478994.zip
Add new MavenPackage build system base class (#18185)
* Add new MavenPackage build system base class * Fix flake8 and doc tests * More specific regex * Java 8 required for these packages
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/docs/build_systems.rst1
-rw-r--r--lib/spack/docs/build_systems/mavenpackage.rst84
-rw-r--r--lib/spack/spack/build_systems/maven.py55
-rw-r--r--lib/spack/spack/cmd/create.py13
-rw-r--r--lib/spack/spack/pkgkit.py1
-rw-r--r--lib/spack/spack/test/build_system_guess.py1
6 files changed, 155 insertions, 0 deletions
diff --git a/lib/spack/docs/build_systems.rst b/lib/spack/docs/build_systems.rst
index a68dd99911..84c608077f 100644
--- a/lib/spack/docs/build_systems.rst
+++ b/lib/spack/docs/build_systems.rst
@@ -29,6 +29,7 @@ on these ideas for each distinct build system that Spack supports:
:maxdepth: 1
:caption: Make-incompatible
+ build_systems/mavenpackage
build_systems/sconspackage
build_systems/wafpackage
diff --git a/lib/spack/docs/build_systems/mavenpackage.rst b/lib/spack/docs/build_systems/mavenpackage.rst
new file mode 100644
index 0000000000..e8a8a1b86c
--- /dev/null
+++ b/lib/spack/docs/build_systems/mavenpackage.rst
@@ -0,0 +1,84 @@
+.. Copyright 2013-2020 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)
+
+.. _mavenpackage:
+
+------------
+MavenPackage
+------------
+
+Apache Maven is a general-purpose build system that does not rely
+on Makefiles to build software. It is designed for building and
+managing and Java-based project.
+
+^^^^^^
+Phases
+^^^^^^
+
+The ``MavenPackage`` base class comes with the following phases:
+
+#. ``build`` - compile code and package into a JAR file
+#. ``install`` - copy to installation prefix
+
+By default, these phases run:
+
+.. code-block:: console
+
+ $ mvn package
+ $ install . <prefix>
+
+
+^^^^^^^^^^^^^^^
+Important files
+^^^^^^^^^^^^^^^
+
+Maven packages can be identified by the presence of a ``pom.xml`` file.
+This file lists dependencies and other metadata about the project.
+There may also be configuration files in the ``.mvn`` directory.
+
+^^^^^^^^^^^^^^^^^^^^^^^^^
+Build system dependencies
+^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Maven requires the ``mvn`` executable to build the project. It also
+requires Java at both build- and run-time. Because of this, the base
+class automatically adds the following dependencies:
+
+.. code-block:: python
+
+ depends_on('java', type=('build', 'run'))
+ depends_on('maven', type='build')
+
+
+In the ``pom.xml`` file, you may see sections like:
+
+.. code-block:: xml
+
+ <requireJavaVersion>
+ <version>[1.7,)</version>
+ </requireJavaVersion>
+ <requireMavenVersion>
+ <version>[3.5.4,)</version>
+ </requireMavenVersion>
+
+
+This specifies the versions of Java and Maven that are required to
+build the package. See
+https://docs.oracle.com/middleware/1212/core/MAVEN/maven_version.htm#MAVEN402
+for a description of this version range syntax. In this case, you
+should add:
+
+.. code-block:: python
+
+ depends_on('java@7:', type='build')
+ depends_on('maven@3.5.4:', type='build')
+
+
+^^^^^^^^^^^^^^^^^^^^^^
+External documentation
+^^^^^^^^^^^^^^^^^^^^^^
+
+For more information on the Maven build system, see:
+https://maven.apache.org/index.html
diff --git a/lib/spack/spack/build_systems/maven.py b/lib/spack/spack/build_systems/maven.py
new file mode 100644
index 0000000000..c7faaf2014
--- /dev/null
+++ b/lib/spack/spack/build_systems/maven.py
@@ -0,0 +1,55 @@
+# Copyright 2013-2020 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 llnl.util.filesystem import install_tree, working_dir
+from spack.directives import depends_on
+from spack.package import PackageBase, run_after
+from spack.util.executable import which
+
+
+class MavenPackage(PackageBase):
+ """Specialized class for packages that are built using the
+ Maven build system. See https://maven.apache.org/index.html
+ for more information.
+
+ This class provides the following phases that can be overridden:
+
+ * build
+ * install
+ """
+ # Default phases
+ phases = ['build', 'install']
+
+ # To be used in UI queries that require to know which
+ # build-system class we are using
+ build_system_class = 'MavenPackage'
+
+ depends_on('java', type=('build', 'run'))
+ depends_on('maven', type='build')
+
+ @property
+ def build_directory(self):
+ """The directory containing the ``pom.xml`` file."""
+ return self.stage.source_path
+
+ def build(self, spec, prefix):
+ """Compile code and package into a JAR file."""
+
+ with working_dir(self.build_directory):
+ mvn = which('mvn')
+ if self.run_tests:
+ mvn('verify')
+ else:
+ mvn('package', '-DskipTests')
+
+ def install(self, spec, prefix):
+ """Copy to installation prefix."""
+
+ with working_dir(self.build_directory):
+ install_tree('.', prefix)
+
+ # Check that self.prefix is there after installation
+ run_after('install')(PackageBase.sanity_check_prefix)
diff --git a/lib/spack/spack/cmd/create.py b/lib/spack/spack/cmd/create.py
index 57d4bd7ded..a31b9537b6 100644
--- a/lib/spack/spack/cmd/create.py
+++ b/lib/spack/spack/cmd/create.py
@@ -204,6 +204,17 @@ class QMakePackageTemplate(PackageTemplate):
return args"""
+class MavenPackageTemplate(PackageTemplate):
+ """Provides appropriate overrides for Maven-based packages"""
+
+ base_class_name = 'MavenPackage'
+
+ body_def = """\
+ def build(self, spec, prefix):
+ # FIXME: If not needed delete this function
+ pass"""
+
+
class SconsPackageTemplate(PackageTemplate):
"""Provides appropriate overrides for SCons-based packages"""
@@ -430,6 +441,7 @@ templates = {
'cmake': CMakePackageTemplate,
'bundle': BundlePackageTemplate,
'qmake': QMakePackageTemplate,
+ 'maven': MavenPackageTemplate,
'scons': SconsPackageTemplate,
'waf': WafPackageTemplate,
'bazel': BazelPackageTemplate,
@@ -515,6 +527,7 @@ class BuildSystemGuesser:
(r'/configure$', 'autotools'),
(r'/configure\.(in|ac)$', 'autoreconf'),
(r'/Makefile\.am$', 'autoreconf'),
+ (r'/pom\.xml$', 'maven'),
(r'/SConstruct$', 'scons'),
(r'/waf$', 'waf'),
(r'/setup\.py$', 'python'),
diff --git a/lib/spack/spack/pkgkit.py b/lib/spack/spack/pkgkit.py
index 5ffec6caef..ac0a7eee0d 100644
--- a/lib/spack/spack/pkgkit.py
+++ b/lib/spack/spack/pkgkit.py
@@ -21,6 +21,7 @@ from spack.build_systems.autotools import AutotoolsPackage
from spack.build_systems.cmake import CMakePackage
from spack.build_systems.cuda import CudaPackage
from spack.build_systems.qmake import QMakePackage
+from spack.build_systems.maven import MavenPackage
from spack.build_systems.scons import SConsPackage
from spack.build_systems.waf import WafPackage
from spack.build_systems.octave import OctavePackage
diff --git a/lib/spack/spack/test/build_system_guess.py b/lib/spack/spack/test/build_system_guess.py
index 64b37e546e..6c2e3c6be5 100644
--- a/lib/spack/spack/test/build_system_guess.py
+++ b/lib/spack/spack/test/build_system_guess.py
@@ -16,6 +16,7 @@ import spack.stage
('configure', 'autotools'),
('CMakeLists.txt', 'cmake'),
('project.pro', 'qmake'),
+ ('pom.xml', 'maven'),
('SConstruct', 'scons'),
('waf', 'waf'),
('setup.py', 'python'),