From 5508a64d60df1699d592d9dccea775786a7b0273 Mon Sep 17 00:00:00 2001 From: Martin Trojer Date: Wed, 30 Oct 2019 07:17:08 -0700 Subject: [PATCH] new flag to find infer-deps when `buck target` fails to Reviewed By: skcho Differential Revision: D18201162 fbshipit-source-id: 2ae4fd7f5 --- infer/lib/python/inferlib/capture/buck.py | 20 +++++++++++++++++++- infer/man/man1/infer-capture.txt | 5 +++++ infer/man/man1/infer-full.txt | 6 ++++++ infer/man/man1/infer.txt | 6 ++++++ infer/src/base/Config.ml | 9 +++++++++ infer/src/base/Config.mli | 2 ++ infer/src/integration/Driver.ml | 1 + 7 files changed, 48 insertions(+), 1 deletion(-) diff --git a/infer/lib/python/inferlib/capture/buck.py b/infer/lib/python/inferlib/capture/buck.py index 9ea5ae715..4b1ed7b2a 100644 --- a/infer/lib/python/inferlib/capture/buck.py +++ b/infer/lib/python/inferlib/capture/buck.py @@ -69,6 +69,9 @@ def create_argparser(group_name=MODULE_NAME): help='Pass values as command-line arguments to ' 'invocations of `buck build`.' 'NOTE: value should be wrapped in single quotes') + group.add_argument('--buck-merge-all-deps', + action='store_true', + help='Find and merge all deps produced by buck') return parser @@ -195,6 +198,19 @@ class BuckAnalyzer: print('time elapsed in finding captured files in buck-out: % 6.2fs' % elapsed_time) + def _find_depsfiles_and_merge(self, merge_out_path): + """ Sometimes buck targets --show-output gets confused and returns a + folder that doesn't contain infer-deps.txt. This can happen with on + for example objc targes with a certain combination of BUCK modes and + flavours. This function will walk buck-out and find infer-deps.txt + It will merge ALL infer-deps.txt in buck-out, so you might want + to do a buck clean first.""" + fs = [] + for root, dirs, files in os.walk(config.BUCK_OUT_GEN): + fs += [os.path.dirname(os.path.join(root, f)) for f in files + if f == config.INFER_BUCK_DEPS_FILENAME] + self._merge_infer_dep_files(fs, merge_out_path) + def _move_buck_out(self): """ If keep-going is passed, we may need to compute the infer-deps file with the paths to the captured files. To make sure that @@ -249,8 +265,10 @@ class BuckAnalyzer: merged_deps_path = os.path.join( self.args.infer_out, config.INFER_BUCK_DEPS_FILENAME) self._merge_infer_report_files(result_paths, merged_reports_path) - if not ret == os.EX_OK and self.keep_going: + if (not ret == os.EX_OK and self.keep_going): self._find_deps_and_merge(merged_deps_path) + elif self.args.buck_merge_all_deps: + self._find_depsfiles_and_merge(merged_deps_path) else: self._merge_infer_dep_files(result_paths, merged_deps_path) infer_out = self.args.infer_out diff --git a/infer/man/man1/infer-capture.txt b/infer/man/man1/infer-capture.txt index a96ca1b84..cdbd591c5 100644 --- a/infer/man/man1/infer-capture.txt +++ b/infer/man/man1/infer-capture.txt @@ -129,6 +129,11 @@ BUCK FLAVORS OPTIONS (only the "flavors (C++)" Buck integration is supported, not Java). + --buck-merge-all-deps + Activates: Find and merge all infer dependencies produced by buck. + Use this flag if infer doesn't find any files to analyze after a + successful capture. (Conversely: --no-buck-merge-all-deps) + --capture-blacklist regex Skip capture of files matched by the specified OCaml regular expression (only supported by the javac integration for now). diff --git a/infer/man/man1/infer-full.txt b/infer/man/man1/infer-full.txt index 51cca7cd5..b9689c510 100644 --- a/infer/man/man1/infer-full.txt +++ b/infer/man/man1/infer-full.txt @@ -150,6 +150,12 @@ OPTIONS option. By default, all recursive dependencies are captured. See also infer-capture(1). + --buck-merge-all-deps + Activates: Find and merge all infer dependencies produced by buck. + Use this flag if infer doesn't find any files to analyze after a + successful capture. (Conversely: --no-buck-merge-all-deps) + See also infer-capture(1). + --buck-out dir Specify the root directory of buck-out See also infer-capture(1). diff --git a/infer/man/man1/infer.txt b/infer/man/man1/infer.txt index f0f611b0e..f36588b14 100644 --- a/infer/man/man1/infer.txt +++ b/infer/man/man1/infer.txt @@ -150,6 +150,12 @@ OPTIONS option. By default, all recursive dependencies are captured. See also infer-capture(1). + --buck-merge-all-deps + Activates: Find and merge all infer dependencies produced by buck. + Use this flag if infer doesn't find any files to analyze after a + successful capture. (Conversely: --no-buck-merge-all-deps) + See also infer-capture(1). + --buck-out dir Specify the root directory of buck-out See also infer-capture(1). diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index adfe81dbd..aa9ff0fd1 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -914,6 +914,13 @@ and buck_compilation_database = ~symbols:[("no-deps", `NoDeps); ("deps", `DepsTmp)] +and buck_merge_all_deps = + CLOpt.mk_bool ~long:"buck-merge-all-deps" ~default:false + ~in_help:InferCommand.[(Capture, manual_buck_flavors)] + "Find and merge all infer dependencies produced by buck. Use this flag if infer doesn't find \ + any files to analyze after a successful capture." + + and buck_out = CLOpt.mk_path_opt ~long:"buck-out" ~in_help:InferCommand.[(Capture, manual_buck_java)] @@ -2749,6 +2756,8 @@ and buck_compilation_database = None +and buck_merge_all_deps = !buck_merge_all_deps + and buck_out = !buck_out and buck_targets_blacklist = !buck_targets_blacklist diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index 1fb110d81..3676c8a7a 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -249,6 +249,8 @@ val buck_cache_mode : bool val buck_compilation_database : compilation_database_dependencies option +val buck_merge_all_deps : bool + val buck_out : string option val buck_targets_blacklist : string list diff --git a/infer/src/integration/Driver.ml b/infer/src/integration/Driver.ml index 86fe953c6..0b08850ce 100644 --- a/infer/src/integration/Driver.ml +++ b/infer/src/integration/Driver.ml @@ -256,6 +256,7 @@ let python_capture build_system build_cmd = [] | Some d -> ["--xcode-developer-dir"; d] ) + @ (if not Config.buck_merge_all_deps then [] else ["--buck-merge-all-deps"]) @ ("--" :: updated_build_cmd) ) in if in_buck_mode && Config.flavors then ( RunState.set_merge_capture true ; RunState.store () ) ;