Improve `make format`.

* Use `yapf` from environment if it exists.
 * Better way to generate exclude.
 * Make TCL formatting work.

Signed-off-by: Tim 'mithro' Ansell <me@mith.ro>
This commit is contained in:
Tim 'mithro' Ansell 2018-12-13 17:27:44 -08:00
parent 9108adad3a
commit 23c435aa6e
3 changed files with 11 additions and 7 deletions

View File

@ -1,7 +1,10 @@
CLANG_FORMAT ?= clang-format-3.9
CLANG_FORMAT ?= clang-format-5.0
PYTHON_FORMAT ?= yapf
TCL_FORMAT ?= utils//tcl-reformat.sh
.PHONY: database format clean env
IN_ENV = if [ -e env/bin/activate ]; then . env/bin/activate; fi;
env:
virtualenv --python=python3 env
. env/bin/activate; pip install -r requirements.txt
@ -15,11 +18,13 @@ build:
database: build
$(MAKE) -C $@
FORMAT_EXCLUDE = third_party git env build
FIND_EXCLUDE = $(foreach x,$(FORMAT_EXCLUDE),-and -not -path './$(x)/*')
format:
find . -name \*.cc -and -not -path './third_party/*' -and -not -path './.git/*' -print0 | xargs -0 -P $$(nproc) ${CLANG_FORMAT} -style=file -i
find . -name \*.h -and -not -path './third_party/*' -and -not -path './.git/*' -print0 | xargs -0 -P $$(nproc) ${CLANG_FORMAT} -style=file -i
find . -name \*.py -and -not -path './third_party/*' -and -not -path './.git/*' -print0 | xargs -0 -P $$(nproc) yapf -p -i
find . -name \*.tcl -and -not -path './third_party/*' -and -not -path './.git/*' -print0 | xargs -0 -P $$(nproc) -n 1 ${XRAY_TCL_REFORMAT} 2>/dev/null
find . -name \*.cc $(FIND_EXCLUDE) -print0 | xargs -0 -P $$(nproc) ${CLANG_FORMAT} -style=file -i
find . -name \*.h $(FIND_EXCLUDE) -print0 | xargs -0 -P $$(nproc) ${CLANG_FORMAT} -style=file -i
$(IN_ENV) find . -name \*.py $(FIND_EXCLUDE) -print0 | xargs -0 -P $$(nproc) yapf -p -i
find . -name \*.tcl $(FIND_EXCLUDE) -print0 | xargs -0 -P $$(nproc) -n 1 $(TCL_FORMAT)
clean:
$(MAKE) -C database clean

View File

@ -27,6 +27,5 @@ export XRAY_FASM2FRAMES="python3 ${XRAY_UTILS_DIR}/fasm2frames.py"
export XRAY_BITTOOL="${XRAY_TOOLS_DIR}/bittool"
export XRAY_BLOCKWIDTH="python3 ${XRAY_UTILS_DIR}/blockwidth.py"
export XRAY_PARSEDB="python3 ${XRAY_UTILS_DIR}/parsedb.py"
export XRAY_REFORMAT_TCL="${XRAY_DIR}/third_party/reformat.tcl"
export XRAY_TCL_REFORMAT="${XRAY_UTILS_DIR}/tcl-reformat.sh"

View File

@ -4,7 +4,7 @@
fn=$1
$XRAY_REFORMAT_TCL $fn >/dev/null
third_party/reformat.tcl $fn >/dev/null
# Always puts a newline at the end, even if there was one before
# remove duplicates, but keep at least one
printf "%s\n" "$(< $fn)" >$fn.tmp