From 259a1d926861a2818e961b0172b703ac9222ba95 Mon Sep 17 00:00:00 2001 From: Philip Sakievich Date: Thu, 7 Nov 2024 21:59:21 -0700 Subject: [PATCH] Make dev-build compatible with spack develop --- lib/spack/spack/cmd/dev_build.py | 50 ++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/lib/spack/spack/cmd/dev_build.py b/lib/spack/spack/cmd/dev_build.py index 696c16f4dcd..57a20865864 100644 --- a/lib/spack/spack/cmd/dev_build.py +++ b/lib/spack/spack/cmd/dev_build.py @@ -12,6 +12,7 @@ import spack.cmd import spack.cmd.common.arguments import spack.config +import spack.environment as ev import spack.repo from spack.cmd.common import arguments from spack.installer import PackageInstaller @@ -102,29 +103,40 @@ def dev_build(self, args): 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?" - ) + env = ev.active_environment() + if env: + matches = env.all_matching_specs(spec) + dev_matches = [m for m in matches if m.is_develop] + if len(dev_matches) > 1: + tty.die("Too many matching develop specs in the active environment") + elif len(dev_matches) < 1: + tty.die("No matching develop specs found in the active environment") + else: + spec = dev_matches[0] + else: + 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) + 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() + # 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) + 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") + # disable checksumming if requested + if args.no_checksum: + spack.config.set("config:checksum", False, scope="command_line") tests = False if args.test == "all":