diff --git a/Makefile b/Makefile index 5aa590d0f..6dd642885 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ DIRECT_TESTS += \ cpp_bufferoverrun cpp_errors cpp_frontend cpp_liveness cpp_quandary cpp_siof cpp_threadsafety \ ifneq ($(BUCK),no) -BUILD_SYSTEMS_TESTS += buck-clang-db buck_flavors buck_flavors_deterministic +BUILD_SYSTEMS_TESTS += buck-clang-db buck_flavors buck_flavors_run buck_flavors_deterministic endif ifneq ($(CMAKE),no) BUILD_SYSTEMS_TESTS += clang_compilation_db cmake inferconfig diff --git a/infer/src/backend/InferAnalyze.ml b/infer/src/backend/InferAnalyze.ml index 34c6082e7..b871e4f02 100644 --- a/infer/src/backend/InferAnalyze.ml +++ b/infer/src/backend/InferAnalyze.ml @@ -124,7 +124,6 @@ let main ~changed_files ~makefile = -> process_cluster_cmdline fname | None -> if Config.allow_specs_cleanup then DB.Results_dir.clean_specs_dir () ; - if Config.merge then MergeCapture.merge_captured_targets () ; let all_clusters = DB.find_source_dirs () in let clusters_to_analyze = List.filter ~f:(cluster_should_be_analyzed ~changed_files) all_clusters diff --git a/infer/src/backend/InferAnalyze.mli b/infer/src/backend/InferAnalyze.mli index 940f687d6..8abbbd337 100644 --- a/infer/src/backend/InferAnalyze.mli +++ b/infer/src/backend/InferAnalyze.mli @@ -12,8 +12,7 @@ open! IStd (** Main module for the analysis after the capture phase *) -(** Given a name of the Makefile to use for multicore analysis, analyze the captured code *) - val main : changed_files:SourceFile.Set.t option -> makefile:string -> unit +(** Given a name of the Makefile to use for multicore analysis, analyze the captured code *) val register_perf_stats_report : unit -> unit diff --git a/infer/src/backend/mergeCapture.ml b/infer/src/backend/mergeCapture.ml index 53a41f5ba..9769260e2 100644 --- a/infer/src/backend/mergeCapture.ml +++ b/infer/src/backend/mergeCapture.ml @@ -178,9 +178,10 @@ let process_merge_file deps_file = | Error error -> L.internal_error "Couldn't read deps file '%s': %s" deps_file error ) ; create_multilinks () ; - L.progress "Captured results merged.@." ; L.progress "Targets merged: %d@." stats.targets_merged ; L.progress "Files linked: %d@." stats.files_linked ; L.progress "Files multilinked: %d@." stats.files_multilinked -let merge_captured_targets () = process_merge_file (infer_deps ()) +let merge_captured_targets () = + L.progress "Merging captured Buck targets...@\n%!" ; + process_merge_file (infer_deps ()) diff --git a/infer/src/integration/Buck.ml b/infer/src/integration/Buck.ml index 7686266aa..dc1ae5839 100644 --- a/infer/src/integration/Buck.ml +++ b/infer/src/integration/Buck.ml @@ -48,10 +48,8 @@ let add_flavor_to_target target = -> add "compilation-database" | None, CompileOnly -> target - | None, (Linters | CaptureOnly) + | None, (BiAbduction | CaptureOnly | Checkers | Linters) -> add "infer-capture-all" - | None, (BiAbduction | Checkers) - -> add "infer" | None, Crashcontext -> failwithf "Analyzer %s is Java-only; not supported with Buck flavors" (Config.string_of_analyzer Config.analyzer) diff --git a/infer/src/integration/Driver.ml b/infer/src/integration/Driver.ml index 448e7bfb4..bb1827560 100644 --- a/infer/src/integration/Driver.ml +++ b/infer/src/integration/Driver.ml @@ -407,9 +407,8 @@ let report () = let analyze_and_report ~changed_files mode = let should_analyze, should_report = match (mode, Config.analyzer) with - | PythonCapture (BBuck, _), _ - -> (* In Buck mode when compilation db is not used, analysis is invoked either from capture or - a separate Analyze invocation is necessary, depending on the buck flavor used. *) + | PythonCapture (BBuck, _), _ when not Config.flavors + -> (* In Buck mode when compilation db is not used, analysis is invoked from capture if buck flavors are not used *) (false, false) | _ when Config.maven -> (* Called from Maven, only do capture. *) @@ -421,6 +420,15 @@ let analyze_and_report ~changed_files mode = | _, Linters -> (false, true) in + let should_merge = + match mode with + | PythonCapture (BBuck, _) when Config.flavors && CLOpt.(equal_command Run) Config.command + -> (* if doing capture + analysis of buck with flavors, we always need to merge targets before the analysis phase *) + true + | _ + -> (* else rely on the command line value *) Config.merge + in + if should_merge then MergeCapture.merge_captured_targets () ; if (should_analyze || should_report) && (Sys.file_exists Config.captured_dir <> `Yes || check_captured_empty mode) then L.user_error "There was nothing to analyze.@\n@." diff --git a/infer/tests/build_systems/buck_flavors_run/.buckconfig b/infer/tests/build_systems/buck_flavors_run/.buckconfig new file mode 100644 index 000000000..e69de29bb diff --git a/infer/tests/build_systems/buck_flavors_run/Makefile b/infer/tests/build_systems/buck_flavors_run/Makefile new file mode 100644 index 000000000..758c7e521 --- /dev/null +++ b/infer/tests/build_systems/buck_flavors_run/Makefile @@ -0,0 +1,33 @@ +# Copyright (c) 2017 - present Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the BSD style license found in the +# LICENSE file in the root directory of this source tree. An additional grant +# of patent rights can be found in the PATENTS file in the same directory. + +TESTS_DIR = ../.. +ROOT_DIR = $(TESTS_DIR)/../.. + +ANALYZER = infer +BUCK_TARGET = //src:hello +SOURCES = $(wildcard src/hello.c) +OBJECTS = buck-out/gen/src/hello\#compile-hello.c.o1f717d69,default/hello.c.o +INFER_OPTIONS = --report-custom-error --developer-mode --project-root $(TESTS_DIR) --no-keep-going +INFERPRINT_OPTIONS = --project-root $(TESTS_DIR) --issues-tests +CLEAN_EXTRA = buck-out + +include $(TESTS_DIR)/infer.make + +# Buck passes -a capture to infer +export INFER_STRICT_MODE=0 + +$(OBJECTS): $(JAVA_SOURCE_FILES) + $(QUIET)$(call silent_on_success,Compiling Buck flavors tests,\ + NO_BUCKD=1 $(BUCK) build --no-cache $(BUCK_TARGET)) + +infer-out/report.json: $(CLANG_DEPS) $(SOURCES) $(MAKEFILE_LIST) + $(QUIET)$(REMOVE_DIR) buck-out && \ + $(call silent_on_success,Testing infer-run Buck flavors integration,\ + NO_BUCKD=1 \ + $(INFER_BIN) $(INFER_OPTIONS) run --flavors --results-dir $(CURDIR)/infer-out -- \ + $(BUCK) build --no-cache $(BUCK_TARGET)) diff --git a/infer/tests/build_systems/buck_flavors_run/issues.exp b/infer/tests/build_systems/buck_flavors_run/issues.exp new file mode 100644 index 000000000..5b0c5bc28 --- /dev/null +++ b/infer/tests/build_systems/buck_flavors_run/issues.exp @@ -0,0 +1,2 @@ +src/hello.c, test, 2, NULL_DEREFERENCE, [start of procedure test()] +src/hello2.c, test2, 2, NULL_DEREFERENCE, [start of procedure test2()] diff --git a/infer/tests/build_systems/buck_flavors_run/src/BUCK b/infer/tests/build_systems/buck_flavors_run/src/BUCK new file mode 100644 index 000000000..ee8db4c9a --- /dev/null +++ b/infer/tests/build_systems/buck_flavors_run/src/BUCK @@ -0,0 +1,6 @@ +cxx_library( + name = 'hello', + srcs = [ + 'hello.c', 'hello2.c', + ], +) diff --git a/infer/tests/build_systems/buck_flavors_run/src/hello.c b/infer/tests/build_systems/buck_flavors_run/src/hello.c new file mode 100644 index 000000000..0ab05ae25 --- /dev/null +++ b/infer/tests/build_systems/buck_flavors_run/src/hello.c @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#include + +void test() { + int* s = NULL; + *s = 42; +} diff --git a/infer/tests/build_systems/buck_flavors_run/src/hello2.c b/infer/tests/build_systems/buck_flavors_run/src/hello2.c new file mode 100644 index 000000000..35f858d26 --- /dev/null +++ b/infer/tests/build_systems/buck_flavors_run/src/hello2.c @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#include + +void test2() { + int* s = NULL; + *s = 42; +}