Revert "[python] Remove more unused args"

Reviewed By: jvillard

Differential Revision: D4081048

fbshipit-source-id: 0354954
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent 085a031d3b
commit 278c705790

@ -172,6 +172,10 @@ def main():
' '.join(map(utils.decode, sys.argv)))
logging.info('Path to infer script %s (%s)', utils.decode(__file__),
os.path.realpath(utils.decode(__file__)))
if not args.buck:
# Should not print the Infer version when Infer is run by Buck.
# Buck reads the whole stderr output to compute the target key
logging.info(analyze.get_infer_version())
logging.info('Platform: %s', utils.decode(platform.platform()))
def log_getenv(k):

@ -27,6 +27,45 @@ csv.field_size_limit(sys.maxsize)
INFER_ANALYZE_BINARY = 'InferAnalyze'
def get_infer_version():
try:
return subprocess.check_output([
utils.get_cmd_in_bin_dir(INFER_ANALYZE_BINARY), '-version'])
except subprocess.CalledProcessError:
utils.stdout('Failed to run {0} binary, exiting'
.format(INFER_ANALYZE_BINARY))
sys.exit(os.EX_UNAVAILABLE)
# https://github.com/python/cpython/blob/aa8ea3a6be22c92e774df90c6a6ee697915ca8ec/Lib/argparse.py
class VersionAction(argparse._VersionAction):
def __call__(self, parser, namespace, values, option_string=None):
# set self.version so that argparse version action knows it
self.version = get_infer_version()
super(VersionAction, self).__call__(parser,
namespace,
values,
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')
base_group.add_argument('-o', '--out', metavar='<directory>',
@ -60,6 +99,10 @@ base_group.add_argument('--android-harness', action='store_true',
help='''[experimental] Create harness to detect bugs
involving the Android lifecycle''')
base_parser.add_argument('-v', '--version',
help='''Print the version of Infer and exit''',
action=VersionAction)
base_group.add_argument('--pmd-xml',
action='store_true',
help='''Output issues in (PMD) XML format.''')
@ -81,7 +124,7 @@ infer_group.add_argument('--buck', action='store_true', dest='buck',
infer_group.add_argument('-pr', '--project_root',
dest='project_root',
default=os.getcwd(),
default=get_pwd(),
help='Location of the project root '
'(default is current directory)')
@ -236,6 +279,8 @@ class AnalyzerWrapper(object):
for path in self.javac.args.classpath.split(os.pathsep):
if os.path.isfile(path):
infer_options += ['-ziplib', os.path.abspath(path)]
elif self.args.project_root:
infer_options += ['-project_root', self.args.project_root]
infer_options = map(utils.decode_or_not, infer_options)
infer_options_str = ' '.join(infer_options)

Loading…
Cancel
Save