From 863e08909e785dc6e596dfd03076a63924c5b81b Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Fri, 27 Apr 2018 15:28:24 -0700 Subject: [PATCH] [gradle] fix compilation error caused by mishandling of empty classpath Summary: Previously, the command parsing code filtered out any elements that were `False`y in the Python sense (starting with D5507925). This meant that a command like `javac -classpath '' -Xmaxerrs 1000 MyFile.java` would be parsed as `javac -classpath -Xmaxerrs 1000 MyFile.java`, which will fail with "unrecognized option 1000". This diff removes the filtering and fixes that issue. Reviewed By: jeremydubreil Differential Revision: D7797560 fbshipit-source-id: 63df06b --- infer/lib/python/inferlib/capture/gradle.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/infer/lib/python/inferlib/capture/gradle.py b/infer/lib/python/inferlib/capture/gradle.py index 03a301b37..c43918c29 100644 --- a/infer/lib/python/inferlib/capture/gradle.py +++ b/infer/lib/python/inferlib/capture/gradle.py @@ -54,7 +54,7 @@ def extract_argfiles_from_rev(javac_arguments): java_opts = [] saved = [] java_arg = pop(javac_arguments) - while java_arg: + while java_arg is not None: if java_arg.startswith('@'): # Probably got an @argfile path = ' '.join([java_arg[1:]] + saved) @@ -114,7 +114,7 @@ def extract_all(javac_arguments): # Reversed Javac options parameters rev_opt_params = [] java_arg = pop(javac_arguments) - while java_arg: + while java_arg is not None: if java_arg.endswith('.java'): # Probably got a file remainder, path = extract_filepath(javac_arguments + [java_arg]) @@ -187,8 +187,10 @@ class GradleCapture: if build_agnostic_cmd in seen_build_cmds: continue seen_build_cmds.add(build_agnostic_cmd) - # Filter out the empty elements - arguments = list(filter(None, content.split(' '))) + arguments = content.split(' ') + # Note: do *not* try to filter out empty strings from the arguments (as was done + # here previously)! It will make compilation commands like + # `javac -classpath '' -Xmaxerrs 1000` fail with "Unrecognized option 1000" extracted = extract_all(arguments) java_files = extracted['files'] java_args = extracted['opts']