Skip to content

Commit

Permalink
submodules: update clippy from b029042 to 164310d
Browse files Browse the repository at this point in the history
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
````
  • Loading branch information
matthiaskrgr committed Jul 16, 2019
1 parent 4272fb2 commit ea2cfe0
Show file tree
Hide file tree
Showing 21 changed files with 377 additions and 97 deletions.
28 changes: 22 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ branches:
env:
global:
- RUST_BACKTRACE=1
- secure: "OKulfkA5OGd/d1IhvBKzRkHQwMcWjzrzbimo7+5NhkUkWxndAzl+719TB3wWvIh1i2wXXrEXsyZkXM5FtRrHm55v1VKQ5ibjEvFg1w3NIg81iDyoLq186fLqywvxGkOAFPrsePPsBj5USd5xvhwwbrjO6L7/RK6Z8shBwOSc41s="

install:
- |
Expand Down Expand Up @@ -45,7 +46,7 @@ matrix:
- os: linux
env: BASE_TESTS=true
- os: windows
env: CARGO_INCREMENTAL=0 BASE_TESTS=true
env: CARGO_INCREMENTAL=0 BASE_TESTS=true OS_WINDOWS=true

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

script:
- |
if [ "$TRAVIS_BRANCH" == "auto" ] || [ "$TRAVIS_BRANCH" == "try" ]; then
pr=$(echo $TRAVIS_COMMIT_MESSAGE | grep -o "#[0-9]*" | head -1 | sed 's/^#//g')
output=$(curl -H "Authorization: token $GITHUB_API_TOKEN" -s "https://api.github.com/repos/rust-lang/rust-clippy/pulls/$pr" | \
python -c "import sys, json; print(json.load(sys.stdin)['body'])" | \
grep "^changelog: " | \
sed "s/changelog: //g")
if [ -z "$output" ]; then
echo "ERROR: PR body must contain 'changelog: ...'"
exit 1
elif [ "$output" = "none" ]; then
echo "WARNING: changelog is 'none'"
fi
fi
- |
rm rust-toolchain
./setup-toolchain.sh
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib
if [ "$TRAVIS_OS_NAME" == "windows" ]; then
export PATH=$PATH:$(rustc --print sysroot)/bin
else
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib
fi
- |
if [ -z ${INTEGRATION} ]; then
travis_wait 30 ./ci/base-tests.sh && sleep 5
Expand All @@ -104,7 +120,7 @@ script:
after_success: |
#!/bin/bash
if [ $(uname) == Linux ]; then
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
set -ex
if [ -z ${INTEGRATION} ]; then
./.github/deploy.sh
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ rustc-workspace-hack = "1.0.0"
rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}

