summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-06-20 10:54:13 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-07-01 11:18:53 +0300
commitda863c6e52f656bd35c3d3346093a24d747d0bbd (patch)
tree7fffcf205e6abbb0eaaef8faa307d9ff90762881
parenta440598e2b1dd224a03646c7e30a4d1b94769a27 (diff)
downloadqtlocation-mapboxgl-da863c6e52f656bd35c3d3346093a24d747d0bbd.tar.gz
[build] Added 'lint' Make target
m---------.mason0
-rw-r--r--Makefile24
-rwxr-xr-xscripts/clang-tidy.sh35
-rwxr-xr-xscripts/clang-tools.sh66
4 files changed, 85 insertions, 40 deletions
diff --git a/.mason b/.mason
-Subproject 56e8cd4b8128f456356f999d215816618f47e57
+Subproject 98feac14b1ae298322ee30291105b40ba29dac0
diff --git a/Makefile b/Makefile
index f45925f0ce..7cf6fcc1c0 100644
--- a/Makefile
+++ b/Makefile
@@ -318,7 +318,7 @@ endif
test-%: test
$(GDB) $(LINUX_OUTPUT_PATH)/$(BUILDTYPE)/test --gtest_catch_exceptions=0 --gtest_filter=$*
-check: test
+coverage: test
scripts/collect-coverage.sh $(LINUX_OUTPUT_PATH)/$(BUILDTYPE)
# Generates a compilation database with ninja for use in clang tooling
@@ -338,15 +338,29 @@ compdb-macos: platform/macos/platform.gyp $(MACOS_OUTPUT_PATH)/config.gypi
tidy: compdb tidy-$(BUILD_PLATFORM)
-tidy-linux:
+clang-tools-linux:
if test -z $(CLANG_TIDY); then .mason/mason install clang-tidy 3.8.0; fi
+ if test -z $(CLANG_FORMAT); then .mason/mason install clang-format 3.8.0; fi
deps/ninja/ninja-linux -C $(LINUX_OUTPUT_PATH)/$(BUILDTYPE) headers
- scripts/clang-tidy.sh $(LINUX_OUTPUT_PATH)/$(BUILDTYPE)
-tidy-macos:
+tidy-linux: clang-tools-linux
+ scripts/clang-tools.sh $(LINUX_OUTPUT_PATH)/$(BUILDTYPE)
+
+clang-tools-macos:
if test -z $(CLANG_TIDY); then .mason/mason install clang-tidy 3.8.0; fi
+ if test -z $(CLANG_FORMAT); then .mason/mason install clang-format 3.8.0; fi
deps/ninja/ninja-macos -C $(MACOS_OUTPUT_PATH)/$(BUILDTYPE) headers
- scripts/clang-tidy.sh $(MACOS_OUTPUT_PATH)/$(BUILDTYPE)
+
+tidy-macos: clang-tools-macos
+ scripts/clang-tools.sh $(MACOS_OUTPUT_PATH)/$(BUILDTYPE)
+
+check: compdb check-$(BUILD_PLATFORM)
+
+check-linux: clang-tools-linux
+ scripts/clang-tools.sh $(LINUX_OUTPUT_PATH)/$(BUILDTYPE) --diff
+
+check-macos: clang-tools-macos
+ scripts/clang-tools.sh $(MACOS_OUTPUT_PATH)/$(BUILDTYPE) --diff
#### Miscellaneous targets #####################################################
diff --git a/scripts/clang-tidy.sh b/scripts/clang-tidy.sh
deleted file mode 100755
index 7665180cf7..0000000000
--- a/scripts/clang-tidy.sh
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-set -o pipefail
-
-export PATH="`pwd`/.mason:${PATH}" MASON_DIR="`pwd`/.mason"
-
-CLANG_TIDY=${CLANG_TIDY:-$(mason prefix clang-tidy 3.8.0)/bin/clang-tidy}
-
-command -v ${CLANG_TIDY} >/dev/null 2>&1 || {
- echo "Can't find ${CLANG_TIDY} in PATH."
- if [ -z ${CLANG_TIDY} ]; then
- echo "Alternatively, you can set CLANG_TIDY to point to clang-tidy."
- fi
- exit 1
-}
-
-cd $1
-
-function check_tidy() {
- echo "Checking $0..."
- OUTPUT=$(${CLANG_TIDY} -p=$PWD $0 2>/dev/null)
- if [[ -n $OUTPUT ]]; then
- echo "Caught clang-tidy warning/error:"
- echo -e "$OUTPUT"
- exit 1
- fi
-}
-
-export CLANG_TIDY
-export -f check_tidy
-
-echo "Running clang-tidy checks... (this might take a while)"
-git ls-files '../../../src/mbgl/*.cpp' '../../../platform/*.cpp' '../../../test/*.cpp' | \
- xargs -I{} -P ${JOBS} bash -c 'check_tidy' {}
diff --git a/scripts/clang-tools.sh b/scripts/clang-tools.sh
new file mode 100755
index 0000000000..23d5b289ef
--- /dev/null
+++ b/scripts/clang-tools.sh
@@ -0,0 +1,66 @@
+#!/usr/bin/env bash
+
+set -e
+set -o pipefail
+
+export PATH="`pwd`/.mason:${PATH}" MASON_DIR="`pwd`/.mason"
+
+CLANG_TIDY=${CLANG_TIDY:-$(mason prefix clang-tidy 3.8.0)/bin/clang-tidy}
+CLANG_FORMAT=${CLANG_FORMAT:-$(mason prefix clang-format 3.8.0)/bin/clang-format}
+
+command -v ${CLANG_TIDY} >/dev/null 2>&1 || {
+ echo "Can't find ${CLANG_TIDY} in PATH."
+ if [ -z ${CLANG_TIDY} ]; then
+ echo "Alternatively, you can set CLANG_TIDY to point to clang-tidy."
+ fi
+ exit 1
+}
+
+cd $1
+
+function check_tidy() {
+ echo "Running clang-tidy on $0..."
+ if [ -n $1 ] && [ $1 == "--fix" ]; then
+ OUTPUT=$(${CLANG_TIDY} -p=$PWD -fix -fix-errors $0 2>/dev/null)
+ else
+ OUTPUT=$(${CLANG_TIDY} -p=$PWD $0 2>/dev/null)
+ fi
+ if [[ -n $OUTPUT ]]; then
+ echo "Caught clang-tidy warning/error:"
+ echo -e "$OUTPUT"
+ exit 1
+ fi
+}
+
+function check_format() {
+ echo "Running clang-format on $0..."
+ ${CLANG_FORMAT} -i ../../../$0
+}
+
+export CLANG_TIDY CLANG_FORMAT
+export -f check_tidy check_format
+
+git diff-index --quiet HEAD || {
+ echo "Your repository contains unstaged and/or uncommitted changes."
+ echo "Please commit all changes before proceeding."
+ exit 1
+}
+
+echo "Running clang checks... (this might take a while)"
+
+if [ -n $2 ] && [ $2 == "--diff" ]; then
+ DIFF_FILES=$(for file in `git diff origin/master..HEAD --name-only | grep "pp$"`; do echo $file; done)
+ if [[ -n $DIFF_FILES ]]; then
+ echo "${DIFF_FILES}" | xargs -I{} -P ${JOBS} bash -c 'check_tidy --fix' {}
+ # XXX disabled until we run clang-format over the entire codebase.
+ #echo "${DIFF_FILES}" | xargs -I{} -P ${JOBS} bash -c 'check_format' {}
+ git diff-index --quiet HEAD || {
+ echo "Changes were made to source files - please review them before committing."
+ exit 1
+ }
+ fi
+ echo "All looks good!"
+else
+ git ls-files '../../../src/mbgl/*.cpp' '../../../platform/*.cpp' '../../../test/*.cpp' | \
+ xargs -I{} -P ${JOBS} bash -c 'check_tidy' {}
+fi