Skip to content

Commit

Permalink
Prepare for applying clang-format and checking it on travis
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinPitrat committed Sep 25, 2017
1 parent b2d9029 commit cf4c086
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
25 changes: 25 additions & 0 deletions check_clang_format.sh
@@ -0,0 +1,25 @@
#!/bin/bash

TMPDIR=`mktemp -d`

CLANG_FORMAT=$1
shift
CLANG_ARGS=$1
shift

error_files=""
format_error=0
for file in $@
do
mkdir -p `dirname $TMPDIR/$file`
$CLANG_FORMAT -style=Google $file > $TMPDIR/$file
if ! diff $file $TMPDIR/$file
then
format_error=1
error_files="$error_files $file"
fi
done
#rm -rf $TMPDIR
[ $format_error -eq 0 ] || echo "**ERROR**: Files with improper formatting: $error_files"

exit $format_error
9 changes: 9 additions & 0 deletions makefile
Expand Up @@ -67,6 +67,7 @@ GIT_HASH = $(shell git rev-parse --verify HEAD)
COMMON_CFLAGS += -DHASH=\"$(GIT_HASH)\"
endif

CLANG_FORMAT=clang-format
CLANG_TIDY=clang-tidy-3.8
CLANG_CHECKS=modernize-*,performance-*,misc-*,-misc-definitions-in-headers,readability-*,-readability-implicit-bool-cast,-readability-braces-around-statements,-readability-function-size

Expand All @@ -81,10 +82,12 @@ GROFF_DOC:=doc/man6/cap32.6
MAIN:=$(OBJDIR)/main.o

SOURCES:=$(shell find $(SRCDIR) -name \*.cpp)
HEADERS:=$(shell find $(SRCDIR) -name \*.h)
DEPENDS:=$(foreach file,$(SOURCES:.cpp=.d),$(shell echo "$(OBJDIR)/$(file)"))
OBJECTS:=$(DEPENDS:.d=.o)

TEST_SOURCES:=$(shell find $(TSTDIR) -name \*.cpp)
TEST_HEADERS:=$(shell find $(TSTDIR) -name \*.h)
TEST_DEPENDS:=$(foreach file,$(TEST_SOURCES:.cpp=.d),$(shell echo "$(OBJDIR)/$(file)"))
TEST_OBJECTS:=$(TEST_DEPENDS:.d=.o)

Expand Down Expand Up @@ -249,6 +252,12 @@ endif
clang-tidy:
if $(CLANG_TIDY) -checks=-*,$(CLANG_CHECKS) $(SOURCES) -header-filter=src/* -- $(COMMON_CFLAGS) | grep "."; then false; fi

clang-format:
./check_clang_format.sh $(CLANG_FORMAT) "-style=Google" $(SOURCES) $(TEST_SOURCES) $(HEADERS) $(TEST_HEADERS)

fix-clang-format:
$(CLANG_FORMAT) -style=Google -i $(SOURCES) $(TEST_SOURCES) $(HEADERS) $(TEST_HEADERS)

clean:
rm -rf obj/ release/ .pc/
rm -f test_runner test_runner.exe cap32 cap32.exe .debug tags
Expand Down

0 comments on commit cf4c086

Please sign in to comment.