Skip the Buck build command when the list of target is empty

Summary: public
Since we are only running the analysis on the Buck targets that are of type java_library or android_library, it may happen that the filtering gives an empty list of targets.

This diff does two things:
 1) it filters out the empty strings `''` that can be returned when parsing the `buck query` command, and
 2) skip the analysis when the list of targets to analyze is empty.

It also fixes the debug output for the list of targets to analyze, which was previously always printing the list of targets passed in the command line argument, which led for this issue to be unoticed even though it may have been there for a while already.

Reviewed By: sblackshear

Differential Revision: D2704949

fb-gh-sync-id: 83c62d8
master
jrm 9 years ago committed by facebook-github-bot-1
parent a49b0965ef
commit 1aa354cf1f

@ -147,10 +147,12 @@ def get_normalized_targets(targets):
buck_cmd = BUCK_GET_JAVA_TARGETS + targets
try:
targets = subprocess.check_output(buck_cmd).decode().strip().split('\n')
if args.verbose:
targets = filter(
lambda line: len(line) > 0,
subprocess.check_output(buck_cmd).decode().strip().split('\n'))
if len(targets) > 0 and args.verbose:
logging.debug('Targets to analyze:')
for target in args.targets:
for target in targets:
logging.debug(target)
return targets
except subprocess.CalledProcessError as e:
@ -474,19 +476,22 @@ if __name__ == '__main__':
normalized_targets = get_normalized_targets(args.targets)
timer.stop('%d targets computed', len(normalized_targets))
timer.start('Running buck...')
buck_cmd = ['buck', 'build']
if args.no_cache:
buck_cmd += ['--no-cache']
if args.verbose:
buck_cmd += ['-v', '2']
compile_cmd = buck_cmd + normalized_targets
subprocess.check_call(compile_cmd)
timer.stop('Buck finished')
timer.start('Collecting results...')
collect_results(args, start_time)
timer.stop('Done')
if len(normalized_targets) == 0:
logging.info('Nothing to analyze')
else:
timer.start('Running buck...')
buck_cmd = ['buck', 'build']
if args.no_cache:
buck_cmd += ['--no-cache']
if args.verbose:
buck_cmd += ['-v', '2']
compile_cmd = buck_cmd + normalized_targets
subprocess.check_call(compile_cmd)
timer.stop('Buck finished')
timer.start('Collecting results...')
collect_results(args, start_time)
timer.stop('Done')
except KeyboardInterrupt as e:
timer.stop('Exiting')

Loading…
Cancel
Save