[driver] crash early if infer was not compiled for the requested build mode

Summary:
One gets very obscure errors when trying to run infer for clang when it was
compiled for Java, or vice-versa. This diff makes sure we crash early with the
appropriate error message. For instance:

```
$ ./build-infer java
$ infer -- clang -c hello.c
Uncaught exception:

  (Failure
    "Unsupported build mode: make/cc\
   \nInfer was built with clang analyzers disabled.\
   \nPlease rebuild infer with clang enabled.\
   \n")

Raised at file "pervasives.ml", line 30, characters 22-33
Called from file "backend/infer.ml", line 398, characters 6-48
Called from file "backend/infer.ml", line 449, characters 20-38
$ infer --clang-compilation-db-files foo.json
Uncaught exception:

  (Failure
    "Unsupported build mode: clang compilation database\
   \nInfer was built with clang analyzers disabled.\
   \nPlease rebuild infer with clang enabled.\
   \n")

Raised at file "pervasives.ml", line 30, characters 22-33
Called from file "backend/infer.ml", line 392, characters 8-65
Called from file "backend/infer.ml", line 449, characters 20-38
```

Reviewed By: sblackshear

Differential Revision: D4566641

fbshipit-source-id: d9a118f
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent 451adc7949
commit f796ba6bb8

@ -360,7 +360,7 @@ $(CLANG_BINIOU_DICT): $(CLANG_ATDGEN_STUB_ATD)
| sort | uniq \ | sort | uniq \
> $@ > $@
base/Version.ml: base/Version.ml.in Makefile base/Version.ml: base/Version.ml.in Makefile $(ROOT_DIR)/Makefile.autoconf
TMPFILE=$$(mktemp $@.tmp.XXXX); \ TMPFILE=$$(mktemp $@.tmp.XXXX); \
INFER_GIT_COMMIT=$$(git --work-tree=$(ROOT_DIR) --git-dir=$(ROOT_DIR)/.git rev-parse --short HEAD || printf "unknown"); \ INFER_GIT_COMMIT=$$(git --work-tree=$(ROOT_DIR) --git-dir=$(ROOT_DIR)/.git rev-parse --short HEAD || printf "unknown"); \
INFER_GIT_BRANCH=$$(git --work-tree=$(ROOT_DIR) --git-dir=$(ROOT_DIR)/.git rev-parse --abbrev-ref HEAD || printf "unknown"); \ INFER_GIT_BRANCH=$$(git --work-tree=$(ROOT_DIR) --git-dir=$(ROOT_DIR)/.git rev-parse --abbrev-ref HEAD || printf "unknown"); \
@ -371,6 +371,9 @@ base/Version.ml: base/Version.ml.in Makefile
-e 's|@IS_RELEASE_TREE[@]|$(IS_RELEASE_TREE)|g' \ -e 's|@IS_RELEASE_TREE[@]|$(IS_RELEASE_TREE)|g' \
-e "s|@INFER_GIT_COMMIT[@]|$$INFER_GIT_COMMIT|g" \ -e "s|@INFER_GIT_COMMIT[@]|$$INFER_GIT_COMMIT|g" \
-e "s|@INFER_GIT_BRANCH[@]|$$INFER_GIT_BRANCH|g" \ -e "s|@INFER_GIT_BRANCH[@]|$$INFER_GIT_BRANCH|g" \
-e "s|@BUILD_C_ANALYZERS[@]|$(BUILD_C_ANALYZERS)|g" \
-e "s|@BUILD_JAVA_ANALYZERS[@]|$(BUILD_JAVA_ANALYZERS)|g" \
-e "s|@XCODE_SELECT[@]|$(XCODE_SELECT)|g" \
$< > "$$TMPFILE"; \ $< > "$$TMPFILE"; \
mv "$$TMPFILE" $@ mv "$$TMPFILE" $@

@ -357,14 +357,51 @@ let log_infer_args driver_mode =
L.out "CWD = %s@\n" (Sys.getcwd ()); L.out "CWD = %s@\n" (Sys.getcwd ());
L.out "Driver mode:@\n%a@." pp_driver_mode driver_mode L.out "Driver mode:@\n%a@." pp_driver_mode driver_mode
let assert_supported_mode required_analyzer requested_mode_string =
let analyzer_enabled = match required_analyzer with
| `Clang -> Version.clang_enabled
| `Java -> Version.java_enabled
| `Xcode -> Version.clang_enabled && Version.xcode_enabled in
if not analyzer_enabled then
let analyzer_string = match required_analyzer with
| `Clang -> "clang"
| `Java -> "java"
| `Xcode -> "clang and xcode" in
failwithf
"Unsupported build mode: %s@\nInfer was built with %s analyzers disabled.@ Please rebuild \
infer with %s enabled.@."
requested_mode_string analyzer_string analyzer_string
let assert_supported_build_system build_system = match build_system with
| BAnt | BGradle | BJava | BJavac | BMvn ->
string_of_build_system build_system
|> assert_supported_mode `Java
| BMake | BNdk ->
string_of_build_system build_system
|> assert_supported_mode `Clang
| BXcode ->
string_of_build_system build_system
|> assert_supported_mode `Xcode
| BBuck ->
let (analyzer, build_string) = if Config.flavors then
(`Clang, "buck with flavors")
else
(`Java, string_of_build_system build_system) in
assert_supported_mode analyzer build_string
| BAnalyze ->
()
let driver_mode_of_build_cmd build_cmd = let driver_mode_of_build_cmd build_cmd =
match build_cmd with match build_cmd with
| [] -> | [] ->
if not (List.is_empty !Config.clang_compilation_dbs) then if not (List.is_empty !Config.clang_compilation_dbs) then (
assert_supported_mode `Clang "clang compilation database";
ClangCompilationDB !Config.clang_compilation_dbs ClangCompilationDB !Config.clang_compilation_dbs
else ) else
Analyze Analyze
| prog :: args -> | prog :: args ->
let build_system = 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_of_exe_name (Filename.basename prog) with
| BAnalyze -> | BAnalyze ->
Analyze Analyze
@ -390,6 +427,7 @@ let get_driver_mode () =
| [] -> [] in | [] -> [] in
Javac (Javac.Javac, "javac", build_args) Javac (Javac.Javac, "javac", build_args)
| Some path -> | Some path ->
assert_supported_mode `Java "Buck genrule";
BuckGenrule path BuckGenrule path
| None -> | None ->
driver_mode_of_build_cmd (IList.rev Config.rest) driver_mode_of_build_cmd (IList.rev Config.rest)

@ -10,13 +10,16 @@
open! IStd open! IStd
let is_yes = String.equal "yes"
let is_not_no = Fn.non (String.equal "no")
let major = @INFER_MAJOR@ let major = @INFER_MAJOR@
let minor = @INFER_MINOR@ let minor = @INFER_MINOR@
let patch = @INFER_PATCH@ let patch = @INFER_PATCH@
let commit = "@INFER_GIT_COMMIT@" let commit = "@INFER_GIT_COMMIT@"
let branch = "@INFER_GIT_BRANCH@" let branch = "@INFER_GIT_BRANCH@"
let is_release = String.equal "@IS_RELEASE_TREE@" "yes" let is_release = is_yes "@IS_RELEASE_TREE@"
let tag = Printf.sprintf "v%d.%d.%d" major minor patch let tag = Printf.sprintf "v%d.%d.%d" major minor patch
let versionString = let versionString =
@ -30,3 +33,7 @@ let versionJson = String.concat ~sep:"\n" [
"\"commit\": \"" ^ commit ^ "\", "; "\"commit\": \"" ^ commit ^ "\", ";
"\"branch\": \"" ^ branch ^ "\", "; "\"branch\": \"" ^ branch ^ "\", ";
"\"tag\": \"" ^ tag ^ "\""; "}" ] "\"tag\": \"" ^ tag ^ "\""; "}" ]
let clang_enabled = is_yes "@BUILD_C_ANALYZERS@"
let java_enabled = is_yes "@BUILD_JAVA_ANALYZERS@"
let xcode_enabled = is_not_no "@XCODE_SELECT@"

@ -12,3 +12,7 @@ open! IStd
val commit : string val commit : string
val versionString : string val versionString : string
val versionJson : string val versionJson : string
val clang_enabled : bool
val java_enabled : bool
val xcode_enabled : bool

Loading…
Cancel
Save