|
|
|
import os
|
|
|
|
|
|
|
|
original_java_library = java_library
|
|
|
|
original_android_library = android_library
|
|
|
|
|
|
|
|
def _get_project_root():
|
|
|
|
return "\$(git rev-parse --show-toplevel)/infer/tests/build_systems/genrulecapture"
|
|
|
|
|
|
|
|
def _infer_capture_genrule(
|
|
|
|
name,
|
|
|
|
srcs
|
|
|
|
):
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"--jobs",
|
|
|
|
"1",
|
|
|
|
"--genrule-mode",
|
|
|
|
"--quiet",
|
|
|
|
"--no-progress-bar",
|
|
|
|
"--results-dir",
|
|
|
|
"$OUT",
|
|
|
|
"--sourcepath",
|
|
|
|
"$SRCDIR",
|
|
|
|
"--project-root",
|
|
|
|
_get_project_root(),
|
|
|
|
"--classpath",
|
|
|
|
"$(classpath :{})".format(name),
|
|
|
|
"--generated-classes",
|
|
|
|
"$(location :{})".format(name),
|
|
|
|
"capture",
|
|
|
|
]
|
|
|
|
|
|
|
|
args_file = os.path.join("$TMP", "args.txt")
|
|
|
|
subcommands = [
|
|
|
|
"echo {} >> {}".format(arg, args_file)
|
|
|
|
for arg in args
|
|
|
|
] + [
|
|
|
|
"infer @" + args_file
|
|
|
|
]
|
|
|
|
|
|
|
|
genrule(
|
|
|
|
name = name + "_infer",
|
|
|
|
srcs = srcs,
|
|
|
|
cmd = " && ".join(subcommands),
|
|
|
|
out = "infer_out",
|
|
|
|
labels = ["infer_genrule"],
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def _make_infer_capture_genrule(name, kwargs):
|
|
|
|
java_sources = [
|
|
|
|
f
|
|
|
|
for f in kwargs.get("srcs", [])
|
|
|
|
if f.endswith(".java")
|
|
|
|
]
|
|
|
|
|
|
|
|
if java_sources != []:
|
|
|
|
_infer_capture_genrule(name, java_sources)
|
|
|
|
kwargs["labels"] = kwargs.get("labels", []) + ["infer_enabled"]
|
|
|
|
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
|
|
|
|
def java_library(name, **kwargs):
|
|
|
|
new_kwargs = _make_infer_capture_genrule(name, kwargs)
|
|
|
|
|
|
|
|
original_java_library(
|
|
|
|
name=name,
|
|
|
|
**new_kwargs
|
|
|
|
)
|
|
|
|
|
|
|
|
def android_library(name, **kwargs):
|
|
|
|
new_kwargs = _make_infer_capture_genrule(name, kwargs)
|
|
|
|
|
|
|
|
original_android_library(
|
|
|
|
name=name,
|
|
|
|
**new_kwargs
|
|
|
|
)
|