Skip to content

Commit bb4d769

Browse files
authored
Add basic tool management. (#27)
Foundation for running commands with locked tool versions.
1 parent 106b419 commit bb4d769

22 files changed

Lines changed: 593 additions & 180 deletions

.prep/prep.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
[project]
22
name = "Prep"
33
license = "Apache-2.0 OR MIT"
4+
5+
[tools]
6+
rustup = "=1"
7+
rust = "=1.93"
8+
ripgrep = "=14.1.1"

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
### Added
66

7+
* `tools` command for tool management. ([#27] by [@xStrom])
8+
* `--strict` option to `clippy`, `copyright`, and `format` commands to use locked tool versions. ([#27] by [@xStrom])
9+
710
## [0.2.0] - 2026-02-07
811

912
### Added
@@ -35,6 +38,7 @@
3538
[#22]: https://github.com/Nevermore/prep/pull/22
3639
[#23]: https://github.com/Nevermore/prep/pull/23
3740
[#24]: https://github.com/Nevermore/prep/pull/24
41+
[#27]: https://github.com/Nevermore/prep/pull/27
3842

3943
[Unreleased]: https://github.com/Nevermore/prep/compare/v0.2.0...HEAD
4044
[0.2.0]: https://github.com/Nevermore/prep/compare/v0.1.0...v0.2.0

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ anyhow = "1.0.101"
1818
cargo_metadata = "0.23.1"
1919
clap = "4.5.57"
2020
regex = "1.12.3"
21+
semver = "1.0.27"
2122
serde = "1.0.228"
2223
time = "0.3.47"
2324
toml = "0.9.11"

prep/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ anyhow.workspace = true
2323
cargo_metadata.workspace = true
2424
clap = { workspace = true, features = ["derive"] }
2525
regex.workspace = true
26+
semver.workspace = true
2627
serde = { workspace = true, features = ["derive"] }
2728
time.workspace = true
2829
toml.workspace = true

prep/src/cmd/ci.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use crate::session::Session;
99
/// Can be ran in `extended` mode for more thorough checks.
1010
///
1111
/// Set `fail_fast` to `false` to run the checks to the end regardless of failure.
12-
pub fn run(session: &Session, extended: bool, fail_fast: bool) -> anyhow::Result<()> {
12+
pub fn run(session: &mut Session, extended: bool, fail_fast: bool) -> anyhow::Result<()> {
1313
let mut errs: Vec<anyhow::Error> = Vec::new();
14-
let mut step = |f: &dyn Fn() -> anyhow::Result<()>| -> anyhow::Result<()> {
14+
let mut step = |f: &mut dyn FnMut() -> anyhow::Result<()>| -> anyhow::Result<()> {
1515
if let Err(e) = f() {
1616
if fail_fast {
1717
return Err(e);
@@ -22,16 +22,16 @@ pub fn run(session: &Session, extended: bool, fail_fast: bool) -> anyhow::Result
2222
};
2323

2424
//step(&|| copyright::run(session))?;
25-
step(&|| format::run(session, true))?;
25+
step(&mut || format::run(session, true, true))?;
2626

2727
if extended {
2828
// We need to avoid --all-targets because it will unify dev and regular dep features.
29-
step(&|| clippy::run(session, CargoTargets::Main, true))?;
30-
step(&|| clippy::run(session, CargoTargets::Auxiliary, true))?;
29+
step(&mut || clippy::run(session, true, CargoTargets::Main))?;
30+
step(&mut || clippy::run(session, true, CargoTargets::Auxiliary))?;
3131
} else {
3232
// Slightly faster due to shared build cache,
3333
// but will miss unified feature bugs.
34-
step(&|| clippy::run(session, CargoTargets::All, true))?;
34+
step(&mut || clippy::run(session, true, CargoTargets::All))?;
3535
}
3636

3737
if errs.is_empty() {

prep/src/cmd/clippy.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,25 @@ use anyhow::{Context, ensure};
55

66
use crate::cmd::CargoTargets;
77
use crate::session::Session;
8-
use crate::tools::cargo;
8+
use crate::tools::cargo::{Cargo, CargoDeps};
99
use crate::ui;
1010

1111
/// Runs Clippy analysis on the given `targets`.
1212
///
13-
/// In `strict` mode warnings are treated as errors.
14-
pub fn run(session: &Session, targets: CargoTargets, strict: bool) -> anyhow::Result<()> {
15-
let mut cmd = cargo::new("")?;
13+
/// In `strict` mode warnings are treated as errors and Cargo version is locked.
14+
pub fn run(session: &mut Session, strict: bool, targets: CargoTargets) -> anyhow::Result<()> {
15+
let mut cmd = if strict {
16+
let tools_cfg = session.config().tools();
17+
let rustup_ver_req = tools_cfg.rustup().clone();
18+
let ver_req = tools_cfg.rust().clone();
19+
let toolset = session.toolset();
20+
let deps = CargoDeps::new(rustup_ver_req);
21+
toolset.get::<Cargo>(&deps, &ver_req)?
22+
} else {
23+
let toolset = session.toolset();
24+
let deps = CargoDeps::new(None);
25+
toolset.get::<Cargo>(&deps, None)?
26+
};
1627
let mut cmd = cmd
1728
.current_dir(session.root_dir())
1829
.arg("clippy")

prep/src/cmd/copyright.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ use crate::ui::style::{ERROR, HEADER, LITERAL, NOTE};
1414
// TODO: Allow excluding files from the check
1515

1616
/// Verify copyright headers.
17-
pub fn run(session: &Session) -> anyhow::Result<()> {
17+
///
18+
/// In `strict` mode ripgrep version is locked.
19+
pub fn run(session: &mut Session, _strict: bool) -> anyhow::Result<()> {
1820
let config = session.config();
1921
let project = config.project();
2022
let header_regex = header_regex(project.name(), project.license());
2123

24+
// TODO: Strict mode for ripgrep.
2225
let mut cmd = Command::new("rg");
2326
let cmd = cmd
2427
.current_dir(session.root_dir())

prep/src/cmd/format.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@
44
use anyhow::{Context, ensure};
55

66
use crate::session::Session;
7-
use crate::tools::cargo;
7+
use crate::tools::cargo::{Cargo, CargoDeps};
88
use crate::ui;
99

10-
/// Format the workspace
11-
pub fn run(session: &Session, check: bool) -> anyhow::Result<()> {
12-
let mut cmd = cargo::new("")?;
10+
/// Format the workspace.
11+
///
12+
/// In `strict` mode Cargo version is locked.
13+
pub fn run(session: &mut Session, strict: bool, check: bool) -> anyhow::Result<()> {
14+
let mut cmd = if strict {
15+
let tools_cfg = session.config().tools();
16+
let rustup_ver_req = tools_cfg.rustup().clone();
17+
let ver_req = tools_cfg.rust().clone();
18+
let toolset = session.toolset();
19+
let deps = CargoDeps::new(rustup_ver_req);
20+
toolset.get::<Cargo>(&deps, &ver_req)?
21+
} else {
22+
let toolset = session.toolset();
23+
let deps = CargoDeps::new(None);
24+
toolset.get::<Cargo>(&deps, None)?
25+
};
1326
let mut cmd = cmd.current_dir(session.root_dir()).arg("fmt").arg("--all");
1427
if check {
1528
cmd = cmd.arg("--check");

prep/src/cmd/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub mod clippy;
88
pub mod copyright;
99
pub mod format;
1010
pub mod init;
11+
pub mod tools;
1112

1213
/// Cargo targets.
1314
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]

0 commit comments

Comments
 (0)