diff options
author | Heejin Ahn <aheejin@gmail.com> | 2019-04-26 14:42:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-26 14:42:40 -0700 |
commit | 87636dccd404a340d75acb1d96301581343f29ca (patch) | |
tree | f56ec2ea8e166e5d02018cf7adc1c960dbeba55d | |
parent | 34dd4c7893056e13cc9174db988d03e438a6af3d (diff) | |
download | binaryen-87636dccd404a340d75acb1d96301581343f29ca.tar.gz binaryen-87636dccd404a340d75acb1d96301581343f29ca.tar.bz2 binaryen-87636dccd404a340d75acb1d96301581343f29ca.zip |
Add clang-format-diff hook (#2057)
This adds a commit hook to Travis CI that errors out if incoming PRs'
diffs are not clang-formatted. Turns out clang-format is also capable of
formatting JavaScript, but we haven't agreed on a style for JS yet, this
PR disables JavaScript formatting for now. This also adds clang-format
exempt header/footer to a generated source file.
-rw-r--r-- | .clang-format | 6 | ||||
-rw-r--r-- | .travis.yml | 1 | ||||
-rwxr-xr-x | clang-format-diff.sh | 11 | ||||
-rwxr-xr-x | scripts/gen-s-parser.py | 6 | ||||
-rw-r--r-- | src/gen-s-parser.inc | 4 |
5 files changed, 28 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format index 9ca4dd982..cedadcbd0 100644 --- a/.clang-format +++ b/.clang-format @@ -1,3 +1,5 @@ +--- +Language: Cpp BasedOnStyle: LLVM PointerAlignment: Left IndentCaseLabels: true @@ -6,3 +8,7 @@ ConstructorInitializerIndentWidth: 2 SpaceAfterTemplateKeyword: false BinPackArguments: false BinPackParameters: false +--- +Language: JavaScript +DisableFormat: true +--- diff --git a/.travis.yml b/.travis.yml index 1a94debec..a070c8977 100644 --- a/.travis.yml +++ b/.travis.yml @@ -59,6 +59,7 @@ jobs: script: - set -o errexit - flake8 + - ./clang-format-diff.sh # ensure generated parser is up to date - ./scripts/gen-s-parser.py | diff src/gen-s-parser.inc - - BUILD_SUBDIR=${BUILD_SUBDIR:-.} diff --git a/clang-format-diff.sh b/clang-format-diff.sh new file mode 100755 index 000000000..53020e59b --- /dev/null +++ b/clang-format-diff.sh @@ -0,0 +1,11 @@ +#!/bin/bash +MERGE_BASE=$(git merge-base master HEAD) +FORMAT_MSG=$(git clang-format $MERGE_BASE -q --diff -- src/) +if [ -n "$FORMAT_MSG" -a "$FORMAT_MSG" != "no modified files to format" ] +then + echo "Run git clang-format before committing!" + echo + # Run git clang-format once again to show the error + git clang-format $MERGE_BASE -q --diff -- src/ + exit 1 +fi diff --git a/scripts/gen-s-parser.py b/scripts/gen-s-parser.py index 04f10c471..262c0aeaf 100755 --- a/scripts/gen-s-parser.py +++ b/scripts/gen-s-parser.py @@ -533,6 +533,11 @@ def instruction_parser(): def print_header(): print("// DO NOT EDIT! This file generated by scripts/gen-s-parser.py\n") + print("// clang-format off\n") + + +def print_footer(): + print("\n// clang-format on") def generate_with_guard(generator, guard): @@ -549,6 +554,7 @@ def main(): sys.exit(1) print_header() generate_with_guard(instruction_parser, "INSTRUCTION_PARSER") + print_footer() if __name__ == "__main__": diff --git a/src/gen-s-parser.inc b/src/gen-s-parser.inc index c9daba100..a27de9041 100644 --- a/src/gen-s-parser.inc +++ b/src/gen-s-parser.inc @@ -1,5 +1,7 @@ // DO NOT EDIT! This file generated by scripts/gen-s-parser.py +// clang-format off + #ifdef INSTRUCTION_PARSER #undef INSTRUCTION_PARSER char op[27] = {'\0'}; @@ -2260,3 +2262,5 @@ switch (op[0]) { parse_error: throw ParseException(std::string(op)); #endif // INSTRUCTION_PARSER + +// clang-format on |