Skip to content

Commit

Permalink
Obey rustfmt
Browse files Browse the repository at this point in the history
Reformatted the code using cargo fmt.
Added a separate Travis job to the build matrix that fails when code is
not properly formatted
  • Loading branch information
cyplo committed Apr 8, 2018
1 parent 76beb88 commit 90306c7
Show file tree
Hide file tree
Showing 67 changed files with 5,710 additions and 3,491 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ language: rust

matrix:
include:
# Separate build to detect if the code is formatted correctly
- os: linux
env: TARGET=x86_64-unknown-linux-gnu
DOCKER=alexcrichton/rust-slave-dist:2015-10-20b
RUSTFMT_ONLY=1
NO_ADD=1
ALLOW_PR=1
# Linux builds use the `rust-slave-dist` image so we link them against a
# "super old glibc" to ensure that it runs on as many platforms as possible.
- os: linux
Expand Down Expand Up @@ -124,6 +131,7 @@ branches:

install:
- if [ -z "$NO_ADD" ]; then rustup target add $TARGET; fi
- rustup component add rustfmt-preview

script:
- mkdir -p target/$TARGET;
Expand All @@ -134,7 +142,7 @@ script:
echo 'skipping master build';
else
if [ ! -z "$DOCKER" ]; then
sh ci/build-run-docker.sh "$DOCKER" "$TARGET" "$SKIP_TESTS";
sh ci/build-run-docker.sh "$DOCKER" "$TARGET" "$SKIP_TESTS" "$RUSTFMT_ONLY";
else
PATH=$HOME/rust/bin:$PATH sh ci/run.sh;
fi
Expand Down
28 changes: 16 additions & 12 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use std::process::Command;
struct Ignore;

impl<E> From<E> for Ignore
where E: Error
where
E: Error,
{
fn from(_: E) -> Ignore {
Ignore
Expand All @@ -35,18 +36,21 @@ fn commit_info() -> String {
}

fn commit_hash() -> Result<String, Ignore> {
Ok(try!(String::from_utf8(try!(Command::new("git")
.args(&["rev-parse", "--short=9", "HEAD"])
.output())
.stdout)))
Ok(try!(String::from_utf8(
try!(
Command::new("git")
.args(&["rev-parse", "--short=9", "HEAD"])
.output()
).stdout
)))
}

fn commit_date() -> Result<String, Ignore> {
Ok(try!(String::from_utf8(try!(Command::new("git")
.args(&["log",
"-1",
"--date=short",
"--pretty=format:%cd"])
.output())
.stdout)))
Ok(try!(String::from_utf8(
try!(
Command::new("git")
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
.output()
).stdout
)))
}
2 changes: 2 additions & 0 deletions ci/build-run-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mkdir -p target
DOCKER="$1"
TARGET="$2"
SKIP_TESTS="$3"
RUSTFMT_ONLY="$4"

if [ -f "ci/docker/$DOCKER/Dockerfile" ]; then
docker build -t "$DOCKER" "ci/docker/$DOCKER/"
Expand All @@ -21,6 +22,7 @@ docker run \
--workdir /src \
--env TARGET=$TARGET \
--env SKIP_TESTS=$SKIP_TESTS \
--env RUSTFMT_ONLY=$RUSTFMT_ONLY \
$DOCKER \
ci/run-docker.sh

Expand Down
5 changes: 5 additions & 0 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ echo "toolchain versions\n------------------"
rustc -vV
cargo -vV

if [ ! -z "$RUSTFMT_ONLY" ]; then
cargo fmt --all -- --write-mode=diff
exit 0
fi

cargo build --locked -v --release --target $TARGET

if [ -z "$SKIP_TESTS" ]; then
Expand Down
2 changes: 0 additions & 2 deletions src/download/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


error_chain! {
links { }

Expand Down
Loading

0 comments on commit 90306c7

Please sign in to comment.