Skip to content

Commit a3de3fc

Browse files
author
bors-servo
authored
Auto merge of #473 - fitzgen:fmt-in-ci, r=emilio
Assert that code is properly `rustfmt`ed in CI r? @emilio
2 parents 9c8b593 + 50dc792 commit a3de3fc

File tree

7 files changed

+71
-20
lines changed

7 files changed

+71
-20
lines changed

.travis.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,9 @@ cache:
2525
before_install: . ./ci/before_install.sh
2626

2727
script:
28-
- cargo test --features "$BINDGEN_FEATURES assert_no_dangling_items"
29-
- cargo test --release --features "$BINDGEN_FEATURES assert_no_dangling_items"
30-
- git add -A
31-
- git diff @
32-
- git diff-index --quiet HEAD
33-
- cargo build --features "$BINDGEN_FEATURES docs_"
34-
- cd tests/expectations
35-
- cargo test
36-
- cd ../../bindgen-integration
37-
- cargo test --features "$BINDGEN_FEATURES"
38-
- cargo test --release --features "$BINDGEN_FEATURES"
28+
- ./ci/assert-rustfmt.sh
29+
- BINDGEN_FEATURES="$BINDGEN_FEATURES" ./ci/assert-docs.sh
30+
- BINDGEN_FEATURES="$BINDGEN_FEATURES" ./ci/test.sh
3931

4032
notifications:
4133
webhooks: http://build.servo.org:54856/travis

CONTRIBUTING.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,26 @@ $ cargo test -p tests_expectations
114114

115115
## Automatic code formatting
116116

117-
There's a `rustfmt.toml` file in the repo. Ideally changes should be consistent
118-
with the style, though that's not enforced right now.
117+
We use [`rustfmt`](https://github.com/rust-lang-nursery/rustfmt) to enforce a
118+
consistent code style across the whole `bindgen` code base. This is enforced in
119+
CI, and your pull requests will get automatically rejected if you don't
120+
re-format with the latest `rustfmt` before pushing.
119121

120-
[`rustfmt`](https://github.com/rust-lang-nursery/rustfmt) can catch and fix
121-
automatically all the coding style issues it finds. In order to use it it
122-
suffices to do:
122+
You can install the latest version of `rustfmt` with this command:
123123

124124
```
125-
$ cargo fmt
125+
$ cargo install -f rustfmt
126126
```
127127

128-
For it to work, you need to have `rustfmt` installed. To do so:
128+
Ensure that `~/.cargo/bin` is on your path.
129+
130+
Once that is taken care of, you can (re)format all code by running this command:
129131

130132
```
131-
$ cargo install rustfmt
133+
$ cargo fmt
132134
```
133135

134-
And ensure `~/.cargo/bin` is on your path.
136+
The code style is described in the `rustfmt.toml` file in top level of the repo.
135137

136138
## Debug Logging
137139

ci/assert-docs.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -xeu
4+
cd "$(dirname "$0")/.."
5+
6+
cargo build --features "$BINDGEN_FEATURES docs_"

ci/assert-no-diff.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
set -xeu
4+
cd "$(dirname "$0")/.."
5+
6+
git add -u
7+
git diff @
8+
git diff-index --quiet HEAD

ci/assert-rustfmt.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
set -xeu
4+
cd "$(dirname "$0")/.."
5+
6+
# Ensure we have the most up-to-date `rustfmt`.
7+
cargo install -f rustfmt
8+
9+
# Run `rustfmt` on the crate! If `rustfmt` can't make a long line shorter, it
10+
# prints an error and exits non-zero, so tell it to kindly shut its yapper and
11+
# make sure it doesn't cause us to exit this whole script non-zero.
12+
cargo fmt --quiet || true
13+
14+
# Exit non-zero if this resulted in any diffs.
15+
./ci/assert-no-diff.sh
16+

ci/test.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
set -xeu
4+
cd "$(dirname "$0")/.."
5+
6+
# Regenerate the test headers' bindings in debug and release modes, and assert
7+
# that we always get the expected generated bindings.
8+
9+
cargo test --features "$BINDGEN_FEATURES assert_no_dangling_items"
10+
./ci/assert-no-diff.sh
11+
12+
cargo test --release --features "$BINDGEN_FEATURES assert_no_dangling_items"
13+
./ci/assert-no-diff.sh
14+
15+
# Now test the expectations' size and alignment tests.
16+
17+
pushd tests/expectations
18+
cargo test
19+
cargo test --release
20+
popd
21+
22+
# And finally, test our example bindgen + build.rs integration template project.
23+
24+
cd bindgen-integration
25+
cargo test --features "$BINDGEN_FEATURES"
26+
cargo test --release --features "$BINDGEN_FEATURES"

src/ir/objc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Objective C types
22
33
// use clang_sys::CXCursor_ObjCSuperClassRef;
4+
45
use super::context::BindgenContext;
56
use clang;
67
use clang_sys::CXChildVisit_Continue;

0 commit comments

Comments
 (0)