Add --fix to lint-packages (#2351)

* Add --fix to lint-packages

* Fix suggestion that breaks clippy
This commit is contained in:
Dániel Buga 2024-10-15 11:33:15 +02:00 committed by GitHub
parent f0a361e448
commit 67bc37fb93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 11 deletions

View File

@ -1142,7 +1142,7 @@ where
}; };
let max_div = 0b1111_1111_1111 - 1; let max_div = 0b1111_1111_1111 - 1;
let clk_div = ((clk) + (max_div * baudrate) - 1) / (max_div * baudrate); let clk_div = clk.div_ceil(max_div * baudrate);
// UART clocks are configured via PCR // UART clocks are configured via PCR
let pcr = unsafe { &*crate::peripherals::PCR::PTR }; let pcr = unsafe { &*crate::peripherals::PCR::PTR };
@ -2531,9 +2531,9 @@ pub mod lp_uart {
fn change_baud_internal(&mut self, baudrate: u32, clock_source: super::ClockSource) { fn change_baud_internal(&mut self, baudrate: u32, clock_source: super::ClockSource) {
// TODO: Currently it's not possible to use XtalD2Clk // TODO: Currently it's not possible to use XtalD2Clk
let clk = 16_000_000; let clk = 16_000_000_u32;
let max_div = 0b1111_1111_1111 - 1; let max_div = 0b1111_1111_1111 - 1;
let clk_div = ((clk) + (max_div * baudrate) - 1) / (max_div * baudrate); let clk_div = clk.div_ceil(max_div * baudrate);
self.uart.clk_conf().modify(|_, w| unsafe { self.uart.clk_conf().modify(|_, w| unsafe {
w.sclk_div_a() w.sclk_div_a()

View File

@ -142,6 +142,10 @@ struct LintPackagesArgs {
/// Lint for a specific chip /// Lint for a specific chip
#[arg(long, value_enum, default_values_t = Chip::iter())] #[arg(long, value_enum, default_values_t = Chip::iter())]
chips: Vec<Chip>, chips: Vec<Chip>,
/// Automatically apply fixes
#[arg(long)]
fix: bool,
} }
#[derive(Debug, Args)] #[derive(Debug, Args)]
@ -585,6 +589,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
&format!("--target={}", chip.target()), &format!("--target={}", chip.target()),
&format!("--features={chip},defmt"), &format!("--features={chip},defmt"),
], ],
args.fix,
)?; )?;
} }
@ -613,6 +618,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
&format!("--target={}", chip.target()), &format!("--target={}", chip.target()),
&features, &features,
], ],
args.fix,
)?; )?;
} }
@ -624,6 +630,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
&format!("--target={}", chip.target()), &format!("--target={}", chip.target()),
&format!("--features={chip},executors,defmt,integrated-timers"), &format!("--features={chip},executors,defmt,integrated-timers"),
], ],
args.fix,
)?; )?;
} }
@ -637,6 +644,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
&format!("--target={}", chip.target()), &format!("--target={}", chip.target()),
&features, &features,
], ],
args.fix,
)?; )?;
} }
} }
@ -649,6 +657,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
&format!("--target={}", chip.lp_target().unwrap()), &format!("--target={}", chip.lp_target().unwrap()),
&format!("--features={chip},embedded-io"), &format!("--features={chip},embedded-io"),
], ],
args.fix,
)?; )?;
} }
} }
@ -661,6 +670,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
&format!("--target={}", chip.target()), &format!("--target={}", chip.target()),
&format!("--features={chip},defmt-espflash"), &format!("--features={chip},defmt-espflash"),
], ],
args.fix,
)?; )?;
} }
@ -669,6 +679,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
lint_package( lint_package(
&path, &path,
&["-Zbuild-std=core", &format!("--target={}", chip.target())], &["-Zbuild-std=core", &format!("--target={}", chip.target())],
args.fix,
)?; )?;
} }
} }
@ -681,6 +692,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
&format!("--target={}", chip.target()), &format!("--target={}", chip.target()),
&format!("--features={chip},storage,nor-flash,low-level"), &format!("--features={chip},storage,nor-flash,low-level"),
], ],
args.fix,
)?; )?;
} }
@ -705,6 +717,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
"--no-default-features", "--no-default-features",
&features, &features,
], ],
args.fix,
)?; )?;
} }
@ -717,6 +730,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
&format!("--target={}", chip.target()), &format!("--target={}", chip.target()),
&format!("--features={chip}"), &format!("--features={chip}"),
], ],
args.fix,
)? )?
} }
} }
@ -726,7 +740,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
Package::Examples | Package::HilTest => {} Package::Examples | Package::HilTest => {}
// By default, no `clippy` arguments are required: // By default, no `clippy` arguments are required:
_ => lint_package(&path, &[])?, _ => lint_package(&path, &[], args.fix)?,
} }
} }
} }
@ -734,7 +748,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
Ok(()) Ok(())
} }
fn lint_package(path: &Path, args: &[&str]) -> Result<()> { fn lint_package(path: &Path, args: &[&str], fix: bool) -> Result<()> {
log::info!("Linting package: {}", path.display()); log::info!("Linting package: {}", path.display());
let mut builder = CargoArgsBuilder::default().subcommand("clippy"); let mut builder = CargoArgsBuilder::default().subcommand("clippy");
@ -744,12 +758,14 @@ fn lint_package(path: &Path, args: &[&str]) -> Result<()> {
} }
// build in release to reuse example artifacts // build in release to reuse example artifacts
let cargo_args = builder let cargo_args = builder.arg("--release");
.arg("--release") let cargo_args = if fix {
.arg("--") cargo_args.arg("--fix").arg("--lib")
.arg("-D") } else {
.arg("warnings") cargo_args.arg("--").arg("-D").arg("warnings")
.build(); };
let cargo_args = cargo_args.build();
xtask::cargo::run(&cargo_args, path) xtask::cargo::run(&cargo_args, path)
} }