From 998b4104a40a55c7f44e398f8888aebb5610d6c8 Mon Sep 17 00:00:00 2001 From: cushon Date: Mon, 1 Apr 2019 08:59:07 -0700 Subject: [PATCH] Remove obsolete --incompatible_ flags https://github.com/bazelbuild/bazel/issues/6661 https://github.com/bazelbuild/bazel/issues/7196 https://github.com/bazelbuild/bazel/issues/7197 PiperOrigin-RevId: 241334080 --- .../lib/rules/java/JavaConfiguration.java | 2 +- .../build/lib/rules/java/JavaOptions.java | 73 +------ .../integration/java_integration_test.sh | 191 +++--------------- 3 files changed, 34 insertions(+), 232 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java index 550ba51e03ecea..210547a4075cbf 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java @@ -200,7 +200,7 @@ public boolean alwaysGenerateOutputMapping() { this.proguardBinary = javaOptions.proguard; this.extraProguardSpecs = ImmutableList.copyOf(javaOptions.extraProguardSpecs); this.bundleTranslations = javaOptions.bundleTranslations; - this.toolchainLabel = javaOptions.getJavaToolchain(); + this.toolchainLabel = javaOptions.javaToolchain; this.runtimeLabel = javaOptions.javaBase; this.javaOptimizationMode = javaOptions.javaOptimizationMode; this.useLegacyBazelJavaTest = javaOptions.legacyBazelJavaTest; diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java index 0a010f543b2c4f..0756af0d8f6543 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java @@ -82,7 +82,7 @@ public ImportDepsCheckingLevelConverter() { @Option( name = "java_toolchain", - defaultValue = "null", + defaultValue = "@bazel_tools//tools/jdk:remote_toolchain", converter = LabelConverter.class, documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, effectTags = {OptionEffectTag.UNKNOWN}, @@ -91,7 +91,7 @@ public ImportDepsCheckingLevelConverter() { @Option( name = "host_java_toolchain", - defaultValue = "null", + defaultValue = "@bazel_tools//tools/jdk:remote_toolchain", converter = LabelConverter.class, documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, effectTags = {OptionEffectTag.UNKNOWN}, @@ -109,18 +109,6 @@ public ImportDepsCheckingLevelConverter() { + "tools during a build.") public Label hostJavaBase; - @Option( - name = "incompatible_use_jdk10_as_host_javabase", - defaultValue = "true", - documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, - effectTags = {OptionEffectTag.UNKNOWN}, - metadataTags = { - OptionMetadataTag.INCOMPATIBLE_CHANGE, - OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES - }, - help = "If enabled, the default --host_javabase is JDK 10.") - public boolean useJDK10AsHostJavaBase; - @Option( name = "incompatible_use_jdk11_as_host_javabase", defaultValue = "true", @@ -597,34 +585,6 @@ public ImportDepsCheckingLevelConverter() { + "--java_header_compilation is enabled.") public boolean requireJavaToolchainHeaderCompilerDirect; - @Option( - name = "incompatible_use_remote_java_toolchain", - defaultValue = "true", - documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, - effectTags = {OptionEffectTag.UNKNOWN}, - metadataTags = { - OptionMetadataTag.INCOMPATIBLE_CHANGE, - OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES - }, - help = - "If enabled, uses the remote Java tools for the default --java_toolchain. " - + "See #7196.") - public boolean useRemoteJavaToolchain; - - @Option( - name = "incompatible_use_remote_host_java_toolchain", - defaultValue = "true", - documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, - effectTags = {OptionEffectTag.UNKNOWN}, - metadataTags = { - OptionMetadataTag.INCOMPATIBLE_CHANGE, - OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES - }, - help = - "If enabled, uses the remote Java tools for the default --host_java_toolchain. " - + "See #7197.") - public boolean useRemoteHostJavaToolchain; - @Option( name = "incompatible_disallow_resource_jars", defaultValue = "false", @@ -664,36 +624,11 @@ private Label getHostJavaBase() { if (useJDK11AsHostJavaBase) { return Label.parseAbsoluteUnchecked("@bazel_tools//tools/jdk:remote_jdk11"); } - if (useJDK10AsHostJavaBase) { - return Label.parseAbsoluteUnchecked("@bazel_tools//tools/jdk:remote_jdk10"); - } - return Label.parseAbsoluteUnchecked("@bazel_tools//tools/jdk:host_jdk"); + return Label.parseAbsoluteUnchecked("@bazel_tools//tools/jdk:remote_jdk10"); } return hostJavaBase; } - private Label getHostJavaToolchain() { - if (hostJavaToolchain == null) { - if (useRemoteHostJavaToolchain) { - return Label.parseAbsoluteUnchecked("@bazel_tools//tools/jdk:remote_toolchain"); - } else { - return Label.parseAbsoluteUnchecked("@bazel_tools//tools/jdk:toolchain"); - } - } - return hostJavaToolchain; - } - - Label getJavaToolchain() { - if (javaToolchain == null) { - if (useRemoteJavaToolchain) { - return Label.parseAbsoluteUnchecked("@bazel_tools//tools/jdk:remote_toolchain"); - } else { - return Label.parseAbsoluteUnchecked("@bazel_tools//tools/jdk:toolchain"); - } - } - return javaToolchain; - } - @Override public FragmentOptions getHost() { JavaOptions host = (JavaOptions) getDefault(); @@ -702,7 +637,7 @@ public FragmentOptions getHost() { host.jvmOpts = ImmutableList.of("-XX:ErrorFile=/dev/stderr"); host.javacOpts = hostJavacOpts; - host.javaToolchain = getHostJavaToolchain(); + host.javaToolchain = hostJavaToolchain; host.javaLauncher = hostJavaLauncher; diff --git a/src/test/shell/integration/java_integration_test.sh b/src/test/shell/integration/java_integration_test.sh index 9435e13101cc98..4b5f12d13b8faf 100755 --- a/src/test/shell/integration/java_integration_test.sh +++ b/src/test/shell/integration/java_integration_test.sh @@ -166,13 +166,12 @@ EOF # This test intentionally show some errors on the standard output. function test_compiles_hello_world() { - declare -a bazel_opts=("${@:+$@}") local -r pkg="${FUNCNAME[0]}" mkdir "$pkg" || fail "mkdir $pkg" write_hello_world_files "$pkg" bazel clean - bazel build ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/hello:hello || fail "build failed" + bazel build //$pkg/java/hello:hello || fail "build failed" ${PRODUCT_NAME}-bin/$pkg/java/hello/hello | grep -q 'Hello, World!' \ || fail "comparison failed" function check_deploy_jar_should_not_exist() { @@ -189,32 +188,25 @@ function test_compiles_hello_world() { check_arglists ${PRODUCT_NAME}-bin/$pkg/java/hello/hello } -function test_compiles_hello_world_remote_java_tools() { - test_compiles_hello_world \ - --incompatible_use_remote_host_java_toolchain \ - --incompatible_use_remote_java_toolchain -} - function test_compiles_hello_world_from_deploy_jar() { - declare -a bazel_opts=("${@:+$@}") local -r pkg="${FUNCNAME[0]}" mkdir "$pkg" || fail "mkdir $pkg" write_hello_world_files "$pkg" - bazel build ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/hello:hello_deploy.jar || fail "build failed" + bazel build //$pkg/java/hello:hello_deploy.jar || fail "build failed" - bazel run ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/hello:hello -- --singlejar | grep -q 'Hello, World!' \ + bazel run //$pkg/java/hello:hello -- --singlejar | grep -q 'Hello, World!' \ || fail "comparison failed" ${PRODUCT_NAME}-bin/$pkg/java/hello/hello -- --singlejar | \ grep -q 'Hello, World!' || fail "comparison failed" - bazel run ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/hello:hello -- --wrapper_script_flag=--singlejar \ + bazel run //$pkg/java/hello:hello -- --wrapper_script_flag=--singlejar \ | grep -q 'Hello, World!' || fail "comparison failed" ${PRODUCT_NAME}-bin/$pkg/java/hello/hello -- \ --wrapper_script_flag=--singlejar | grep -q 'Hello, World!' \ || fail "comparison failed" - bazel run ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/hello:hello -- REGULAR_ARG \ + bazel run //$pkg/java/hello:hello -- REGULAR_ARG \ --wrapper_script_flag=--singlejar | grep -q 'Hello, World!' \ || fail "comparison failed" ${PRODUCT_NAME}-bin/$pkg/java/hello/hello -- REGULAR_ARG \ @@ -222,19 +214,12 @@ function test_compiles_hello_world_from_deploy_jar() { || fail "comparison failed" } -function test_compiles_hello_world_from_deploy_jar_remote_java_tools() { - test_compiles_hello_world_from_deploy_jar \ - --incompatible_use_remote_host_java_toolchain \ - --incompatible_use_remote_java_toolchain -} - function test_explicit_bogus_wrapper_args_are_rejected() { - declare -a bazel_opts=("${@:+$@}") local -r pkg="${FUNCNAME[0]}" mkdir "$pkg" || fail "mkdir $pkg" write_hello_world_files "$pkg" - bazel build ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/hello:hello_deploy.jar || fail "build failed" + bazel build //$pkg/java/hello:hello_deploy.jar || fail "build failed" function check_arg_rejected() { "$@" && fail "bogus arg should be rejected" true # reset the last exit code so the test won't be considered failed @@ -247,11 +232,6 @@ function test_explicit_bogus_wrapper_args_are_rejected() { check_arglists ${PRODUCT_NAME}-bin/$pkg/java/hello/hello } -function test_explicit_bogus_wrapper_args_are_rejected_remote_java_tools() { - test_explicit_bogus_wrapper_args_are_rejected \ - --incompatible_use_remote_host_java_toolchain \ - --incompatible_use_remote_java_toolchain -} function assert_singlejar_works() { local -r pkg="$1" local -r copy_jdk="$2" @@ -324,13 +304,12 @@ function test_singlejar_with_custom_jdk_without_stamp() { # Regression test for b/18191163: ensure that the build is deterministic when # used with --nostamp. function test_deterministic_nostamp_build() { - declare -a bazel_opts=("${@:+$@}") local -r pkg="${FUNCNAME[0]}" mkdir "$pkg" || fail "mkdir $pkg" write_hello_world_files "$pkg" bazel clean || fail "Clean failed" - bazel build ${bazel_opts[@]+"${bazel_opts[@]}"} --nostamp //$pkg/java/hello:hello_deploy.jar \ + bazel build --nostamp //$pkg/java/hello:hello_deploy.jar \ || fail "Build failed" # TODO(bazel-team) .a files (C/C++ static library file generated by # archive tool) on darwin OS only are not deterministic. @@ -355,58 +334,37 @@ function test_deterministic_nostamp_build() { assert_equals "$first_run" "$second_run" } -function test_deterministic_nostamp_build_remote_java_tools() { - test_deterministic_nostamp_build \ - --incompatible_use_remote_host_java_toolchain \ - --incompatible_use_remote_java_toolchain -} - function test_compiles_hello_library() { - declare -a bazel_opts=("${@:+$@}") local -r pkg="${FUNCNAME[0]}" mkdir "$pkg" || fail "mkdir $pkg" write_hello_library_files "$pkg" bazel clean - bazel build ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/main:main || fail "build failed" + bazel build //$pkg/java/main:main || fail "build failed" ${PRODUCT_NAME}-bin/$pkg/java/main/main \ | grep -q "Hello, Library!;Hello, World!" || fail "comparison failed" - bazel run ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/main:main -- --singlejar && fail "deploy jar should not exist" + bazel run //$pkg/java/main:main -- --singlejar && fail "deploy jar should not exist" true # reset the last exit code so the test won't be considered failed } -function test_compiles_hello_library_remote_java_tools() { - test_compiles_hello_library \ - --incompatible_use_remote_host_java_toolchain \ - --incompatible_use_remote_java_toolchain -} - function test_compiles_hello_library_using_ijars() { - declare -a bazel_opts=("${@:+$@}") local -r pkg="${FUNCNAME[0]}" mkdir "$pkg" || fail "mkdir $pkg" write_hello_library_files "$pkg" bazel clean - bazel build ${bazel_opts[@]+"${bazel_opts[@]}"} --use_ijars //$pkg/java/main:main || fail "build failed" + bazel build --use_ijars //$pkg/java/main:main || fail "build failed" ${PRODUCT_NAME}-bin/$pkg/java/main/main \ | grep -q "Hello, Library!;Hello, World!" || fail "comparison failed" } -function test_compiles_hello_library_using_ijars_remote_java_tools() { - test_compiles_hello_library_using_ijars \ - --incompatible_use_remote_host_java_toolchain \ - --incompatible_use_remote_java_toolchain -} - function test_compiles_hello_library_from_deploy_jar() { - declare -a bazel_opts=("${@:+$@}") local -r pkg="${FUNCNAME[0]}" mkdir "$pkg" || fail "mkdir $pkg" write_hello_library_files "$pkg" - bazel build ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/main:main_deploy.jar || fail "build failed" + bazel build //$pkg/java/main:main_deploy.jar || fail "build failed" ${PRODUCT_NAME}-bin/$pkg/java/main/main --singlejar \ | grep -q "Hello, Library!;Hello, World!" || fail "comparison failed" @@ -416,40 +374,26 @@ function test_compiles_hello_library_from_deploy_jar() { | grep -q "k2: v2" || fail "missing manifest lines" } -function test_compiles_hello_library_from_deploy_jar_remote_java_tools() { - test_compiles_hello_library_from_deploy_jar \ - --incompatible_use_remote_host_java_toolchain \ - --incompatible_use_remote_java_toolchain -} - function test_building_deploy_jar_twice_does_not_rebuild() { - declare -a bazel_opts=("${@:+$@}") local -r pkg="${FUNCNAME[0]}" mkdir "$pkg" || fail "mkdir $pkg" write_hello_library_files "$pkg" - bazel build ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/main:main_deploy.jar || fail "build failed" + bazel build //$pkg/java/main:main_deploy.jar || fail "build failed" touch -r ${PRODUCT_NAME}-bin/$pkg/java/main/main_deploy.jar old - bazel build ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/main:main_deploy.jar || fail "build failed" + bazel build //$pkg/java/main:main_deploy.jar || fail "build failed" find ${PRODUCT_NAME}-bin/$pkg/java/main/main_deploy.jar -newer old \ | grep -q . && fail "file was rebuilt" true # reset the last exit code so the test won't be considered failed } -function test_building_deploy_jar_twice_does_not_rebuild_remote_java_tools() { - test_building_deploy_jar_twice_does_not_rebuild \ - --incompatible_use_remote_host_java_toolchain \ - --incompatible_use_remote_java_toolchain -} - function test_does_not_create_executable_when_not_asked_for() { - declare -a bazel_opts=("${@:+$@}") local -r pkg="${FUNCNAME[0]}" mkdir "$pkg" || fail "mkdir $pkg" write_hello_sailor_files "$pkg" - bazel build ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/hellosailor:hellosailor_deploy.jar \ + bazel build //$pkg/java/hellosailor:hellosailor_deploy.jar \ || fail "build failed" if [[ ! -e ${PRODUCT_NAME}-bin/$pkg/java/hellosailor/hellosailor.jar ]]; then @@ -463,17 +407,11 @@ function test_does_not_create_executable_when_not_asked_for() { if [[ ! -e ${PRODUCT_NAME}-bin/$pkg/java/hellosailor/hellosailor_deploy.jar ]]; then fail "output deploy jar does not exist"; fi -} -function test_does_not_create_executable_when_not_asked_for_remote_java_tools() { - test_does_not_create_executable_when_not_asked_for \ - --incompatible_use_remote_host_java_toolchain \ - --incompatible_use_remote_java_toolchain } # Assert that the a deploy jar can be a dependency of another java_binary. function test_building_deploy_jar_dependent_on_deploy_jar() { - declare -a bazel_opts=("${@:+$@}") local -r pkg="${FUNCNAME[0]}" mkdir -p $pkg/java/deploy || fail "mkdir" cat > $pkg/java/deploy/BUILD <$pkg/hello/BUILD echo "Some other File" >$pkg/hello/Test.txt - bazel build ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/deploy:Hello_deploy.jar || fail "build failed" + bazel build //$pkg/java/deploy:Hello_deploy.jar || fail "build failed" unzip -p ${PRODUCT_NAME}-bin/$pkg/java/deploy/Hello_deploy.jar \ $pkg/hello/Test.txt | grep -q "Some other File" || fail "missing resource" } -function test_building_deploy_jar_dependent_on_deploy_jar_remote_java_tools() { - test_building_deploy_jar_dependent_on_deploy_jar \ - --incompatible_use_remote_host_java_toolchain \ - --incompatible_use_remote_java_toolchain -} - function test_wrapper_script_arg_handling() { - declare -a bazel_opts=("${@:+$@}") local -r pkg="${FUNCNAME[0]}" mkdir -p $pkg/java/hello/ || fail "Expected success" cat > $pkg/java/hello/Test.java <&$TEST_log || fail "Build failed" expect_log "Args: '' 'foo' '' '' 'bar quux' ''" } -function test_wrapper_script_arg_handling_remote_java_tools() { - test_wrapper_script_arg_handling \ - --incompatible_use_remote_host_java_toolchain \ - --incompatible_use_remote_java_toolchain -} - function test_srcjar_compilation() { - declare -a bazel_opts=("${@:+$@}") local -r pkg="${FUNCNAME[0]}" mkdir -p $pkg/java/hello/ || fail "Expected success" cat > $pkg/java/hello/Test.java < $pkg/java/hello/BUILD <&$TEST_log || fail "Expected success" - bazel run ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/hello:hello -- --singlejar >&$TEST_log + bazel run //$pkg/java/hello:hello -- --singlejar >&$TEST_log expect_log "Hello World!" } -function test_srcjar_compilation_remote_java_tools() { - test_srcjar_compilation \ - --incompatible_use_remote_host_java_toolchain \ - --incompatible_use_remote_java_toolchain -} - function test_private_initializers() { local -r pkg="${FUNCNAME[0]}" mkdir -p $pkg/java/hello/ || fail "Expected success" @@ -619,7 +537,6 @@ EOF } function test_java_plugin() { - declare -a bazel_opts=("${@:+$@}") local -r pkg="${FUNCNAME[0]}" mkdir -p $pkg/java/test/processor || fail "mkdir" @@ -704,24 +621,17 @@ import test.processor.TestAnnotation; class ProcessorClient { } EOF - bazel build ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/test/client:client --use_ijars || fail "build failed" + bazel build //$pkg/java/test/client:client --use_ijars || fail "build failed" unzip -l ${PRODUCT_NAME}-bin/$pkg/java/test/client/libclient.jar > $TEST_log expect_log " test/Generated.class" "missing class file from annotation processing" - bazel build ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/test/client:libclient-src.jar --use_ijars \ + bazel build //$pkg/java/test/client:libclient-src.jar --use_ijars \ || fail "build failed" unzip -l ${PRODUCT_NAME}-bin/$pkg/java/test/client/libclient-src.jar > $TEST_log expect_log " test/Generated.java" "missing source file from annotation processing" } -function test_java_plugin_remote_java_tools() { - test_java_plugin \ - --incompatible_use_remote_host_java_toolchain \ - --incompatible_use_remote_java_toolchain -} - function test_jvm_flags_are_passed_verbatim() { - declare -a bazel_opts=("${@:+$@}") local -r pkg="${FUNCNAME[0]}" mkdir -p $pkg/java/com/google/jvmflags || fail "mkdir" cat >$pkg/java/com/google/jvmflags/BUILD < $pkg/java/foo/Foo.java < $TEST_log @@ -892,14 +781,7 @@ function test_header_compilation() { "missing class file from header compilation" } -function test_header_compilation_remote_java_tools() { - test_header_compilation \ - --incompatible_use_remote_host_java_toolchain \ - --incompatible_use_remote_java_toolchain -} - function test_header_compilation_errors() { - declare -a bazel_opts=("${@:+$@}") local -r pkg="${FUNCNAME[0]}" mkdir -p $pkg/java/test/ || fail "Expected success" cat > $pkg/java/test/A.java <& "$TEST_log" && fail "Unexpected success" expect_log "symbol not found missing.NoSuch" } -function test_header_compilation_errors_remote_java_tools() { - test_header_compilation_errors \ - --incompatible_use_remote_host_java_toolchain \ - --incompatible_use_remote_java_toolchain -} - function test_java_import_with_empty_jars_attribute() { - declare -a bazel_opts=("${@:+$@}") local -r pkg="${FUNCNAME[0]}" mkdir -p $pkg/java/hello/ || fail "Expected success" cat > $pkg/java/hello/Hello.java <& "$TEST_log" \ + bazel build //$pkg/java/hello:hello //$pkg/java/hello:hello_deploy.jar >& "$TEST_log" \ || fail "Expected success" - bazel run ${bazel_opts[@]+"${bazel_opts[@]}"} //$pkg/java/hello:hello -- --singlejar >& "$TEST_log" + bazel run //$pkg/java/hello:hello -- --singlejar >& "$TEST_log" expect_log "Hello World!" } -function test_java_import_with_empty_jars_attribute_remote_java_tools() { - test_java_import_with_empty_jars_attribute \ - --incompatible_use_remote_host_java_toolchain \ - --incompatible_use_remote_java_toolchain -} - - run_suite "Java integration tests"