Skip to content

Commit 1b682e9

Browse files
author
Nichol Yip
committed
Implmented LintedBuildSpec struct to properly evaluate error if any, in the visitor method instead of the from implementation.
Signed-off-by: Nichol Yip <[email protected]>
1 parent d364d49 commit 1b682e9

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

crates/spk-schema/src/v0/spec.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -847,14 +847,19 @@ where
847847
}
848848
}
849849

850+
pub struct LintedBuildSpec {
851+
build_spec: BuildSpec,
852+
lints: Vec<Lint>,
853+
}
854+
850855
#[derive(FieldNamesAsArray)]
851856
struct SpecVisitor<B, T> {
852857
pkg: Option<Ident<B, T>>,
853858
meta: Option<LintedItem<Meta>>,
854859
compat: Option<Compat>,
855860
deprecated: Option<bool>,
856861
sources: Option<Vec<LintedItem<SourceSpec>>>,
857-
build: Option<LintedItem<UncheckedBuildSpec>>,
862+
build: Option<LintedBuildSpec>,
858863
tests: Option<Vec<LintedItem<TestSpec>>>,
859864
install: Option<LintedItem<InstallSpec>>,
860865
#[field_names_as_array(skip)]
@@ -902,14 +907,7 @@ where
902907
.collect_vec()
903908
},
904909
build: match value.build.take() {
905-
Some(build_spec) if !value.check_build_spec => {
906-
// Safety: see the SpecVisitor::package constructor
907-
unsafe { build_spec.item.into_inner() }
908-
}
909-
Some(build_spec) => match build_spec.item.try_into() {
910-
Ok(b) => b,
911-
Err(_) => BuildSpec::default(),
912-
},
910+
Some(build) => build.build_spec,
913911
None => Default::default(),
914912
},
915913
tests: value
@@ -995,7 +993,20 @@ where
995993
"compat" => self.compat = Some(map.next_value::<Compat>()?),
996994
"deprecated" => self.deprecated = Some(map.next_value::<bool>()?),
997995
"sources" => self.sources = Some(map.next_value::<Vec<LintedItem<SourceSpec>>>()?),
998-
"build" => self.build = Some(map.next_value::<LintedItem<UncheckedBuildSpec>>()?),
996+
"build" => {
997+
self.build = {
998+
let build = map.next_value::<LintedItem<UncheckedBuildSpec>>()?;
999+
let lints = build.lints.clone();
1000+
let build_spec = if !self.check_build_spec {
1001+
// Safety: see the SpecVisitor::package constructor
1002+
unsafe { build.item.into_inner() }
1003+
} else {
1004+
build.item.try_into().map_err(serde::de::Error::custom)?
1005+
};
1006+
1007+
Some(LintedBuildSpec { build_spec, lints })
1008+
}
1009+
}
9991010
"tests" => self.tests = Some(map.next_value::<Vec<LintedItem<TestSpec>>>()?),
10001011
"install" => self.install = Some(map.next_value::<LintedItem<InstallSpec>>()?),
10011012
"api" => {
@@ -1015,12 +1026,6 @@ where
10151026
.as_ref()
10161027
.ok_or_else(|| serde::de::Error::missing_field("pkg"))?;
10171028

1018-
if self.check_build_spec {
1019-
if let Some(build_spec) = self.build.as_ref() {
1020-
TryInto::<BuildSpec>::try_into(build_spec.item).map_err(serde::de::Error::custom)?;
1021-
}
1022-
}
1023-
10241029
Ok(self)
10251030
}
10261031
}

0 commit comments

Comments
 (0)