Skip to content

Commit ea2cfe0

Browse files
committed
submodules: update clippy from b029042 to 164310d
Changes: ```` Lint Fix float_cmp false positive when comparing signum grep only lines, that start with 'changelog: ' Get PR number from bors commit message Authenticate with github_api_token Check PRs for changelog entry in the body Deny warnings in CI Disable dogfood on windows for faster build time on travis Revert "Remove `CARGO_INCREMENTAL=0` from windows build" Remove `CARGO_INCREMENTAL=0` from windows build Test with different sysroots dependent on the OS Build sys_root in driver with PathBuf instead of String Don't re-set the LD_LIBRARY_PATH in base_tests.sh Add master toolchain binaries to the PATH Change conditional Stop allowing failures in Travis windows build Fix bug in `implicit_hasher` causing crashes Avoid rustfmt bug on Windows Add rustfmt nightly to appveyor install Work around rustup fallback error on Windows Update documentation to the dev fmt command Remove format checks from CI scripts again. Remove format checks from CI script Improve fmt test failure message Fix crash on `dev --limit-stderr-length` Add dev fmt subcommand don't strip blank lines in lint documentation ````
1 parent 4272fb2 commit ea2cfe0

21 files changed

+377
-97
lines changed

.travis.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ branches:
1717
env:
1818
global:
1919
- RUST_BACKTRACE=1
20+
- secure: "OKulfkA5OGd/d1IhvBKzRkHQwMcWjzrzbimo7+5NhkUkWxndAzl+719TB3wWvIh1i2wXXrEXsyZkXM5FtRrHm55v1VKQ5ibjEvFg1w3NIg81iDyoLq186fLqywvxGkOAFPrsePPsBj5USd5xvhwwbrjO6L7/RK6Z8shBwOSc41s="
2021

2122
install:
2223
- |
@@ -45,7 +46,7 @@ matrix:
4546
- os: linux
4647
env: BASE_TESTS=true
4748
- os: windows
48-
env: CARGO_INCREMENTAL=0 BASE_TESTS=true
49+
env: CARGO_INCREMENTAL=0 BASE_TESTS=true OS_WINDOWS=true
4950

5051
# Builds that are only executed when a PR is r+ed or a try build is started
5152
# We don't want to run these always because they go towards
@@ -81,20 +82,35 @@ matrix:
8182
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
8283
- env: INTEGRATION=chronotope/chrono
8384
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
84-
allow_failures:
85-
- os: windows
86-
env: CARGO_INCREMENTAL=0 BASE_TESTS=true
8785
# prevent these jobs with default env vars
8886
exclude:
8987
- os: linux
9088
- os: osx
9189
- os: windows
9290

9391
script:
92+
- |
93+
if [ "$TRAVIS_BRANCH" == "auto" ] || [ "$TRAVIS_BRANCH" == "try" ]; then
94+
pr=$(echo $TRAVIS_COMMIT_MESSAGE | grep -o "#[0-9]*" | head -1 | sed 's/^#//g')
95+
output=$(curl -H "Authorization: token $GITHUB_API_TOKEN" -s "https://api.github.com/repos/rust-lang/rust-clippy/pulls/$pr" | \
96+
python -c "import sys, json; print(json.load(sys.stdin)['body'])" | \
97+
grep "^changelog: " | \
98+
sed "s/changelog: //g")
99+
if [ -z "$output" ]; then
100+
echo "ERROR: PR body must contain 'changelog: ...'"
101+
exit 1
102+
elif [ "$output" = "none" ]; then
103+
echo "WARNING: changelog is 'none'"
104+
fi
105+
fi
94106
- |
95107
rm rust-toolchain
96108
./setup-toolchain.sh
97-
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib
109+
if [ "$TRAVIS_OS_NAME" == "windows" ]; then
110+
export PATH=$PATH:$(rustc --print sysroot)/bin
111+
else
112+
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib
113+
fi
98114
- |
99115
if [ -z ${INTEGRATION} ]; then
100116
travis_wait 30 ./ci/base-tests.sh && sleep 5
@@ -104,7 +120,7 @@ script:
104120
105121
after_success: |
106122
#!/bin/bash
107-
if [ $(uname) == Linux ]; then
123+
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
108124
set -ex
109125
if [ -z ${INTEGRATION} ]; then
110126
./.github/deploy.sh

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,5 @@ rustc-workspace-hack = "1.0.0"
6161
rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}
6262

