resolve symlinks recursively until the real infer executable is found

Summary:
This is needed on osx, where one of {`Sys.executable_name`, `Unix.readlink`}
does not behave the same as Linux.

Reviewed By: jberdine

Differential Revision: D3614254

fbshipit-source-id: a376636
master
Jules Villard 8 years ago committed by Facebook Github Bot 0
parent 241ea2c780
commit 01ffc387bb

@ -28,18 +28,23 @@ let set_env_for_clang_wrapper () =
let () = let () =
set_env_for_clang_wrapper () ; set_env_for_clang_wrapper () ;
(* The infer executable in the bin directory is a symbolic link to the real binary in the lib (* The infer executable in the bin directory is a symbolic link to the real binary in the lib
directory, so that the python script in the lib directory can be found relative to it. *) directory, so that the python script in the lib directory can be found relative to
it. Packaging may also create longer symlink chains to the real executable, hence the
recursion. *)
let real_exe = let real_exe =
match Unix.readlink Sys.executable_name with let rec real_path path =
| link when Filename.is_relative link -> match Unix.readlink path with
(* Sys.executable_name is a relative symbolic link *) | link when Filename.is_relative link ->
(Filename.dirname Sys.executable_name) // link (* [path] is a relative symbolic link *)
| link -> real_path ((Filename.dirname path) // link)
(* Sys.executable_name is an absolute symbolic link *) | link ->
link (* [path] is an absolute symbolic link *)
| exception Unix.Unix_error(Unix.EINVAL, _, _) -> real_path link
(* Sys.executable_name is not a symbolic link *) | exception Unix.Unix_error(Unix.EINVAL, _, _) ->
Sys.executable_name (* [path] is not a symbolic link *)
path
in
real_path Sys.executable_name
in in
let infer_py = (Filename.dirname real_exe) // "python" // "infer.py" in let infer_py = (Filename.dirname real_exe) // "python" // "infer.py" in
let build_cmd = IList.rev Config.rest in let build_cmd = IList.rev Config.rest in

Loading…
Cancel
Save