Skip to content

Commit a642b42

Browse files
committed
Auto merge of rust-lang#6450 - matthiaskrgr:dont_format_local_repo, r=ebroto
cargo dev fmt: don't format entire rustc repo if we ran ra_setup previously It turns out that rustfmt sees a rustc repo that we pulled in as path dependency via `cargo dev ra-setup` as part of the tree and would try to format it :D Of course we don't want this, so skip formatting if we see that we ran `ra-setup` previously. changelog: none
2 parents 6b2b357 + 27dc565 commit a642b42

File tree

5 files changed

+80
-57
lines changed

5 files changed

+80
-57
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ All contributors are expected to follow the [Rust Code of Conduct].
1919
- [Writing code](#writing-code)
2020
- [Getting code-completion for rustc internals to work](#getting-code-completion-for-rustc-internals-to-work)
2121
- [How Clippy works](#how-clippy-works)
22-
- [Fixing build failures caused by Rust](#fixing-build-failures-caused-by-rust)
22+
- [Syncing changes between Clippy and [`rust-lang/rust`]](#syncing-changes-between-clippy-and-rust-langrust)
2323
- [Patching git-subtree to work with big repos](#patching-git-subtree-to-work-with-big-repos)
24-
- [Performing the sync](#performing-the-sync)
25-
- [Syncing back changes in Clippy to [`rust-lang/rust`]](#syncing-back-changes-in-clippy-to-rust-langrust)
24+
- [Performing the sync from [`rust-lang/rust`] to Clippy](#performing-the-sync-from-rust-langrust-to-clippy)
25+
- [Performing the sync from Clippy to [`rust-lang/rust`]](#performing-the-sync-from-clippy-to-rust-langrust)
2626
- [Defining remotes](#defining-remotes)
2727
- [Issue and PR triage](#issue-and-pr-triage)
2828
- [Bors and Homu](#bors-and-homu)
@@ -111,7 +111,7 @@ To work around this, you need to have a copy of the [rustc-repo][rustc_repo] ava
111111
`git clone https://github.com/rust-lang/rust/`.
112112
Then you can run a `cargo dev` command to automatically make Clippy use the rustc-repo via path-dependencies
113113
which rust-analyzer will be able to understand.
114-
Run `cargo dev ra-setup --repo-path <repo-path>` where `<repo-path>` is an absolute path to the rustc repo
114+
Run `cargo dev ra_setup --repo-path <repo-path>` where `<repo-path>` is an absolute path to the rustc repo
115115
you just cloned.
116116
The command will add path-dependencies pointing towards rustc-crates inside the rustc repo to
117117
Clippys `Cargo.toml`s and should allow rust-analyzer to understand most of the types that Clippy uses.

clippy_dev/src/fmt.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::clippy_project_root;
22
use shell_escape::escape;
33
use std::ffi::OsStr;
4-
use std::io;
54
use std::path::Path;
65
use std::process::{self, Command};
6+
use std::{fs, io};
77
use walkdir::WalkDir;
88

99
#[derive(Debug)]
@@ -12,6 +12,7 @@ pub enum CliError {
1212
IoError(io::Error),
1313
RustfmtNotInstalled,
1414
WalkDirError(walkdir::Error),
15+
RaSetupActive,
1516
}
1617

1718
impl From<io::Error> for CliError {
@@ -31,12 +32,23 @@ struct FmtContext {
3132
verbose: bool,
3233
}
3334

35+
// the "main" function of cargo dev fmt
3436
pub fn run(check: bool, verbose: bool) {
3537
fn try_run(context: &FmtContext) -> Result<bool, CliError> {
3638
let mut success = true;
3739

3840
let project_root = clippy_project_root();
3941

42+
// if we added a local rustc repo as path dependency to clippy for rust analyzer, we do NOT want to
43+
// format because rustfmt would also format the entire rustc repo as it is a local
44+
// dependency
45+
if fs::read_to_string(project_root.join("Cargo.toml"))
46+
.expect("Failed to read clippy Cargo.toml")
47+
.contains(&"[target.'cfg(NOT_A_PLATFORM)'.dependencies]")
48+
{
49+
return Err(CliError::RaSetupActive);
50+
}
51+
4052
rustfmt_test(context)?;
4153

4254
success &= cargo_fmt(context, project_root.as_path())?;
@@ -75,6 +87,13 @@ pub fn run(check: bool, verbose: bool) {
7587
CliError::WalkDirError(err) => {
7688
eprintln!("error: {}", err);
7789
},
90+
CliError::RaSetupActive => {
91+
eprintln!(
92+
"error: a local rustc repo is enabled as path dependency via `cargo dev ra_setup`.
93+
Not formatting because that would format the local repo as well!
94+
Please revert the changes to Cargo.tomls first."
95+
);
96+
},
7897
}
7998
}
8099

clippy_dev/src/main.rs

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,52 @@
11
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
22

3-
use clap::{App, Arg, SubCommand};
3+
use clap::{App, Arg, ArgMatches, SubCommand};
44
use clippy_dev::{bless, fmt, new_lint, ra_setup, serve, stderr_length_check, update_lints};
55

66
fn main() {
7-
let matches = App::new("Clippy developer tooling")
7+
let matches = get_clap_config();
8+
9+
match matches.subcommand() {
10+
("bless", Some(_)) => {
11+
bless::bless();
12+
},
13+
("fmt", Some(matches)) => {
14+
fmt::run(matches.is_present("check"), matches.is_present("verbose"));
15+
},
16+
("update_lints", Some(matches)) => {
17+
if matches.is_present("print-only") {
18+
update_lints::print_lints();
19+
} else if matches.is_present("check") {
20+
update_lints::run(update_lints::UpdateMode::Check);
21+
} else {
22+
update_lints::run(update_lints::UpdateMode::Change);
23+
}
24+
},
25+
("new_lint", Some(matches)) => {
26+
match new_lint::create(
27+
matches.value_of("pass"),
28+
matches.value_of("name"),
29+
matches.value_of("category"),
30+
) {
31+
Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
32+
Err(e) => eprintln!("Unable to create lint: {}", e),
33+
}
34+
},
35+
("limit_stderr_length", _) => {
36+
stderr_length_check::check();
37+
},
38+
("ra_setup", Some(matches)) => ra_setup::run(matches.value_of("rustc-repo-path")),
39+
("serve", Some(matches)) => {
40+
let port = matches.value_of("port").unwrap().parse().unwrap();
41+
let lint = matches.value_of("lint");
42+
serve::run(port, lint);
43+
},
44+
_ => {},
45+
}
46+
}
47+
48+
fn get_clap_config<'a>() -> ArgMatches<'a> {
49+
App::new("Clippy developer tooling")
850
.subcommand(SubCommand::with_name("bless").about("bless the test output changes"))
951
.subcommand(
1052
SubCommand::with_name("fmt")
@@ -26,16 +68,16 @@ fn main() {
2668
.about("Updates lint registration and information from the source code")
2769
.long_about(
2870
"Makes sure that:\n \
29-
* the lint count in README.md is correct\n \
30-
* the changelog contains markdown link references at the bottom\n \
31-
* all lint groups include the correct lints\n \
32-
* lint modules in `clippy_lints/*` are visible in `src/lib.rs` via `pub mod`\n \
33-
* all lints are registered in the lint store",
71+
* the lint count in README.md is correct\n \
72+
* the changelog contains markdown link references at the bottom\n \
73+
* all lint groups include the correct lints\n \
74+
* lint modules in `clippy_lints/*` are visible in `src/lifb.rs` via `pub mod`\n \
75+
* all lints are registered in the lint store",
3476
)
3577
.arg(Arg::with_name("print-only").long("print-only").help(
3678
"Print a table of lints to STDOUT. \
37-
This does not include deprecated and internal lints. \
38-
(Does not modify any files)",
79+
This does not include deprecated and internal lints. \
80+
(Does not modify any files)",
3981
))
4082
.arg(
4183
Arg::with_name("check")
@@ -89,7 +131,7 @@ fn main() {
89131
.about("Ensures that stderr files do not grow longer than a certain amount of lines."),
90132
)
91133
.subcommand(
92-
SubCommand::with_name("ra-setup")
134+
SubCommand::with_name("ra_setup")
93135
.about("Alter dependencies so rust-analyzer can find rustc internals")
94136
.arg(
95137
Arg::with_name("rustc-repo-path")
@@ -114,43 +156,5 @@ fn main() {
114156
)
115157
.arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),
116158
)
117-
.get_matches();
118-
119-
match matches.subcommand() {
120-
("bless", Some(_)) => {
121-
bless::bless();
122-
},
123-
("fmt", Some(matches)) => {
124-
fmt::run(matches.is_present("check"), matches.is_present("verbose"));
125-
},
126-
("update_lints", Some(matches)) => {
127-
if matches.is_present("print-only") {
128-
update_lints::print_lints();
129-
} else if matches.is_present("check") {
130-
update_lints::run(update_lints::UpdateMode::Check);
131-
} else {
132-
update_lints::run(update_lints::UpdateMode::Change);
133-
}
134-
},
135-
("new_lint", Some(matches)) => {
136-
match new_lint::create(
137-
matches.value_of("pass"),
138-
matches.value_of("name"),
139-
matches.value_of("category"),
140-
) {
141-
Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
142-
Err(e) => eprintln!("Unable to create lint: {}", e),
143-
}
144-
},
145-
("limit_stderr_length", _) => {
146-
stderr_length_check::check();
147-
},
148-
("ra-setup", Some(matches)) => ra_setup::run(matches.value_of("rustc-repo-path")),
149-
("serve", Some(matches)) => {
150-
let port = matches.value_of("port").unwrap().parse().unwrap();
151-
let lint = matches.value_of("lint");
152-
serve::run(port, lint);
153-
},
154-
_ => {},
155-
}
159+
.get_matches()
156160
}

clippy_dev/src/ra_setup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn inject_deps_into_manifest(
5252
// do not inject deps if we have aleady done so
5353
if cargo_toml.contains("[target.'cfg(NOT_A_PLATFORM)'.dependencies]") {
5454
eprintln!(
55-
"cargo dev ra-setup: warning: deps already found inside {}, doing nothing.",
55+
"cargo dev ra_setup: warning: deps already found inside {}, doing nothing.",
5656
manifest_path
5757
);
5858
return Ok(());

doc/basics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ the codebase take a look at [Adding Lints] or [Common Tools].
88
[Common Tools]: https://github.com/rust-lang/rust-clippy/blob/master/doc/common_tools_writing_lints.md
99

1010
- [Basics for hacking on Clippy](#basics-for-hacking-on-clippy)
11-
- [Get the code](#get-the-code)
11+
- [Get the Code](#get-the-code)
1212
- [Building and Testing](#building-and-testing)
1313
- [`cargo dev`](#cargo-dev)
1414
- [PR](#pr)
@@ -87,7 +87,7 @@ cargo dev update_lints
8787
# create a new lint and register it
8888
cargo dev new_lint
8989
# (experimental) Setup Clippy to work with rust-analyzer
90-
cargo dev ra-setup
90+
cargo dev ra_setup
9191
```
9292

9393
## PR

0 commit comments

Comments
 (0)