diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2021-01-22 02:07:22 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2021-01-22 02:07:22 +0000 |
commit | 3f77be26020f34b8f31cfa85d531573fe2d5da51 (patch) | |
tree | 70bb2d604d556baff0aaa19fb234feef5625efcc | |
parent | 1960e6d8811e700a4857220d5e11e3bcfa1b8815 (diff) | |
parent | 5197623930b8c7b7cad418f2bee37e233e50da90 (diff) | |
download | repohooks-android-12.0.0_r1.tar.gz |
Snap for 7095583 from 5197623930b8c7b7cad418f2bee37e233e50da90 to sc-releaseandroid-vts-12.0_r9android-vts-12.0_r8android-vts-12.0_r7android-vts-12.0_r6android-vts-12.0_r5android-vts-12.0_r4android-vts-12.0_r3android-vts-12.0_r2android-vts-12.0_r12android-vts-12.0_r11android-vts-12.0_r10android-vts-12.0_r1android-security-12.0.0_r59android-security-12.0.0_r58android-security-12.0.0_r57android-security-12.0.0_r56android-security-12.0.0_r55android-security-12.0.0_r54android-security-12.0.0_r53android-security-12.0.0_r52android-security-12.0.0_r51android-security-12.0.0_r50android-security-12.0.0_r49android-security-12.0.0_r48android-security-12.0.0_r47android-security-12.0.0_r46android-security-12.0.0_r45android-security-12.0.0_r44android-security-12.0.0_r43android-security-12.0.0_r42android-security-12.0.0_r41android-security-12.0.0_r40android-security-12.0.0_r39android-security-12.0.0_r38android-security-12.0.0_r37android-security-12.0.0_r36android-security-12.0.0_r35android-security-12.0.0_r34android-platform-12.0.0_r9android-platform-12.0.0_r8android-platform-12.0.0_r7android-platform-12.0.0_r6android-platform-12.0.0_r5android-platform-12.0.0_r4android-platform-12.0.0_r31android-platform-12.0.0_r30android-platform-12.0.0_r3android-platform-12.0.0_r29android-platform-12.0.0_r28android-platform-12.0.0_r27android-platform-12.0.0_r26android-platform-12.0.0_r25android-platform-12.0.0_r24android-platform-12.0.0_r23android-platform-12.0.0_r22android-platform-12.0.0_r21android-platform-12.0.0_r20android-platform-12.0.0_r2android-platform-12.0.0_r19android-platform-12.0.0_r18android-platform-12.0.0_r17android-platform-12.0.0_r16android-platform-12.0.0_r15android-platform-12.0.0_r14android-platform-12.0.0_r13android-platform-12.0.0_r12android-platform-12.0.0_r11android-platform-12.0.0_r10android-platform-12.0.0_r1android-cts-12.0_r9android-cts-12.0_r8android-cts-12.0_r7android-cts-12.0_r6android-cts-12.0_r5android-cts-12.0_r4android-cts-12.0_r3android-cts-12.0_r2android-cts-12.0_r12android-cts-12.0_r11android-cts-12.0_r10android-cts-12.0_r1android-12.0.0_r9android-12.0.0_r8android-12.0.0_r34android-12.0.0_r33android-12.0.0_r31android-12.0.0_r30android-12.0.0_r3android-12.0.0_r25android-12.0.0_r2android-12.0.0_r11android-12.0.0_r10android-12.0.0_r1android12-tests-releaseandroid12-security-releaseandroid12-s5-releaseandroid12-s4-releaseandroid12-s3-releaseandroid12-s2-releaseandroid12-s1-releaseandroid12-releaseandroid12-platform-release
Change-Id: I40a0053d0e8aef27e8ef066e320a3256f38e6009
-rw-r--r-- | README.md | 10 | ||||
-rw-r--r-- | rh/hooks.py | 22 | ||||
-rwxr-xr-x | rh/hooks_unittest.py | 14 |
3 files changed, 42 insertions, 4 deletions
@@ -170,6 +170,9 @@ some dog = tool --no-cat-in-commit-message ${PREUPLOAD_COMMIT_MESSAGE} This section allows for turning on common/builtin hooks. There are a bunch of canned hooks already included geared towards AOSP style guidelines. +* `aidl_format`: Run AIDL files (.aidl) through `aidl-format`. +* `android_test_mapping_format`: Validate TEST_MAPPING files in Android source + code. Refer to go/test-mapping for more details. * `bpfmt`: Run Blueprint files (.bp) through `bpfmt`. * `checkpatch`: Run commits through the Linux kernel's `checkpatch.pl` script. * `clang_format`: Run git-clang-format against the commit. The default style is @@ -195,8 +198,6 @@ canned hooks already included geared towards AOSP style guidelines. * `pylint3`: Run Python code through `pylint` using Python 3. * `rustfmt`: Run Rust code through `rustfmt`. * `xmllint`: Run XML code through `xmllint`. -* `android_test_mapping_format`: Validate TEST_MAPPING files in Android source - code. Refer to go/test-mapping for more details. Note: Builtin hooks tend to match specific filenames (e.g. `.json`). If no files match in a specific commit, then the hook will be skipped for that commit. @@ -263,6 +264,9 @@ executables can be overridden through `[Tool Paths]`. This is helpful to provide consistent behavior for developers across different OS and Linux distros/versions. The following tools are recognized: +* `aidl-format`: used for the `aidl_format` builtin hook. +* `android-test-mapping-format`: used for the `android_test_mapping_format` + builtin hook. * `bpfmt`: used for the `bpfmt` builtin hook. * `clang-format`: used for the `clang_format` builtin hook. * `cpplint`: used for the `cpplint` builtin hook. @@ -272,8 +276,6 @@ distros/versions. The following tools are recognized: * `google-java-format-diff`: used for the `google_java_format` builtin hook. * `pylint`: used for the `pylint` builtin hook. * `rustfmt`: used for the `rustfmt` builtin hook. -* `android-test-mapping-format`: used for the `android_test_mapping_format` - builtin hook. See [Placeholders](#Placeholders) for variables you can expand automatically. diff --git a/rh/hooks.py b/rh/hooks.py index 8cea251..0b3bb29 100644 --- a/rh/hooks.py +++ b/rh/hooks.py @@ -974,9 +974,30 @@ def check_android_test_mapping(project, commit, _desc, diff, options=None): return _check_cmd('android-test-mapping-format', project, commit, cmd) +def check_aidl_format(project, commit, _desc, diff, options=None): + """Checks that AIDL files are formatted with aidl-format.""" + # All *.aidl files except for those under aidl_api directory. + filtered = _filter_diff(diff, [r'\.aidl$'], [r'/aidl_api/']) + if not filtered: + return None + aidl_format = options.tool_path('aidl-format') + cmd = [aidl_format, '-d'] + options.args((), filtered) + ret = [] + for d in filtered: + data = rh.git.get_file_content(commit, d.file) + result = _run(cmd, input=data) + if result.stdout: + fixup_func = _fixup_func_caller([aidl_format, '-w', d.file]) + ret.append(rh.results.HookResult( + 'aidl-format', project, commit, error=result.stdout, + files=(d.file,), fixup_func=fixup_func)) + return ret + + # Hooks that projects can opt into. # Note: Make sure to keep the top level README.md up to date when adding more! BUILTIN_HOOKS = { + 'aidl_format': check_aidl_format, 'android_test_mapping_format': check_android_test_mapping, 'bpfmt': check_bpfmt, 'checkpatch': check_checkpatch, @@ -1002,6 +1023,7 @@ BUILTIN_HOOKS = { # Additional tools that the hooks can call with their default values. # Note: Make sure to keep the top level README.md up to date when adding more! TOOL_PATHS = { + 'aidl-format': 'aidl-format', 'android-test-mapping-format': os.path.join(TOOLS_DIR, 'android_test_mapping_format.py'), 'bpfmt': 'bpfmt', diff --git a/rh/hooks_unittest.py b/rh/hooks_unittest.py index 716e1da..8466319 100755 --- a/rh/hooks_unittest.py +++ b/rh/hooks_unittest.py @@ -823,6 +823,20 @@ class BuiltinHooksTests(unittest.TestCase): self.project, 'commit', 'desc', diff, options=self.options) self.assertIsNotNone(ret) + def test_aidl_format(self, mock_check, _mock_run): + """Verify the aidl_format builtin hook.""" + # First call should do nothing as there are no files to check. + ret = rh.hooks.check_aidl_format( + self.project, 'commit', 'desc', (), options=self.options) + self.assertIsNone(ret) + self.assertFalse(mock_check.called) + + # Second call will have some results. + diff = [rh.git.RawDiffEntry(file='IFoo.go')] + ret = rh.hooks.check_gofmt( + self.project, 'commit', 'desc', diff, options=self.options) + self.assertIsNotNone(ret) + if __name__ == '__main__': unittest.main() |