@ -45,24 +45,27 @@ WARNING = 'WARNING'
INFO = ' INFO '
def get_infer_version ( ) :
try :
return subprocess . check_output ( [
utils . get_cmd_in_bin_dir ( INFER_ANALYZE_BINARY ) , ' -version ' ] )
except :
print ( " 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 = self . get_infer_version ( )
self . version = get_infer_version ( )
super ( VersionAction , self ) . __call__ ( parser ,
namespace ,
values ,
option_string )
def get_infer_version ( self ) :
try :
return subprocess . check_output ( [
utils . get_cmd_in_bin_dir ( INFER_ANALYZE_BINARY ) , ' -version ' ] )
except :
print ( " Failed to run {0} binary, exiting " .
format ( INFER_ANALYZE_BINARY ) )
exit ( 2 )
base_parser = argparse . ArgumentParser ( add_help = False )
@ -84,6 +87,10 @@ base_group.add_argument('-nf', '--no-filtering', action='store_true',
help = ''' Also show the results from the experimental
checks . Warning : some checks may contain many false
alarms ''' )
base_group . add_argument ( ' --log_to_stderr ' , action = ' store_true ' ,
help = ''' When set, all logging will go to stderr instead
of log file ''' )
base_parser . add_argument ( ' -v ' , ' --version ' , help = ' Get version of the analyzer ' ,
action = VersionAction )
@ -153,6 +160,18 @@ def remove_infer_out(infer_out):
shutil . rmtree ( infer_out , True )
def mkdir_if_not_exists ( path ) :
if not os . path . exists ( path ) :
os . mkdir ( path )
def create_results_dir ( results_dir ) :
mkdir_if_not_exists ( results_dir )
mkdir_if_not_exists ( os . path . join ( results_dir , ' specs ' ) )
mkdir_if_not_exists ( os . path . join ( results_dir , ' captured ' ) )
mkdir_if_not_exists ( os . path . join ( results_dir , ' sources ' ) )
def clean_infer_out ( infer_out ) :
directories = [ ' multicore ' , ' classnames ' , ' sources ' ]
@ -399,6 +418,7 @@ class Infer:
return javac_status
def analyze ( self ) :
logging . info ( ' Starting analysis ' )
infer_analyze = [
utils . get_cmd_in_bin_dir ( INFER_ANALYZE_BINARY ) ,
' -results_dir ' ,
@ -504,6 +524,9 @@ class Infer:
captured_plural = ' ' if captured_total < = 1 else ' s '
print ( ' \n %d file %s analyzed ' % ( captured_total , captured_plural ) )
logging . info ( ' Analyzed file count: %d ' , captured_total )
logging . info ( ' Analysis status: %d ' , exit_status )
return exit_status
def file_stats ( self , file , stats ) :