prefix-dev / rattler-build

rattler-build is a universal package builder for Windows, macOS and Linux
https://prefix-dev.github.io/rattler-build
BSD 3-Clause "New" or "Revised" License
185 stars 38 forks source link

variant is undefined when trying to evaluate it even though it's set in variant config #985

Open pavelzw opened 1 month ago

pavelzw commented 1 month ago
# yaml-language-server: $schema=https://raw.githubusercontent.com/prefix-dev/recipe-format/main/schema.json

context:
  name: my-package

recipe:
  name: ${{ name }}
  version: '1.0.0'

outputs:
  - package:
      name: ${{ name + '-' + variant }}
variant:
  - a
  - b
❯ rattler-build build -r recipe/recipe.yaml -m recipe/variants.yaml

 ╭─ Finding outputs from recipe
 │
 ╰─────────────────── (took 0 seconds)
Error:   × Failed to parse recipe

Error:   × Parsing: failed to render Jinja expression: invalid operation: tried to use + operator on unsupported types string and undefined (in <string>:1)
    ╭─[12:13]
 11 │   - package:
 12 │       name: ${{ name + '-' + variant }}
    ·             ─────────────┬─────────────
    ·                          ╰── invalid operation: tried to use + operator on unsupported types string and undefined
    ╰────
wolfv commented 1 month ago

There is one (semi-working) workaround:

      name: ${{ name }}-${{ variant }}

But then it's still missing when printing the variant config:

 ╭─ Finding outputs from recipe
 │ Found 2 variants
 │ Build variant: my-package--1.0.0-hcdbb9e0_0
 │ 
 │ ╭─────────────────┬───────────╮
 │ │ Variant         ┆ Version   │
 │ ╞═════════════════╪═══════════╡
 │ │ target_platform ┆ osx-arm64 │
 │ │ variant         ┆ a         │
 │ ╰─────────────────┴───────────╯
 │ Build variant: my-package--1.0.0-h89e5c08_0
 │ 
 │ ╭─────────────────┬───────────╮
 │ │ Variant         ┆ Version   │
 │ ╞═════════════════╪═══════════╡
 │ │ target_platform ┆ osx-arm64 │
 │ │ variant         ┆ b         │
 │ ╰─────────────────┴───────────╯
 │
 ╰─────────────────── (took 0 seconds)
wolfv commented 1 month ago

I think we should already load the variant and inject it here:

https://github.com/prefix-dev/rattler-build/blob/main/src/variant_config.rs#L396

Because the used_vars are discovered correctly.

jaimergp commented 1 month ago

I thought string concatenation in (mini)jinja used ~ not +

wolfv commented 1 month ago

I think both work? But this is also the same problem as #1011 :)

wolfv commented 1 month ago

Although ~ seems to convert the elements to strings, so it might deal with undefined better.

pavelzw commented 1 month ago

There is one (semi-working) workaround:

name: ${{ name }}-${{ variant }}

I experienced this in pin_subpackage, so unfortunately this doesn't fix it for me

wolfv commented 1 month ago

@pavelzw you could try using ~.

pavelzw commented 1 month ago

Yes, ~ seems to work 🤔 (Although 'foo' + 'bar' also works while var + 'bar' doesn't)

Feel free to close this issue if you think we should just use ~ 😃

wolfv commented 1 month ago

Yeah, I think ~ casts (even an undefined value) to a string. While + needs both values to be of matching types.

I do want to fix this issue (also to close #1011)