From 44502c1673a3e879d929d8b0d5980145ee9723a7 Mon Sep 17 00:00:00 2001 From: martinoluca Date: Tue, 1 Mar 2016 08:04:45 -0800 Subject: [PATCH] Merge infer-deps files generated by Buck Summary:public With this change, all the `infer-deps.txt` files generated by buck for those targets running with the `#infer` flavor, will be merged into one `infer-deps.txt` located in the designated output folder. Reviewed By: jvillard Differential Revision: D2994397 fb-gh-sync-id: 14d8109 shipit-source-id: 14d8109 --- infer/lib/python/inferlib/capture/buck.py | 14 ++++++++++++++ infer/lib/python/inferlib/config.py | 1 + infer/lib/python/inferlib/utils.py | 9 +++++++++ 3 files changed, 24 insertions(+) diff --git a/infer/lib/python/inferlib/capture/buck.py b/infer/lib/python/inferlib/capture/buck.py index ac7878b65..d3d11d411 100644 --- a/infer/lib/python/inferlib/capture/buck.py +++ b/infer/lib/python/inferlib/capture/buck.py @@ -59,6 +59,10 @@ def create_argparser(group_name=MODULE_NAME): group.add_argument('--blacklist-regex', help='Specify the regex for files to skip during ' 'the analysis (requires --use-flavors to work)') + group.add_argument('--merge-deps-files', action='store_true', + help='Merge the infer-deps.txt files generated by Buck ' + 'during the analysis (requires --use-flavors to ' + 'work)') return parser @@ -148,6 +152,16 @@ class BuckAnalyzer: merged_results_path = os.path.join(self.args.infer_out, config.JSON_REPORT_FILENAME) utils.dump_json_to_path(all_results, merged_results_path) + if self.args.merge_deps_files: + infer_deps_to_merge = [ + os.path.join( + os.path.dirname(x), config.INFER_BUCK_DEPS_FILENAME) + for x in result_files] + merged_infer_deps_path = os.path.join( + self.args.infer_out, + config.INFER_BUCK_DEPS_FILENAME) + utils.merge_and_dedup_files_into_path(infer_deps_to_merge, + merged_infer_deps_path) utils.stdout('Results saved in {results_path}' .format(results_path=merged_results_path)) return os.EX_OK diff --git a/infer/lib/python/inferlib/config.py b/infer/lib/python/inferlib/config.py index 8e6e8cd94..03cc25ca5 100644 --- a/infer/lib/python/inferlib/config.py +++ b/infer/lib/python/inferlib/config.py @@ -41,6 +41,7 @@ PROC_STATS_FILENAME = 'proc_stats.json' CSV_REPORT_FILENAME = 'report.csv' JSON_REPORT_FILENAME = 'report.json' +INFER_BUCK_DEPS_FILENAME = 'infer-deps.txt' BUGS_FILENAME = 'bugs.txt' JAVAC_FILELISTS_FILENAME = 'filelists' diff --git a/infer/lib/python/inferlib/utils.py b/infer/lib/python/inferlib/utils.py index 8de94e3f6..05416acf6 100644 --- a/infer/lib/python/inferlib/utils.py +++ b/infer/lib/python/inferlib/utils.py @@ -302,6 +302,15 @@ def stderr(s, errors='replace'): print(encode(s, errors=errors), file=sys.stderr) +def merge_and_dedup_files_into_path(files_to_merge, dest): + lines = set() + for file_to_merge in files_to_merge: + with open(file_to_merge, 'r') as fsrc: + lines |= set(fsrc.readlines()) + with open(dest, 'w') as fdest: + fdest.writelines(lines) + + class AbsolutePathAction(argparse.Action): """Convert a path from relative to absolute in the arg parser""" def __call__(self, parser, namespace, values, option_string=None):