Skip to content

Conversation

@rydrman
Copy link
Collaborator

@rydrman rydrman commented Jan 24, 2023

Defines the Variant trait 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::build which 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.

@rydrman rydrman added the Rust API Pertaining to the public rust API of the library label Jan 24, 2023
@rydrman rydrman added this to the V1 Spec milestone Jan 24, 2023
@rydrman rydrman requested review from dcookspi and jrray January 24, 2023 03:39
@rydrman rydrman self-assigned this Jan 24, 2023
@rydrman rydrman mentioned this pull request Jan 24, 2023
11 tasks
@codecov
Copy link

codecov bot commented Jan 24, 2023

Codecov Report

Merging #635 (960b1b2) into master (cb66714) will increase coverage by 0.30%.
The diff coverage is 75.74%.

@@            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     
Impacted Files Coverage Δ
crates/parsedbuf/src/lib.rs 78.26% <0.00%> (+1.33%) ⬆️
crates/spk-cli/cmd-build/src/cmd_build.rs 85.71% <ø> (ø)
crates/spk-cli/common/src/exec.rs 0.00% <0.00%> (ø)
crates/spk-cli/group4/src/cmd_view.rs 0.00% <0.00%> (ø)
crates/spk-exec/src/exec.rs 61.64% <0.00%> (+1.64%) ⬆️
crates/spk-schema/src/error.rs 50.00% <ø> (ø)
crates/spk-solve/crates/solution/src/solution.rs 70.10% <0.00%> (ø)
crates/spk-schema/src/recipe.rs 34.78% <38.46%> (+4.01%) ⬆️
crates/spk-cli/cmd-test/src/cmd_test.rs 81.05% <50.00%> (+0.20%) ⬆️
crates/spk-schema/crates/ident/src/request.rs 81.69% <60.00%> (-0.38%) ⬇️
... and 9 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@jrray
Copy link
Collaborator

jrray commented Mar 7, 2023

Responding to my being tagged here, getting the tests in #653 to pass would be what I consider required to allow this branch to replace #433.

@rydrman rydrman force-pushed the 296-variant-trait branch from 0f662dc to 3856e52 Compare March 12, 2023 03:42
@rydrman
Copy link
Collaborator Author

rydrman commented Mar 12, 2023

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 OptionMap for functions like resolve_options and get_build_requirements

Copy link
Collaborator

@jrray jrray left a 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}");
Copy link
Collaborator

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]} })

Copy link
Collaborator Author

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}");
Copy link
Collaborator

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]} })

Copy link
Collaborator Author

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 

f.write_str("\nadditional requirements:\n")?;
for r in self.requirements.iter() {
f.write_str(" - ")?;
std::fmt::Debug::fmt(r, f)?;
Copy link
Collaborator

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.

for request in requirements.iter() {
f.write_char('\n')?;
f.write_str(" - ")?;
f.write_fmt(format_args!("{request:?}"))?;
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

Copy link
Collaborator Author

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

rydrman and others added 8 commits April 7, 2023 15:05
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>
@rydrman rydrman force-pushed the 296-variant-trait branch from dc11e70 to 960b1b2 Compare April 7, 2023 22:08
@rydrman rydrman requested a review from jrray April 7, 2023 22:19
@rydrman rydrman merged commit b10c261 into master Apr 8, 2023
@rydrman rydrman deleted the 296-variant-trait branch April 8, 2023 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Rust API Pertaining to the public rust API of the library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants