Skip to content

Commit

Permalink
redo of FNALssi #162
Browse files Browse the repository at this point in the history
  • Loading branch information
marcmengel committed Sep 14, 2023
1 parent b483b75 commit f92ed6e
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions lib/spack/spack/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def _execute_conflicts(pkg):


@directive(("dependencies"))
def depends_on(spec, when=None, type=default_deptype, patches=None):
def depends_on(spec, when=None, type=default_deptype, patches=None, version_translator=None):
"""Creates a dict of deps with specs defining when they apply.
Args:
Expand All @@ -535,6 +535,12 @@ def depends_on(spec, when=None, type=default_deptype, patches=None):
type (str or tuple): str or tuple of legal Spack deptypes
patches (typing.Callable or list): single result of ``patch()`` directive, a
``str`` to be passed to ``patch``, or a list of these
version_translator (function): function to generate a version-ish for spec
from a parent version. If provided, this function will be called for
each version defined for pkg, and any non-vacuous result will be used to
add a dependency with that version as an extra constraint on spec.
Examples of suitable functions: ``spack.version.Version`` (NOP) or
``lambda v: v.up_to(2)`` (minor version match)
This directive is to be used inside a Package definition to declare
that the package requires other packages to be built first.
Expand All @@ -543,7 +549,29 @@ def depends_on(spec, when=None, type=default_deptype, patches=None):
"""

def _execute_depends_on(pkg):
_depends_on(pkg, spec, when=when, type=type, patches=patches)
executed = False
if version_translator:
# Produce a different dependency for every package version
# for which version_translator returns an answer that alters
# the spec.
for pkg_version in pkg.versions:
version_ish = version_translator(pkg_version)
if version_ish is not None:
constrained_spec = spack.spec.Spec(spec)
if constrained_spec.constrain(f"@{version_ish}"):
_depends_on(
pkg,
constrained_spec,
when=f"@{pkg_version} {when}" if when else f"@{pkg_version}",
type=type,
patches=patches,
)
executed = True

# If we haven't already produced one or more version-specific
# dependencies, do the basic dependency for spec.
if not executed:
_depends_on(pkg, spec, when=when, type=type, patches=patches)

return _execute_depends_on

Expand Down

0 comments on commit f92ed6e

Please sign in to comment.