summaryrefslogtreecommitdiff
path: root/lib/spack/spack/build_systems/racket.py
blob: 7b37d85cf2ecabe198c2c50e314961fa59af7838 (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
# Copyright 2013-2021 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 os
from typing import Optional

import llnl.util.lang as lang
import llnl.util.tty as tty
from llnl.util.filesystem import working_dir

from spack.build_environment import SPACK_NO_PARALLEL_MAKE, determine_number_of_jobs
from spack.directives import extends
from spack.package_base import PackageBase
from spack.util.environment import env_flag
from spack.util.executable import Executable, ProcessError


class RacketPackage(PackageBase):
    """Specialized class for packages that are built using Racket's
    `raco pkg install` and `raco setup` commands.

    This class provides the following phases that can be overridden:

    * install
    * setup
    """

    #: Package name, version, and extension on PyPI
    maintainers = ["elfprince13"]

    # Default phases
    phases = ["install"]

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

    extends("racket")

    pkgs = False
    subdirectory = None  # type: Optional[str]
    racket_name = None  # type: Optional[str]
    parallel = True

    @lang.classproperty
    def homepage(cls):
        if cls.pkgs:
            return "https://pkgs.racket-lang.org/package/{0}".format(cls.racket_name)

    @property
    def build_directory(self):
        ret = os.getcwd()
        if self.subdirectory:
            ret = os.path.join(ret, self.subdirectory)
        return ret

    def install(self, spec, prefix):
        """Install everything from build directory."""
        raco = Executable("raco")
        with working_dir(self.build_directory):
            allow_parallel = self.parallel and (not env_flag(SPACK_NO_PARALLEL_MAKE))
            args = [
                "pkg",
                "install",
                "-t",
                "dir",
                "-n",
                self.racket_name,
                "--deps",
                "fail",
                "--ignore-implies",
                "--copy",
                "-i",
                "-j",
                str(determine_number_of_jobs(allow_parallel)),
                "--",
                os.getcwd(),
            ]
            try:
                raco(*args)
            except ProcessError:
                args.insert(-2, "--skip-installed")
                raco(*args)
                tty.warn(
                    (
                        "Racket package {0} was already installed, uninstalling via "
                        "Spack may make someone unhappy!"
                    ).format(self.racket_name)
                )