diff --git a/CHANGELOG.md b/CHANGELOG.md index e67944c3..5b123224 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## v1.0.17-alpha - unreleased +### Added + +- **aiken**: add ability to force warnings to cause a failing exit code on check, build, and docs + ### Fixed - **uplc**: trim whitespace when loading files with hex strings to avoid confusing errors #720 diff --git a/crates/aiken/src/cmd/blueprint/address.rs b/crates/aiken/src/cmd/blueprint/address.rs index fdf1f386..7f7ebbe5 100644 --- a/crates/aiken/src/cmd/blueprint/address.rs +++ b/crates/aiken/src/cmd/blueprint/address.rs @@ -34,7 +34,7 @@ pub fn exec( rebuild, }: Args, ) -> miette::Result<()> { - with_project(directory, |p| { + with_project(directory, false, |p| { if rebuild { p.build(false, Tracing::NoTraces)?; } diff --git a/crates/aiken/src/cmd/blueprint/apply.rs b/crates/aiken/src/cmd/blueprint/apply.rs index 56881538..e8555f44 100644 --- a/crates/aiken/src/cmd/blueprint/apply.rs +++ b/crates/aiken/src/cmd/blueprint/apply.rs @@ -48,7 +48,7 @@ pub fn exec( validator, }: Args, ) -> miette::Result<()> { - with_project(None, |p| { + with_project(None, false, |p| { let title = module.as_ref().map(|m| { format!( "{m}{}", diff --git a/crates/aiken/src/cmd/blueprint/hash.rs b/crates/aiken/src/cmd/blueprint/hash.rs index 0e7ca4f9..95471be8 100644 --- a/crates/aiken/src/cmd/blueprint/hash.rs +++ b/crates/aiken/src/cmd/blueprint/hash.rs @@ -29,7 +29,7 @@ pub fn exec( rebuild, }: Args, ) -> miette::Result<()> { - with_project(directory, |p| { + with_project(directory, false, |p| { if rebuild { p.build(false, Tracing::NoTraces)?; } diff --git a/crates/aiken/src/cmd/blueprint/policy.rs b/crates/aiken/src/cmd/blueprint/policy.rs index 982c17d5..549236f7 100644 --- a/crates/aiken/src/cmd/blueprint/policy.rs +++ b/crates/aiken/src/cmd/blueprint/policy.rs @@ -29,7 +29,7 @@ pub fn exec( rebuild, }: Args, ) -> miette::Result<()> { - with_project(directory, |p| { + with_project(directory, false, |p| { if rebuild { p.build(false, Tracing::NoTraces)?; } diff --git a/crates/aiken/src/cmd/build.rs b/crates/aiken/src/cmd/build.rs index f735dcb6..898c0796 100644 --- a/crates/aiken/src/cmd/build.rs +++ b/crates/aiken/src/cmd/build.rs @@ -6,6 +6,10 @@ pub struct Args { /// Path to project directory: Option, + /// Deny warnings; warnings will be treated as errors + #[clap(short = 'D', long)] + deny: bool, + /// Also dump textual uplc #[clap(short, long)] uplc: bool, @@ -18,9 +22,10 @@ pub struct Args { pub fn exec( Args { directory, + deny, uplc, keep_traces, }: Args, ) -> miette::Result<()> { - crate::with_project(directory, |p| p.build(uplc, keep_traces.into())) + crate::with_project(directory, deny, |p| p.build(uplc, keep_traces.into())) } diff --git a/crates/aiken/src/cmd/check.rs b/crates/aiken/src/cmd/check.rs index b6c0f312..5b9aa278 100644 --- a/crates/aiken/src/cmd/check.rs +++ b/crates/aiken/src/cmd/check.rs @@ -6,6 +6,10 @@ pub struct Args { /// Path to project directory: Option, + /// Deny warnings; warnings will be treated as errors + #[clap(short = 'D', long)] + deny: bool, + /// Skip tests; run only the type-checker #[clap(short, long)] skip_tests: bool, @@ -33,6 +37,7 @@ pub struct Args { pub fn exec( Args { directory, + deny, skip_tests, debug, match_tests, @@ -40,7 +45,7 @@ pub fn exec( no_traces, }: Args, ) -> miette::Result<()> { - crate::with_project(directory, |p| { + crate::with_project(directory, deny, |p| { p.check( skip_tests, match_tests.clone(), diff --git a/crates/aiken/src/cmd/docs.rs b/crates/aiken/src/cmd/docs.rs index ec2e4442..9b3e94a7 100644 --- a/crates/aiken/src/cmd/docs.rs +++ b/crates/aiken/src/cmd/docs.rs @@ -6,6 +6,10 @@ pub struct Args { /// Path to project directory: Option, + /// Deny warnings; warnings will be treated as errors + #[clap(short = 'D', long)] + deny: bool, + /// Output directory for the documentation #[clap(short = 'o', long)] destination: Option, @@ -14,8 +18,9 @@ pub struct Args { pub fn exec( Args { directory, + deny, destination, }: Args, ) -> miette::Result<()> { - crate::with_project(directory, |p| p.docs(destination.clone())) + crate::with_project(directory, deny, |p| p.docs(destination.clone())) } diff --git a/crates/aiken/src/cmd/new.rs b/crates/aiken/src/cmd/new.rs index 33738e49..5c93b159 100644 --- a/crates/aiken/src/cmd/new.rs +++ b/crates/aiken/src/cmd/new.rs @@ -199,7 +199,7 @@ fn create_github_action(root: &Path) -> miette::Result<()> { version: v{version} - run: aiken fmt --check - - run: aiken check + - run: aiken check -D - run: aiken build "#, version = built_info::PKG_VERSION, diff --git a/crates/aiken/src/lib.rs b/crates/aiken/src/lib.rs index 6e603a93..cc3c1ba2 100644 --- a/crates/aiken/src/lib.rs +++ b/crates/aiken/src/lib.rs @@ -13,7 +13,7 @@ pub mod built_info { include!(concat!(env!("OUT_DIR"), "/built.rs")); } -pub fn with_project(directory: Option, mut action: A) -> miette::Result<()> +pub fn with_project(directory: Option, deny: bool, mut action: A) -> miette::Result<()> where A: FnMut(&mut Project) -> Result<(), Vec>, { @@ -37,7 +37,7 @@ where let warning_count = warnings.len(); - for warning in warnings { + for warning in &warnings { warning.report() } @@ -85,6 +85,11 @@ where warning_text.if_supports_color(Stderr, |s| s.yellow()), ); } + + if warning_count > 0 && deny { + process::exit(1); + } + Ok(()) }