Skip to content

Commit 4d1a11d

Browse files
committed
Deprecate util/dev in favor of cargo alias
If you've been using `./util/dev` before, this now becomes `cargo dev`. The key part of this change is found in `.cargo/config`. This means one less shell script and a bit more cross-platform support for contributors.
1 parent f69835b commit 4d1a11d

File tree

11 files changed

+41
-28
lines changed

11 files changed

+41
-28
lines changed

.cargo/config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[alias]
22
uitest = "test --test compile-test"
3+
dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
34

45
[build]
56
rustflags = ["-Zunstable-options"]

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ checked during review or continuous integration.
1515
- [ ] Followed [lint naming conventions][lint_naming]
1616
- [ ] Added passing UI tests (including committed `.stderr` file)
1717
- [ ] `cargo test` passes locally
18-
- [ ] Executed `./util/dev update_lints`
18+
- [ ] Executed `cargo dev update_lints`
1919
- [ ] Added lint documentation
20-
- [ ] Run `./util/dev fmt`
20+
- [ ] Run `cargo dev fmt`
2121

2222
[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
2323

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub fn register_plugins(reg: &mut rustc_driver::plugin::Registry) {
105105

106106
The [`plugin::PluginRegistry`][plugin_registry] provides two methods to register lints: [register_early_lint_pass][reg_early_lint_pass] and [register_late_lint_pass][reg_late_lint_pass].
107107
Both take an object that implements an [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass] respectively. This is done in every single lint.
108-
It's worth noting that the majority of `clippy_lints/src/lib.rs` is autogenerated by `util/dev update_lints` and you don't have to add anything by hand. When you are writing your own lint, you can use that script to save you some time.
108+
It's worth noting that the majority of `clippy_lints/src/lib.rs` is autogenerated by `cargo dev update_lints` and you don't have to add anything by hand. When you are writing your own lint, you can use that script to save you some time.
109109

110110
```rust
111111
// ./clippy_lints/src/else_if_without_else.rs

ci/base-tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ cargo test --features deny-warnings
2222
)
2323

2424
# Perform various checks for lint registration
25-
./util/dev update_lints --check
26-
./util/dev --limit-stderr-length
25+
cargo dev update_lints --check
26+
cargo dev --limit-stderr-length
2727

2828
# Check running clippy-driver without cargo
2929
(

clippy_dev/src/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn run(check: bool, verbose: bool) {
8888
Ok(false) => {
8989
eprintln!();
9090
eprintln!("Formatting check failed.");
91-
eprintln!("Run `./util/dev fmt` to update formatting.");
91+
eprintln!("Run `cargo dev fmt` to update formatting.");
9292
1
9393
},
9494
Err(err) => {

clippy_dev/src/lib.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::collections::HashMap;
77
use std::ffi::OsStr;
88
use std::fs;
99
use std::io::prelude::*;
10+
use std::path::{Path, PathBuf};
1011
use walkdir::WalkDir;
1112

1213
lazy_static! {
@@ -205,7 +206,8 @@ fn parse_contents(content: &str, filename: &str) -> impl Iterator<Item = Lint> {
205206
fn lint_files() -> impl Iterator<Item = walkdir::DirEntry> {
206207
// We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
207208
// Otherwise we would not collect all the lints, for example in `clippy_lints/src/methods/`.
208-
WalkDir::new("../clippy_lints/src")
209+
let path = clippy_project_dir().join("clippy_lints/src");
210+
WalkDir::new(path)
209211
.into_iter()
210212
.filter_map(std::result::Result::ok)
211213
.filter(|f| f.path().extension() == Some(OsStr::new("rs")))
@@ -225,7 +227,7 @@ pub struct FileChange {
225227
/// See `replace_region_in_text` for documentation of the other options.
226228
#[allow(clippy::expect_fun_call)]
227229
pub fn replace_region_in_file<F>(
228-
path: &str,
230+
path: &Path,
229231
start: &str,
230232
end: &str,
231233
replace_start: bool,
@@ -235,14 +237,15 @@ pub fn replace_region_in_file<F>(
235237
where
236238
F: Fn() -> Vec<String>,
237239
{
238-
let mut f = fs::File::open(path).expect(&format!("File not found: {}", path));
240+
let path = clippy_project_dir().join(path);
241+
let mut f = fs::File::open(&path).expect(&format!("File not found: {}", path.to_string_lossy()));
239242
let mut contents = String::new();
240243
f.read_to_string(&mut contents)
241244
.expect("Something went wrong reading the file");
242245
let file_change = replace_region_in_text(&contents, start, end, replace_start, replacements);
243246

244247
if write_back {
245-
let mut f = fs::File::create(path).expect(&format!("File not found: {}", path));
248+
let mut f = fs::File::create(&path).expect(&format!("File not found: {}", path.to_string_lossy()));
246249
f.write_all(file_change.new_lines.as_bytes())
247250
.expect("Unable to write file");
248251
// Ensure we write the changes with a trailing newline so that
@@ -318,6 +321,12 @@ where
318321
}
319322
}
320323

324+
/// Returns the path to the Clippy project directory
325+
fn clippy_project_dir() -> PathBuf {
326+
let clippy_dev_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
327+
clippy_dev_dir.parent().unwrap().to_path_buf()
328+
}
329+
321330
#[test]
322331
fn test_parse_contents() {
323332
let result: Vec<Lint> = parse_contents(

clippy_dev/src/main.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use clap::{App, Arg, SubCommand};
44
use clippy_dev::*;
5+
use std::path::Path;
56

67
mod fmt;
78
mod new_lint;
@@ -49,12 +50,12 @@ fn main() {
4950
.arg(
5051
Arg::with_name("check")
5152
.long("check")
52-
.help("Checks that util/dev update_lints has been run. Used on CI."),
53+
.help("Checks that `cargo dev update_lints` has been run. Used on CI."),
5354
),
5455
)
5556
.subcommand(
5657
SubCommand::with_name("new_lint")
57-
.about("Create new lint and run util/dev update_lints")
58+
.about("Create new lint and run `cargo dev update_lints`")
5859
.arg(
5960
Arg::with_name("pass")
6061
.short("p")
@@ -170,7 +171,7 @@ fn update_lints(update_mode: &UpdateMode) {
170171
sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
171172

172173
let mut file_change = replace_region_in_file(
173-
"../src/lintlist/mod.rs",
174+
Path::new("src/lintlist/mod.rs"),
174175
"begin lint list",
175176
"end lint list",
176177
false,
@@ -189,7 +190,7 @@ fn update_lints(update_mode: &UpdateMode) {
189190
.changed;
190191

191192
file_change |= replace_region_in_file(
192-
"../README.md",
193+
Path::new("README.md"),
193194
r#"\[There are \d+ lints included in this crate!\]\(https://rust-lang.github.io/rust-clippy/master/index.html\)"#,
194195
"",
195196
true,
@@ -202,7 +203,7 @@ fn update_lints(update_mode: &UpdateMode) {
202203
).changed;
203204

204205
file_change |= replace_region_in_file(
205-
"../CHANGELOG.md",
206+
Path::new("CHANGELOG.md"),
206207
"<!-- begin autogenerated links to lint list -->",
207208
"<!-- end autogenerated links to lint list -->",
208209
false,
@@ -212,7 +213,7 @@ fn update_lints(update_mode: &UpdateMode) {
212213
.changed;
213214

214215
file_change |= replace_region_in_file(
215-
"../clippy_lints/src/lib.rs",
216+
Path::new("clippy_lints/src/lib.rs"),
216217
"begin deprecated lints",
217218
"end deprecated lints",
218219
false,
@@ -222,7 +223,7 @@ fn update_lints(update_mode: &UpdateMode) {
222223
.changed;
223224

224225
file_change |= replace_region_in_file(
225-
"../clippy_lints/src/lib.rs",
226+
Path::new("clippy_lints/src/lib.rs"),
226227
"begin register lints",
227228
"end register lints",
228229
false,
@@ -232,7 +233,7 @@ fn update_lints(update_mode: &UpdateMode) {
232233
.changed;
233234

234235
file_change |= replace_region_in_file(
235-
"../clippy_lints/src/lib.rs",
236+
Path::new("clippy_lints/src/lib.rs"),
236237
"begin lints modules",
237238
"end lints modules",
238239
false,
@@ -243,7 +244,7 @@ fn update_lints(update_mode: &UpdateMode) {
243244

244245
// Generate lists of lints in the clippy::all lint group
245246
file_change |= replace_region_in_file(
246-
"../clippy_lints/src/lib.rs",
247+
Path::new("clippy_lints/src/lib.rs"),
247248
r#"store.register_group\(true, "clippy::all""#,
248249
r#"\]\);"#,
249250
false,
@@ -266,7 +267,7 @@ fn update_lints(update_mode: &UpdateMode) {
266267
// Generate the list of lints for all other lint groups
267268
for (lint_group, lints) in Lint::by_lint_group(&usable_lints) {
268269
file_change |= replace_region_in_file(
269-
"../clippy_lints/src/lib.rs",
270+
Path::new("clippy_lints/src/lib.rs"),
270271
&format!("store.register_group\\(true, \"clippy::{}\"", lint_group),
271272
r#"\]\);"#,
272273
false,
@@ -279,7 +280,7 @@ fn update_lints(update_mode: &UpdateMode) {
279280
if update_mode == &UpdateMode::Check && file_change {
280281
println!(
281282
"Not all lints defined properly. \
282-
Please run `util/dev update_lints` to make sure all lints are defined properly."
283+
Please run `cargo dev update_lints` to make sure all lints are defined properly."
283284
);
284285
std::process::exit(1);
285286
}

doc/adding_lints.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ lint. Fortunately, you can use the clippy dev tools to handle this for you. We
3939
are naming our new lint `foo_functions` (lints are generally written in snake
4040
case), and we don't need type information so it will have an early pass type
4141
(more on this later on). To get started on this lint you can run
42-
`./util/dev new_lint --name=foo_functions --pass=early --category=pedantic`
42+
`cargo dev new_lint --name=foo_functions --pass=early --category=pedantic`
4343
(category will default to nursery if not provided). This command will create
4444
two files: `tests/ui/foo_functions.rs` and `clippy_lints/src/foo_functions.rs`,
45-
as well as run `./util/dev update_lints` to register the new lint. Next, we'll
45+
as well as run `cargo dev update_lints` to register the new lint. Next, we'll
4646
open up these files and add our lint!
4747

4848
### Testing
@@ -386,7 +386,7 @@ It can be installed via `rustup`:
386386
rustup component add rustfmt --toolchain=nightly
387387
```
388388

389-
Use `./util/dev fmt` to format the whole codebase. Make sure that `rustfmt` is
389+
Use `cargo dev fmt` to format the whole codebase. Make sure that `rustfmt` is
390390
installed for the nightly toolchain.
391391

392392
### Debugging
@@ -404,9 +404,9 @@ Before submitting your PR make sure you followed all of the basic requirements:
404404
- [ ] Followed [lint naming conventions][lint_naming]
405405
- [ ] Added passing UI tests (including committed `.stderr` file)
406406
- [ ] `cargo test` passes locally
407-
- [ ] Executed `./util/dev update_lints`
407+
- [ ] Executed `cargo dev update_lints`
408408
- [ ] Added lint documentation
409-
- [ ] Run `./util/dev fmt`
409+
- [ ] Run `cargo dev fmt`
410410

411411
### Cheatsheet
412412

src/lintlist/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! This file is managed by `util/dev update_lints`. Do not edit.
1+
//! This file is managed by `cargo dev update_lints`. Do not edit.
22
33
pub mod lint;
44
pub use lint::Level;

tests/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ fn fmt() {
3434

3535
assert!(
3636
output.status.success(),
37-
"Formatting check failed. Run `./util/dev fmt` to update formatting."
37+
"Formatting check failed. Run `cargo dev fmt` to update formatting."
3838
);
3939
}

util/dev

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
CARGO_TARGET_DIR=$(pwd)/target/
33
export CARGO_TARGET_DIR
44

5+
echo 'Deprecated! `util/dev` usage is deprecated, please use `cargo dev` instead.'
6+
57
cd clippy_dev && cargo run -- "$@"

0 commit comments

Comments
 (0)