Buck: Activate error prone checks

Given that Bazel activates error prone static analyzer per default,
allow to activate it for Buck as well.  We already monkey patch
java_library and java_test rules, so it's trivial to munge javac_jar
and compiler_class_name attributes as well.

Due to compile performance coniderations and some issues that were
reported with error prone activated by default in Buck driven build,
we make the integration optional and disabled by default. There are
two option to activate it:

1. Add these lines to your private .buckconfig.local to permanently
activate error prone checks:

  [sanitizers]
    error_prone = 1

2. Use this config option to instantly run error prone check:

  buck build --config sanitizers.error_prone=1  gerrit

Error prone has an issue with naming artifact with all transitive
dependencies included: while it has the suffix "ant", it should be
just called "all". But, TBH, we don't care.

Error Prone is Google library and is released under Apache 2 license.

Change-Id: I2bbe0313ad3e54df1d52968cc28d7e13db36d83f
This commit is contained in:
David Ostrovsky
2016-12-10 23:35:58 +01:00
committed by David Ostrovsky
parent 24669bb247
commit 8b73d9cb56
3 changed files with 32 additions and 0 deletions

View File

@@ -685,6 +685,25 @@ Watchman can either be de-installed or disabled. See
link:#buck-daemon[Using Buck daemon] section above how to temporarily link:#buck-daemon[Using Buck daemon] section above how to temporarily
disable `buckd`. disable `buckd`.
== Error Prone integration
link:http://errorprone.info[Error Prone] is a static analysis tool for
Java that catches common programming mistakes at compile-time. It can
be permanenty or instantly activated. For permanent activation, add these
lines to your `.buckconfig.local` file in gerrit tree:
```
[sanitizers]
error_prone = 1
```
For instant activation, pass this config option to the `build` or `test`
commands:
```
buck build --config sanitizers.error_prone=1 gerrit
```
== Troubleshooting Buck == Troubleshooting Buck
In some cases problems with Buck itself need to be investigated. See for example In some cases problems with Buck itself need to be investigated. See for example

View File

@@ -310,3 +310,10 @@ maven_jar(
sha1 = '198ea005f41219f038f4291f0b0e9f3259730e92', sha1 = '198ea005f41219f038f4291f0b0e9f3259730e92',
license = 'icu4j', license = 'icu4j',
) )
maven_jar(
name = 'errorprone',
id = 'com.google.errorprone:error_prone_ant:2.0.15',
sha1 = '607e3866e2ee25b74708c2898f84eac2f5452d2f',
license = 'Apache2.0',
)

View File

@@ -41,9 +41,15 @@ def java_test(*args, **kwargs):
# Munge kwargs to set Gerrit-specific defaults. # Munge kwargs to set Gerrit-specific defaults.
def _munge_args(kwargs): def _munge_args(kwargs):
if read_config('sanitizers', 'error_prone'):
_set_error_prone(kwargs)
_set_auto_value(kwargs) _set_auto_value(kwargs)
_set_extra_arguments(kwargs) _set_extra_arguments(kwargs)
def _set_error_prone(kwargs):
kwargs['javac_jar'] = '//lib:errorprone'
kwargs['compiler_class_name'] = 'com.google.errorprone.ErrorProneJavaCompiler'
def _set_extra_arguments(kwargs): def _set_extra_arguments(kwargs):
ext = 'extra_arguments' ext = 'extra_arguments'
if ext not in kwargs: if ext not in kwargs: