[infer] python integration: parser, cfg support

Reviewed By: jvillard

Differential Revision: D5657644

fbshipit-source-id: 3c7d231
master
Sam Blackshear 7 years ago committed by Facebook Github Bot
parent 4065b1d120
commit 81c68a34cd

@ -13,6 +13,7 @@ bindir = @bindir@
BUCK = @BUCK@ BUCK = @BUCK@
BUILD_C_ANALYZERS = @BUILD_C_ANALYZERS@ BUILD_C_ANALYZERS = @BUILD_C_ANALYZERS@
BUILD_JAVA_ANALYZERS = @BUILD_JAVA_ANALYZERS@ BUILD_JAVA_ANALYZERS = @BUILD_JAVA_ANALYZERS@
BUILD_PYTHON_ANALYZERS = @BUILD_PYTHON_ANALYZERS@
CAML_LD_LIBRARY_PATH = @CAML_LD_LIBRARY_PATH@ CAML_LD_LIBRARY_PATH = @CAML_LD_LIBRARY_PATH@
CC = @CC@ CC = @CC@
CFLAGS = @CFLAGS@ CFLAGS = @CFLAGS@

@ -70,6 +70,15 @@ AC_ARG_ENABLE(java-analyzers,
BUILD_JAVA_ANALYZERS=$enable_java_analyzers BUILD_JAVA_ANALYZERS=$enable_java_analyzers
AC_SUBST([BUILD_JAVA_ANALYZERS]) AC_SUBST([BUILD_JAVA_ANALYZERS])
AC_ARG_ENABLE(python-analyzers,
AS_HELP_STRING([--disable-python-analyzers],
[do not build the Python analyzers (default is to build them)]),
,
enable_python_analyzers=yes)
BUILD_PYTHON_ANALYZERS=$enable_python_analyzers
AC_SUBST([BUILD_PYTHON_ANALYZERS])
AC_ARG_WITH(fcp-clang, AC_ARG_WITH(fcp-clang,
AS_HELP_STRING([--without-fcp-clang], AS_HELP_STRING([--without-fcp-clang],
[do not use $CLANG_PREFIX/bin/clang to override the default compiler (default is to override if in an infer release)]), [do not use $CLANG_PREFIX/bin/clang to override the default compiler (default is to override if in an infer release)]),

@ -255,6 +255,7 @@ $(GENERATED_FROM_AUTOCONF): $(MAKEFILE_LIST)
-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_C_ANALYZERS[@]|$(BUILD_C_ANALYZERS)|g" \
-e "s|@BUILD_JAVA_ANALYZERS[@]|$(BUILD_JAVA_ANALYZERS)|g" \ -e "s|@BUILD_JAVA_ANALYZERS[@]|$(BUILD_JAVA_ANALYZERS)|g" \
-e "s|@BUILD_PYTHON_ANALYZERS[@]|$(BUILD_PYTHON_ANALYZERS)|g" \
-e "s|@OPAMSWITCH[@]|$(OPAMSWITCH)|g" \ -e "s|@OPAMSWITCH[@]|$(OPAMSWITCH)|g" \
-e "s|@XCODE_SELECT[@]|$(XCODE_SELECT)|g" \ -e "s|@XCODE_SELECT[@]|$(XCODE_SELECT)|g" \
-e "s|@INFER_MAN_LAST_MODIFIED[@]|$(INFER_MAN_LAST_MODIFIED)|g" \ -e "s|@INFER_MAN_LAST_MODIFIED[@]|$(INFER_MAN_LAST_MODIFIED)|g" \

@ -757,6 +757,8 @@ let prop_init_formals_seed tenv new_formals (prop: 'a Prop.t) : Prop.exposed Pro
-> Exp.Sizeof {typ; nbytes= None; dynamic_length= None; subtype= Subtype.exact} -> Exp.Sizeof {typ; nbytes= None; dynamic_length= None; subtype= Subtype.exact}
| Config.Java | Config.Java
-> Exp.Sizeof {typ; nbytes= None; dynamic_length= None; subtype= Subtype.subtypes} -> Exp.Sizeof {typ; nbytes= None; dynamic_length= None; subtype= Subtype.subtypes}
| Config.Python
-> L.die InternalError "prop_init_formals_seed not implemented for Python"
in in
Prop.mk_ptsto_lvar tenv Prop.Fld_init Sil.inst_formal (pv, texp, None) Prop.mk_ptsto_lvar tenv Prop.Fld_init Sil.inst_formal (pv, texp, None)
in in

@ -2306,6 +2306,8 @@ and sigma_imply tenv calc_index_frame calc_missing subs prop1 sigma2 : subst2 *
; "java.lang.String.value" ] ; "java.lang.String.value" ]
in in
Sil.Estruct (List.map ~f:mk_fld_sexp fields, Sil.inst_none) Sil.Estruct (List.map ~f:mk_fld_sexp fields, Sil.inst_none)
| Config.Python
-> L.die InternalError "mk_constant_string_hpred not implemented for Python"
in in
let const_string_texp = let const_string_texp =
match !Config.curr_language with match !Config.curr_language with
@ -2322,6 +2324,8 @@ and sigma_imply tenv calc_index_frame calc_missing subs prop1 sigma2 : subst2 *
; nbytes= None ; nbytes= None
; dynamic_length= None ; dynamic_length= None
; subtype= Subtype.exact } ; subtype= Subtype.exact }
| Config.Python
-> L.die InternalError "const_string_texp not implemented for Python"
in in
Sil.Hpointsto (root, sexp, const_string_texp) Sil.Hpointsto (root, sexp, const_string_texp)
in in

@ -462,6 +462,8 @@ let mk_ptsto_exp_footprint pname tenv orig_prop (lexp, typ) max_stamp inst
-> Subtype.exact -> Subtype.exact
| Config.Java | Config.Java
-> Subtype.subtypes -> Subtype.subtypes
| Config.Python
-> L.die InternalError "Subtypes for Python not implemented"
in in
let create_ptsto footprint_part off0 = let create_ptsto footprint_part off0 =
match (root, off0, typ.Typ.desc) with match (root, off0, typ.Typ.desc) with

@ -43,11 +43,11 @@ let string_of_analyzer a =
let clang_frontend_action_symbols = let clang_frontend_action_symbols =
[("lint", `Lint); ("capture", `Capture); ("lint_and_capture", `Lint_and_capture)] [("lint", `Lint); ("capture", `Capture); ("lint_and_capture", `Lint_and_capture)]
type language = Clang | Java [@@deriving compare] type language = Clang | Java | Python [@@deriving compare]
let equal_language = [%compare.equal : language] let equal_language = [%compare.equal : language]
let string_of_language = function Java -> "Java" | Clang -> "C_CPP" let string_of_language = function Java -> "Java" | Clang -> "C_CPP" | Python -> "python"
let ml_bucket_symbols = let ml_bucket_symbols =
[ ("all", `MLeak_all) [ ("all", `MLeak_all)

@ -30,7 +30,7 @@ val string_to_analyzer : (string * analyzer) list
val string_of_analyzer : analyzer -> string val string_of_analyzer : analyzer -> string
type language = Clang | Java [@@deriving compare] type language = Clang | Java | Python [@@deriving compare]
val equal_language : language -> language -> bool val equal_language : language -> language -> bool

@ -45,6 +45,8 @@ let clang_enabled = is_yes "@BUILD_C_ANALYZERS@"
let java_enabled = is_yes "@BUILD_JAVA_ANALYZERS@" let java_enabled = is_yes "@BUILD_JAVA_ANALYZERS@"
let python_enabled = is_yes "@BUILD_PYTHON_ANALYZERS@"
let xcode_enabled = is_not_no "@XCODE_SELECT@" let xcode_enabled = is_not_no "@XCODE_SELECT@"
let man_pages_last_modify_date = "@INFER_MAN_LAST_MODIFIED@" let man_pages_last_modify_date = "@INFER_MAN_LAST_MODIFIED@"

@ -19,6 +19,8 @@ val clang_enabled : bool
val java_enabled : bool val java_enabled : bool
val python_enabled : bool
val xcode_enabled : bool val xcode_enabled : bool
val man_pages_last_modify_date : string val man_pages_last_modify_date : string

@ -26,6 +26,7 @@ type build_system =
| BMake | BMake
| BMvn | BMvn
| BNdk | BNdk
| BPython
| BXcode | BXcode
[@@deriving compare] [@@deriving compare]
@ -55,6 +56,7 @@ let build_system_exe_assoc =
; (BMvn, "mvn") ; (BMvn, "mvn")
; (BMvn, "mvnw") ; (BMvn, "mvnw")
; (BNdk, "ndk-build") ; (BNdk, "ndk-build")
; (BPython, "python")
; (BXcode, "xcodebuild") ] ; (BXcode, "xcodebuild") ]
let build_system_of_exe_name name = let build_system_of_exe_name name =
@ -73,6 +75,7 @@ type mode =
| ClangCompilationDB of [`Escaped of string | `Raw of string] list | ClangCompilationDB of [`Escaped of string | `Raw of string] list
| Javac of Javac.compiler * string * string list | Javac of Javac.compiler * string * string list
| Maven of string * string list | Maven of string * string list
| Python of string list
| PythonCapture of build_system * string list | PythonCapture of build_system * string list
| XcodeXcpretty of string * string list | XcodeXcpretty of string * string list
[@@deriving compare] [@@deriving compare]
@ -92,6 +95,7 @@ let pp_mode fmt mode =
| BuckGenrule _ | BuckGenrule _
| BuckCompilationDB _ | BuckCompilationDB _
| ClangCompilationDB _ | ClangCompilationDB _
| Python _
| PythonCapture (_, _) | PythonCapture (_, _)
| XcodeXcpretty _ | XcodeXcpretty _
-> (* these are pretty boring, do not log anything *) -> (* these are pretty boring, do not log anything *)
@ -268,6 +272,9 @@ let capture ~changed_files = function
-> L.progress "Capturing in javac mode...@." ; Javac.capture compiler ~prog ~args -> L.progress "Capturing in javac mode...@." ; Javac.capture compiler ~prog ~args
| Maven (prog, args) | Maven (prog, args)
-> L.progress "Capturing in maven mode...@." ; Maven.capture ~prog ~args -> L.progress "Capturing in maven mode...@." ; Maven.capture ~prog ~args
| Python args
-> (* pretend prog is the root directory of the project *)
PythonMain.go args
| PythonCapture (build_system, build_cmd) | PythonCapture (build_system, build_cmd)
-> L.progress "Capturing in %s mode...@." (string_of_build_system build_system) ; -> L.progress "Capturing in %s mode...@." (string_of_build_system build_system) ;
let in_buck_mode = equal_build_system build_system BBuck in let in_buck_mode = equal_build_system build_system BBuck in
@ -461,6 +468,8 @@ let assert_supported_mode required_analyzer requested_mode_string =
-> Version.clang_enabled -> Version.clang_enabled
| `Java | `Java
-> Version.java_enabled -> Version.java_enabled
| `Python
-> Version.python_enabled
| `Xcode | `Xcode
-> Version.clang_enabled && Version.xcode_enabled -> Version.clang_enabled && Version.xcode_enabled
in in
@ -471,6 +480,8 @@ let assert_supported_mode required_analyzer requested_mode_string =
-> "clang" -> "clang"
| `Java | `Java
-> "java" -> "java"
| `Python
-> "python"
| `Xcode | `Xcode
-> "clang and xcode" -> "clang and xcode"
in in
@ -484,6 +495,8 @@ let assert_supported_build_system build_system =
-> string_of_build_system build_system |> assert_supported_mode `Java -> string_of_build_system build_system |> assert_supported_mode `Java
| BClang | BMake | BNdk | BClang | BMake | BNdk
-> string_of_build_system build_system |> assert_supported_mode `Clang -> string_of_build_system build_system |> assert_supported_mode `Clang
| BPython
-> string_of_build_system build_system |> assert_supported_mode `Python
| BXcode | BXcode
-> string_of_build_system build_system |> assert_supported_mode `Xcode -> string_of_build_system build_system |> assert_supported_mode `Xcode
| BBuck | BBuck
@ -528,6 +541,8 @@ let mode_of_build_command build_cmd =
-> Javac (Javac.Javac, prog, args) -> Javac (Javac.Javac, prog, args)
| BMvn | BMvn
-> Maven (prog, args) -> Maven (prog, args)
| BPython
-> Python args
| BXcode when Config.xcpretty | BXcode when Config.xcpretty
-> XcodeXcpretty (prog, args) -> XcodeXcpretty (prog, args)
| BAnt | BBuck | BGradle | BNdk | BXcode as build_system | BAnt | BBuck | BGradle | BNdk | BXcode as build_system

@ -23,6 +23,7 @@ type mode =
| ClangCompilationDB of [`Escaped of string | `Raw of string] list | ClangCompilationDB of [`Escaped of string | `Raw of string] list
| Javac of Javac.compiler * string * string list | Javac of Javac.compiler * string * string list
| Maven of string * string list | Maven of string * string list
| Python of string list
| PythonCapture of build_system * string list | PythonCapture of build_system * string list
| XcodeXcpretty of string * string list | XcodeXcpretty of string * string list
[@@deriving compare] [@@deriving compare]

@ -7,6 +7,8 @@ let clang = is_yes "@BUILD_C_ANALYZERS@"
let java = is_yes "@BUILD_JAVA_ANALYZERS@" let java = is_yes "@BUILD_JAVA_ANALYZERS@"
let python = is_yes "@BUILD_PYTHON_ANALYZERS@"
let facebook = is_yes "@IS_FACEBOOK_TREE@" let facebook = is_yes "@IS_FACEBOOK_TREE@"
let extra_cflags = if "@EXTRA_CFLAGS" = "" then [] else ["@EXTRA_CFLAGS@"] let extra_cflags = if "@EXTRA_CFLAGS" = "" then [] else ["@EXTRA_CFLAGS@"]

@ -17,6 +17,7 @@ let sources =
:: ( ( if clang then ["clang"; ("unit" ^/ "clang")] :: ( ( if clang then ["clang"; ("unit" ^/ "clang")]
else ["clang_stubs"; ("unit" ^/ "clang_stubs")] ) else ["clang_stubs"; ("unit" ^/ "clang_stubs")] )
@ [ (if java then "java" else "java_stubs") @ [ (if java then "java" else "java_stubs")
; (if python && facebook then "python" else "python_stubs")
; "absint" ; "absint"
; "backend" ; "backend"
; "base" ; "base"
@ -66,6 +67,8 @@ let stanzas =
( if clang then ( if clang then
["(ocamllex (types_lexer ctl_lexer))"; "(menhir ((modules (types_parser ctl_parser))))"] ["(ocamllex (types_lexer ctl_lexer))"; "(menhir ((modules (types_parser ctl_parser))))"]
else [] ) else [] )
@ ( if python && facebook then ["(ocamllex (pythonLexer))"; "(menhir ((modules (pythonParser))))"]
else [] )
@ [ Format.sprintf @ [ Format.sprintf
{| {|
(library (library
@ -73,7 +76,7 @@ let stanzas =
(flags (%s)) (flags (%s))
(libraries (%s)) (libraries (%s))
(modules (:standard \ %s infertop)) (modules (:standard \ %s infertop))
(preprocess (pps (ppx_compare))) (preprocess (pps (ppx_compare ppx_sexp_conv -no-check)))
)) ))
|} |}
(String.concat " " infer_cflags) (String.concat " " infer_libraries) (String.concat " " infer_cflags) (String.concat " " infer_libraries)
@ -85,7 +88,7 @@ let stanzas =
(flags (%s -open InferModules)) (flags (%s -open InferModules))
(libraries (InferModules)) (libraries (InferModules))
(modules (%s)) (modules (%s))
(preprocess (pps (ppx_compare))) (preprocess (pps (ppx_compare ppx_sexp_conv -no-check)))
)) ))
|} |}
(String.concat " " infer_binaries) (String.concat " " infer_cflags) (String.concat " " infer_binaries) (String.concat " " infer_cflags)

@ -0,0 +1,10 @@
(*
* 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.
*)
let go _ = ()

@ -0,0 +1,10 @@
(*
* 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.
*)
val go : string list -> unit
Loading…
Cancel
Save