import os original_cxx_library = cxx_library original_java_library = java_library infer_clang_flavor = "infer-capture-all" def _cxx_infer_capture_genrule(name): cmd = "echo $(location :{}#{}) > $OUT".format(name, infer_clang_flavor) genrule( name = name + "_infer", out = "dummy_out", cmd = cmd, ) def cxx_library(name, **kwargs): _cxx_infer_capture_genrule(name) new_kwargs = dict(kwargs, labels=kwargs.get("labels", []) + ["infer_enabled"]) original_cxx_library( name=name, **new_kwargs ) def _get_project_root(): return "\$(git rev-parse --show-toplevel)/infer/tests/build_systems/buck_combined" 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 )