From 87e5df5e44109b12c1a6b7665e5ea7d72e800cda Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Thu, 19 May 2016 08:07:22 -0700 Subject: [PATCH] Use pwd to resolve project_root when possible Summary: getcwd() resolves symbolic links, but rest of our code (clang plugin, ocaml) don't. Use pwd to get "compatible" paths. Reviewed By: jberdine, jvillard Differential Revision: D2971762 fbshipit-source-id: 6c01df2 --- infer/lib/python/inferlib/analyze.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/infer/lib/python/inferlib/analyze.py b/infer/lib/python/inferlib/analyze.py index fbb320735..fd96ca90d 100644 --- a/infer/lib/python/inferlib/analyze.py +++ b/infer/lib/python/inferlib/analyze.py @@ -52,6 +52,22 @@ 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') @@ -132,7 +148,7 @@ infer_group.add_argument('--infer_cache', metavar='', infer_group.add_argument('-pr', '--project_root', dest='project_root', - default=os.getcwd(), + default=get_pwd(), type=utils.decode, help='Location of the project root ' '(default is current directory)')