Add clang-format preupload check.
This will check that new and changed lines conform to the style defined
in .clang-format. Specific code sections can be excluded if it gets in
the way (some examples included).
Also fix the java style to not line break in "/// CHECK" comments, and
use the AOSP style import order.
Java files in art/tools/ahat and art/tools/dexfuzz use indentation
width 2, so they get an override .clang-format with that style.
Java files in test/ have a mix of different indentation widths, so that
directory is excluded for the time being.
openjdkjvmti/include/jvmti.h is an imported file that should be ignored
altogether. However, it is not straightforward to configure a whole
file exclude. Upload it with --no-verify if it needs to be updated.
Test: clang-format -i art/dex2oat/dex2oat_options.cc \
art/benchmark/const-class/src/ConstClassBenchmark.java \
art/tools/ahat/src/main/com/android/ahat/heapdump/Parser.java \
art/tools/dexfuzz/src/dexfuzz/program/IdCreator.java
Check that reformatted files look reasonable
Test: Create a local commit with changes in both art/libartservice and
art/test, run tools/repohooks/pre-upload.py, and verify that only the
changes in art/libartservice get checked.
Bug: 181877164
Change-Id: I991ff032694bf5063e8516fdf71a95d0b047ffea
diff --git a/.clang-format-java-2 b/.clang-format-java-2
new file mode 100644
index 0000000..3ae2e00
--- /dev/null
+++ b/.clang-format-java-2
@@ -0,0 +1,55 @@
+# Variant of .clang-format but with 2 space indent for Java files, for use in
+# subdirectories with that style.
+# Please keep in sync with .clang-format where applicable.
+---
+BasedOnStyle: Google
+---
+
+Language: Cpp
+
+AlignConsecutiveMacros: AcrossComments
+AllowShortBlocksOnASingleLine: Empty
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLoopsOnASingleLine: false
+AttributeMacros: ['__', 'NO_RETURN']
+BinPackArguments: false
+BinPackParameters: false
+BreakConstructorInitializers: BeforeColon
+BreakBeforeTernaryOperators: false
+ColumnLimit: 100
+CommentPragmas: NOLINT:.*
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+FixNamespaceComments: true
+PointerAlignment: Left
+TabWidth: 2
+
+---
+
+Language: Java
+
+AccessModifierOffset: -2
+AlignOperands: false
+AllowShortFunctionsOnASingleLine: Inline
+AlwaysBreakBeforeMultilineStrings: false
+ColumnLimit: 100
+CommentPragmas: (NOLINT|CHECK[^ ]*):.*
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+IndentWidth: 2
+JavaImportGroups:
+- android
+- androidx
+- com.android
+- dalvik
+- libcore
+- com
+- junit
+- net
+- org
+- java
+- javax
+PenaltyBreakBeforeFirstCallParameter: 100000
+SpacesBeforeTrailingComments: 1