Skip to content

Commit

Permalink
reformat source code, add build rule to check formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
igrr committed Feb 12, 2018
1 parent 27bb995 commit dc797c2
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 95 deletions.
21 changes: 9 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ sudo: required
services:
- docker

env:
global:
- BUILD_CMD=./build_all_configs.sh
- BUILD_DIR=/workdir
- DOCKER_IMAGE=multiarch/crossbuild

matrix:
include:
- env:
- TARGET_OS=linux64
- DOCKER_IMAGE=multiarch/crossbuild
- CROSS_TRIPLE=x86_64-linux-gnu
- BUILD_DIR=/workdir
- env:
- TARGET_OS=linux32
# multiarch/crossbuild doesn't come with 32-bit compilers, use a different image
Expand All @@ -18,25 +22,18 @@ matrix:
- BUILD_DIR=/work
- env:
- TARGET_OS=linux-armhf
- DOCKER_IMAGE=multiarch/crossbuild
- CROSS_TRIPLE=arm-linux-gnueabihf
- BUILD_DIR=/workdir
- EXTRA_ARGS="-e SKIP_TESTS=1"
- EXTRA_ARGS='-e SKIP_TESTS=1'
- env:
- TARGET_OS=win32
- DOCKER_IMAGE=multiarch/crossbuild
- CROSS_TRIPLE=i686-w64-mingw32
- BUILD_DIR=/workdir
# multiarch/crossbuild doesn't come with 'zip',
# so we build a tgz archive in the container, and re-package it later in the script.
- EXTRA_ARGS='-e ARCHIVE=tar -e SKIP_TESTS=1'
- env:
- TARGET_OS=osx
- DOCKER_IMAGE=multiarch/crossbuild
- CROSS_TRIPLE=x86_64-apple-darwin
- BUILD_DIR=/workdir
- EXTRA_ARGS="-e SKIP_TESTS=1 -e CXX=c++"

- EXTRA_ARGS='-e SKIP_TESTS=1 -e CXX=c++'

script:
- export VER=$(git describe)
Expand All @@ -49,7 +46,7 @@ script:
-e CROSS_TRIPLE=${CROSS_TRIPLE}
${EXTRA_ARGS}
${DOCKER_IMAGE}
./build_all_configs.sh
${BUILD_CMD}
# Diagnostics
- ls -l
Expand Down
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ OBJ := main.o \

INCLUDES := -Itclap -Iinclude -Ispiffs/src -I.

FILES_TO_FORMAT := $(shell find . -not -path './spiffs/*' \( -name '*.c' -o -name '*.cpp' \))

DIFF_FILES := $(addsuffix .diff,$(FILES_TO_FORMAT))

# clang doesn't seem to handle -D "ARG=\"foo bar\"" correctly, so replace spaces with \x20:
BUILD_CONFIG_STR := $(shell echo $(CPPFLAGS) | sed 's- -\\\\x20-')

Expand All @@ -86,8 +90,6 @@ DIST_NAME := mkspiffs-$(VERSION)$(BUILD_CONFIG_NAME)-$(TARGET_OS)
DIST_DIR := $(DIST_NAME)
DIST_ARCHIVE := $(DIST_NAME).$(ARCHIVE_EXTENSION)

.PHONY: all clean dist

all: $(TARGET)

dist: $(DIST_ARCHIVE)
Expand All @@ -108,7 +110,7 @@ $(DIST_DIR):
@mkdir -p $@

clean:
@rm -f $(TARGET) $(OBJ)
@rm -f $(TARGET) $(OBJ) $(DIFF_FILES)

SPIFFS_TEST_FS_CONFIG := -s 0x100000 -p 512 -b 0x2000

Expand All @@ -132,3 +134,19 @@ test: $(TARGET)
diff spiffs_t spiffs_u
rm -f out.{list0,list1,list2,list_u,spiffs_t}
rm -R spiffs_u spiffs_t

format-check: $(DIFF_FILES)
@rm -f $(DIFF_FILES)

$(DIFF_FILES): %.diff: %
@./format.sh < $< >$<.new
@diff $<.new $< >$@ || ( \
echo "File $^ not formatted correctly. Please use format.sh to re-format it." && \
echo "Here's the diff that caused an error:" && \
echo "" && \
cat $@ && \
rm $@ $<.new && \
exit 1 )
@rm -f $@ $<.new

.PHONY: all clean dist format-check
10 changes: 10 additions & 0 deletions format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
# Runs astyle with the full set of formatting options
astyle \
--style=otbs \
--indent=spaces=4 \
--convert-tabs \
--keep-one-line-statements \
--pad-header \
--pad-oper \
"$@"
Loading

0 comments on commit dc797c2

Please sign in to comment.