diff --git a/Cargo.lock b/Cargo.lock index 67ad0ca026..039ea80855 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3804,6 +3804,7 @@ dependencies = [ "spk-storage", "tempfile", "tokio", + "tracing", ] [[package]] @@ -3941,6 +3942,7 @@ dependencies = [ "async-trait", "clap 4.4.7", "miette", + "serde_yaml 0.9.27", "spfs", "spk-build", "spk-cli-common", diff --git a/crates/spk-cli/cmd-build/Cargo.toml b/crates/spk-cli/cmd-build/Cargo.toml index c94992e7b3..641f66b0d8 100644 --- a/crates/spk-cli/cmd-build/Cargo.toml +++ b/crates/spk-cli/cmd-build/Cargo.toml @@ -21,10 +21,11 @@ clap = { workspace = true } spk-cli-common = { path = '../common' } spk-cmd-make-binary = { path = '../cmd-make-binary' } spk-cmd-make-source = { path = '../cmd-make-source' } +spk-schema = { path = '../../spk-schema' } +tracing = { workspace = true } [dev-dependencies] rstest = { workspace = true } -spk-schema = { path = '../../spk-schema' } spk-storage = { path = '../../spk-storage' } tempfile = { workspace = true } tokio = { workspace = true } diff --git a/crates/spk-cli/cmd-build/src/cmd_build.rs b/crates/spk-cli/cmd-build/src/cmd_build.rs index df19b8791a..6828466863 100644 --- a/crates/spk-cli/cmd-build/src/cmd_build.rs +++ b/crates/spk-cli/cmd-build/src/cmd_build.rs @@ -2,10 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // https://github.com/imageworks/spk +use std::collections::BTreeMap; + use clap::Args; use miette::Result; use spk_cli_common::{flags, CommandArgs, Run}; use spk_cmd_make_binary::cmd_make_binary::PackageSpecifier; +use spk_schema::Lint::Key; #[cfg(test)] #[path = "./cmd_build_test.rs"] @@ -68,6 +71,7 @@ impl Run for Build { runs.push(Vec::new()); } + let mut generated_lints = BTreeMap::new(); let mut builds_for_summary = Vec::new(); for packages in runs { let mut make_source = spk_cmd_make_source::cmd_make_source::MakeSource { @@ -76,10 +80,13 @@ impl Run for Build { packages: packages.clone(), runtime: self.runtime.clone(), created_src: std::mem::take(&mut builds_for_summary), + lints: BTreeMap::new(), }; let idents = make_source.make_source().await?; builds_for_summary = std::mem::take(&mut make_source.created_src); + generated_lints.extend(std::mem::take(&mut make_source.lints)); + let mut make_binary = spk_cmd_make_binary::cmd_make_binary::MakeBinary { verbose: self.verbose, runtime: self.runtime.clone(), @@ -113,6 +120,17 @@ impl Run for Build { println!("{msg}"); } + if !generated_lints.is_empty() { + println!("Lints:"); + for (pkg, lints) in generated_lints.iter() { + for lint in lints.iter() { + match lint { + Key(k) => tracing::warn!("{} {}", pkg, k.generate_message()), + } + } + } + } + Ok(0) } } diff --git a/crates/spk-cli/cmd-make-source/Cargo.toml b/crates/spk-cli/cmd-make-source/Cargo.toml index 1358842159..d8a139ca85 100644 --- a/crates/spk-cli/cmd-make-source/Cargo.toml +++ b/crates/spk-cli/cmd-make-source/Cargo.toml @@ -19,6 +19,7 @@ migration-to-components = [ miette = { workspace = true, features = ["fancy"] } async-trait = { workspace = true } clap = { workspace = true } +serde_yaml = { workspace = true } spfs = { path = '../../spfs' } spk-build = { path = '../../spk-build' } spk-cli-common = { path = '../common' } diff --git a/crates/spk-cli/cmd-make-source/src/cmd_make_source.rs b/crates/spk-cli/cmd-make-source/src/cmd_make_source.rs index afdb1ed65a..8439b0074c 100644 --- a/crates/spk-cli/cmd-make-source/src/cmd_make_source.rs +++ b/crates/spk-cli/cmd-make-source/src/cmd_make_source.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // https://github.com/imageworks/spk +use std::collections::BTreeMap; use std::path::PathBuf; use std::sync::Arc; @@ -12,7 +13,17 @@ use spk_cli_common::{flags, CommandArgs, Run}; use spk_schema::foundation::format::FormatIdent; use spk_schema::foundation::spec_ops::Named; use spk_schema::ident::LocatedBuildIdent; -use spk_schema::{Package, Recipe, SpecTemplate, Template, TemplateExt}; +use spk_schema::v0::Spec; +use spk_schema::{ + AnyIdent, + Lint, + LintedItem, + Package, + Recipe, + SpecTemplate, + Template, + TemplateExt, +}; use spk_storage as storage; /// Build a source package from a spec file. @@ -33,7 +44,12 @@ pub struct MakeSource { pub packages: Vec, /// Populated with the created src to generate a summary from the caller. + #[clap(skip)] pub created_src: Vec, + + /// Used to gather lints to output at the end of a build. + #[clap(skip)] + pub lints: BTreeMap>, } #[async_trait::async_trait] @@ -79,6 +95,7 @@ impl MakeSource { template } }; + let root = template .file_path() .parent() @@ -89,6 +106,20 @@ impl MakeSource { let recipe = template.render(&options)?; let ident = recipe.ident(); + let lints: std::result::Result>, serde_yaml::Error> = + serde_yaml::from_str(&template.render_to_string(&options)?); + + match lints { + Ok(linted_item) => match linted_item.lints.is_empty() { + true => (), + false => { + self.lints + .insert(ident.format_ident(), linted_item.lints.clone()); + } + }, + Err(e) => tracing::error!("Failed to retrieve lints: {e}"), + } + tracing::info!("saving package recipe for {}", ident.format_ident()); local.force_publish_recipe(&recipe).await?;