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

70
DEFS

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

@ -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