@@ -19,7 +19,7 @@ use crate::manifest::component_build_configs;
1919pub async fn build (
2020 manifest_file : & Path ,
2121 component_ids : & [ String ] ,
22- skip_target_checks : bool ,
22+ target_checks : TargetChecking ,
2323 cache_root : Option < PathBuf > ,
2424) -> Result < ( ) > {
2525 let build_info = component_build_configs ( manifest_file)
@@ -42,7 +42,7 @@ pub async fn build(
4242 // Checking deployment targets requires a healthy manifest (because trigger types etc.),
4343 // if any of these were specified, warn they are being skipped.
4444 let should_have_checked_targets =
45- !skip_target_checks && build_info. has_deployment_targets ( ) ;
45+ target_checks . check ( ) && build_info. has_deployment_targets ( ) ;
4646 if should_have_checked_targets {
4747 terminal:: warn!(
4848 "The manifest error(s) prevented Spin from checking the deployment targets."
@@ -59,7 +59,7 @@ pub async fn build(
5959 return Ok ( ( ) ) ;
6060 } ;
6161
62- if !skip_target_checks {
62+ if target_checks . check ( ) {
6363 let application = spin_environments:: ApplicationToValidate :: new (
6464 manifest. clone ( ) ,
6565 manifest_file. parent ( ) . unwrap ( ) ,
@@ -85,6 +85,13 @@ pub async fn build(
8585 Ok ( ( ) )
8686}
8787
88+ /// Run all component build commands, using the default options (build all
89+ /// components, perform target checking). We run a "default build" in several
90+ /// places and this centralises the logic of what such a "default build" means.
91+ pub async fn build_default ( manifest_file : & Path , cache_root : Option < PathBuf > ) -> Result < ( ) > {
92+ build ( manifest_file, & [ ] , TargetChecking :: Check , cache_root) . await
93+ }
94+
8895fn build_components (
8996 component_ids : & [ String ] ,
9097 components : Vec < ComponentBuildInfo > ,
@@ -207,6 +214,21 @@ fn construct_workdir(app_dir: &Path, workdir: Option<impl AsRef<Path>>) -> Resul
207214 Ok ( cwd)
208215}
209216
217+ /// Specifies target environment checking behaviour
218+ pub enum TargetChecking {
219+ /// The build should check that all components are compatible with all target environments.
220+ Check ,
221+ /// The build should not check target environments.
222+ Skip ,
223+ }
224+
225+ impl TargetChecking {
226+ /// Should the build check target environments?
227+ fn check ( & self ) -> bool {
228+ matches ! ( self , Self :: Check )
229+ }
230+ }
231+
210232#[ cfg( test) ]
211233mod tests {
212234 use super :: * ;
@@ -219,6 +241,8 @@ mod tests {
219241 #[ tokio:: test]
220242 async fn can_load_even_if_trigger_invalid ( ) {
221243 let bad_trigger_file = test_data_root ( ) . join ( "bad_trigger.toml" ) ;
222- build ( & bad_trigger_file, & [ ] , true , None ) . await . unwrap ( ) ;
244+ build ( & bad_trigger_file, & [ ] , TargetChecking :: Skip , None )
245+ . await
246+ . unwrap ( ) ;
223247 }
224248}
0 commit comments