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

Loading…
Cancel
Save