Skip to content

Host options should be automatic and opt-out #917

@jrray

Description

@jrray

Problem

I have started experimenting with using spk with two different OSes sharing the same origin repo and it has come to my attention that some of our packages, and perhaps a lot of them, are written like this:

build:
  options:
    - var: os
    - var: arch
    - var: centos
    # ... other non-host options

There are two problems here. First off, this is unfortunately missing - var: distro which means that when solving on a different linux distro, the solver finds no reason to reject builds for centos.

 INITIAL REQUEST {arch=x86_64}
 INITIAL REQUEST {distro=rocky}
 INITIAL REQUEST {os=linux}
 INITIAL REQUEST {rocky=9.2}

arch and os still have the same values as on centos. No centos host option is present when on rocky, so it doesn't reject builds with centos=7. And crucially, there is no distro=centos to cause a conflict with distro=rocky. I can't prevent the solver from picking centos builds of this package when running on rocky.

The second problem is the fact that the recipe has - var: centos hard-coded into it. It is desirable to have this var in my package, but it is undesirable to have to add it manually, or have to edit it to be "rocky" when building on rocky, or maybe even just adding all the distros to the list:

build:
  options:
    - var: centos
    - var: rocky
    # predict the future...
    - var: distro3
    - var: distro4

Proposal

It is safer and better if these vars are automatically added to the build options at build time, unless the package author elects to opt-out of this behavior using some new build property to control that.

  • Package authors may not know when they need these vars.
  • Package authors may make mistakes and not include all the vars they should.
  • Adding the vars when they are not needed is "harmless" whereas not adding them when they are needed is dangerous.
  • Experienced package authors who know what they are doing can opt-out.

Automatically adding the host vars has the added bonus that the appropriate -var: <distro name> var can be added without having to spell it out in the recipe. For those experienced package authors that want control, perhaps there is already a way with the templating mechanism to substitute in the detected distro name?

We need a new build section to opt-out to auto-adding these vars. This needs more thought but the goal is to have a way in the recipe to turn it off:

See later comment for revised proposal

build:
  settings:
    AutomaticHostOptions: false

The default would be true and the build options would get the [usually] four options that host_options calculates injected into the build.options list. Just the var names, with no values, like we usually write into our recipes (when we remember to!).

Metadata

Metadata

Assignees

Labels

QoLquality of life fixesSPI AOIArea of interest for SPIenhancementNew feature or requestpackage recipePackaging recipes

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions