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
master
Andrzej Kotulski 9 years ago committed by Facebook Github Bot 2
parent 9fdd094a89
commit 87e5df5e44

@ -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='<directory>',
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)')

Loading…
Cancel
Save