From 1bd6615abca503f4fd0d97c63f9cc041405b6e1f Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Mon, 31 Oct 2016 15:01:50 -0700 Subject: [PATCH] [config] Treat default models_jar in ZipLib instead of analyze.py Summary: This diff moves the implementation that considers the default value of --models to be Config.models_jar if it exists from analyze.py to ZipLib. Reviewed By: cristianoc Differential Revision: D4100421 fbshipit-source-id: 322fbcf --- infer/lib/python/inferlib/analyze.py | 2 -- infer/src/base/Config.ml | 6 ++-- infer/src/base/Config.mli | 1 + infer/src/base/ZipLib.ml | 53 ++++++++++++++++------------ 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/infer/lib/python/inferlib/analyze.py b/infer/lib/python/inferlib/analyze.py index 845476be1..8632b27ba 100644 --- a/infer/lib/python/inferlib/analyze.py +++ b/infer/lib/python/inferlib/analyze.py @@ -250,8 +250,6 @@ class AnalyzerWrapper(object): else: if self.args.analyzer == config.ANALYZER_TRACING: infer_options.append('-tracing') - if os.path.isfile(config.MODELS_JAR): - infer_options += ['-models', config.MODELS_JAR] if self.args.debug: infer_options += [ diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index 700e5ee64..0145cf44a 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -259,6 +259,9 @@ let etc_dir = let models_dir = lib_dir // specs_dir_name +let models_jar = + lib_dir // "java" // "models.jar" + let cpp_models_dir = let dir = bin_dir // Filename.parent_dir_name // "models" // "cpp" // "include" in Utils.filename_to_absolute dir (* Normalize the path *) @@ -969,10 +972,9 @@ and ml_buckets = - 'cpp' from C++ code" ~symbols:ml_bucket_symbols -(* Add a zip file containing the Java models *) and models_file = CLOpt.mk_string_opt ~deprecated:["models"] ~long:"models" ~f:resolve - ~meta:"zip file" "" + ~exes:CLOpt.[Analyze;Java] ~meta:"jar file" "Specify a jar file containing the Java models" and models_mode = CLOpt.mk_bool ~deprecated:["models_mode"; "-models_mode"] ~long:"models-mode" diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index acba85132..38101d4aa 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -92,6 +92,7 @@ val log_dir_name : string val max_recursion : int val meet_level : int val models_dir : string +val models_jar : string val ncpu : int val nsnotification_center_checker_backend : bool val os_type : os_type diff --git a/infer/src/base/ZipLib.ml b/infer/src/base/ZipLib.ml index 90dd344dd..d6cc352ac 100644 --- a/infer/src/base/ZipLib.ml +++ b/infer/src/base/ZipLib.ml @@ -62,27 +62,36 @@ let load_data serializer path zip_library = (** list of the zip files to search for specs files *) let zip_libraries = - let mk_zip_lib models zip_filename = - { models; zip_filename; zip_channel = lazy (Zip.open_in zip_filename) } in - let zip_libs = - if Config.use_jar_cache && Config.infer_cache <> None then - [] - else - (* Order matters, jar files should appear in the order in which they should be searched for - specs files. Config.specs_library is in reverse order of appearance on command line. *) - let add_zip zip_libs fname = - if Filename.check_suffix fname ".jar" then - (* fname is a zip of specs *) - (mk_zip_lib false fname) :: zip_libs - else - (* fname is a dir of specs *) - zip_libs in - IList.fold_left add_zip [] Config.specs_library in - match Config.models_file with - | None -> - zip_libs - | Some file -> - (mk_zip_lib true file) :: zip_libs + (* delay until load is called, to avoid stating/opening files at init time *) + lazy ( + let mk_zip_lib models zip_filename = + { models; zip_filename; zip_channel = lazy (Zip.open_in zip_filename) } in + let zip_libs = + if Config.use_jar_cache && Config.infer_cache <> None then + [] + else + (* Order matters, jar files should appear in the order in which they should be searched for + specs files. Config.specs_library is in reverse order of appearance on command line. *) + let add_zip zip_libs fname = + if Filename.check_suffix fname ".jar" then + (* fname is a zip of specs *) + (mk_zip_lib false fname) :: zip_libs + else + (* fname is a dir of specs *) + zip_libs in + IList.fold_left add_zip [] Config.specs_library in + let add_models file = + (mk_zip_lib true file) :: zip_libs in + match Config.models_file with + | _ when Config.checkers -> + zip_libs + | Some file -> + add_models file + | None when Sys.file_exists Config.models_jar -> + add_models Config.models_jar + | None -> + zip_libs + ) (* Search path in the list of zip libraries and use a cache directory to save already deserialized data *) @@ -93,4 +102,4 @@ let load serializer path = let opt = load_data serializer path zip_library in if Option.is_some opt then opt else loop other_libraries in - loop zip_libraries + loop (Lazy.force zip_libraries)