diff --git a/infer/lib/python/inferlib/analyze.py b/infer/lib/python/inferlib/analyze.py index db9b0dbe7..5ad32fee7 100644 --- a/infer/lib/python/inferlib/analyze.py +++ b/infer/lib/python/inferlib/analyze.py @@ -49,23 +49,6 @@ class VersionAction(argparse._VersionAction): option_string) -def get_pwd(): - pwd = os.getenv('PWD') - if pwd is not None: - try: - # Compare whether 'PWD' and '.' point to same place - # Approach is borrowed from llvm implementation of - # llvm::sys::fs::current_path (implemented in Path.inc file) - pwd_stat = os.stat(pwd) - dot_stat = os.stat('.') - if pwd_stat.st_dev == dot_stat.st_dev and \ - pwd_stat.st_ino == dot_stat.st_ino: - return pwd - except OSError: - # fallthrough to default case - pass - return os.getcwd() - base_parser = argparse.ArgumentParser(add_help=False) base_group = base_parser.add_argument_group('global arguments') base_group.add_argument('-o', '--out', metavar='', @@ -122,12 +105,6 @@ infer_group.add_argument('-l', '--load-average', metavar='', type=float, infer_group.add_argument('--buck', action='store_true', dest='buck', help='To use when run with buck') -infer_group.add_argument('-pr', '--project_root', - dest='project_root', - default=get_pwd(), - help='Location of the project root ' - '(default is current directory)') - infer_group.add_argument('--absolute-paths', action='store_true', default=False, @@ -236,14 +213,11 @@ class AnalyzerWrapper(object): exit_status = os.EX_OK if self.javac is not None and self.args.buck: - infer_options += ['-project_root', utils.decode(os.getcwd()), - '-java'] + infer_options += ['-java'] if self.javac.args.classpath is not None: for path in self.javac.args.classpath.split(os.pathsep): if os.path.isfile(path): infer_options += ['-ziplib', os.path.abspath(path)] - elif self.args.project_root: - infer_options += ['-project_root', self.args.project_root] infer_options = map(utils.decode_or_not, infer_options) infer_options_str = ' '.join(infer_options) diff --git a/infer/lib/python/inferlib/capture/buck.py b/infer/lib/python/inferlib/capture/buck.py index 62721e9bc..712f180dc 100644 --- a/infer/lib/python/inferlib/capture/buck.py +++ b/infer/lib/python/inferlib/capture/buck.py @@ -213,8 +213,6 @@ class BuckAnalyzer: def capture_with_compilation_database(self): buck_args = self.cmd cmd = [utils.get_cmd_in_bin_dir('InferBuckCompilationDatabase')] - if self.args.project_root: - cmd += ['--project-root', self.args.project_root] cmd += ['--'] cmd += buck_args return subprocess.check_call(cmd) diff --git a/infer/lib/python/inferlib/capture/clang-compilation-database.py b/infer/lib/python/inferlib/capture/clang-compilation-database.py index 6f5cdbbb2..54224dbd4 100644 --- a/infer/lib/python/inferlib/capture/clang-compilation-database.py +++ b/infer/lib/python/inferlib/capture/clang-compilation-database.py @@ -31,8 +31,6 @@ class ClangCompilationDatabase: def capture(self): args = self.cmd cmd = [utils.get_cmd_in_bin_dir('InferBuckCompilationDatabase')] - if self.args.project_root: - cmd += ['--project-root', self.args.project_root] cmd += ['--clang-compilation-database', args[1]] print(cmd) return subprocess.check_call(cmd) diff --git a/infer/lib/python/inferlib/jwlib.py b/infer/lib/python/inferlib/jwlib.py index 9d7ab7101..c6bb66422 100644 --- a/infer/lib/python/inferlib/jwlib.py +++ b/infer/lib/python/inferlib/jwlib.py @@ -307,9 +307,6 @@ class AnalyzerWithFrontendWrapper(analyze.AnalyzerWrapper): infer_cmd = [utils.get_cmd_in_bin_dir('InferJava')] infer_cmd += ['-classpath', self._create_frontend_classpath()] - if not self.args.absolute_paths: - infer_cmd += ['-project_root', self.args.project_root] - infer_cmd += [ '-results_dir', self.args.infer_out, '-verbose_out', self.javac.verbose_out, diff --git a/infer/src/backend/crashcontext.ml b/infer/src/backend/crashcontext.ml index 654e6a0a5..6ea328c57 100644 --- a/infer/src/backend/crashcontext.ml +++ b/infer/src/backend/crashcontext.ml @@ -121,13 +121,10 @@ let crashcontext_epilogue ~in_buck_mode = infer-out/ directory, but instead it is buck-out/, which contains the infer output directories for every buck target. *) let root_summaries_dir = if in_buck_mode then begin - let project_root = match Config.project_root with - | Some root -> root - | None -> Filename.dirname Config.results_dir in let buck_out = match Config.buck_out with | Some dir -> dir | None -> "buck-out" in - project_root // buck_out + Config.project_root // buck_out end else Config.results_dir in collect_all_summaries diff --git a/infer/src/backend/infer.ml b/infer/src/backend/infer.ml index 1e1d4f037..773dd0315 100644 --- a/infer/src/backend/infer.ml +++ b/infer/src/backend/infer.ml @@ -65,8 +65,6 @@ let () = (if not Config.reactive_mode then [] else ["--reactive"]) @ "--out" :: Config.results_dir :: - (match Config.project_root with None -> [] | Some pr -> - ["--project_root"; pr]) @ (match Config.xcode_developer_dir with None -> [] | Some d -> ["--xcode-developer-dir"; d]) @ (if Config.rest = [] then [] else diff --git a/infer/src/backend/mergeCapture.ml b/infer/src/backend/mergeCapture.ml index 8d4637e75..6ad02cffa 100644 --- a/infer/src/backend/mergeCapture.ml +++ b/infer/src/backend/mergeCapture.ml @@ -20,12 +20,7 @@ let use_multilinks = true is used to determine whether a captured directory needs to be merged. *) let check_timestamp_of_symlinks = true -let buck_out () = - match Config.project_root with - | Some root -> - Filename.concat root "buck-out" - | None -> - Filename.concat (Filename.dirname Config.results_dir) "buck-out" +let buck_out () = Filename.concat Config.project_root "buck-out" let infer_deps () = Filename.concat Config.results_dir Config.buck_infer_deps_file_name diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index d1904b2f7..a11232f0d 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -425,9 +425,8 @@ let inferconfig_home = ~exes:all_exes ~meta:"dir" "Path to the .inferconfig file" and project_root = - CLOpt.mk_string_opt ~deprecated:["project_root"; "-project_root"] ~long:"project-root" ~short:"pr" - ?default:CLOpt.(match current_exe with Print | Toplevel | StatsAggregator | Clang -> - Some init_work_dir | _ -> None) + CLOpt.mk_string ~deprecated:["project_root"; "-project_root"] ~long:"project-root" ~short:"pr" + ~default:init_work_dir ~f:resolve ~exes:CLOpt.[Analyze;Clang;Java;Print;Toplevel] ~meta:"dir" "Specify the root directory of the project" @@ -442,9 +441,9 @@ let inferconfig_home = !inferconfig_home and project_root = !project_root let inferconfig_path = - match inferconfig_home, project_root with - | Some dir, _ | _, Some dir -> dir // inferconfig_file - | None, None -> inferconfig_file + match inferconfig_home with + | Some dir -> dir // inferconfig_file + | None -> project_root // inferconfig_file (* Proceed to declare and parse the remaining options *) diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index 38101d4aa..908ee76f4 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -229,7 +229,7 @@ val print_types : bool val print_using_diff : bool val procs_csv : outfile option val procs_xml : outfile option -val project_root : string option +val project_root : string val quandary : bool val quiet : bool val reactive_mode : bool diff --git a/infer/src/base/DB.ml b/infer/src/base/DB.ml index fd49e7ba6..890e3361c 100644 --- a/infer/src/base/DB.ml +++ b/infer/src/base/DB.ml @@ -68,17 +68,10 @@ let source_file_to_string fname = | Relative path | Absolute path -> path -exception No_project_root - -let project_root () = - match Config.project_root with - | None -> L.err "No --project-root option passed@."; raise No_project_root - | Some path -> path - (* Checking if the path exists may be needed only in some cases, hence the flag check_exists *) let source_file_to_abs_path fname = match fname with - | Relative path -> Filename.concat (project_root()) path + | Relative path -> Filename.concat Config.project_root path | Absolute path -> path let inode_equal sf1 sf2 = @@ -89,7 +82,7 @@ let inode_equal sf1 sf2 = let source_file_to_rel_path fname = match fname with | Relative path -> path - | Absolute path -> filename_to_relative (project_root ()) path + | Absolute path -> filename_to_relative Config.project_root path (** string encoding of a source file (including path) as a single filename *) let source_file_encoding source_file = diff --git a/infer/src/clang/cFrontend_utils.ml b/infer/src/clang/cFrontend_utils.ml index 204861c9e..fba375913 100644 --- a/infer/src/clang/cFrontend_utils.ml +++ b/infer/src/clang/cFrontend_utils.ml @@ -669,10 +669,7 @@ struct let get_rel_file_path file_opt = match file_opt with | Some file -> - (match Config.project_root with - | Some root -> - DB.source_file_to_rel_path (DB.rel_source_file_from_abs_path root file) - | None -> file) + DB.source_file_to_rel_path (DB.rel_source_file_from_abs_path Config.project_root file) | None -> "" let is_cpp_translation translation_unit_context = diff --git a/infer/src/clang/cLocation.ml b/infer/src/clang/cLocation.ml index 3aae2bd96..2000cb870 100644 --- a/infer/src/clang/cLocation.ml +++ b/infer/src/clang/cLocation.ml @@ -20,14 +20,11 @@ let source_file_from_path path = (failwithf "ERROR: Path %s is relative. Please pass an absolute path in the -c argument.@." path); - match Config.project_root with - | Some root -> - (try - DB.rel_source_file_from_abs_path root path - with Failure _ -> - Logging.err_debug "ERROR: %s should be a prefix of %s.@." root path; - DB.source_file_from_string path) - | None -> DB.source_file_from_string path + try + DB.rel_source_file_from_abs_path Config.project_root path + with Failure _ -> + Logging.err_debug "ERROR: %s should be a prefix of %s.@." Config.project_root path; + DB.source_file_from_string path let choose_sloc_to_update_curr_file trans_unit_ctx sloc1 sloc2 = match sloc2.Clang_ast_t.sl_file with @@ -70,18 +67,15 @@ let clang_to_sil_location trans_unit_ctx clang_loc procdesc_opt = Location.{line; col; file; nLOC} let file_in_project file = - match Config.project_root with - | Some root -> - let real_root = real_path root in - let real_file = real_path file in - let file_in_project = string_is_prefix real_root real_file in - let paths = Config.skip_translation_headers in - let file_should_be_skipped = - IList.exists - (fun path -> string_is_prefix (Filename.concat real_root path) real_file) - paths in - file_in_project && not (file_should_be_skipped) - | None -> false + let real_root = real_path Config.project_root in + let real_file = real_path file in + let file_in_project = string_is_prefix real_root real_file in + let paths = Config.skip_translation_headers in + let file_should_be_skipped = + IList.exists + (fun path -> string_is_prefix (Filename.concat real_root path) real_file) + paths in + file_in_project && not (file_should_be_skipped) let should_do_frontend_check trans_unit_ctx (loc_start, _) = match loc_start.Clang_ast_t.sl_file with diff --git a/infer/src/java/jClasspath.ml b/infer/src/java/jClasspath.ml index 0789e6d1a..d0922021b 100644 --- a/infer/src/java/jClasspath.ml +++ b/infer/src/java/jClasspath.ml @@ -76,9 +76,7 @@ let java_source_file_from_path path = if Filename.is_relative path then failwith "Expect absolute path for java source files" else - match Config.project_root with - | None -> DB.abs_source_file_from_path path - | Some project_root -> DB.rel_source_file_from_abs_path project_root path + DB.rel_source_file_from_abs_path Config.project_root path (** Add the android.jar containing bytecode at the beginning of the class path *)