[features]
deny-warnings = []
debugging = []
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ install:
- del rust-toolchain
- cargo install rustup-toolchain-install-master --debug || echo "rustup-toolchain-install-master already installed"
- rustup-toolchain-install-master %RUSTC_HASH% -f -n master
- rustup component add rustfmt --toolchain nightly
- rustup default master
- set PATH=%PATH%;C:\Users\appveyor\.rustup\toolchains\master\bin
- rustc -V
Expand Down
49 changes: 11 additions & 38 deletions ci/base-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ if [ "$TRAVIS_OS_NAME" == "linux" ]; then
remark -f *.md -f doc/*.md > /dev/null
fi
# build clippy in debug mode and run tests
cargo build --features debugging
cargo test --features debugging
cargo build --features "debugging deny-warnings"
cargo test --features "debugging deny-warnings"
# for faster build, share target dir between subcrates
export CARGO_TARGET_DIR=`pwd`/target/
(cd clippy_lints && cargo test)
Expand All @@ -24,21 +24,23 @@ export CARGO_TARGET_DIR=`pwd`/target/
# Perform various checks for lint registration
./util/dev update_lints --check
./util/dev --limit-stderr-length
cargo +nightly fmt --all -- --check

# Check running clippy-driver without cargo
(
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib

# Check sysroot handling
sysroot=$(./target/debug/clippy-driver --print sysroot)
test $sysroot = $(rustc --print sysroot)

sysroot=$(./target/debug/clippy-driver --sysroot /tmp --print sysroot)
test $sysroot = /tmp
if [ -z $OS_WINDOWS ]; then
desired_sysroot=/tmp
else
desired_sysroot=C:/tmp
fi
sysroot=$(./target/debug/clippy-driver --sysroot $desired_sysroot --print sysroot)
test $sysroot = $desired_sysroot

sysroot=$(SYSROOT=/tmp ./target/debug/clippy-driver --print sysroot)
test $sysroot = /tmp
sysroot=$(SYSROOT=$desired_sysroot ./target/debug/clippy-driver --print sysroot)
test $sysroot = $desired_sysroot

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

# TODO: CLIPPY_CONF_DIR / CARGO_MANIFEST_DIR
)

# make sure tests are formatted

# some lints are sensitive to formatting, exclude some files
tests_need_reformatting="false"
# switch to nightly
rustup override set nightly
# avoid loop spam and allow cmds with exit status != 0
set +ex

# Excluding `ice-3891.rs` because the code triggers a rustc parse error which
# makes rustfmt fail.
for file in `find tests -not -path "tests/ui/crashes/ice-3891.rs" | grep "\.rs$"` ; do
rustfmt ${file} --check
if [ $? -ne 0 ]; then
echo "${file} needs reformatting!"
tests_need_reformatting="true"
fi
done

set -ex # reset

if [ "${tests_need_reformatting}" == "true" ] ; then
echo "Tests need reformatting!"
exit 2
fi

# switch back to master
rustup override set master
1 change: 1 addition & 0 deletions clippy_dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ clap = "2.33"
itertools = "0.8"
regex = "1"
lazy_static = "1.0"
shell-escape = "0.1"
walkdir = "2"
171 changes: 171 additions & 0 deletions clippy_dev/src/fmt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
use shell_escape::escape;
use std::ffi::OsStr;
use std::io;
use std::path::{Path, PathBuf};
use std::process::{self, Command};
use walkdir::WalkDir;

#[derive(Debug)]
pub enum CliError {
CommandFailed(String),
IoError(io::Error),
ProjectRootNotFound,
WalkDirError(walkdir::Error),
}

impl From<io::Error> for CliError {
fn from(error: io::Error) -> Self {
CliError::IoError(error)
}
}

impl From<walkdir::Error> for CliError {
fn from(error: walkdir::Error) -> Self {
CliError::WalkDirError(error)
}
}

struct FmtContext {
check: bool,
verbose: bool,
}

pub fn run(check: bool, verbose: bool) {
fn try_run(context: &FmtContext) -> Result<bool, CliError> {
let mut success = true;

let project_root = project_root()?;

success &= cargo_fmt(context, project_root.as_path())?;
success &= cargo_fmt(context, &project_root.join("clippy_dev"))?;
success &= cargo_fmt(context, &project_root.join("rustc_tools_util"))?;

for entry in WalkDir::new(project_root.join("tests")) {
let entry = entry?;
let path = entry.path();

if path.extension() != Some("rs".as_ref())
|| entry.file_name() == "ice-3891.rs"
// Avoid rustfmt bug rust-lang/rustfmt#1873
|| cfg!(windows) && entry.file_name() == "implicit_hasher.rs"
{
continue;
}

success &= rustfmt(context, &path)?;
}

Ok(success)
}

fn output_err(err: CliError) {
match err {
CliError::CommandFailed(command) => {
eprintln!("error: A command failed! `{}`", command);
},
CliError::IoError(err) => {
eprintln!("error: {}", err);
},
CliError::ProjectRootNotFound => {
eprintln!("error: Can't determine root of project. Please run inside a Clippy working dir.");
},
CliError::WalkDirError(err) => {
eprintln!("error: {}", err);
},
}
}

let context = FmtContext { check, verbose };
let result = try_run(&context);
let code = match result {
Ok(true) => 0,
Ok(false) => {
eprintln!();
eprintln!("Formatting check failed.");
eprintln!("Run `./util/dev fmt` to update formatting.");
1
},
Err(err) => {
output_err(err);
1
},
};
process::exit(code);
}

fn format_command(program: impl AsRef<OsStr>, dir: impl AsRef<Path>, args: &[impl AsRef<OsStr>]) -> String {
let arg_display: Vec<_> = args
.iter()
.map(|a| escape(a.as_ref().to_string_lossy()).to_owned())
.collect();

format!(
"cd {} && {} {}",
escape(dir.as_ref().to_string_lossy()),
escape(program.as_ref().to_string_lossy()),
arg_display.join(" ")
)
}

fn exec(
context: &FmtContext,
program: impl AsRef<OsStr>,
dir: impl AsRef<Path>,
args: &[impl AsRef<OsStr>],
) -> Result<bool, CliError> {
if context.verbose {
println!("{}", format_command(&program, &dir, args));
}

let mut child = Command::new(&program).current_dir(&dir).args(args.iter()).spawn()?;
let code = child.wait()?;
let success = code.success();

if !context.check && !success {
return Err(CliError::CommandFailed(format_command(&program, &dir, args)));
}

Ok(success)
}

fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
let mut args = vec!["+nightly", "fmt", "--all"];
if context.check {
args.push("--");
args.push("--check");
}
let success = exec(context, "cargo", path, &args)?;

Ok(success)
}

fn rustfmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
let mut args = vec!["+nightly".as_ref(), path.as_os_str()];
if context.check {
args.push("--check".as_ref());
}
let success = exec(context, "rustfmt", std::env::current_dir()?, &args)?;
if !success {
eprintln!("rustfmt failed on {}", path.display());
}
Ok(success)
}

fn project_root() -> Result<PathBuf, CliError> {
let current_dir = std::env::current_dir()?;
for path in current_dir.ancestors() {
let result = std::fs::read_to_string(path.join("Cargo.toml"));
if let Err(err) = &result {
if err.kind() == io::ErrorKind::NotFound {
continue;
}
}

let content = result?;
if content.contains("[package]\nname = \"clippy\"") {
return Ok(path.to_path_buf());
}
}

Err(CliError::ProjectRootNotFound)
}
40 changes: 32 additions & 8 deletions clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ extern crate regex;

use clap::{App, Arg, SubCommand};
use clippy_dev::*;

mod fmt;
mod stderr_length_check;

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

fn main() {
let matches = App::new("Clippy developer tooling")
.subcommand(
SubCommand::with_name("fmt")
.about("Run rustfmt on all projects and tests")
.arg(
Arg::with_name("check")
.long("check")
.help("Use the rustfmt --check option"),
)
.arg(
Arg::with_name("verbose")
.short("v")
.long("verbose")
.help("Echo commands run"),
),
)
.subcommand(
SubCommand::with_name("update_lints")
.about("Updates lint registration and information from the source code")
Expand Down Expand Up @@ -46,14 +63,21 @@ fn main() {
if matches.is_present("limit-stderr-length") {
stderr_length_check::check();
}
if let Some(matches) = matches.subcommand_matches("update_lints") {
if matches.is_present("print-only") {
print_lints();
} else if matches.is_present("check") {
update_lints(&UpdateMode::Check);
} else {
update_lints(&UpdateMode::Change);
}

match matches.subcommand() {
("fmt", Some(matches)) => {
fmt::run(matches.is_present("check"), matches.is_present("verbose"));
},
("update_lints", Some(matches)) => {
if matches.is_present("print-only") {
print_lints();
} else if matches.is_present("check") {
update_lints(&UpdateMode::Check);
} else {
update_lints(&UpdateMode::Change);
}
},
_ => {},
}
}

Expand Down
Loading

0 comments on commit ea2cfe0

Please sign in to comment.