summaryrefslogtreecommitdiff
path: root/lib/spack/spack/cmd/dev_build.py
blob: fbd8a78f09258420915e3977ff1ef5e7b1c25700 (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
152
# 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 os
import sys

import llnl.util.tty as tty

import spack.cmd
import spack.config
import spack.repo
from spack.cmd.common import arguments

description = "developer build: build from code in current working directory"
section = "build"
level = "long"


def setup_parser(subparser):
    arguments.add_common_arguments(subparser, ["jobs"])
    subparser.add_argument(
        "-d",
        "--source-path",
        dest="source_path",
        default=None,
        help="path to source directory (defaults to the current directory)",
    )
    subparser.add_argument(
        "-i",
        "--ignore-dependencies",
        action="store_true",
        dest="ignore_deps",
        help="do not try to install dependencies of requested packages",
    )
    arguments.add_common_arguments(subparser, ["no_checksum", "deprecated"])
    subparser.add_argument(
        "--keep-prefix",
        action="store_true",
        help="do not remove the install prefix if installation fails",
    )
    subparser.add_argument(
        "--skip-patch", action="store_true", help="skip patching for the developer build"
    )
    subparser.add_argument(
        "-q",
        "--quiet",
        action="store_true",
        dest="quiet",
        help="do not display verbose build output while installing",
    )
    subparser.add_argument(
        "--drop-in",
        type=str,
        dest="shell",
        default=None,
        help="drop into a build environment in a new shell, e.g., bash",
    )
    subparser.add_argument(
        "--test",
        default=None,
        choices=["root", "all"],
        help="run tests on only root packages or all packages",
    )
    arguments.add_common_arguments(subparser, ["spec"])

    stop_group = subparser.add_mutually_exclusive_group()
    stop_group.add_argument(
        "-b",
        "--before",
        type=str,
        dest="before",
        default=None,
        help="phase to stop before when installing (default None)",
    )
    stop_group.add_argument(
        "-u",
        "--until",
        type=str,
        dest="until",
        default=None,
        help="phase to stop after when installing (default None)",
    )

    cd_group = subparser.add_mutually_exclusive_group()
    arguments.add_common_arguments(cd_group, ["clean", "dirty"])

    spack.cmd.common.arguments.add_concretizer_args(subparser)


def dev_build(self, args):
    if not args.spec:
        tty.die("spack dev-build requires a package spec argument.")

    specs = spack.cmd.parse_specs(args.spec)
    if len(specs) > 1:
        tty.die("spack dev-build only takes one spec.")

    spec = specs[0]
    if not spack.repo.PATH.exists(spec.name):
        raise spack.repo.UnknownPackageError(spec.name)

    if not spec.versions.concrete_range_as_version:
        tty.die(
            "spack dev-build spec must have a single, concrete version. "
            "Did you forget a package version number?"
        )

    source_path = args.source_path
    if source_path is None:
        source_path = os.getcwd()
    source_path = os.path.abspath(source_path)

    # Forces the build to run out of the source directory.
    spec.constrain("dev_path=%s" % source_path)
    spec.concretize()

    if spec.installed:
        tty.error("Already installed in %s" % spec.prefix)
        tty.msg("Uninstall or try adding a version suffix for this dev build.")
        sys.exit(1)

    # disable checksumming if requested
    if args.no_checksum:
        spack.config.set("config:checksum", False, scope="command_line")

    if args.deprecated:
        spack.config.set("config:deprecated", True, scope="command_line")

    tests = False
    if args.test == "all":
        tests = True
    elif args.test == "root":
        tests = [spec.name for spec in specs]

    spec.package.do_install(
        tests=tests,
        make_jobs=args.jobs,
        keep_prefix=args.keep_prefix,
        install_deps=not args.ignore_deps,
        verbose=not args.quiet,
        dirty=args.dirty,
        stop_before=args.before,
        skip_patch=args.skip_patch,
        stop_at=args.until,
    )

    # drop into the build environment of the package?
    if args.shell is not None:
        spack.build_environment.setup_package(spec.package, dirty=False)
        os.execvp(args.shell, [args.shell])