Skip to content

Context variables referencing variant values and other context vars #1306

@minrk

Description

@minrk

I'm looking at updating the fairly complex petsc recipe, and one thing that's been super useful for simplifying the recipe is defining variables that reference variant/other context variables. I'll need this less in a v1 recipe with the nicer conditionals, but it would still be useful.

Is there any way to define a variable that references another variable in a v1 recipe?

For example, the build string prefix is cuda${{ cuda_major }}_mpi${{ mpi }}_ if cuda is used, and just mpi${{ mpi }}_ if not. This string needs to be computed more than once, because it also goes in run_exports. Further, cuda_major is already a derivative value, since cuda_compiler_version contains a minor version that we need to exclude.

If this worked:

context:
    cuda_major: ${{ cuda_compiler_version | split('.') | first }}
    build_prefix:
        if: cuda_compiler_version != "None"
        then: cuda${{ cuda_major }}_mpi${{ mpi }}
        else: mpi${{ mpi }}

I think I could get pretty far. That would ideally mean templates in context vars where:

  1. context vars can be templates
  2. templates can reference variant values
  3. templates can reference context vars that are defined before them

I know I can recompute the whole thing every time it is used, but it is really a lot simpler and results in a clearer, more reliable, more likely correct recipe to compute these variables just once.

Is there any way to create variables that are derived from other context variables or variant values?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions