xref: /aosp_15_r20/external/angle/build/android/docs/static_analysis.md (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker# Static Analysis
2*8975f5c5SAndroid Build Coastguard Worker
3*8975f5c5SAndroid Build Coastguard WorkerWe use several tools for static analysis in chromium.
4*8975f5c5SAndroid Build Coastguard Worker
5*8975f5c5SAndroid Build Coastguard Worker[TOC]
6*8975f5c5SAndroid Build Coastguard Worker
7*8975f5c5SAndroid Build Coastguard Worker## [Android Lint](lint.md)
8*8975f5c5SAndroid Build Coastguard Worker* Runs as part of normal compilation.
9*8975f5c5SAndroid Build Coastguard Worker* Controlled by GN arg: `disable_android_lint` (or `android_static_analysis`).
10*8975f5c5SAndroid Build Coastguard Worker* [Useful checks include](https://googlesamples.github.io/android-custom-lint-rules/checks/index.md.html):
11*8975f5c5SAndroid Build Coastguard Worker  * `NewApi` (ensureing `Build.VERSION.SDK_INT` checks are in place).
12*8975f5c5SAndroid Build Coastguard Worker* A list of disabled checks is found [within `lint.py`].
13*8975f5c5SAndroid Build Coastguard Worker  * and [`lint-baseline.xml`] files contain individual suppressions.
14*8975f5c5SAndroid Build Coastguard Worker* Custom lint checks [are possible], but we don't have any.
15*8975f5c5SAndroid Build Coastguard Worker* Checks run on the entire codebase, not only on changed lines.
16*8975f5c5SAndroid Build Coastguard Worker* Does not run when `chromium_code = false` (e.g. for `//third_party`).
17*8975f5c5SAndroid Build Coastguard Worker
18*8975f5c5SAndroid Build Coastguard Worker[are possible]: https://googlesamples.github.io/android-custom-lint-rules/api-guide.md.html
19*8975f5c5SAndroid Build Coastguard Worker[within `lint.py`]: https://source.chromium.org/chromium/chromium/src/+/main:build/android/gyp/lint.py;l=25
20*8975f5c5SAndroid Build Coastguard Worker[`lint-baseline.xml`]: https://source.chromium.org/search?q=f:lint-baseline.xml%20-f:third_party
21*8975f5c5SAndroid Build Coastguard Worker
22*8975f5c5SAndroid Build Coastguard Worker## [ErrorProne](https://errorprone.info/)
23*8975f5c5SAndroid Build Coastguard Worker* Runs as part of normal compilation.
24*8975f5c5SAndroid Build Coastguard Worker* Controlled by GN arg: `use_errorprone_java_compiler` (or
25*8975f5c5SAndroid Build Coastguard Worker  `android_static_analysis`).
26*8975f5c5SAndroid Build Coastguard Worker* [Useful checks include](https://errorprone.info/bugpatterns):
27*8975f5c5SAndroid Build Coastguard Worker  * Enforcement of `@GuardedBy`, `@CheckReturnValue`, and `@DoNotMock`.
28*8975f5c5SAndroid Build Coastguard Worker  * Enforcement of `/* paramName= */` comments.
29*8975f5c5SAndroid Build Coastguard Worker* A list of enabled / disabled checks is found [within `compile_java.py`](https://cs.chromium.org/chromium/src/build/android/gyp/compile_java.py?l=30)
30*8975f5c5SAndroid Build Coastguard Worker  * Many checks are currently disabled because there is work involved in fixing
31*8975f5c5SAndroid Build Coastguard Worker    violations they introduce. Please help!
32*8975f5c5SAndroid Build Coastguard Worker* Chrome has [a few custom checks]:
33*8975f5c5SAndroid Build Coastguard Worker* Checks run on the entire codebase, not only on changed lines.
34*8975f5c5SAndroid Build Coastguard Worker* Does not run when `chromium_code = false` (e.g. for `//third_party`).
35*8975f5c5SAndroid Build Coastguard Worker
36*8975f5c5SAndroid Build Coastguard Worker[a few custom checks]: /tools/android/errorprone_plugin/src/org/chromium/tools/errorprone/plugin/
37*8975f5c5SAndroid Build Coastguard Worker
38*8975f5c5SAndroid Build Coastguard Worker## [Checkstyle](https://checkstyle.sourceforge.io/)
39*8975f5c5SAndroid Build Coastguard Worker* Mainly used for checking Java formatting & style.
40*8975f5c5SAndroid Build Coastguard Worker  * E.g.: Unused imports and naming conventions.
41*8975f5c5SAndroid Build Coastguard Worker* Allows custom checks to be added via XML. Here [is ours].
42*8975f5c5SAndroid Build Coastguard Worker* Preferred over adding checks via `PRESUBMIT.py` because the tool understands
43*8975f5c5SAndroid Build Coastguard Worker  `@SuppressWarnings` annotations.
44*8975f5c5SAndroid Build Coastguard Worker* Runs only on changed lines as a part of `PRESUBMIT.py`.
45*8975f5c5SAndroid Build Coastguard Worker
46*8975f5c5SAndroid Build Coastguard Worker[is ours]:  /tools/android/checkstyle/chromium-style-5.0.xml
47*8975f5c5SAndroid Build Coastguard Worker
48*8975f5c5SAndroid Build Coastguard Worker## [PRESUBMIT.py](/PRESUBMIT.py):
49*8975f5c5SAndroid Build Coastguard Worker* Checks for banned patterns via `_BANNED_JAVA_FUNCTIONS`.
50*8975f5c5SAndroid Build Coastguard Worker  * (These should likely be moved to checkstyle).
51*8975f5c5SAndroid Build Coastguard Worker* Checks for a random set of things in `ChecksAndroidSpecificOnUpload()`.
52*8975f5c5SAndroid Build Coastguard Worker  * Including running Checkstyle.
53*8975f5c5SAndroid Build Coastguard Worker* Runs only on changed lines.
54*8975f5c5SAndroid Build Coastguard Worker
55*8975f5c5SAndroid Build Coastguard Worker## [Bytecode Processor](/build/android/bytecode/)
56*8975f5c5SAndroid Build Coastguard Worker* Runs as part of normal compilation.
57*8975f5c5SAndroid Build Coastguard Worker* Controlled by GN arg: `android_static_analysis`.
58*8975f5c5SAndroid Build Coastguard Worker* Performs a single check:
59*8975f5c5SAndroid Build Coastguard Worker  * Enforces that targets do not rely on indirect dependencies to populate
60*8975f5c5SAndroid Build Coastguard Worker    their classpath.
61*8975f5c5SAndroid Build Coastguard Worker  * In other words: that `deps` are not missing any entries.
62