diff --git a/infer/src/backend/infer.ml b/infer/src/backend/infer.ml index 5ef1b8763..2ae0d9f84 100644 --- a/infer/src/backend/infer.ml +++ b/infer/src/backend/infer.ml @@ -144,7 +144,8 @@ let check_xcpretty () = exit 1 let capture_with_compilation_database db_files = - Config.clang_compilation_db_files := IList.map Utils.filename_to_absolute db_files; + let root = Unix.getcwd () in + Config.clang_compilation_db_files := IList.map (Utils.filename_to_absolute ~root) db_files; let compilation_database = CompilationDatabase.from_json_files db_files in CaptureCompilationDatabase.capture_files_in_database compilation_database diff --git a/infer/src/base/CommandLineOption.ml b/infer/src/base/CommandLineOption.ml index dc5bcda9e..d4fc82558 100644 --- a/infer/src/base/CommandLineOption.ml +++ b/infer/src/base/CommandLineOption.ml @@ -362,7 +362,8 @@ let mk_path_helper ~setter ~default_to_string that [!arg_being_parsed] points at the option name position in [!args_to_parse], as is the case e.g. when calling [Arg.parse_argv_dynamic ~current:arg_being_parsed !args_to_parse ...]. *) - let abs_path = Utils.filename_to_absolute str in + let root = Unix.getcwd () in + let abs_path = Utils.filename_to_absolute ~root str in (!args_to_parse).(!arg_being_parsed + 1) <- abs_path; abs_path ) else diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index 93284080b..d887eec60 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -263,8 +263,9 @@ let models_jar = lib_dir ^/ "java" ^/ "models.jar" let models_src_dir = + let root = Unix.getcwd () in let dir = bin_dir ^/ Filename.parent_dir_name ^/ "models" in - Utils.filename_to_absolute dir (* Normalize the path *) + Utils.filename_to_absolute ~root dir (* Normalize the path *) let relative_cpp_extra_include_dir = "cpp" ^/ "include" @@ -304,7 +305,7 @@ let init_work_dir, is_originator = (** Resolve relative paths passed as command line options, i.e., with respect to the working directory of the initial invocation of infer. *) -let resolve = Utils.filename_to_absolute +let resolve = Utils.filename_to_absolute ~root:init_work_dir (** Command Line options *) diff --git a/infer/src/base/Utils.ml b/infer/src/base/Utils.ml index 6d5d54de8..2e1e62d09 100644 --- a/infer/src/base/Utils.ml +++ b/infer/src/base/Utils.ml @@ -105,7 +105,7 @@ let close_outf outf = (** Convert a filename to an absolute one if it is relative, and normalize "." and ".." *) -let filename_to_absolute fname = +let filename_to_absolute ~root fname = let add_entry rev_done entry = match entry, rev_done with | ".", [] -> entry :: rev_done (* id on . *) @@ -115,11 +115,11 @@ let filename_to_absolute fname = | "..", _ :: rev_done_parent -> rev_done_parent (* path/dir/.. --> path *) | _ -> entry :: rev_done in - let abs_fname = if Filename.is_absolute fname then fname else (Unix.getcwd ()) ^/ fname in + let abs_fname = if Filename.is_absolute fname then fname else root ^/ fname in Filename.of_parts (List.rev (List.fold_left ~f:add_entry ~init:[] (Filename.parts abs_fname))) -(** Convert an absolute filename to one relative to the current directory. *) +(** Convert an absolute filename to one relative to the given directory. *) let filename_to_relative root fname = let rec relativize_if_under origin target = match origin, target with diff --git a/infer/src/base/Utils.mli b/infer/src/base/Utils.mli index 2d13fec94..90c93d002 100644 --- a/infer/src/base/Utils.mli +++ b/infer/src/base/Utils.mli @@ -30,7 +30,7 @@ val copy_file : string -> string -> int option val read_file : string -> string list option (** Convert a filename to an absolute one if it is relative, and normalize "." and ".." *) -val filename_to_absolute : string -> string +val filename_to_absolute : root:string -> string -> string (** Convert an absolute filename to one relative to a root directory *) val filename_to_relative : string -> string -> string diff --git a/infer/src/clang/Capture.re b/infer/src/clang/Capture.re index 31f4ef240..c803cadb6 100644 --- a/infer/src/clang/Capture.re +++ b/infer/src/clang/Capture.re @@ -152,9 +152,10 @@ let run_plugin_and_frontend source_path frontend clang_args => { let cc1_capture clang_cmd => { let source_path = { + let root = Unix.getcwd (); let orig_argv = ClangCommand.get_orig_argv clang_cmd; /* the source file is always the last argument of the original -cc1 clang command */ - Utils.filename_to_absolute orig_argv.(Array.length orig_argv - 1) + Utils.filename_to_absolute root::root orig_argv.(Array.length orig_argv - 1) }; Logging.out "@\n*** Beginning capture of file %s ***@\n" source_path; if (Config.analyzer == Config.Compile || CLocation.is_file_blacklisted source_path) { diff --git a/infer/src/java/jClasspath.ml b/infer/src/java/jClasspath.ml index ab3dc0aca..3e19fdb85 100644 --- a/infer/src/java/jClasspath.ml +++ b/infer/src/java/jClasspath.ml @@ -77,7 +77,8 @@ let split_classpath cp = Str.split (Str.regexp JFile.sep) cp let append_path classpath path = if Sys.file_exists path = `Yes then - let full_path = Utils.filename_to_absolute path in + let root = Unix.getcwd () in + let full_path = Utils.filename_to_absolute ~root path in if String.length classpath = 0 then full_path else