[driver] add a way to force infer to use a particular integration

Summary:
This is useful if some command behaves like one infer knows how to integrate with. For instance:

```
infer --force-integration clang -- clang-3.8 -c examples/hello.c
```

Reviewed By: jeremydubreil, mbouaziz

Differential Revision: D6051589

fbshipit-source-id: dd693b0
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent 0e70845801
commit e56af27b38

@ -88,6 +88,57 @@ type compilation_database_dependencies =
| NoDeps
[@@deriving compare]
type build_system =
| BAnalyze
| BAnt
| BBuck
| BClang
| BGradle
| BJava
| BJavac
| BMake
| BMvn
| BNdk
| BPython
| BXcode
[@@deriving compare]
let equal_build_system = [%compare.equal : build_system]
(* List of ([build system], [executable name]). Several executables may map to the same build
system. In that case, the first one in the list will be used for printing, eg, in which mode
infer is running. *)
let build_system_exe_assoc =
[ (BAnalyze, "analyze")
; (BAnt, "ant")
; (BBuck, "buck")
; (BGradle, "gradle")
; (BGradle, "gradlew")
; (BJava, "java")
; (BJavac, "javac")
; (BClang, "cc")
; (BClang, "clang")
; (BClang, "gcc")
; (BClang, "clang++")
; (BClang, "c++")
; (BClang, "g++")
; (BMake, "make")
; (BMake, "configure")
; (BMake, "cmake")
; (BMake, "waf")
; (BMvn, "mvn")
; (BMvn, "mvnw")
; (BNdk, "ndk-build")
; (BPython, "python")
; (BXcode, "xcodebuild") ]
let build_system_of_exe_name name =
try List.Assoc.find_exn ~equal:String.equal (List.Assoc.inverse build_system_exe_assoc) name
with Not_found -> L.(die InternalError) "Unsupported build command %s" name
let string_of_build_system build_system =
List.Assoc.find_exn ~equal:equal_build_system build_system_exe_assoc build_system
(** Constant configuration values *)
let anonymous_block_num_sep = "______"
@ -1112,6 +1163,15 @@ and force_delete_results_dir =
; (Run, manual_generic) ]))
"Do not refuse to delete the results directory if it doesn't look like an infer results directory."
and force_integration =
CLOpt.mk_symbol_opt ~long:"force-integration" ~meta:"command"
~symbols:(List.Assoc.inverse build_system_exe_assoc)
~in_help:CLOpt.([(Capture, manual_generic); (Run, manual_generic)])
(Printf.sprintf
"Proceed as if the first argument after $(b,--) was $(i,command). Possible values: %s."
( List.map build_system_exe_assoc ~f:(fun (_, s) -> Printf.sprintf "$(i,%s)" s)
|> String.concat ~sep:", " ))
and from_json_report =
CLOpt.mk_path_opt ~long:"from-json-report"
~in_help:CLOpt.([(Report, manual_generic)])
@ -2080,6 +2140,8 @@ and force_delete_results_dir = !force_delete_results_dir
and fragment_retains_view = !fragment_retains_view
and force_integration = !force_integration
and from_json_report = !from_json_report
and frontend_stats = !frontend_stats

@ -77,6 +77,27 @@ val equal_dynamic_dispatch : dynamic_dispatch -> dynamic_dispatch -> bool
val string_of_dynamic_dispatch : dynamic_dispatch -> string
type build_system =
| BAnalyze
| BAnt
| BBuck
| BClang
| BGradle
| BJava
| BJavac
| BMake
| BMvn
| BNdk
| BPython
| BXcode
[@@deriving compare]
val equal_build_system : build_system -> build_system -> bool
val build_system_of_exe_name : string -> build_system
val string_of_build_system : build_system -> string
val env_inside_maven : Unix.env
(** Constant configuration values *)
@ -404,6 +425,8 @@ val force_delete_results_dir : bool
val fragment_retains_view : bool
val force_integration : build_system option
val from_json_report : string option
val frontend_tests : bool

