-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding host_compat setting to package BuildSpec #922
Adding host_compat setting to package BuildSpec #922
Conversation
efb0cee
to
2087873
Compare
Added a todo for what to do about the os version comparison discussison we had today. |
Added codes to the new errors. |
I've removed the validation check and error, and the config option to enable/disable it. |
Supports these values: distro, arch, os, and any. The value determines which host os related options are automatically added to the package build's options. Adds 'host_compat' section with 'validate' setting to spk's config file to control whether checks are run on a build's option to ensure there no host os related options set that are incopmatible with the package's host_compat value. Signed-off-by: David Gilligan-Cook <[email protected]>
Signed-off-by: David Gilligan-Cook <[email protected]>
Signed-off-by: David Gilligan-Cook <[email protected]>
Signed-off-by: David Gilligan-Cook <[email protected]>
Signed-off-by: David Gilligan-Cook <[email protected]>
Signed-off-by: David Gilligan-Cook <[email protected]>
Signed-off-by: David Gilligan-Cook <[email protected]>
92d2ec4
to
4287114
Compare
Signed-off-by: David Gilligan-Cook <[email protected]>
Signed-off-by: David Gilligan-Cook <[email protected]>
I've fixed an issue with the |
crates/spk-schema/src/build_spec.rs
Outdated
pub enum HostCompat { | ||
/// Package can only be used on the same OS distribution | ||
#[default] | ||
Distro, | ||
/// Package can be used anywhere that has the same OS and cpu type | ||
Arch, | ||
/// Package can be used on the same OS with any cpu or distro | ||
Os, | ||
/// Package can be used on any Os | ||
Any, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has @lgritz been able to put eyes on this addition? I am having memories of talking about being able to handle CPU capabilities, etc, and wondering if we should consider making host_compat
a list - or at least not lock ourselves into a state where cpu architecture is tied to os/distro. Eg you can't say "any arch but must be the same distro"...
sorry to throw another question into the mix here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. I think @lgritz might been some of the internal meetings where it was mentioned, @jrray may know more. But I don't think we got into details.
The host_compat:
enum values in this change are an initial set of possibilities. They expand into lists of vars, most with known names, one with a dynamic name (the value of the distro
host option). We could add other host_compat
values in future if we need to, e.g. a 'DistroOnly' value could expand into just the <distroname>=<version>
var option (if I understand what you mean by "any arch but the same distro" correctly). We could add other enum values that turn into other, stranger sets of vars, later, as needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eg you can't say "any arch but must be the same distro"...
David already answered this but to put it another way, individual specs can set host_compat: Any
and be back to the original behavior, and then add back in whatever combination of host vars they want.
I really hope this PR doesn't get bogged down over perceived limitations of what this is doing, in my mind we're not introducing any new concepts here but just putting some more formal structure around what the existing behavior has been. It's important for us to get these vars added by default ASAP so we can make progress on our new OS testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does seem a little counter-intuitive to read a spec with host_compat: Any
that, in fact, has a very specific host compat defined elsewhere.
My goal is never to "bog down" a PR, and I hope you don't see these discussions as purely bureaucratic. My goal is to make sure we are thinking about these things from all angles. It's very hard to go backwards in spk and with every feature we add to fix a specific need we add complexity for new folks to learn and understand. I just want to make sure that the design feels intuitive for newcomers and doesn't shoehorn us into any undesirable futures...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just trying to reconcile the above in my brain - maybe we are complicating things by abstracting what's going on here? Aka Any
actually means inject no vars, but doesn't preclude them existing elsewhere....
As one idea, we could instead be explicit and call the field something like auto_host_vars
, changing Any
to None
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can rename the field and value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed this over to use auto_host_vars
and None
. The internals haven't changed.
crates/spk-schema/src/build_spec.rs
Outdated
return Err(Error::HostOptionNotValidDistroNameError( | ||
distro_name.to_string(), | ||
err, | ||
)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still have concerns with this being an error case, but curious about your thoughts...
The value that's incorrect is loaded from the host machine for an option that's injected - I think there's a potential for users to have no idea what went wrong or how to fix this and we should at least have a good explanation and possible work-around --- or maybe we need some kind of reliable conversion+fallback for distro names so that it never fails in this way?
The main question is - how do you recover if you run spk on a machine where the distro name is seen as invalid? I know you have "contact admin" now but what would the admin even do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth erroring. But I can see that stopping spk
dead isn't good either. I'm not sure there's a good easy solution.
I looked again at what the existing host_options()
function does, and updated this code to do the same. The host_options()
displays a warning and skips over making the <distroname>
var, which is slightly concerning, but its consistent for now. It's something we can also ticket up to look at in-depth in future, if necessary.
Here are some options:
- Error and Stop spk, until there's a valid distroname - if that's even posssible for some sysadmin to do sensibly (the original code did this)
- Warn and Skip making the
<distroname>=<version_id>
var opt at all (the current code does this) - Warn and Fallback, use either:
- some predefined value (
unknown_distro=<version_id>
?), or - convert the distroname into a valid opt name, which I think at the moment involves:
- lowercasing it,
- filtering out all character that aren't letters, numbers, _'s and -'s,
- then making sure the leftover string is > 2 and < 64 chars, by either padding or truncating it.
- some predefined value (
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Internally, for name-like types we often add a new_lossy
constructor that does the kind of translation that you mention in a predictable and infallible way. That seems ideal to me in this case because it would still give a consistent value on which to check compatibility, but not fail as we're discussing.
In the future, once we allow a custom host options command then we could allow it to yield an alternative name, but the above feels like the best default behavior to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add a constructor that converts the name to a valid one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a new_lossy()
and unknown_distro()
methods.
Co-authored-by: Ryan Bottriell <[email protected]> Signed-off-by: David Gilligan-Cook <[email protected]>
Signed-off-by: David Gilligan-Cook <[email protected]>
ec9f385
to
f5541aa
Compare
Signed-off-by: David Gilligan-Cook <[email protected]>
} | ||
|
||
impl HostCompat { | ||
pub fn is_default(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recently learned about the variantly crate which unfortunately doesn't generate an is_default
method but does generate other useful methods for enums.
crates/spk-schema/src/build_spec.rs
Outdated
pub enum HostCompat { | ||
/// Package can only be used on the same OS distribution | ||
#[default] | ||
Distro, | ||
/// Package can be used anywhere that has the same OS and cpu type | ||
Arch, | ||
/// Package can be used on the same OS with any cpu or distro | ||
Os, | ||
/// Package can be used on any Os | ||
Any, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eg you can't say "any arch but must be the same distro"...
David already answered this but to put it another way, individual specs can set host_compat: Any
and be back to the original behavior, and then add back in whatever combination of host vars they want.
I really hope this PR doesn't get bogged down over perceived limitations of what this is doing, in my mind we're not introducing any new concepts here but just putting some more formal structure around what the existing behavior has been. It's important for us to get these vars added by default ASAP so we can make progress on our new OS testing.
Signed-off-by: David Gilligan-Cook <[email protected]>
string is not a valid var option name. Signed-off-by: David Gilligan-Cook <[email protected]>
Signed-off-by: David Gilligan-Cook <[email protected]>
Signed-off-by: David Gilligan-Cook <[email protected]>
Co-authored-by: Ryan Bottriell <[email protected]> Signed-off-by: David Gilligan-Cook <[email protected]>
8417691
to
d5df810
Compare
Signed-off-by: David Gilligan-Cook <[email protected]>
This add the
host_compat
field a package'sBuildSpec
, based on the discussion in the related ticket, e.g.The value of
host_compat
the determines which host os related options are automatically added to the package build's options. It also describes the kind of host os compatibility required for builds of this package. The supported values are:distro
(default),arch
,os
, andany
.This also adds a
host_compat
section withvalidate
field to spk's config file. This contols whether checks are run on a build's option to ensure no incompatible host os related options are also being by a package variant. The default is for these checks to be disabled (should it be that?).This does not include:
spk lint
command, there'll be another PR for that (DRAFT: Add host_compat lints (requires spk-lint-update) #929 which is based on this and Capture unrecognized fields with lint #851)todo
makers where they could be added later.Todo:
<distroname>
vars comparison issue, e.g. 9.2 vs 9.3 for rocky 9's being treated as equal (in the solver and builds, so any comparisons) if those versions of the distro are application compatible.