diff --git a/infer/lib/python/inferlib/analyze.py b/infer/lib/python/inferlib/analyze.py index ae08dbbce..ac8ba25bd 100644 --- a/infer/lib/python/inferlib/analyze.py +++ b/infer/lib/python/inferlib/analyze.py @@ -156,6 +156,11 @@ infer_group.add_argument('--specs-dir', help='add dir to the list of directories to be ' 'searched for spec files. Repeat the argument ' 'in case multiple folders are needed') +infer_group.add_argument('--specs-dir-list-file', + metavar='', + help='add the newline-separated directories listed ' + 'in to the list of directories to be ' + 'searched for spec files') def detect_javac(args): for index, arg in enumerate(args): @@ -279,6 +284,14 @@ class Infer: (['-lib', os.path.abspath(path)] for path in self.args.specs_dirs) for item in argument] + if self.args.specs_dir_list_file: + # Convert the path to the file list to an absolute path, because + # the analyzer will run from different paths and may not find the + # file otherwise. + self.args.specs_dir_list_file = \ + ['-specs-dir-list-file', + os.path.abspath(self.args.specs_dir_list_file)] + def clean_exit(self): if os.path.isdir(self.args.infer_out): @@ -376,6 +389,9 @@ class Infer: if self.args.specs_dirs: infer_options += self.args.specs_dirs + if self.args.specs_dir_list_file: + infer_options += self.args.specs_dir_list_file + exit_status = os.EX_OK if self.args.buck: diff --git a/infer/src/backend/utils.ml b/infer/src/backend/utils.ml index c461946ed..14f42f701 100644 --- a/infer/src/backend/utils.ml +++ b/infer/src/backend/utils.ml @@ -622,6 +622,17 @@ type arg_list = (string * Arg.spec * string option * string) list let arg_desc_filter options_to_keep = IList.filter (function (option_name, _, _, _) -> IList.mem string_equal option_name options_to_keep) +(* Given a filename with a list of paths, convert it into a list of string iff they are absolute *) +let read_specs_dir_list_file fname = + let validate_path path = + if Filename.is_relative path then + failwith ("Failing because path " ^ path ^ " is not absolute") in + match read_file fname with + | Some pathlist -> + IList.iter validate_path pathlist; + pathlist + | None -> failwith ("cannot read file " ^ fname) + let base_arg_desc = [ "-results_dir", @@ -636,6 +647,11 @@ let base_arg_desc = Arg.String (fun s -> Config.specs_library := filename_to_absolute s :: !Config.specs_library), Some "dir", "add dir to the list of directories to be searched for spec files"; + "-specs-dir-list-file", + Arg.String (fun s -> Config.specs_library := (read_specs_dir_list_file s) @ !Config.specs_library), + Some "file", + "add the newline-separated directories listed in to the list of directories to \ + be searched for spec files"; "-models", Arg.String (fun s -> Config.add_models (filename_to_absolute s)), Some "zip file",