Skip to content

Commit ae77cd9

Browse files
committed
Abolish a bool, and the double negatives it rode in on
Signed-off-by: itowlson <ivan.towlson@fermyon.com>
1 parent 8427a07 commit ae77cd9

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

crates/build/src/lib.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::manifest::component_build_configs;
1919
pub 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(),
@@ -207,6 +207,21 @@ fn construct_workdir(app_dir: &Path, workdir: Option<impl AsRef<Path>>) -> Resul
207207
Ok(cwd)
208208
}
209209

210+
/// Specifies target environment checking behaviour
211+
pub enum TargetChecking {
212+
/// The build should check that all components are compatible with all target environments.
213+
Check,
214+
/// The build should not check target environments.
215+
Skip,
216+
}
217+
218+
impl TargetChecking {
219+
/// Should the build check target environments?
220+
fn check(&self) -> bool {
221+
matches!(self, Self::Check)
222+
}
223+
}
224+
210225
#[cfg(test)]
211226
mod tests {
212227
use super::*;
@@ -219,6 +234,8 @@ mod tests {
219234
#[tokio::test]
220235
async fn can_load_even_if_trigger_invalid() {
221236
let bad_trigger_file = test_data_root().join("bad_trigger.toml");
222-
build(&bad_trigger_file, &[], true, None).await.unwrap();
237+
build(&bad_trigger_file, &[], TargetChecking::Skip, None)
238+
.await
239+
.unwrap();
223240
}
224241
}

src/commands/build.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl BuildCommand {
5656
spin_build::build(
5757
&manifest_file,
5858
&self.component_id,
59-
self.skip_target_checks,
59+
self.target_checking(),
6060
None,
6161
)
6262
.await?;
@@ -75,4 +75,12 @@ impl BuildCommand {
7575
Ok(())
7676
}
7777
}
78+
79+
fn target_checking(&self) -> spin_build::TargetChecking {
80+
if self.skip_target_checks {
81+
spin_build::TargetChecking::Skip
82+
} else {
83+
spin_build::TargetChecking::Check
84+
}
85+
}
7886
}

src/commands/registry.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ impl Push {
8484
notify_if_nondefault_rel(&app_file, distance);
8585

8686
if self.build {
87-
spin_build::build(&app_file, &[], false, self.cache_dir.clone()).await?;
87+
spin_build::build(
88+
&app_file,
89+
&[],
90+
spin_build::TargetChecking::Skip,
91+
self.cache_dir.clone(),
92+
)
93+
.await?;
8894
}
8995

9096
let annotations = if self.annotations.is_empty() {

src/commands/up/app_source.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ impl AppSource {
5858

5959
pub async fn build(&self, cache_root: &Option<PathBuf>) -> anyhow::Result<()> {
6060
match self {
61-
Self::File(path) => spin_build::build(path, &[], false, cache_root.clone()).await,
61+
Self::File(path) => {
62+
spin_build::build(
63+
path,
64+
&[],
65+
spin_build::TargetChecking::Skip,
66+
cache_root.clone(),
67+
)
68+
.await
69+
}
6270
_ => Ok(()),
6371
}
6472
}

0 commit comments

Comments
 (0)