Skip to content

Commit b7750b5

Browse files
authored
Speed up source checks in Travis (#885)
* Factor out a whitespace checking script * Factor out a copyright checking script * Rewrite lint.sh to honor revision ranges * Only restyle files that are part of the PR * Run C++ lint before builds to fail faster * Git grep doesn't operate on revision ranges * style.sh accepts clang-format 6 or 7
1 parent 5930ad2 commit b7750b5

File tree

5 files changed

+98
-13
lines changed

5 files changed

+98
-13
lines changed

.travis.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@ before_install:
3030
fi
3131
3232
script:
33-
# Fail on trailing whitespace in non-binary, non-generated-nanopb files
34-
- "! git grep -I ' $' ':(exclude)Firestore/Protos/nanopb'"
35-
- "! git grep -EL --name-only 'Copyright [0-9]{4}.*Google' | grep -v third_party | egrep '\\.(m|h|cc|mm|c)$'"
36-
- ./scripts/style.sh test-only # Validate clang-format compliance
33+
- ./scripts/check_whitespace.sh
34+
- ./scripts/check_copyright.sh
35+
- ./scripts/style.sh test-only $TRAVIS_COMMIT_RANGE
3736
- |
38-
if [ $SKIP_FIREBASE != 1 ]; then
39-
./test.sh
37+
# Google C++ style compliance
38+
if [ $SKIP_FIRESTORE != 1 ]; then
39+
./scripts/lint.sh $TRAVIS_COMMIT_RANGE
4040
fi
41+
4142
- |
42-
if [ $SKIP_FIRESTORE != 1 ]; then
43-
./scripts/lint.sh # Google C++ style compliance
43+
if [ $SKIP_FIREBASE != 1 ]; then
44+
./test.sh
4445
fi
4546
- |
4647
if [ $SKIP_FIRESTORE != 1 ]; then

scripts/check_copyright.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2018 Google
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Check source files for copyright notices
16+
17+
options=(
18+
-E # Use extended regexps
19+
-I # Exclude binary files
20+
-L # Show files that don't have a match
21+
'Copyright [0-9]{4}.*Google'
22+
)
23+
24+
git grep "${options[@]}" \
25+
-- '*.'{c,cc,h,m,mm,sh,swift} \
26+
':(exclude)**/third_party/**'
27+
if [[ $? == 0 ]]; then
28+
echo "ERROR: Missing copyright notices in the files above. Please fix."
29+
exit 1
30+
fi
31+

scripts/check_whitespace.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2018 Google
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Fail on an trailing whitespace characters, excluding
16+
# * binary files (-I)
17+
# * nanopb-generated files
18+
#
19+
# Note: specifying revisions we care about makes this go slower than just
20+
# grepping through the whole repo.
21+
options=(
22+
-n # show line numbers
23+
-I # exclude binary files
24+
' $'
25+
)
26+
27+
git grep "${options[@]}" \
28+
-- ':(exclude)Firestore/Protos/nanopb'
29+
if [[ $? == 0 ]]; then
30+
echo "ERROR: Trailing whitespace found in the files above. Please fix."
31+
exit 1
32+
fi
33+

scripts/lint.sh

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,23 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
find Firestore/core \( \
16-
-name \*.h -o \
17-
-name \*.cc \) -print0 \
15+
# Lints C++ files for conformance with the Google C++ style guide
16+
17+
options=(
18+
-z # \0 terminate output
19+
)
20+
21+
if [[ $# -gt 0 ]]; then
22+
# Interpret any command-line argument as a revision range
23+
command=(git diff --name-only)
24+
options+=("$@")
25+
26+
else
27+
# Default to operating on all files that match the pattern
28+
command=(git ls-files)
29+
fi
30+
31+
32+
"${command[@]}" "${options[@]}" \
33+
-- 'Firestore/core/**/*.'{h,cc} \
1834
| xargs -0 python scripts/cpplint.py --quiet

scripts/style.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323

2424
system=$(uname -s)
2525

26-
if [[ $(clang-format --version) != *"version 6"* ]]; then
27-
echo "Please upgrade to clang-format version 6."
26+
version=$(clang-format --version)
27+
version="${version/*version /}"
28+
version="${version/.*/}"
29+
if [[ "$version" != 6 && "$version" != 7 ]]; then
30+
# Allow an older clang-format to accommodate Travis version skew.
31+
echo "Please upgrade to clang-format version 7."
2832
echo "If it's installed via homebrew you can run: brew upgrade clang-format"
2933
exit 1
3034
fi

0 commit comments

Comments
 (0)