summaryrefslogtreecommitdiff
path: root/lib/spack/spack/build_systems/waf.py
blob: 0fd78d48da7ea7cb37242f3a08518c45264e1ba2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Copyright 2013-2024 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)
import inspect

from llnl.util.filesystem import working_dir

import spack.builder
import spack.package_base
from spack.directives import build_system, depends_on

from ._checks import BaseBuilder, execute_build_time_tests, execute_install_time_tests


class WafPackage(spack.package_base.PackageBase):
    """Specialized class for packages that are built using the
    Waf build system. See https://waf.io/book/ for more information.
    """

    # To be used in UI queries that require to know which
    # build-system class we are using
    build_system_class = "WafPackage"
    #: Legacy buildsystem attribute used to deserialize and install old specs
    legacy_buildsystem = "waf"

    build_system("waf")
    # Much like AutotoolsPackage does not require automake and autoconf
    # to build, WafPackage does not require waf to build. It only requires
    # python to run the waf build script.
    depends_on("python@2.5:", type="build", when="build_system=waf")


@spack.builder.builder("waf")
class WafBuilder(BaseBuilder):
    """The WAF builder provides the following phases that can be overridden:

    * configure
    * build
    * install

    These are all standard Waf commands and can be found by running:

    .. code-block:: console

       $ python waf --help

    Each phase provides a function <phase> that runs:

    .. code-block:: console

       $ python waf -j<jobs> <phase>

    where <jobs> is the number of parallel jobs to build with. Each phase
    also has a <phase_args> function that can pass arguments to this call.
    All of these functions are empty except for the ``configure_args``
    function, which passes ``--prefix=/path/to/installation/prefix``.
    """

    phases = ("configure", "build", "install")

    #: Names associated with package methods in the old build-system format
    legacy_methods = (
        "build_test",
        "install_test",
        "configure_args",
        "build_args",
        "install_args",
        "build_test",
        "install_test",
    )

    #: Names associated with package attributes in the old build-system format
    legacy_attributes = (
        "build_time_test_callbacks",
        "build_directory",
        "install_time_test_callbacks",
    )

    # Callback names for build-time test
    build_time_test_callbacks = ["build_test"]

    # Callback names for install-time test
    install_time_test_callbacks = ["install_test"]

    @property
    def build_directory(self):
        """The directory containing the ``waf`` file."""
        return self.stage.source_path

    def python(self, *args, **kwargs):
        """The python ``Executable``."""
        inspect.getmodule(self.pkg).python(*args, **kwargs)

    def waf(self, *args, **kwargs):
        """Runs the waf ``Executable``."""
        jobs = inspect.getmodule(self.pkg).make_jobs

        with working_dir(self.build_directory):
            self.python("waf", "-j{0}".format(jobs), *args, **kwargs)

    def configure(self, pkg, spec, prefix):
        """Configures the project."""
        args = ["--prefix={0}".format(self.pkg.prefix)]
        args += self.configure_args()

        self.waf("configure", *args)

    def configure_args(self):
        """Arguments to pass to configure."""
        return []

    def build(self, pkg, spec, prefix):
        """Executes the build."""
        args = self.build_args()

        self.waf("build", *args)

    def build_args(self):
        """Arguments to pass to build."""
        return []

    def install(self, pkg, spec, prefix):
        """Installs the targets on the system."""
        args = self.install_args()

        self.waf("install", *args)

    def install_args(self):
        """Arguments to pass to install."""
        return []

    def build_test(self):
        """Run unit tests after build.

        By default, does nothing. Override this if you want to
        add package-specific tests.
        """
        pass

    spack.builder.run_after("build")(execute_build_time_tests)

    def install_test(self):
        """Run unit tests after install.

        By default, does nothing. Override this if you want to
        add package-specific tests.
        """
        pass

    spack.builder.run_after("install")(execute_install_time_tests)