From bdbb8242cff5dc8cda06c767d2bee7e2d72b96df Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Tue, 7 Aug 2018 14:17:07 -0700 Subject: [PATCH] [infer][java] no longer fail on Buck Java project using a custom javac_jar compiler Summary: This makes sure that the javac_jar is disabled when setting the external compiler option to point at the Infer wrapper Closes #976 Reviewed By: jvillard Differential Revision: D9193336 fbshipit-source-id: abafb51fc --- Makefile | 2 +- infer/lib/python/inferlib/bucklib.py | 5 +++- .../build_systems/buck_javac_jar/.buckconfig | 2 ++ .../build_systems/buck_javac_jar/Makefile | 27 +++++++++++++++++++ .../build_systems/buck_javac_jar/issues.exp | 1 + .../build_systems/buck_javac_jar/src/BUCK | 4 +++ .../buck_javac_jar/src/UsingJavacJar.java | 12 +++++++++ 7 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 infer/tests/build_systems/buck_javac_jar/.buckconfig create mode 100644 infer/tests/build_systems/buck_javac_jar/Makefile create mode 100644 infer/tests/build_systems/buck_javac_jar/issues.exp create mode 100644 infer/tests/build_systems/buck_javac_jar/src/BUCK create mode 100644 infer/tests/build_systems/buck_javac_jar/src/UsingJavacJar.java diff --git a/Makefile b/Makefile index a57a1abe0..519932e04 100644 --- a/Makefile +++ b/Makefile @@ -93,7 +93,7 @@ ifneq ($(ANT),no) BUILD_SYSTEMS_TESTS += ant endif ifneq ($(BUCK),no) -BUILD_SYSTEMS_TESTS += buck genrule +BUILD_SYSTEMS_TESTS += buck genrule buck_javac_jar # Introduce the dependency only if the two tests are going to be built in parallel, so that they do # not run in parallel (otherwise Buck has a bad time). This works by checking if one of the main # testing targets was passed as a goal on the command line. diff --git a/infer/lib/python/inferlib/bucklib.py b/infer/lib/python/inferlib/bucklib.py index 9f58f6ba6..a1c124559 100644 --- a/infer/lib/python/inferlib/bucklib.py +++ b/infer/lib/python/inferlib/bucklib.py @@ -278,10 +278,13 @@ class Wrapper: else: self.timer.start('Running Buck ...') buck_config = [ - '--config', 'tools.javac=' + infer_script, '--config', 'client.id=infer.java', '--config', 'java.abi_generation_mode=class', '--config', 'infer.no_custom_javac=true', + '--config', 'tools.javac=' + infer_script, + # make sure the javac_jar option is disabled to + # avoid conficts with the javac option + '--config', 'tools.javac_jar=', ] buck_cmd = self.buck_cmd + buck_config subprocess.check_call(buck_cmd) diff --git a/infer/tests/build_systems/buck_javac_jar/.buckconfig b/infer/tests/build_systems/buck_javac_jar/.buckconfig new file mode 100644 index 000000000..8f67ce98e --- /dev/null +++ b/infer/tests/build_systems/buck_javac_jar/.buckconfig @@ -0,0 +1,2 @@ +[tools] + javac_jar = /dev/null diff --git a/infer/tests/build_systems/buck_javac_jar/Makefile b/infer/tests/build_systems/buck_javac_jar/Makefile new file mode 100644 index 000000000..1824d6e06 --- /dev/null +++ b/infer/tests/build_systems/buck_javac_jar/Makefile @@ -0,0 +1,27 @@ +# Copyright (c) 2018-present, Facebook, Inc. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +TESTS_DIR = ../.. +ROOT_DIR = $(TESTS_DIR)/../.. + +ANALYZER = checkers +TARGET = //src:target +SOURCES = src/UsingJavacJar.java +OBJECTS = buck-out/gen/src/lib__target__output/target.jar +BUCKCONFIG = .buckconfig +INFER_OPTIONS = --eradicate-only +INFERPRINT_OPTIONS = --issues-tests +CLEAN_EXTRA = buck-out + +include $(TESTS_DIR)/infer.make + +$(OBJECTS): $(SOURCES) $(BUCKCONFIG) + $(BUCK) build --config tools.javac_jar= $(TARGET) + +infer-out/report.json: $(SOURCES) $(BUCKCONFIG) + $(REMOVE_DIR) buck-out && \ + $(call silent_on_success,Testing Buck Java integration with javac_jar,\ + INFER_BIN=$(INFER_BIN) \ + $(INFER_BIN) $(INFER_OPTIONS) -- $(BUCK) build $(TARGET)) diff --git a/infer/tests/build_systems/buck_javac_jar/issues.exp b/infer/tests/build_systems/buck_javac_jar/issues.exp new file mode 100644 index 000000000..b12a1f123 --- /dev/null +++ b/infer/tests/build_systems/buck_javac_jar/issues.exp @@ -0,0 +1 @@ +src/UsingJavacJar.java, Object UsingJavacJar.foo(), 0, ERADICATE_RETURN_NOT_NULLABLE, no_bucket, WARNING, [origin,Method `foo()` may return null but it is not annotated with `@Nullable`. (Origin: null constant at line 10)] diff --git a/infer/tests/build_systems/buck_javac_jar/src/BUCK b/infer/tests/build_systems/buck_javac_jar/src/BUCK new file mode 100644 index 000000000..b40bf5cc9 --- /dev/null +++ b/infer/tests/build_systems/buck_javac_jar/src/BUCK @@ -0,0 +1,4 @@ +java_library( + name = 'target', + srcs = glob(['*.java']), +) diff --git a/infer/tests/build_systems/buck_javac_jar/src/UsingJavacJar.java b/infer/tests/build_systems/buck_javac_jar/src/UsingJavacJar.java new file mode 100644 index 000000000..79fa040c9 --- /dev/null +++ b/infer/tests/build_systems/buck_javac_jar/src/UsingJavacJar.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2018-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +public class UsingJavacJar { + + Object foo() { + return null; + } +}