You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.7 KiB
81 lines
2.7 KiB
10 years ago
|
# Copyright (c) 2015 - present Facebook, Inc.
|
||
|
# All rights reserved.
|
||
|
#
|
||
|
# This source code is licensed under the BSD style license found in the
|
||
|
# LICENSE file in the root directory of this source tree. An additional grant
|
||
|
# of patent rights can be found in the PATENTS file in the same directory.
|
||
|
|
||
10 years ago
|
import os
|
||
10 years ago
|
import logging
|
||
9 years ago
|
|
||
10 years ago
|
import util
|
||
|
|
||
|
MODULE_NAME = __name__
|
||
|
MODULE_DESCRIPTION = '''Run analysis of code built with a command like:
|
||
|
ant [options] [target]
|
||
|
|
||
|
Analysis examples:
|
||
|
infer -- ant compile'''
|
||
|
|
||
|
def gen_instance(*args):
|
||
|
return AntCapture(*args)
|
||
|
|
||
|
# This creates an empty argparser for the module, which provides only
|
||
|
# description/usage information and no arguments.
|
||
|
create_argparser = util.base_argparser(MODULE_DESCRIPTION, MODULE_NAME)
|
||
|
|
||
|
|
||
|
class AntCapture:
|
||
|
|
||
|
def __init__(self, args, cmd):
|
||
|
self.args = args
|
||
10 years ago
|
util.log_java_version()
|
||
|
logging.info(util.run_cmd_ignore_fail(['ant', '-version']))
|
||
10 years ago
|
# TODO: make the extraction of targets smarter
|
||
|
self.build_cmd = ['ant', '-verbose'] + cmd[1:]
|
||
|
|
||
|
def is_interesting(self, content):
|
||
|
return self.is_quoted(content) or content.endswith('.java')
|
||
|
|
||
|
def is_quoted(self, argument):
|
||
|
quote = '\''
|
||
|
return len(argument) > 2 and argument[0] == quote\
|
||
|
and argument[-1] == quote
|
||
|
|
||
|
def remove_quotes(self, argument):
|
||
|
if self.is_quoted(argument):
|
||
|
return argument[1:-1]
|
||
|
else:
|
||
|
return argument
|
||
|
|
||
9 years ago
|
def get_infer_commands(self, verbose_output):
|
||
10 years ago
|
javac_pattern = '[javac]'
|
||
|
argument_start_pattern = 'Compilation arguments'
|
||
|
calls = []
|
||
|
javac_arguments = []
|
||
|
collect = False
|
||
|
for line in verbose_output:
|
||
|
if javac_pattern in line:
|
||
|
if argument_start_pattern in line:
|
||
|
collect = True
|
||
|
if javac_arguments != []:
|
||
9 years ago
|
capture = util.create_infer_command(self.args,
|
||
10 years ago
|
javac_arguments)
|
||
|
calls.append(capture)
|
||
|
javac_arguments = []
|
||
|
if collect:
|
||
|
pos = line.index(javac_pattern) + len(javac_pattern)
|
||
|
content = line[pos:].strip()
|
||
|
if self.is_interesting(content):
|
||
|
arg = self.remove_quotes(content)
|
||
|
javac_arguments.append(arg)
|
||
|
if javac_arguments != []:
|
||
9 years ago
|
capture = util.create_infer_command(self.args, javac_arguments)
|
||
10 years ago
|
calls.append(capture)
|
||
|
javac_arguments = []
|
||
|
return calls
|
||
|
|
||
|
def capture(self):
|
||
9 years ago
|
cmds = self.get_infer_commands(util.get_build_output(self.build_cmd))
|
||
10 years ago
|
return util.run_commands(cmds)
|