-
Notifications
You must be signed in to change notification settings - Fork 9
Variant Trait #635
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
Variant Trait #635
Conversation
Codecov Report
@@ Coverage Diff @@
## master #635 +/- ##
==========================================
+ Coverage 57.17% 57.47% +0.30%
==========================================
Files 222 224 +2
Lines 17169 17297 +128
==========================================
+ Hits 9816 9942 +126
- Misses 7353 7355 +2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
27ba68d to
06690c0
Compare
0f662dc to
3856e52
Compare
|
Thanks, @jrray - I've gotten those tests to pass, with some changes both to my code and the tests. I added the heuristics that you had in #433, with minor tweaks, and run them when the spec is deserialized. Above what I already had this code is now leaning farther into the variant trait, using it in place of an |
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.
This is nice, I do like the tidiness of the Variant trait.
I didn't spot what you changed about the tests, beyond filling in TODO comments I left in there. Do you make any changes to the expected results of any of the tests?
| } | ||
|
|
||
| tracing::info!("building variant {}", opts.format_option_map()); | ||
| tracing::info!("building variant:\n{variant}"); |
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.
The variant stringification could use some polish, this is what I see if a variant introduces a novel package dependency:
INFO building variant:
Options: {arch=x86_64, centos=7, distro=centos, os=linux, spi-platform=~2023.1.1.2}
Additional Requirements:
- Pkg(PkgRequest { pkg: RangeIdent { repository_name: None, name: PkgNameBuf("spi-platform"), components: {}, version: VersionFilter { rules: {LowestSpecified(LowestSpecifiedRange { specified: 4, base: Version { parts: VersionParts { parts: [2023, 1, 1, 2], plus_epsilon: false }, pre: TagSet { tags: {} }, post: TagSet { tags: {} } } })} }, build: None }, prerelease_policy: ExcludeAll, inclusion_policy: Always, pin: None, required_compat: Some(Binary), requested_by: {"spi-platform/~2023.1.1.2": [Variant]} })
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.
Thanks, I'm adding the shorter format for this
| for (index, variant) in recipe.default_variants().iter().enumerate() { | ||
| let default_variants = recipe.default_variants(); | ||
| for (index, variant) in default_variants.iter().enumerate() { | ||
| println!("{index}: {variant}"); |
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.
The multiple line stringification output for variants pose a compatibility/usability concern for scripts that just want to count the number of lines to get the answer of how many variants exist in a package.
In reality we haven't stopped using spk num-variants <filename> yet, which prints a number. Automation wants to easily get a number and generate CI jobs per index.
$ ~/git/spk/target/debug/spk num-variants package.spk.yaml
2
$ ~/git/spk/target/debug/spk view --variants package.spk.yaml
0: options: {spi-platform: ~2023.1.1.2}
additional requirements:
- Pkg(PkgRequest { pkg: RangeIdent { repository_name: None, name: PkgNameBuf("spi-platform"), components: {}, version: VersionFilter { rules: {LowestSpecified(LowestSpecifiedRange { specified: 4, base: Version { parts: VersionParts { parts: [2023, 1, 1, 2], plus_epsilon: false }, pre: TagSet { tags: {} }, post: TagSet { tags: {} } } })} }, build: None }, prerelease_policy: ExcludeAll, inclusion_policy: Always, pin: None, required_compat: Some(Binary), requested_by: {"spi-platform/~2023.1.1.2": [Variant]} })
1: options: {maya2023-platform: ~2023.1.1.2}
additional requirements:
- Pkg(PkgRequest { pkg: RangeIdent { repository_name: None, name: PkgNameBuf("maya2023-platform"), components: {}, version: VersionFilter { rules: {LowestSpecified(LowestSpecifiedRange { specified: 4, base: Version { parts: VersionParts { parts: [2023, 1, 1, 2], plus_epsilon: false }, pre: TagSet { tags: {} }, post: TagSet { tags: {} } } })} }, build: None }, prerelease_policy: ExcludeAll, inclusion_policy: Always, pin: None, required_compat: Some(Binary), requested_by: {"maya2023-platform/~2023.1.1.2": [Variant]} })
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'll use a one-line version for this as well - not perfect but at least more predictable
$ spk view --variants test.spk.yaml
0: options: {python: 3, stdfs: 1.0} additional requirements: python/3 stdfs/1.0
crates/spk-schema/src/v0/variant.rs
Outdated
| f.write_str("\nadditional requirements:\n")?; | ||
| for r in self.requirements.iter() { | ||
| f.write_str(" - ")?; | ||
| std::fmt::Debug::fmt(r, f)?; |
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.
The debug output is ugly to display to users. Did you have a specific reason to use it? I put some example output in other comments.
crates/spk-schema/src/variant.rs
Outdated
| for request in requirements.iter() { | ||
| f.write_char('\n')?; | ||
| f.write_str(" - ")?; | ||
| f.write_fmt(format_args!("{request:?}"))?; |
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.
... or I guess this is where the debug output is coming from.
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 don't think that we have Display implemented for a full request - but maybe that has changed, or I suppose there's likely something in the solver formatting that I can use though I'm not sure off the top of my head if that shows additional bits above the version range
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.
we did not, but it was easy to add as the var and pkg types already did
Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
These have no purpose yet, but will be used by v1 spec variants to add additional requirements to the package that are not present for other variants. Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
Extract tests from #433 to test alternate implementations for this behavior. Signed-off-by: J Robert Ray <jrray@jrray.org> Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
This provides access to the additional requests insode the version-specific generation code so that the generated binary build can include additional options which represent those added options Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
This allows for the additional requirements to be considered, and for the recipe to understand how build opts might be inserted for a build of that variant. There's some anooying overlap of work now where the same variant ends up being calculated multiple times in the process of running a build, but there doesn't seem to be any great ways to add efficiency without re-exposing particualr aspects of the v0 spec Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
dc11e70 to
960b1b2
Compare
Defines the
Varianttrait that provides build options as usual, but also has an optional name and set of additional requirements to be used when building. These are both not exercised in this pull request but are required for the v1 package spec features to come.This pull request relates to #433 as it required updating the binary package builder to take a variant to be built. It takes a slightly different approach, however, requiring that the variant is selected and/or defined before calling
BinaryPackageBuilder::buildwhich is so far less intrusive. It may not achieve everything that #278 did, but I don't know that branch well enough to say so maybe @jrray can comment on whether we would hit limitations in this approach.