6363
[features]
64+
deny-warnings = []
6465
debugging = []

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ install:
2222
- del rust-toolchain
2323
- cargo install rustup-toolchain-install-master --debug || echo "rustup-toolchain-install-master already installed"
2424
- rustup-toolchain-install-master %RUSTC_HASH% -f -n master
25+
- rustup component add rustfmt --toolchain nightly
2526
- rustup default master
2627
- set PATH=%PATH%;C:\Users\appveyor\.rustup\toolchains\master\bin
2728
- rustc -V

ci/base-tests.sh

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ if [ "$TRAVIS_OS_NAME" == "linux" ]; then
77
remark -f *.md -f doc/*.md > /dev/null
88
fi
99
# build clippy in debug mode and run tests
10-
cargo build --features debugging
11-
cargo test --features debugging
10+
cargo build --features "debugging deny-warnings"
11+
cargo test --features "debugging deny-warnings"
1212
# for faster build, share target dir between subcrates
1313
export CARGO_TARGET_DIR=`pwd`/target/
1414
(cd clippy_lints && cargo test)
@@ -24,21 +24,23 @@ export CARGO_TARGET_DIR=`pwd`/target/
2424
# Perform various checks for lint registration
2525
./util/dev update_lints --check
2626
./util/dev --limit-stderr-length
27-
cargo +nightly fmt --all -- --check
2827

2928
# Check running clippy-driver without cargo
3029
(
31-
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib
32-
3330
# Check sysroot handling
3431
sysroot=$(./target/debug/clippy-driver --print sysroot)
3532
test $sysroot = $(rustc --print sysroot)
3633

37-
sysroot=$(./target/debug/clippy-driver --sysroot /tmp --print sysroot)
38-
test $sysroot = /tmp
34+
if [ -z $OS_WINDOWS ]; then
35+
desired_sysroot=/tmp
36+
else
37+
desired_sysroot=C:/tmp
38+
fi
39+
sysroot=$(./target/debug/clippy-driver --sysroot $desired_sysroot --print sysroot)
40+
test $sysroot = $desired_sysroot
3941

40-
sysroot=$(SYSROOT=/tmp ./target/debug/clippy-driver --print sysroot)
41-
test $sysroot = /tmp
42+
sysroot=$(SYSROOT=$desired_sysroot ./target/debug/clippy-driver --print sysroot)
43+
test $sysroot = $desired_sysroot
4244

4345
# Make sure this isn't set - clippy-driver should cope without it
4446
unset CARGO_MANIFEST_DIR
@@ -50,32 +52,3 @@ cargo +nightly fmt --all -- --check
5052

5153
# TODO: CLIPPY_CONF_DIR / CARGO_MANIFEST_DIR
5254
)
53-
54-
# make sure tests are formatted
55-
56-
# some lints are sensitive to formatting, exclude some files
57-
tests_need_reformatting="false"
58-
# switch to nightly
59-
rustup override set nightly
60-
# avoid loop spam and allow cmds with exit status != 0
61-
set +ex
62-
63-
# Excluding `ice-3891.rs` because the code triggers a rustc parse error which
64-
# makes rustfmt fail.
65-
for file in `find tests -not -path "tests/ui/crashes/ice-3891.rs" | grep "\.rs$"` ; do
66-
rustfmt ${file} --check
67-
if [ $? -ne 0 ]; then
68-
echo "${file} needs reformatting!"
69-
tests_need_reformatting="true"
70-
fi
71-
done
72-
73-
set -ex # reset
74-
75-
if [ "${tests_need_reformatting}" == "true" ] ; then
76-
echo "Tests need reformatting!"
77-
exit 2
78-
fi
79-
80-
# switch back to master
81-
rustup override set master

clippy_dev/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ clap = "2.33"
99
itertools = "0.8"
1010
regex = "1"
1111
lazy_static = "1.0"
12+
shell-escape = "0.1"
1213
walkdir = "2"

clippy_dev/src/fmt.rs

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
use shell_escape::escape;
2+
use std::ffi::OsStr;
3+
use std::io;
4+
use std::path::{Path, PathBuf};
5+
use std::process::{self, Command};
6+
use walkdir::WalkDir;
7+
8+
#[derive(Debug)]
9+
pub enum CliError {
10+
CommandFailed(String),
11+
IoError(io::Error),
12+
ProjectRootNotFound,
13+
WalkDirError(walkdir::Error),
14+
}
15+
16+
impl From<io::Error> for CliError {
17+
fn from(error: io::Error) -> Self {
18+
CliError::IoError(error)
19+
}
20+
}
21+
22+
impl From<walkdir::Error> for CliError {
23+
fn from(error: walkdir::Error) -> Self {
24+
CliError::WalkDirError(error)
25+
}
26+
}
27+
28+
struct FmtContext {
29+
check: bool,
30+
verbose: bool,
31+
}
32+
33+
pub fn run(check: bool, verbose: bool) {
34+
fn try_run(context: &FmtContext) -> Result<bool, CliError> {
35+
let mut success = true;
36+
37+
let project_root = project_root()?;
38+
39+
success &= cargo_fmt(context, project_root.as_path())?;
40+
success &= cargo_fmt(context, &project_root.join("clippy_dev"))?;
41+
success &= cargo_fmt(context, &project_root.join("rustc_tools_util"))?;
42+
43+
for entry in WalkDir::new(project_root.join("tests")) {
44+
let entry = entry?;
45+
let path = entry.path();
46+
47+
if path.extension() != Some("rs".as_ref())
48+
|| entry.file_name() == "ice-3891.rs"
49+
// Avoid rustfmt bug rust-lang/rustfmt#1873
50+
|| cfg!(windows) && entry.file_name() == "implicit_hasher.rs"
51+
{
52+
continue;
53+
}
54+
55+
success &= rustfmt(context, &path)?;
56+
}
57+
58+
Ok(success)
59+
}
60+
61+
fn output_err(err: CliError) {
62+
match err {
63+
CliError::CommandFailed(command) => {
64+
eprintln!("error: A command failed! `{}`", command);
65+
},
66+
CliError::IoError(err) => {
67+
eprintln!("error: {}", err);
68+
},
69+
CliError::ProjectRootNotFound => {
70+
eprintln!("error: Can't determine root of project. Please run inside a Clippy working dir.");
71+
},
72+
CliError::WalkDirError(err) => {
73+
eprintln!("error: {}", err);
74+
},
75+
}
76+
}
77+
78+
let context = FmtContext { check, verbose };
79+
let result = try_run(&context);
80+
let code = match result {
81+
Ok(true) => 0,
82+
Ok(false) => {
83+
eprintln!();
84+
eprintln!("Formatting check failed.");
85+
eprintln!("Run `./util/dev fmt` to update formatting.");
86+
1
87+
},
88+
Err(err) => {
89+
output_err(err);
90+
1
91+
},
92+
};
93+
process::exit(code);
94+
}
95+
96+
fn format_command(program: impl AsRef<OsStr>, dir: impl AsRef<Path>, args: &[impl AsRef<OsStr>]) -> String {
97+
let arg_display: Vec<_> = args
98+
.iter()
99+
.map(|a| escape(a.as_ref().to_string_lossy()).to_owned())
100+
.collect();
101+
102+
format!(
103+
"cd {} && {} {}",
104+
escape(dir.as_ref().to_string_lossy()),
105+
escape(program.as_ref().to_string_lossy()),
106+
arg_display.join(" ")
107+
)
108+
}
109+
110+
fn exec(
111+
context: &FmtContext,
112+
program: impl AsRef<OsStr>,
113+
dir: impl AsRef<Path>,
114+
args: &[impl AsRef<OsStr>],
115+
) -> Result<bool, CliError> {
116+
if context.verbose {
117+
println!("{}", format_command(&program, &dir, args));
118+
}
119+
120+
let mut child = Command::new(&program).current_dir(&dir).args(args.iter()).spawn()?;
121+
let code = child.wait()?;
122+
let success = code.success();
123+
124+
if !context.check && !success {
125+
return Err(CliError::CommandFailed(format_command(&program, &dir, args)));
126+
}
127+
128+
Ok(success)
129+
}
130+
131+
fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
132+
let mut args = vec!["+nightly", "fmt", "--all"];
133+
if context.check {
134+
args.push("--");
135+
args.push("--check");
136+
}
137+
let success = exec(context, "cargo", path, &args)?;
138+
139+
Ok(success)
140+
}
141+
142+
fn rustfmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
143+
let mut args = vec!["+nightly".as_ref(), path.as_os_str()];
144+
if context.check {
145+
args.push("--check".as_ref());
146+
}
147+
let success = exec(context, "rustfmt", std::env::current_dir()?, &args)?;
148+
if !success {
149+
eprintln!("rustfmt failed on {}", path.display());
150+
}
151+
Ok(success)
152+
}
153+
154+
fn project_root() -> Result<PathBuf, CliError> {
155+
let current_dir = std::env::current_dir()?;
156+
for path in current_dir.ancestors() {
157+
let result = std::fs::read_to_string(path.join("Cargo.toml"));
158+
if let Err(err) = &result {
159+
if err.kind() == io::ErrorKind::NotFound {
160+
continue;
161+
}
162+
}
163+
164+
let content = result?;
165+
if content.contains("[package]\nname = \"clippy\"") {
166+
return Ok(path.to_path_buf());
167+
}
168+
}
169+
170+
Err(CliError::ProjectRootNotFound)
171+
}

clippy_dev/src/main.rs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ extern crate regex;
44

55
use clap::{App, Arg, SubCommand};
66
use clippy_dev::*;
7+
8+
mod fmt;
79
mod stderr_length_check;
810

911
#[derive(PartialEq)]
@@ -14,6 +16,21 @@ enum UpdateMode {
1416

1517
fn main() {
1618
let matches = App::new("Clippy developer tooling")
19+
.subcommand(
20+
SubCommand::with_name("fmt")
21+
.about("Run rustfmt on all projects and tests")
22+
.arg(
23+
Arg::with_name("check")
24+
.long("check")
25+
.help("Use the rustfmt --check option"),
26+
)
27+
.arg(
28+
Arg::with_name("verbose")
29+
.short("v")
30+
.long("verbose")
31+
.help("Echo commands run"),
32+
),
33+
)
1734
.subcommand(
1835
SubCommand::with_name("update_lints")
1936
.about("Updates lint registration and information from the source code")
@@ -46,14 +63,21 @@ fn main() {
4663
if matches.is_present("limit-stderr-length") {
4764
stderr_length_check::check();
4865
}
49-
if let Some(matches) = matches.subcommand_matches("update_lints") {
50-
if matches.is_present("print-only") {
51-
print_lints();
52-
} else if matches.is_present("check") {
53-
update_lints(&UpdateMode::Check);
54-
} else {
55-
update_lints(&UpdateMode::Change);
56-
}
66+
67+
match matches.subcommand() {
68+
("fmt", Some(matches)) => {
69+
fmt::run(matches.is_present("check"), matches.is_present("verbose"));
70+
},
71+
("update_lints", Some(matches)) => {
72+
if matches.is_present("print-only") {
73+
print_lints();
74+
} else if matches.is_present("check") {
75+
update_lints(&UpdateMode::Check);
76+
} else {
77+
update_lints(&UpdateMode::Change);
78+
}
79+
},
80+
_ => {},
5781
}
5882
}
5983

0 commit comments

Comments
 (0)