From 01ffc387bb3959d4581ccf0cc2b877b999631780 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Tue, 26 Jul 2016 03:54:59 -0700 Subject: [PATCH] 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 --- infer/src/backend/infer.ml | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/infer/src/backend/infer.ml b/infer/src/backend/infer.ml index f8fecb4d6..6b1a8fec0 100644 --- a/infer/src/backend/infer.ml +++ b/infer/src/backend/infer.ml @@ -28,18 +28,23 @@ let set_env_for_clang_wrapper () = let () = set_env_for_clang_wrapper () ; (* 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 = - match Unix.readlink Sys.executable_name with - | link when Filename.is_relative link -> - (* Sys.executable_name is a relative symbolic link *) - (Filename.dirname Sys.executable_name) // link - | link -> - (* Sys.executable_name is an absolute symbolic link *) - link - | exception Unix.Unix_error(Unix.EINVAL, _, _) -> - (* Sys.executable_name is not a symbolic link *) - Sys.executable_name + let rec real_path path = + match Unix.readlink path with + | link when Filename.is_relative link -> + (* [path] is a relative symbolic link *) + real_path ((Filename.dirname path) // link) + | link -> + (* [path] is an absolute symbolic link *) + real_path link + | exception Unix.Unix_error(Unix.EINVAL, _, _) -> + (* [path] is not a symbolic link *) + path + in + real_path Sys.executable_name in let infer_py = (Filename.dirname real_exe) // "python" // "infer.py" in let build_cmd = IList.rev Config.rest in