@ -118,7 +118,7 @@ def prepare_build(args):
return temp_files , infer_script . name
return temp_files , infer_script . name
def get_normalized_targets ( targets ):
def get_normalized_targets ( targets , verbose ):
""" Use buck to convert a list of input targets/aliases
""" Use buck to convert a list of input targets/aliases
into a set of the ( transitive ) target deps for all inputs """
into a set of the ( transitive ) target deps for all inputs """
@ -133,7 +133,7 @@ def get_normalized_targets(targets):
targets = filter (
targets = filter (
lambda line : len ( line ) > 0 ,
lambda line : len ( line ) > 0 ,
subprocess . check_output ( buck_cmd ) . decode ( ) . strip ( ) . split ( ' \n ' ) )
subprocess . check_output ( buck_cmd ) . decode ( ) . strip ( ) . split ( ' \n ' ) )
if len ( targets ) > 0 and args. verbose:
if len ( targets ) > 0 and verbose:
logging . debug ( ' Targets to analyze: ' )
logging . debug ( ' Targets to analyze: ' )
for target in targets :
for target in targets :
logging . debug ( target )
logging . debug ( target )
@ -420,67 +420,78 @@ def cleanup(temp_files):
logging . error ( ' Could not remove %s ' % file )
logging . error ( ' Could not remove %s ' % file )
if __name__ == ' __main__ ' :
parser = argparse . ArgumentParser ( )
parser = argparse . ArgumentParser ( parents = [ analyze . base_parser ] )
parser . add_argument ( ' --build-report ' , metavar = ' PATH ' , type = str )
parser . add_argument ( ' --verbose ' , action = ' store_true ' ,
parser . add_argument ( ' --deep ' , action = ' store_true ' )
help = ' Print buck compilation steps ' )
parser . add_argument ( ' --keep-going ' , action = ' store_true ' )
parser . add_argument ( ' --no-cache ' , action = ' store_true ' ,
parser . add_argument ( ' --load-limit ' , ' -L ' )
help = ' Do not use buck distributed cache ' )
parser . add_argument ( ' --no-cache ' , action = ' store_true ' )
parser . add_argument ( ' --print-harness ' , action = ' store_true ' ,
parser . add_argument ( ' --profile ' , action = ' store_true ' )
help = ' Print generated harness code (Android only) ' )
parser . add_argument ( ' --shallow ' , action = ' store_true ' )
parser . add_argument ( ' targets ' , nargs = ' * ' , metavar = ' target ' ,
parser . add_argument ( ' --num-threads ' , ' -j ' , metavar = ' N ' )
help = ' Build targets to analyze ' )
parser . add_argument ( ' --verbose ' , ' -v ' , metavar = ' N ' , type = int )
args = parser . parse_args ( )
parser . add_argument ( ' targets ' , nargs = ' * ' , metavar = ' target ' ,
help = ' Build targets to analyze ' )
utils . configure_logging ( args )
timer = utils . Timer ( logging . info )
temp_files = [ ]
try :
class UnsuportedBuckCommand ( Exception ) :
start_time = time . time ( )
pass
logging . info ( ' Starting the analysis ' )
subprocess . check_call (
[ utils . get_cmd_in_bin_dir ( ' InferAnalyze ' ) , ' -version ' ] )
def parse_buck_command ( args ) :
build_keyword = ' build '
if not os . path . isdir ( args . infer_out ) :
if build_keyword in args and len ( args [ args . index ( build_keyword ) : ] ) > 1 :
os . mkdir ( args . infer_out )
next_index = args . index ( build_keyword ) + 1
buck_args = parser . parse_args ( args [ next_index : ] )
timer . start ( ' Preparing build... ' )
return buck_args
temp_files2 , infer_script = prepare_build ( args )
else :
temp_files + = temp_files2
raise UnsuportedBuckCommand ( args )
timer . stop ( ' Build prepared ' )
# TODO(t3786463) Start buckd.
class Wrapper :
timer . start ( ' Computing library targets ' )
def __init__ ( self , infer_args , buck_cmd ) :
normalized_targets = get_normalized_targets ( args . targets )
self . timer = utils . Timer ( logging . info )
timer . stop ( ' %d targets computed ' , len ( normalized_targets ) )
self . infer_args = infer_args
self . buck_args = parse_buck_command ( buck_cmd )
if len ( normalized_targets ) == 0 :
self . timer . start ( ' Computing library targets ' )
logging . info ( ' Nothing to analyze ' )
self . targets = get_normalized_targets (
else :
self . buck_args . targets ,
timer . start ( ' Running buck... ' )
self . infer_args . verbose )
buck_cmd = [
self . timer . stop ( ' %d targets computed ' , len ( self . targets ) )
' buck ' , ' build ' , ' --config ' , ' tools.javac= ' + infer_script ]
if args . no_cache :
def run ( self ) :
buck_cmd + = [ ' --no-cache ' ]
temp_files = [ ]
if args . verbose :
try :
buck_cmd + = [ ' -v ' , ' 2 ' ]
start_time = time . time ( )
compile_cmd = buck_cmd + normalized_targets
logging . info ( ' Starting the analysis ' )
subprocess . check_call ( compile_cmd )
timer . stop ( ' Buck finished ' )
if not os . path . isdir ( self . infer_args . infer_out ) :
os . mkdir ( self . infer_args . infer_out )
timer . start ( ' Collecting results... ' )
collect_results ( args , start_time )
self . timer . start ( ' Preparing build... ' )
timer . stop ( ' Done ' )
temp_files2 , infer_script = prepare_build ( self . infer_args )
temp_files + = temp_files2
except KeyboardInterrupt as e :
self . timer . stop ( ' Build prepared ' )
timer . stop ( ' Exiting ' )
sys . exit ( 0 )
if len ( self . targets ) == 0 :
except Exception as e :
logging . info ( ' Nothing to analyze ' )
timer . stop ( ' Failed ' )
else :
logging . error ( ' Caught %s : %s ' % ( e . __class__ . __name__ , str ( e ) ) )
self . timer . start ( ' Running buck... ' )
logging . error ( traceback . format_exc ( ) )
buck_cmd = [ ' buck ' , ' build ' ]
sys . exit ( 1 )
if self . buck_args . verbose is not None :
finally :
buck_cmd + = [ ' --verbose ' , str ( self . buck_args . verbose ) ]
cleanup ( temp_files )
buck_cmd + = [ ' --config ' , ' tools.javac= ' + infer_script ]
buck_cmd + = self . targets
subprocess . check_call ( buck_cmd )
self . timer . stop ( ' Buck finished ' )
self . timer . start ( ' Collecting results... ' )
collect_results ( self . infer_args , start_time )
self . timer . stop ( ' Done ' )
return os . EX_OK
except KeyboardInterrupt as e :
self . timer . stop ( ' Exiting ' )
sys . exit ( 0 )
finally :
cleanup ( temp_files )