forked from facebook/infer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[infer][genrule] Add example of Buck DEFS macro to generate Infer ana…
…lysis targets 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: 6430e2e
- Loading branch information
1 parent
8a37078
commit 027bdc3
Showing
10 changed files
with
113 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
[buildfile] | ||
includes = //DEFS | ||
|
||
[project] | ||
ignore = .git, .ml, .mli | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
java_library( | ||
name='annotations', | ||
srcs=['Nullable.java'], | ||
visibility=[ | ||
'PUBLIC' | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package genrule.annotations; | ||
|
||
public @interface Nullable { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
java_library( | ||
name='module1', | ||
srcs=['Class1.java'], | ||
deps=[ | ||
'//infer/tests/build_systems/genrule/annotations:annotations', | ||
], | ||
visibility=[ | ||
'PUBLIC' | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
java_library( | ||
name='module2', | ||
srcs=['Class2.java'], | ||
deps=[ | ||
'//infer/tests/build_systems/genrule/module1:module1' | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters