@ -119,7 +119,7 @@ class BuckAnalyzer:
regex = self . args . blacklist_regex ) )
regex = self . args . blacklist_regex ) )
return args
return args
def _get_analysis_result_ file s( self ) :
def _get_analysis_result_ path s( self ) :
# TODO(8610738): Make targets extraction smarter
# TODO(8610738): Make targets extraction smarter
buck_results_cmd = [
buck_results_cmd = [
self . cmd [ 0 ] ,
self . cmd [ 0 ] ,
@ -130,8 +130,24 @@ class BuckAnalyzer:
( buck_output , _ ) = proc . communicate ( )
( buck_output , _ ) = proc . communicate ( )
# remove target name prefixes from each line and split them into a list
# remove target name prefixes from each line and split them into a list
out = [ x . split ( None , 1 ) [ 1 ] for x in buck_output . strip ( ) . split ( ' \n ' ) ]
out = [ x . split ( None , 1 ) [ 1 ] for x in buck_output . strip ( ) . split ( ' \n ' ) ]
# from the resulting list, get only what ends in json
return [ os . path . dirname ( x )
return [ x for x in out if x . endswith ( ' .json ' ) ]
if os . path . isfile ( x ) else x
for x in out if os . path . exists ( x ) ]
@staticmethod
def _merge_infer_dep_files ( root_paths , merged_out_path ) :
potential_dep_files = [ os . path . join ( p , config . INFER_BUCK_DEPS_FILENAME )
for p in root_paths ]
dep_files = filter ( os . path . exists , potential_dep_files )
utils . merge_and_dedup_files_into_path ( dep_files , merged_out_path )
@staticmethod
def _merge_infer_report_files ( root_paths , merged_out_path ) :
potential_report_files = [ os . path . join ( p , config . JSON_REPORT_FILENAME )
for p in root_paths ]
report_files = filter ( os . path . exists , potential_report_files )
all_results = issues . merge_reports_from_paths ( report_files )
utils . dump_json_to_path ( all_results , merged_out_path )
def _run_buck_with_flavors ( self ) :
def _run_buck_with_flavors ( self ) :
# TODO: Use buck to identify the project's root folder
# TODO: Use buck to identify the project's root folder
@ -147,23 +163,19 @@ class BuckAnalyzer:
ret = self . _run_buck_with_flavors ( )
ret = self . _run_buck_with_flavors ( )
if not ret == os . EX_OK :
if not ret == os . EX_OK :
return ret
return ret
result_files = self . _get_analysis_result_files ( )
result_paths = self . _get_analysis_result_paths ( )
all_results = issues . merge_reports_from_paths ( result_files )
merged_reports_path = os . path . join (
merged_results_path = os . path . join ( self . args . infer_out ,
self . args . infer_out , config . JSON_REPORT_FILENAME )
config . JSON_REPORT_FILENAME )
merged_deps_path = os . path . join (
utils . dump_json_to_path ( all_results , merged_results_path )
self . args . infer_out , config . INFER_BUCK_DEPS_FILENAME )
if self . args . merge_deps_files :
self . _merge_infer_report_files ( result_paths , merged_reports_path )
infer_deps_to_merge = [
self . _merge_infer_dep_files ( result_paths , merged_deps_path )
os . path . join (
bugs_out = os . path . join ( self . args . infer_out , config . BUGS_FILENAME )
os . path . dirname ( x ) , config . INFER_BUCK_DEPS_FILENAME )
xml_out = None
for x in result_files ]
if self . args . pmd_xml :
merged_infer_deps_path = os . path . join (
xml_out = os . path . join (
self . args . infer_out ,
self . args . infer_out , config . PMD_XML_FILENAME )
config . INFER_BUCK_DEPS_FILENAME )
issues . print_and_save_errors ( merged_reports_path , bugs_out , xml_out )
utils . merge_and_dedup_files_into_path ( infer_deps_to_merge ,
merged_infer_deps_path )
utils . stdout ( ' Results saved in {results_path} '
. format ( results_path = merged_results_path ) )
return os . EX_OK
return os . EX_OK
def capture_without_flavors ( self ) :
def capture_without_flavors ( self ) :