Add root dir argument to Utils.filename_to_absolute

Summary:
Force clients to specify the path relative to which relative paths
should be made absolute.

Reviewed By: akotulski

Differential Revision: D4370262

fbshipit-source-id: 36a2807
master
Josh Berdine 8 years ago committed by Facebook Github Bot
parent c88fe26071
commit 8c42cfb364

@ -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

@ -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

@ -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 *)

@ -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

@ -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

@ -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) {

@ -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

Loading…
Cancel
Save