summaryrefslogtreecommitdiff
path: root/lib/spack/spack/build_systems/scons.py
blob: a8adee8959a80084319e52e6ae43bfeb1f71e15c (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
# Copyright 2013-2023 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

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

from ._checks import BaseBuilder, execute_build_time_tests


class SConsPackage(spack.package_base.PackageBase):
    """Specialized class for packages built using SCons.

    See http://scons.org/documentation.html for more information.
    """

    #: To be used in UI queries that require to know which
    #: build-system class we are using
    build_system_class = "SConsPackage"

    #: Legacy buildsystem attribute used to deserialize and install old specs
    legacy_buildsystem = "scons"

    build_system("scons")

    depends_on("scons", type="build", when="build_system=scons")


@spack.builder.builder("scons")
class SConsBuilder(BaseBuilder):
    """The Scons builder provides the following phases that can be overridden:

    1. :py:meth:`~.SConsBuilder.build`
    2. :py:meth:`~.SConsBuilder.install`

    Packages that use SCons as a build system are less uniform than packages that use
    other build systems. Developers can add custom subcommands or variables that
    control the build. You will likely need to override
    :py:meth:`~.SConsBuilder.build_args` to pass the appropriate variables.
    """

    #: Phases of a SCons package
    phases = ("build", "install")

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

    #: Same as legacy_methods, but the signature is different
    legacy_long_methods = ("build_args", "install_args")

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

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

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

    def build(self, pkg, spec, prefix):
        """Build the package."""
        args = self.build_args(spec, prefix)
        inspect.getmodule(self.pkg).scons(*args)

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

    def install(self, pkg, spec, prefix):
        """Install the package."""
        args = self.install_args(spec, prefix)

        inspect.getmodule(self.pkg).scons("install", *args)

    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)