Skip to content

Commit

Permalink
Add --fix to lint-packages (#2351)
Browse files Browse the repository at this point in the history
* Add --fix to lint-packages

* Fix suggestion that breaks clippy
  • Loading branch information
bugadani authored Oct 15, 2024
1 parent f0a361e commit 67bc37f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
6 changes: 3 additions & 3 deletions esp-hal/src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ where
};

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
let pcr = unsafe { &*crate::peripherals::PCR::PTR };
Expand Down Expand Up @@ -2531,9 +2531,9 @@ pub mod lp_uart {

fn change_baud_internal(&mut self, baudrate: u32, clock_source: super::ClockSource) {
// 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 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 {
w.sclk_div_a()
Expand Down
32 changes: 24 additions & 8 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ struct LintPackagesArgs {
/// Lint for a specific chip
#[arg(long, value_enum, default_values_t = Chip::iter())]
chips: Vec<Chip>,

/// Automatically apply fixes
#[arg(long)]
fix: bool,
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -585,6 +589,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
&format!("--target={}", chip.target()),
&format!("--features={chip},defmt"),
],
args.fix,
)?;
}

Expand Down Expand Up @@ -613,6 +618,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
&format!("--target={}", chip.target()),
&features,
],
args.fix,
)?;
}

Expand All @@ -624,6 +630,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
&format!("--target={}", chip.target()),
&format!("--features={chip},executors,defmt,integrated-timers"),
],
args.fix,
)?;
}

Expand All @@ -637,6 +644,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
&format!("--target={}", chip.target()),
&features,
],
args.fix,
)?;
}
}
Expand All @@ -649,6 +657,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
&format!("--target={}", chip.lp_target().unwrap()),
&format!("--features={chip},embedded-io"),
],
args.fix,
)?;
}
}
Expand All @@ -661,6 +670,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
&format!("--target={}", chip.target()),
&format!("--features={chip},defmt-espflash"),
],
args.fix,
)?;
}

Expand All @@ -669,6 +679,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
lint_package(
&path,
&["-Zbuild-std=core", &format!("--target={}", chip.target())],
args.fix,
)?;
}
}
Expand All @@ -681,6 +692,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
&format!("--target={}", chip.target()),
&format!("--features={chip},storage,nor-flash,low-level"),
],
args.fix,
)?;
}

Expand All @@ -705,6 +717,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
"--no-default-features",
&features,
],
args.fix,
)?;
}

Expand All @@ -717,6 +730,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
&format!("--target={}", chip.target()),
&format!("--features={chip}"),
],
args.fix,
)?
}
}
Expand All @@ -726,15 +740,15 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> {
Package::Examples | Package::HilTest => {}

// By default, no `clippy` arguments are required:
_ => lint_package(&path, &[])?,
_ => lint_package(&path, &[], args.fix)?,
}
}
}

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());

let mut builder = CargoArgsBuilder::default().subcommand("clippy");
Expand All @@ -744,12 +758,14 @@ fn lint_package(path: &Path, args: &[&str]) -> Result<()> {
}

// build in release to reuse example artifacts
let cargo_args = builder
.arg("--release")
.arg("--")
.arg("-D")
.arg("warnings")
.build();
let cargo_args = builder.arg("--release");
let cargo_args = if fix {
cargo_args.arg("--fix").arg("--lib")
} else {
cargo_args.arg("--").arg("-D").arg("warnings")
};

let cargo_args = cargo_args.build();

xtask::cargo::run(&cargo_args, path)
}
Expand Down

0 comments on commit 67bc37f

Please sign in to comment.