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
214 stars 45 forks source link

BUG: test:build constraints not respected when using selectors #939

Open h-vetinari opened 4 months ago

h-vetinari commented 4 months ago

Hi! πŸ‘‹

I'm starting to work on emscripten-forge a bit these days, and ran into the following problem, where @DerThorsten asked me to raise an issue.

In our pyjs recipe, there's the following:

tests:
  - script: |
       [...]
    requirements:
      build:      
          - pytester
          - if: linux
            then:
              - pyjs_code_runner >=3.0.0
              - microsoft::playwright <1.42
            else:
              - pyjs_code_runner >=3.0.0
              - microsoft::playwright

however, despite being on linux, my test environment mis-detects the condition:

 β”‚ β”‚ Resolving environment for:
 β”‚ β”‚   Platform: linux-64
 β”‚ β”‚   Channels:
 β”‚ β”‚    - file:///tmp/.tmp4JVVSW
 β”‚ β”‚    - file:///home/[...]/emf/output
 β”‚ β”‚    - https://repo.mamba.pm/emscripten-forge
 β”‚ β”‚    - microsoft
 β”‚ β”‚    - conda-forge
 β”‚ β”‚   Specs:
 β”‚ β”‚    - pytester
 β”‚ β”‚    - pyjs_code_runner >=3.0.0
 β”‚ β”‚    - microsoft::playwright                 # <-- no constraint!

which unsurprisingly installs:

 β”‚ β”‚ β”‚ playwright          ┆ 1.44.0   ┆ py312_0            ┆ microsoft   ┆ 32.58 MiB  β”‚

removing the if: linux portion makes the constraints work again.

wolfv commented 4 months ago

I'll take a look!

wolfv commented 4 months ago

OK, actually there is no bug because the if: linux is for the target_platform (emscripten) and not the build_platform.

You should be able to fix the issue by using build_platform == "linux-64"

wolfv commented 4 months ago

It's a little confusing, but it's also consistent with the rest of the recipe, so not sure what to do here. Ideas welcome!

It also makes me realize that it's not easy to check wether the build_platform is unix, or linux. Maybe we should add is_linux(build_platform), or is_unix(build_platform) functions ...

wolfv commented 4 months ago

We could also add a starts_with filter to minijinja :)

h-vetinari commented 4 months ago

OK, actually there is no bug because the if: linux is for the target_platform (emscripten) and not the build_platform.

You should be able to fix the issue by using build_platform == "linux-64"

OK, that makes sense of course! Clearly I'm not yet used to the test section having a build section as well! πŸ˜…

+1 to the other jinja enhancements too!

mitsuhiko commented 4 months ago

We could also add a starts_with filter to minijinja :)

There is a startingwith test in minijinja:

build_platform is startingwith('linux')