Summary: Adding Buck `DEFS` macros for generating Infer genrules. The generated genrules can be used to run the analysis on any existing `java_library` targets. Reviewed By: sblackshear Differential Revision: D4291234 fbshipit-source-id: 6430e2emaster
parent
8a3707825c
commit
027bdc32e8
@ -0,0 +1,47 @@
|
||||
import os
|
||||
|
||||
original_java_library = java_library
|
||||
def java_library(
|
||||
name,
|
||||
deps=[],
|
||||
**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),
|
||||
'--', 'genrule'
|
||||
]),
|
||||
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', [])
|
||||
)
|
||||
original_java_library(
|
||||
name=compile_name,
|
||||
deps=deps,
|
||||
**kwargs
|
||||
)
|
@ -0,0 +1,7 @@
|
||||
java_library(
|
||||
name='annotations',
|
||||
srcs=['Nullable.java'],
|
||||
visibility=[
|
||||
'PUBLIC'
|
||||
],
|
||||
)
|
@ -0,0 +1,4 @@
|
||||
package genrule.annotations;
|
||||
|
||||
public @interface Nullable {
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
java_library(
|
||||
name='module1',
|
||||
srcs=['Class1.java'],
|
||||
deps=[
|
||||
'//infer/tests/build_systems/genrule/annotations:annotations',
|
||||
],
|
||||
visibility=[
|
||||
'PUBLIC'
|
||||
],
|
||||
)
|
@ -0,0 +1,17 @@
|
||||
package genrule.module1;
|
||||
|
||||
import genrule.annotations.Nullable;
|
||||
|
||||
public class Class1 {
|
||||
|
||||
@Nullable
|
||||
public static String returnsNull() {
|
||||
return null;
|
||||
}
|
||||
|
||||
void localNPE1() {
|
||||
Object obj = null;
|
||||
obj.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
java_library(
|
||||
name='module2',
|
||||
srcs=['Class2.java'],
|
||||
deps=[
|
||||
'//infer/tests/build_systems/genrule/module1:module1'
|
||||
]
|
||||
)
|
@ -0,0 +1,17 @@
|
||||
package genrule.module2;
|
||||
|
||||
import genrule.module1.Class1;
|
||||
|
||||
public class Class2 {
|
||||
|
||||
void interTargetNPE() {
|
||||
Object obj = Class1.returnsNull();
|
||||
obj.toString();
|
||||
}
|
||||
|
||||
void localNPE2() {
|
||||
Object obj = null;
|
||||
obj.toString();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue