Skip to content

Commit

Permalink
[devtools] Move C++ formatting to devtools/format.sh
Browse files Browse the repository at this point in the history
It's now

    devtools/format.sh all-cpp
  • Loading branch information
Andy C committed Jul 27, 2023
1 parent 2e94bd6 commit 21800e7
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 49 deletions.
65 changes: 65 additions & 0 deletions devtools/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@
# Usage:
# test/format.sh <function name>

REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)

. build/dev-shell.sh # python3 in $PATH
. build/common.sh # $CLANG_DIR

set -o nounset
set -o pipefail
set -o errexit
shopt -s strict:all 2>/dev/null || true # dogfood for OSH

#
# Python
#

yapf-version() {
python3 -m yapf --version
Expand All @@ -17,4 +29,57 @@ yapf-files() {
python3 -m yapf -i "$@"
}

#
# C++
#

clang-format() {
# See //.clang-format for the style config.
$CLANG_DIR/bin/clang-format --style=file "$@"
}

readonly -a CPP_FILES=(
{asdl,core}/*.cc
benchmarks/*.c
cpp/*.{c,cc,h}
mycpp/*.{cc,h}
mycpp/demo/*.{cc,h}
demo/*.c

# Could add pyext, but they have sort of a Python style
# pyext/fanos.c
)

cpp-files() {
shopt -s nullglob
for file in "${CPP_FILES[@]}"; do

echo $file
done
}

all-cpp() {
# see build/common.sh
if test -n "$CLANG_IS_MISSING"; then
log ''
log " *** $0: Did not find $CLANG_DIR_1"
log " *** Run deps/from-binary.sh to get it"
log ''
return 1
fi

cpp-files | egrep -v 'greatest.h' | xargs -- $0 clang-format -i
git diff
}

test-asdl-format() {
### Test how clang-format would like our generated code

local file=${1:-_gen/asdl/hnode.asdl.h}

local tmp=_tmp/hnode
clang-format $file > $tmp
diff -u $file $tmp
}

"$@"
49 changes: 0 additions & 49 deletions test/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,55 +37,6 @@ cpplint() {
-readability/todo,-legal/copyright,-build/header_guard,-build/include,-whitespace/comments "$@"
}

clang-format() {
# See //.clang-format for the style config.
$CLANG_DIR/bin/clang-format --style=file "$@"
}

readonly -a CPP_FILES=(
{asdl,core}/*.cc
benchmarks/*.c
cpp/*.{c,cc,h}
mycpp/*.{cc,h}
mycpp/demo/*.{cc,h}
demo/*.c

# Could add pyext, but they have sort of a Python style
# pyext/fanos.c
)

cpp-files() {
shopt -s nullglob
for file in "${CPP_FILES[@]}"; do

echo $file
done
}

format-cpp() {
# see build/common.sh
if test -n "$CLANG_IS_MISSING"; then
log ''
log " *** $0: Did not find $CLANG_DIR_1"
log " *** Run deps/from-binary.sh to get it"
log ''
return 1
fi

cpp-files | egrep -v 'greatest.h' | xargs -- $0 clang-format -i
git diff
}

test-asdl-format() {
### Test how clang-format would like our generated code

local file=${1:-_gen/asdl/hnode.asdl.h}

local tmp=_tmp/hnode
clang-format $file > $tmp
diff -u $file $tmp
}

#
# Python
#
Expand Down

0 comments on commit 21800e7

Please sign in to comment.