Cleanup DEFS file for generating infer genrules

Summary:
- Only generate one extra genrule for running infer. Remove all other java library rules currently being generated
- Generate infer genrule only if the `java_library` has `srcs`, otherwise there is nothing to analyze
- Use `SRCDIR` to avoid making a copy of the target sources as buck will just symlink them instead
- Added support for `android_library` rules as well
- Added support to generate both `infer` and `eradicate` genrules
Closes https://github.com/facebook/infer/pull/558

Reviewed By: sblackshear

Differential Revision: D4400365

Pulled By: jeremydubreil

fbshipit-source-id: 24750e2
master
Gautam Korlam 8 years ago committed by Facebook Github Bot
parent 2add2954da
commit fe24209c3d

74
DEFS

@ -1,46 +1,54 @@
import os
analyzers = ['infer', 'eradicate']
original_java_library = java_library
def java_library(
name,
deps=[],
srcs=[],
**kwargs
):
compile_name = name + '_compile'
top_deps = []
if 'GENERATE_INFER_GENRULES' in os.environ:
export_srcs_name = name + '_export_srcs'
genrule(
name = export_srcs_name,
srcs = kwargs.get('srcs', []),
cmd = 'mkdir -p $OUT && cp -R $SRCDIR/* $OUT/',
out = 'src_copy',
)
infer_name = name + '_infer'
genrule(
name = infer_name,
cmd = ' '.join([
os.getenv('INFER_BIN', 'infer'),
'--results-dir', '$OUT',
'--classpath', '$(classpath :{})'.format(compile_name),
'--sourcepath', '$(location :{})'.format(export_srcs_name),
'--generated-classes', '$(location :{})'.format(compile_name),
]),
out = 'infer_out',
)
top_deps += [':' + infer_name, ':' + export_srcs_name]
original_java_library(
name=name,
exported_deps=[
':' + compile_name,
],
deps=top_deps,
visibility = kwargs.get('visibility', [])
srcs=srcs,
**kwargs
)
original_java_library(
name=compile_name,
deps=deps,
create_genrules(name, srcs)
original_android_library = android_library
def android_library(
name,
srcs=[],
**kwargs
):
original_android_library(
name=name,
srcs=srcs,
**kwargs
)
create_genrules(name, srcs)
def create_genrules(
name,
srcs
):
if 'GENERATE_INFER_GENRULES' in os.environ and srcs:
for analyzer in analyzers:
analyzer_name = name + '_{}'.format(analyzer)
genrule(
name = analyzer_name,
srcs=srcs,
cmd = ' '.join([
os.getenv('INFER_BIN', 'infer'),
'-a', analyzer,
'--results-dir', '$OUT',
'--classpath', '$(classpath :{})'.format(name),
'--sourcepath', '$SRCDIR',
'--generated-classes', '$(location :{})'.format(name),
]),
out = '{}_out'.format(analyzer),
)

@ -1 +1 @@
buck-out/genruletest/gen/infer/tests/build_systems/genrule/module2/module2_export_srcs/src_copy/Class2.java, void Class2.localNPE2(), 2, NULL_DEREFERENCE, [start of procedure localNPE2()]
buck-out/genruletest/gen/infer/tests/build_systems/genrule/module2/module2_infer__srcs/Class2.java, void Class2.localNPE2(), 2, NULL_DEREFERENCE, [start of procedure localNPE2()]

Loading…
Cancel
Save