From fe24209c3d96fa1461c54a20bbce9c34624c42c8 Mon Sep 17 00:00:00 2001 From: Gautam Korlam Date: Wed, 11 Jan 2017 14:41:06 -0800 Subject: [PATCH] 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 --- DEFS | 74 +++++++++++--------- infer/tests/build_systems/genrule/issues.exp | 2 +- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/DEFS b/DEFS index 2d404b55a..dac31f22f 100644 --- a/DEFS +++ b/DEFS @@ -1,46 +1,54 @@ import os +analyzers = ['infer', 'eradicate'] + original_java_library = java_library def java_library( name, - deps=[], + srcs=[], **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), - ]), - 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', []) + srcs=srcs, + **kwargs ) - original_java_library( - name=compile_name, - deps=deps, + + 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( + name = analyzer_name, + srcs=srcs, + cmd = ' '.join([ + os.getenv('INFER_BIN', 'infer'), + '-a', analyzer, + '--results-dir', '$OUT', + '--classpath', '$(classpath :{})'.format(name), + '--sourcepath', '$SRCDIR', + '--generated-classes', '$(location :{})'.format(name), + ]), + out = '{}_out'.format(analyzer), + ) diff --git a/infer/tests/build_systems/genrule/issues.exp b/infer/tests/build_systems/genrule/issues.exp index dcaf6e233..78d9615dd 100644 --- a/infer/tests/build_systems/genrule/issues.exp +++ b/infer/tests/build_systems/genrule/issues.exp @@ -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()]