Skip to content

Commit dc797c2

Browse files
committed
reformat source code, add build rule to check formatting
1 parent 27bb995 commit dc797c2

File tree

4 files changed

+143
-95
lines changed

4 files changed

+143
-95
lines changed

.travis.yml

+9-12
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ sudo: required
33
services:
44
- docker
55

6+
env:
7+
global:
8+
- BUILD_CMD=./build_all_configs.sh
9+
- BUILD_DIR=/workdir
10+
- DOCKER_IMAGE=multiarch/crossbuild
11+
612
matrix:
713
include:
814
- env:
915
- TARGET_OS=linux64
10-
- DOCKER_IMAGE=multiarch/crossbuild
1116
- CROSS_TRIPLE=x86_64-linux-gnu
12-
- BUILD_DIR=/workdir
1317
- env:
1418
- TARGET_OS=linux32
1519
# multiarch/crossbuild doesn't come with 32-bit compilers, use a different image
@@ -18,25 +22,18 @@ matrix:
1822
- BUILD_DIR=/work
1923
- env:
2024
- TARGET_OS=linux-armhf
21-
- DOCKER_IMAGE=multiarch/crossbuild
2225
- CROSS_TRIPLE=arm-linux-gnueabihf
23-
- BUILD_DIR=/workdir
24-
- EXTRA_ARGS="-e SKIP_TESTS=1"
26+
- EXTRA_ARGS='-e SKIP_TESTS=1'
2527
- env:
2628
- TARGET_OS=win32
27-
- DOCKER_IMAGE=multiarch/crossbuild
2829
- CROSS_TRIPLE=i686-w64-mingw32
29-
- BUILD_DIR=/workdir
3030
# multiarch/crossbuild doesn't come with 'zip',
3131
# so we build a tgz archive in the container, and re-package it later in the script.
3232
- EXTRA_ARGS='-e ARCHIVE=tar -e SKIP_TESTS=1'
3333
- env:
3434
- TARGET_OS=osx
35-
- DOCKER_IMAGE=multiarch/crossbuild
3635
- CROSS_TRIPLE=x86_64-apple-darwin
37-
- BUILD_DIR=/workdir
38-
- EXTRA_ARGS="-e SKIP_TESTS=1 -e CXX=c++"
39-
36+
- EXTRA_ARGS='-e SKIP_TESTS=1 -e CXX=c++'
4037

4138
script:
4239
- export VER=$(git describe)
@@ -49,7 +46,7 @@ script:
4946
-e CROSS_TRIPLE=${CROSS_TRIPLE}
5047
${EXTRA_ARGS}
5148
${DOCKER_IMAGE}
52-
./build_all_configs.sh
49+
${BUILD_CMD}
5350
5451
# Diagnostics
5552
- ls -l

Makefile

+21-3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ OBJ := main.o \
6666

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

69+
FILES_TO_FORMAT := $(shell find . -not -path './spiffs/*' \( -name '*.c' -o -name '*.cpp' \))
70+
71+
DIFF_FILES := $(addsuffix .diff,$(FILES_TO_FORMAT))
72+
6973
# clang doesn't seem to handle -D "ARG=\"foo bar\"" correctly, so replace spaces with \x20:
7074
BUILD_CONFIG_STR := $(shell echo $(CPPFLAGS) | sed 's- -\\\\x20-')
7175

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

89-
.PHONY: all clean dist
90-
9193
all: $(TARGET)
9294

9395
dist: $(DIST_ARCHIVE)
@@ -108,7 +110,7 @@ $(DIST_DIR):
108110
@mkdir -p $@
109111

110112
clean:
111-
@rm -f $(TARGET) $(OBJ)
113+
@rm -f $(TARGET) $(OBJ) $(DIFF_FILES)
112114

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

@@ -132,3 +134,19 @@ test: $(TARGET)
132134
diff spiffs_t spiffs_u
133135
rm -f out.{list0,list1,list2,list_u,spiffs_t}
134136
rm -R spiffs_u spiffs_t
137+
138+
format-check: $(DIFF_FILES)
139+
@rm -f $(DIFF_FILES)
140+
141+
$(DIFF_FILES): %.diff: %
142+
@./format.sh < $< >$<.new
143+
@diff $<.new $< >$@ || ( \
144+
echo "File $^ not formatted correctly. Please use format.sh to re-format it." && \
145+
echo "Here's the diff that caused an error:" && \
146+
echo "" && \
147+
cat $@ && \
148+
rm $@ $<.new && \
149+
exit 1 )
150+
@rm -f $@ $<.new
151+
152+
.PHONY: all clean dist format-check

format.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
# Runs astyle with the full set of formatting options
3+
astyle \
4+
--style=otbs \
5+
--indent=spaces=4 \
6+
--convert-tabs \
7+
--keep-one-line-statements \
8+
--pad-header \
9+
--pad-oper \
10+
"$@"

0 commit comments

Comments
 (0)