Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/spk-schema/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,15 @@ impl VarOpt {
}
}

/// If this option is not already pinned, and it has a non-empty default,
/// pin the default value.
pub fn pin_with_default(&mut self) {
if self.value.is_some() || self.default.is_empty() {
return;
}
self.value = Some(self.default.clone());
}

pub fn set_value(&mut self, value: String) -> Result<()> {
if !self.choices.is_empty() && !value.is_empty() && !self.choices.contains(&value) {
return Err(Error::String(format!(
Expand Down
33 changes: 31 additions & 2 deletions crates/spk-storage/src/storage/spfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use spk_schema::ident::{AsVersionIdent, VersionIdent};
use spk_schema::ident_build::parsing::embedded_source_package;
use spk_schema::ident_build::{EmbeddedSource, EmbeddedSourcePackage};
use spk_schema::ident_ops::TagPath;
use spk_schema::{AnyIdent, BuildIdent, FromYaml, Package, Recipe, Spec, SpecRecipe};
use spk_schema::{AnyIdent, BuildIdent, FromYaml, Opt, Package, Recipe, Spec, SpecRecipe};
use tokio::io::AsyncReadExt;

use super::CachePolicy;
Expand Down Expand Up @@ -504,7 +504,6 @@ impl Storage for SpfsRepository {
{
return v.value().clone().into();
}

let r: Result<Arc<Spec>> = async move {
let tag_path = Self::build_spec_tag(pkg);
let tag_spec = spfs::tracking::TagSpec::parse(tag_path.as_str())?;
Expand All @@ -517,6 +516,25 @@ impl Storage for SpfsRepository {
.await
.map_err(|err| Error::FileReadError(filename, err))?;
Spec::from_yaml(&yaml)
.map(|spec| match spec {
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 can understand that this might be undesirable, but it is needed at least in the short term to fix bad solves. With the other fix in this PR in place, we can work on republishing packages to fix their stubs (or write some fixer script), and then I would be good with reverting this.

Spec::V0Package(mut spec) => {
for opt in spec.build.options.iter_mut() {
let Opt::Var(var_opt) = opt else {
continue;
};
var_opt.pin_with_default()
}
for embedded in spec.install.embedded.iter_mut() {
for opt in embedded.build.options.iter_mut() {
let Opt::Var(var_opt) = opt else {
continue;
};
var_opt.pin_with_default()
}
}
Spec::V0Package(spec)
}
})
.map_err(|err| {
Error::InvalidPackageSpec(Box::new(InvalidPackageSpec(
pkg.to_any_ident(),
Expand Down Expand Up @@ -768,6 +786,17 @@ impl crate::Repository for SpfsRepository {
.await
.map_err(|err| Error::FileReadError(tag.target.to_string().into(), err))?;
Spec::from_yaml(yaml)
.map(|spec| match spec {
Spec::V0Package(mut spec) => {
for opt in spec.build.options.iter_mut() {
let Opt::Var(var_opt) = opt else {
continue;
};
var_opt.pin_with_default()
}
Spec::V0Package(spec)
}
})
.map_err(|err| {
Error::InvalidPackageSpec(Box::new(InvalidPackageSpec(
pkg.to_any_ident(),
Expand Down
Loading