@ -15,57 +15,6 @@ module CLOpt = CommandLineOption
module L = Logging
module F = Format
type build_system =
| BAnalyze
| BAnt
| BBuck
| BClang
| BGradle
| BJava
| BJavac
| BMake
| BMvn
| BNdk
| BPython
| BXcode
[@@deriving compare]
let equal_build_system = [%compare.equal : build_system]
(* List of ([build system], [executable name]). Several executables may map to the same build
system. In that case, the first one in the list will be used for printing, eg, in which mode
infer is running. *)
let build_system_exe_assoc =
[ (BAnalyze, "analyze")
; (BAnt, "ant")
; (BBuck, "buck")
; (BGradle, "gradle")
; (BGradle, "gradlew")
; (BJava, "java")
; (BJavac, "javac")
; (BClang, "cc")
; (BClang, "clang")
; (BClang, "gcc")
; (BClang, "clang++")
; (BClang, "c++")
; (BClang, "g++")
; (BMake, "make")
; (BMake, "configure")
; (BMake, "cmake")
; (BMake, "waf")
; (BMvn, "mvn")
; (BMvn, "mvnw")
; (BNdk, "ndk-build")
; (BPython, "python")
; (BXcode, "xcodebuild") ]
let build_system_of_exe_name name =
try List.Assoc.find_exn ~equal:String.equal (List.Assoc.inverse build_system_exe_assoc) name
with Not_found -> L.(die InternalError) "Unsupported build command %s" name
let string_of_build_system build_system =
List.Assoc.find_exn ~equal:equal_build_system build_system_exe_assoc build_system
(* based on the build_system and options passed to infer, we run in different driver modes *)
type mode =
| Analyze
@ -76,7 +25,7 @@ type mode =
| Javac of Javac.compiler * string * string list
| Maven of string * string list
| Python of string list
| PythonCapture of build_system * string list
| PythonCapture of Config.build_system * string list
| XcodeXcpretty of string * string list
[@@deriving compare]
@ -271,8 +220,8 @@ let capture ~changed_files mode =
-> (* pretend prog is the root directory of the project *)
PythonMain.go args
| PythonCapture (build_system, build_cmd)
-> L.progress "Capturing in %s mode...@." (string_of_build_system build_system) ;
let in_buck_mode = equal_build_system build_system BBuck in
-> L.progress "Capturing in %s mode...@." (Config.string_of_build_system build_system) ;
let in_buck_mode = Config.equal_build_system build_system BBuck in
let infer_py = Config.lib_dir ^/ "python" ^/ "infer.py" in
let args =
List.rev_append Config.anon_args
@ -486,15 +435,15 @@ let assert_supported_mode required_analyzer requested_mode_string =
requested_mode_string analyzer_string analyzer_string
let assert_supported_build_system build_system =
match build_system with
match (build_system : Config.build_system) with
| BAnt | BGradle | BJava | BJavac | BMvn
-> string_of_build_system build_system |> assert_supported_mode `Java
-> Config.string_of_build_system build_system |> assert_supported_mode `Java
| BClang | BMake | BNdk
-> string_of_build_system build_system |> assert_supported_mode `Clang
-> Config.string_of_build_system build_system |> assert_supported_mode `Clang
| BPython
-> string_of_build_system build_system |> assert_supported_mode `Python
-> Config.string_of_build_system build_system |> assert_supported_mode `Python
| BXcode
-> string_of_build_system build_system |> assert_supported_mode `Xcode
-> Config.string_of_build_system build_system |> assert_supported_mode `Xcode
| BBuck
-> let analyzer, build_string =
if Config.flavors then (`Clang, "buck with flavors")
@ -504,7 +453,7 @@ let assert_supported_build_system build_system =
if Config.reactive_mode then
L.user_error
"WARNING: The reactive analysis mode is not compatible with the Buck integration for Java" ;
(`Java, string_of_build_system build_system) )
(`Java, Config.string_of_build_system build_system) )
in
assert_supported_mode analyzer build_string
| BAnalyze
@ -518,9 +467,15 @@ let mode_of_build_command build_cmd =
ClangCompilationDB !Config.clang_compilation_dbs )
else Analyze
| prog :: args
-> let build_system = build_system_of_exe_name (Filename.basename prog) in
-> let build_system =
match Config.force_integration with
| Some build_system
-> build_system
| None
-> Config.build_system_of_exe_name (Filename.basename prog)
in
assert_supported_build_system build_system ;
match build_system_of_exe_name (Filename.basename prog) with
match (build_system : Config.build_system) with
| BAnalyze
-> CLOpt.warnf
"WARNING: `infer -- analyze` is deprecated; use the `infer analyze` subcommand instead@." ;

@ -12,25 +12,6 @@ open! IStd
(** entry points for top-level functionalities such as capture under various build systems,
analysis, and reporting *)
type build_system =
| BAnalyze
| BAnt
| BBuck
| BClang
| BGradle
| BJava
| BJavac
| BMake
| BMvn
| BNdk
| BPython
| BXcode
[@@deriving compare]
val equal_build_system : build_system -> build_system -> bool
val string_of_build_system : build_system -> string
(** based on the build_system and options passed to infer, we run in different driver modes *)
type mode =
| Analyze
@ -41,7 +22,7 @@ type mode =
| Javac of Javac.compiler * string * string list
| Maven of string * string list
| Python of string list
| PythonCapture of build_system * string list
| PythonCapture of Config.build_system * string list
| XcodeXcpretty of string * string list
[@@deriving compare]

Loading…
Cancel
Save