Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
Added clang-format binaries & helper scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
derekwbarnett committed Jan 15, 2018
1 parent 04d5ff3 commit 24c82d5
Show file tree
Hide file tree
Showing 9 changed files with 544 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
BasedOnStyle: Google
BreakBeforeBraces: Mozilla

AllowShortLoopsOnASingleLine: false
AccessModifierOffset: -4
BreakConstructorInitializersBeforeComma: true
ColumnLimit: 100
IndentWidth: 4
PointerAlignment: Left
TabWidth: 4

ReflowComments: false # protect ASCII art in comments
KeepEmptyLinesAtTheStartOfBlocks: true
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ if not meson.is_subproject()
pbbam_python = find_program('python')

if get_option('enable-tests')
pbbam_clang_formatter = find_program('tools/check-formatting')
subdir('tests')
endif
endif
Expand Down
2 changes: 2 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ custom_target('pbbam_generate_data',

test('pbbam test', pbbam_test)

test('pbbam formatting check', pbbam_clang_formatter, args : ['--all'], workdir : meson.source_root())

pbbamify_synthetic_dataset = configure_file(
input : files('data/pbbamify/synthetic_movie_all.subreadset.xml.in'),
output : 'synthetic_movie_all.subreadset.xml',
Expand Down
Binary file added tools/Darwin/clang-format
Binary file not shown.
Binary file added tools/Linux/clang-format
Binary file not shown.
34 changes: 34 additions & 0 deletions tools/check-formatting
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

PLATFORM=$(uname)
TOOLSPATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
CLANGFORMAT="${TOOLSPATH}/${PLATFORM}/clang-format -style=file"

if [ "$1" == "--all" ]
then
find include src tests/src tests/unit \( -name *.cpp -or -name *.h \) -print0 \
| xargs -n1 -0 ${CLANGFORMAT} -output-replacements-xml \
| grep -c "<replacement " > /dev/null
grepCode=$?
elif [ "$1" == "--staged" ]
then
git diff --cached --name-only --diff-filter=ACMRT | grep -e '.*\.h$' -e '.*\.cpp' -v '**third-party/*' \
| xargs -n1 ${CLANGFORMAT} -output-replacements-xml \
| grep -c "<replacement " >/dev/null
grepCode=$?
else
echo "Please specify --all or --staged"
exit 1
fi

# grep exits 0 => found needed formatting changes
if [ $grepCode -ne 0 ]
then
echo "Formatting looks good!"
exit 0
else
echo "****************************************************"
echo "Code needs formatting! Please use 'tools/format-all'"
echo "****************************************************"
exit 1
fi
9 changes: 9 additions & 0 deletions tools/format-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

# This command can be run by the user to clang-format everything.

PLATFORM=$(uname)
TOOLSPATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
CLANGFORMAT="${TOOLSPATH}/${PLATFORM}/clang-format -style=file"

find include src tests/src tests/unit \( -name *.cpp -or -name *.h \) -print0 | xargs -n1 -0 ${CLANGFORMAT} -i
Loading

0 comments on commit 24c82d5

Please sign in to comment.