Skip to content

Allow packages to set default variants in dependencies #16909

@mwkrentel

Description

@mwkrentel

This is a request for a new feature and discussion.

I'd like to allow packages to set the preferences (defaults) for
variants in their dependency packages and do so from their
package.py file. Of course, this can be done now in packages.yaml
or the command line, but allowing this in package.py has some
advantages.

For example, my project (hpctoolkit) depends on libunwind, and
libunwind has a variant xz to support xz/lzma compressed symbol
tables, with default False. Of course, hpctoolkit will run either
way, but normally we prefer with xz on. Right now, what I have is:

  depends_on('[email protected]: +xz')

But this is a hard constraint. You can't turn off xz without
editing package.py. I'd rather turn this into a soft preference
with something like:

  depends_on('[email protected]:', prefer='+xz')

That way, the default for libunwind remains False, but if you're
building libunwind as part of hpctoolkit, then the default is True.
Of course, I can't go around and reset the defaults for all of our
dependency packages just to suit my needs.

So why not use packages.yaml? We could, and in fact, we do
distribute a packages.yaml file, mostly as a reference point. But
the file is long and it's tedious to review it for every new machine.

Right now, I'm confronted with a dilemma: I can leave off +xz and
make everyone use our packages.yaml file, or else they won't build
hpctoolkit the way we want. Or, I can require +xz which is
heavy-handed and inflexible. With this feature, I can make the
one-button spack install hpctoolkit almost always produce the right
spec, but still allow flexibility when needed.

Theoretically, I could add an xz variant to hpctoolkit and set the
default there, but that's really awkward and adds a duplicate variant,
just because the default doesn't suit my needs.

Note: the precedence of prefer='+xz' should be next to last. It
should override the default in the dependency package, but you should
be able to override it from packages.yaml or the command line.

@becker33 Is this possible? A good idea?

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureA feature is missing in Spack

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions