Deny on warnings in xtasks

This commit is contained in:
datdenkikniet 2023-04-16 12:51:11 +02:00
parent 4d3361658b
commit 2db26c1015
10 changed files with 123 additions and 58 deletions

View file

@ -25,9 +25,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Fail on warnings
run: find . -type f -name lib.rs -execdir sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' {} +
- name: Cache Dependencies
uses: Swatinem/rust-cache@v2
@ -62,13 +59,10 @@ jobs:
rustup target add thumbv8m.base-none-eabi
rustup target add thumbv8m.main-none-eabi
- name: Fail on warnings
run: find . -type f -name lib.rs -execdir sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' {} +
- name: Cache Dependencies
uses: Swatinem/rust-cache@v2
- run: cargo xtask --backend ${{ matrix.backend }} check
- run: cargo xtask --deny-warnings --backend ${{ matrix.backend }} check
# Clippy
clippy:
@ -101,13 +95,10 @@ jobs:
- name: Add Rust component clippy
run: rustup component add clippy
- name: Fail on warnings
run: find . -type f -name lib.rs -execdir sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' {} +
- name: Cache Dependencies
uses: Swatinem/rust-cache@v2
- run: cargo xtask --backend ${{ matrix.backend }} clippy
- run: cargo xtask --deny-warnings --backend ${{ matrix.backend }} clippy
# Verify all examples, checks
checkexamples:
@ -219,12 +210,8 @@ jobs:
sudo apt update
sudo apt install -y qemu-system-arm
- name: Fail on warnings
working-directory: ./rtic
run: sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' src/lib.rs
- name: Run-pass tests
run: cargo xtask --backend ${{ matrix.backend }} qemu
run: cargo xtask --deny-warnings --backend ${{ matrix.backend }} qemu
# Run test suite
tests:
@ -260,11 +247,8 @@ jobs:
rustup target add thumbv8m.base-none-eabi
rustup target add thumbv8m.main-none-eabi
- name: Fail on warnings
run: find . -type f -name lib.rs -execdir sed -i 's,//deny_warnings_placeholder_for_ci,#![deny(warnings)],' {} +
- name: Run cargo test
run: cargo xtask --backend ${{ matrix.backend }} test ${{ matrix.package }}
run: cargo xtask --deny-warnings --backend ${{ matrix.backend }} test ${{ matrix.package }}
# Build documentation, check links
docs:

View file

@ -2,7 +2,6 @@
#![no_std]
#![deny(missing_docs)]
//deny_warnings_placeholder_for_ci
#[cfg(test)]
#[macro_use]

View file

@ -2,7 +2,6 @@
html_logo_url = "https://raw.githubusercontent.com/rtic-rs/rtic/master/book/en/src/RTIC.svg",
html_favicon_url = "https://raw.githubusercontent.com/rtic-rs/rtic/master/book/en/src/RTIC.svg"
)]
//deny_warnings_placeholder_for_ci
use proc_macro::TokenStream;
use std::{env, fs, path::Path};

View file

@ -2,7 +2,6 @@
#![no_std]
#![deny(missing_docs)]
//deny_warnings_placeholder_for_ci
#![allow(incomplete_features)]
#![feature(async_fn_in_trait)]

View file

@ -2,7 +2,6 @@
#![no_std]
#![deny(missing_docs)]
//deny_warnings_placeholder_for_ci
pub mod arbiter;
pub mod channel;

View file

@ -2,7 +2,6 @@
#![no_std]
#![deny(missing_docs)]
//deny_warnings_placeholder_for_ci
#![allow(incomplete_features)]
#![feature(async_fn_in_trait)]

View file

@ -30,7 +30,6 @@
html_logo_url = "https://raw.githubusercontent.com/rtic-rs/rtic/master/book/en/src/RTIC.svg",
html_favicon_url = "https://raw.githubusercontent.com/rtic-rs/rtic/master/book/en/src/RTIC.svg"
)]
//deny_warnings_placeholder_for_ci
#![allow(clippy::inline_always)]
pub use rtic_core::{prelude as mutex_prelude, Exclusive, Mutex};

View file

@ -94,7 +94,11 @@ impl Package {
pub struct TestMetadata {}
impl TestMetadata {
pub fn match_package(package: Package, backend: Backends) -> CargoCommand<'static> {
pub fn match_package(
deny_warnings: bool,
package: Package,
backend: Backends,
) -> CargoCommand<'static> {
match package {
Package::Rtic => {
let features = format!(
@ -107,32 +111,38 @@ impl TestMetadata {
package: Some(package.name()),
features,
test: Some("ui".to_owned()),
deny_warnings,
}
}
Package::RticMacros => CargoCommand::Test {
package: Some(package.name()),
features: Some(backend.to_rtic_macros_feature().to_owned()),
test: None,
deny_warnings,
},
Package::RticSync => CargoCommand::Test {
package: Some(package.name()),
features: Some("testing".to_owned()),
test: None,
deny_warnings,
},
Package::RticCommon => CargoCommand::Test {
package: Some(package.name()),
features: Some("testing".to_owned()),
test: None,
deny_warnings,
},
Package::RticMonotonics => CargoCommand::Test {
package: Some(package.name()),
features: None,
test: None,
deny_warnings,
},
Package::RticTime => CargoCommand::Test {
package: Some(package.name()),
features: Some("critical-section/std".into()),
test: None,
deny_warnings,
},
}
}
@ -192,6 +202,10 @@ pub enum BuildOrCheck {
#[derive(Parser, Clone)]
pub struct Globals {
/// Error out on warnings
#[arg(short = 'D', long)]
pub deny_warnings: bool,
/// For which backend to build.
#[arg(value_enum, short, default_value = "thumbv7", long, global = true)]
pub backend: Option<Backends>,

View file

@ -28,6 +28,7 @@ pub enum CargoCommand<'a> {
features: Option<String>,
mode: BuildMode,
dir: Option<PathBuf>,
deny_warnings: bool,
},
ExampleBuild {
cargoarg: &'a Option<&'a str>,
@ -36,6 +37,7 @@ pub enum CargoCommand<'a> {
features: Option<String>,
mode: BuildMode,
dir: Option<PathBuf>,
deny_warnings: bool,
},
ExampleCheck {
cargoarg: &'a Option<&'a str>,
@ -43,6 +45,7 @@ pub enum CargoCommand<'a> {
target: Option<Target<'a>>,
features: Option<String>,
mode: BuildMode,
deny_warnings: bool,
},
Build {
cargoarg: &'a Option<&'a str>,
@ -51,6 +54,7 @@ pub enum CargoCommand<'a> {
features: Option<String>,
mode: BuildMode,
dir: Option<PathBuf>,
deny_warnings: bool,
},
Check {
cargoarg: &'a Option<&'a str>,
@ -59,6 +63,7 @@ pub enum CargoCommand<'a> {
features: Option<String>,
mode: BuildMode,
dir: Option<PathBuf>,
deny_warnings: bool,
},
Clippy {
cargoarg: &'a Option<&'a str>,
@ -81,6 +86,7 @@ pub enum CargoCommand<'a> {
package: Option<String>,
features: Option<String>,
test: Option<String>,
deny_warnings: bool,
},
Book {
arguments: Option<ExtraArguments>,
@ -123,6 +129,7 @@ impl core::fmt::Display for CargoCommand<'_> {
}
fn details(
deny_warnings: bool,
target: &Option<Target>,
mode: Option<&BuildMode>,
features: &Option<String>,
@ -150,14 +157,20 @@ impl core::fmt::Display for CargoCommand<'_> {
format!("debug")
};
if cargoarg.is_some() && path.is_some() {
format!("({target}, {mode}, {feat}, {carg}, {in_dir})")
} else if cargoarg.is_some() {
format!("({target}, {mode}, {feat}, {carg})")
} else if path.is_some() {
format!("({target}, {mode}, {feat}, {in_dir})")
let deny_warnings = if deny_warnings {
format!("deny warnings, ")
} else {
format!("({target}, {mode}, {feat})")
format!("")
};
if cargoarg.is_some() && path.is_some() {
format!("({deny_warnings}{target}, {mode}, {feat}, {carg}, {in_dir})")
} else if cargoarg.is_some() {
format!("({deny_warnings}{target}, {mode}, {feat}, {carg})")
} else if path.is_some() {
format!("({deny_warnings}{target}, {mode}, {feat}, {in_dir})")
} else {
format!("({deny_warnings}{target}, {mode}, {feat})")
}
}
@ -173,7 +186,7 @@ impl core::fmt::Display for CargoCommand<'_> {
write!(
f,
"Run example {example} {}",
details(target, Some(mode), features, cargoarg, dir.as_ref())
details(false, target, Some(mode), features, cargoarg, dir.as_ref())
)
}
CargoCommand::Qemu {
@ -183,8 +196,10 @@ impl core::fmt::Display for CargoCommand<'_> {
features,
mode,
dir,
deny_warnings,
} => {
let details = details(target, Some(mode), features, cargoarg, dir.as_ref());
let warns = *deny_warnings;
let details = details(warns, target, Some(mode), features, cargoarg, dir.as_ref());
write!(f, "Run example {example} in QEMU {details}",)
}
CargoCommand::ExampleBuild {
@ -194,8 +209,10 @@ impl core::fmt::Display for CargoCommand<'_> {
features,
mode,
dir,
deny_warnings,
} => {
let details = details(target, Some(mode), features, cargoarg, dir.as_ref());
let warns = *deny_warnings;
let details = details(warns, target, Some(mode), features, cargoarg, dir.as_ref());
write!(f, "Build example {example} {details}",)
}
CargoCommand::ExampleCheck {
@ -204,10 +221,11 @@ impl core::fmt::Display for CargoCommand<'_> {
target,
features,
mode,
deny_warnings,
} => write!(
f,
"Check example {example} {}",
details(target, Some(mode), features, cargoarg, None)
details(*deny_warnings, target, Some(mode), features, cargoarg, None)
),
CargoCommand::Build {
cargoarg,
@ -216,12 +234,14 @@ impl core::fmt::Display for CargoCommand<'_> {
features,
mode,
dir,
deny_warnings,
} => {
let package = p(package);
let warns = *deny_warnings;
write!(
f,
"Build {package} {}",
details(target, Some(mode), features, cargoarg, dir.as_ref())
details(warns, target, Some(mode), features, cargoarg, dir.as_ref())
)
}
@ -232,12 +252,14 @@ impl core::fmt::Display for CargoCommand<'_> {
features,
mode,
dir,
deny_warnings,
} => {
let package = p(package);
let warns = *deny_warnings;
write!(
f,
"Check {package} {}",
details(target, Some(mode), features, cargoarg, dir.as_ref())
details(warns, target, Some(mode), features, cargoarg, dir.as_ref())
)
}
CargoCommand::Clippy {
@ -247,14 +269,9 @@ impl core::fmt::Display for CargoCommand<'_> {
features,
deny_warnings,
} => {
let details = details(target, None, features, cargoarg, None);
let details = details(*deny_warnings, target, None, features, cargoarg, None);
let package = p(package);
let deny_warns = if *deny_warnings {
format!(" (deny warnings)")
} else {
format!("")
};
write!(f, "Clippy{deny_warns} {package} {details}")
write!(f, "Clippy {package} {details}")
}
CargoCommand::Format {
cargoarg,
@ -297,14 +314,20 @@ impl core::fmt::Display for CargoCommand<'_> {
package,
features,
test,
deny_warnings,
} => {
let p = p(package);
let test = test
.clone()
.map(|t| format!("test {t}"))
.unwrap_or("all tests".into());
let deny_warnings = if *deny_warnings {
format!("deny warnings, ")
} else {
format!("")
};
let feat = feat(features);
write!(f, "Run {test} in {p} (features: {feat})")
write!(f, "Run {test} in {p} ({deny_warnings}features: {feat})")
}
CargoCommand::Book { arguments: _ } => write!(f, "Build the book"),
CargoCommand::ExampleSize {
@ -316,7 +339,7 @@ impl core::fmt::Display for CargoCommand<'_> {
arguments: _,
dir,
} => {
let details = details(target, Some(mode), features, cargoarg, dir.as_ref());
let details = details(false, target, Some(mode), features, cargoarg, dir.as_ref());
write!(f, "Compute size of example {example} {details}")
}
}
@ -459,6 +482,8 @@ impl<'a> CargoCommand<'a> {
dir: _,
// Target is added by build_args
target: _,
// deny_warnings is exposed through `rustflags`
deny_warnings: _,
} => self.build_args(
true,
cargoarg,
@ -471,10 +496,12 @@ impl<'a> CargoCommand<'a> {
package,
features,
mode,
// Dir is exposed through `chdir`
dir: _,
// Target is added by build_args
target: _,
// Dir is exposed through `chdir`
dir: _,
// deny_warnings is exposed through `rustflags`
deny_warnings: _,
} => self.build_args(true, cargoarg, features, Some(mode), p(package)),
CargoCommand::Check {
cargoarg,
@ -485,23 +512,25 @@ impl<'a> CargoCommand<'a> {
dir: _,
// Target is added by build_args
target: _,
// deny_warnings is exposed through `rustflags`
deny_warnings: _,
} => self.build_args(true, cargoarg, features, Some(mode), p(package)),
CargoCommand::Clippy {
cargoarg,
package,
features,
deny_warnings,
// Target is added by build_args
target: _,
deny_warnings,
} => {
let package = p(package);
let extra = if *deny_warnings {
vec!["--", "-D", "warnings"].into_iter()
let deny_warnings = if *deny_warnings {
vec!["--", "-D", "warnings"]
} else {
vec![].into_iter()
vec![]
};
self.build_args(true, cargoarg, features, None, package.chain(extra))
let extra = p(package).chain(deny_warnings);
self.build_args(true, cargoarg, features, None, extra)
}
CargoCommand::Doc {
cargoarg,
@ -515,6 +544,8 @@ impl<'a> CargoCommand<'a> {
package,
features,
test,
// deny_warnings is exposed through `rustflags`
deny_warnings: _,
} => {
let extra = if let Some(test) = test {
vec!["--test", test]
@ -564,6 +595,8 @@ impl<'a> CargoCommand<'a> {
dir: _,
// Target is added by build_args
target: _,
// deny_warnings is exposed through `rustflags`
deny_warnings: _,
} => self.build_args(
true,
cargoarg,
@ -578,6 +611,8 @@ impl<'a> CargoCommand<'a> {
mode,
// Target is added by build_args
target: _,
// deny_warnings is exposed through `rustflags`
deny_warnings: _,
} => self.build_args(
true,
cargoarg,
@ -632,6 +667,27 @@ impl<'a> CargoCommand<'a> {
}
}
pub fn rustflags(&self) -> Option<&str> {
match self {
// Clippy is a special case: it sets deny warnings
// through an argument to rustc.
CargoCommand::Clippy { .. } => None,
CargoCommand::Check { deny_warnings, .. }
| CargoCommand::ExampleCheck { deny_warnings, .. }
| CargoCommand::Build { deny_warnings, .. }
| CargoCommand::ExampleBuild { deny_warnings, .. }
| CargoCommand::Test { deny_warnings, .. }
| CargoCommand::Qemu { deny_warnings, .. } => {
if *deny_warnings {
Some("-D warnings")
} else {
None
}
}
_ => None,
}
}
pub fn print_stdout_intermediate(&self) -> bool {
match self {
Self::ExampleSize { .. } => true,

View file

@ -172,6 +172,7 @@ pub fn cargo<'c>(
features,
mode: BuildMode::Release,
dir: None,
deny_warnings: globals.deny_warnings,
},
BuildOrCheck::Build => CargoCommand::Build {
cargoarg,
@ -180,6 +181,7 @@ pub fn cargo<'c>(
features,
mode: BuildMode::Release,
dir: None,
deny_warnings: globals.deny_warnings,
},
};
@ -209,6 +211,7 @@ pub fn cargo_usage_example(
package: None,
target: None,
features: None,
deny_warnings: globals.deny_warnings,
},
BuildOrCheck::Build => CargoCommand::Build {
cargoarg: &None,
@ -217,6 +220,7 @@ pub fn cargo_usage_example(
features: None,
mode: BuildMode::Release,
dir: Some(path.into()),
deny_warnings: globals.deny_warnings,
},
};
(globals, command, false)
@ -244,6 +248,7 @@ pub fn cargo_example<'c>(
target: Some(backend.to_target()),
features,
mode: BuildMode::Release,
deny_warnings: globals.deny_warnings,
},
BuildOrCheck::Build => CargoCommand::ExampleBuild {
cargoarg,
@ -252,6 +257,7 @@ pub fn cargo_example<'c>(
features,
mode: BuildMode::Release,
dir: Some(PathBuf::from("./rtic")),
deny_warnings: globals.deny_warnings,
},
};
(globals, command, false)
@ -337,7 +343,10 @@ pub fn cargo_test<'c>(
) -> Vec<FinalRunResult<'c>> {
package
.packages()
.map(|p| (globals, TestMetadata::match_package(p, backend), false))
.map(|p| {
let meta = TestMetadata::match_package(globals.deny_warnings, p, backend);
(globals, meta, false)
})
.run_and_coalesce()
}
@ -378,6 +387,7 @@ pub fn qemu_run_examples<'c>(
features: features.clone(),
mode: BuildMode::Release,
dir: Some(PathBuf::from("./rtic")),
deny_warnings: globals.deny_warnings,
};
let cmd_qemu = CargoCommand::Qemu {
@ -387,6 +397,7 @@ pub fn qemu_run_examples<'c>(
features: features.clone(),
mode: BuildMode::Release,
dir: Some(PathBuf::from("./rtic")),
deny_warnings: globals.deny_warnings,
};
into_iter([cmd_build, cmd_qemu])
@ -417,7 +428,9 @@ pub fn build_and_check_size<'c>(
features: features.clone(),
mode: BuildMode::Release,
dir: Some(PathBuf::from("./rtic")),
deny_warnings: globals.deny_warnings,
};
if let Err(err) = command_parser(globals, &cmd, false) {
error!("{err}");
}
@ -455,6 +468,10 @@ fn run_command(
process.current_dir(dir.canonicalize()?);
}
if let Some(rustflags) = command.rustflags() {
process.env("RUSTFLAGS", rustflags);
}
let result = process.output()?;
let exit_status = result.status;