Skip to content

Commit

Permalink
Flip --incompatible_disallow_legacy_javainfo.
Browse files Browse the repository at this point in the history
Fixes #5821.

Closes #9156.

PiperOrigin-RevId: 263302456
  • Loading branch information
iirina authored and copybara-github committed Aug 14, 2019
1 parent f0eeec5 commit 81216e3
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public class StarlarkSemanticsOptions extends OptionsBase implements Serializabl

@Option(
name = "incompatible_disallow_legacy_javainfo",
defaultValue = "false",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS},
metadataTags = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public static Builder builderWithDefaults() {
.incompatibleDisallowDictPlus(true)
.incompatibleDisallowEmptyGlob(false)
.incompatibleDisallowLegacyJavaProvider(false)
.incompatibleDisallowLegacyJavaInfo(false)
.incompatibleDisallowLegacyJavaInfo(true)
.incompatibleDisallowOldStyleArgsAdd(true)
.incompatibleDisallowRuleExecutionPlatformConstraintsAllowed(true)
.incompatibleDisallowStructProviderSyntax(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,32 +693,6 @@ public void buildHelperCreateJavaInfoWithJdeps_javaRuleOutputJarsProvider() thro
assertThat(ruleOutputs.getJdeps().prettyPrint()).isEqualTo("foo/my_jdeps.pb");
}

@Test
public void testMixMatchNewAndLegacyArgsIsError() throws Exception {
ImmutableList.Builder<String> lines = ImmutableList.builder();
lines.add(
"result = provider()",
"def _impl(ctx):",
" output_jar = ctx.actions.declare_file('output_jar')",
" source_jar = ctx.actions.declare_file('source_jar')",
" javaInfo = JavaInfo(",
" output_jar = output_jar, ",
" source_jar = source_jar,",
" source_jars = [source_jar],",
" )",
" return [result(property = javaInfo)]",
"my_rule = rule(",
" implementation = _impl,",
")");
scratch.file("foo/extension.bzl", lines.build().toArray(new String[] {}));
checkError(
"foo",
"my_skylark_rule",
"Cannot use deprecated arguments at the same time",
"load(':extension.bzl', 'my_rule')",
"my_rule(name = 'my_skylark_rule')");
}

@Test
public void testIncompatibleDisallowLegacyJavaInfo() throws Exception {
setSkylarkSemanticsOptions("--incompatible_disallow_legacy_javainfo");
Expand All @@ -740,7 +714,7 @@ public void testIncompatibleDisallowLegacyJavaInfo() throws Exception {
checkError(
"foo",
"my_skylark_rule",
"Cannot use deprecated argument when --incompatible_disallow_legacy_javainfo is set. ",
"Cannot use deprecated argument when --incompatible_disallow_legacy_javainfo is set",
"load(':extension.bzl', 'my_rule')",
"my_rule(name = 'my_skylark_rule')");
}
Expand Down
77 changes: 1 addition & 76 deletions src/test/shell/bazel/bazel_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ def _impl(ctx):
host_javabase = ctx.attr._host_javabase[java_common.JavaRuntimeInfo],
)
imported_provider = JavaInfo(output_jar = imported_jar, use_ijar=False);
imported_provider = JavaInfo(output_jar = imported_jar, compile_jar = imported_jar);
final_provider = java_common.merge([compilation_provider, imported_provider])
Expand Down Expand Up @@ -1453,81 +1453,6 @@ EOF
expect_log "<generated file java/com/google/sandwich/libb.jar>"
}



function test_java_info_constructor_with_ijar_unset_actions() {
mkdir -p java/com/google/foo
touch java/com/google/foo/{BUILD,my_rule.bzl}
cat > java/com/google/foo/BUILD << EOF
load(":my_rule.bzl", "my_rule")
my_rule(
name = 'my_skylark_rule',
output_jar = 'my_skylark_rule_lib.jar',
source_jars = ['my_skylark_rule_src.jar']
)
EOF

cat > java/com/google/foo/my_rule.bzl << EOF
result = provider()
def _impl(ctx):
javaInfo = JavaInfo(
output_jar = ctx.file.output_jar,
source_jars = ctx.files.source_jars,
use_ijar = True,
java_toolchain = ctx.attr._java_toolchain[java_common.JavaToolchainInfo]
)
return [result(property = javaInfo)]
my_rule = rule(
implementation = _impl,
attrs = {
'output_jar' : attr.label(allow_single_file=True),
'source_jars' : attr.label_list(allow_files=['.jar']),
"_java_toolchain": attr.label(default = Label("@bazel_tools//tools/jdk:remote_toolchain"))
}
)
EOF

bazel build java/com/google/foo:my_skylark_rule >& "$TEST_log" && fail "Unexpected success"
expect_log "The value of use_ijar is True. Make sure the ctx.actions argument is valid."
}

function test_java_info_constructor_with_ijar_unset_java_toolchain() {
mkdir -p java/com/google/foo
touch java/com/google/foo/{BUILD,my_rule.bzl}
cat > java/com/google/foo/BUILD << EOF
load(":my_rule.bzl", "my_rule")
my_rule(
name = 'my_skylark_rule',
output_jar = 'my_skylark_rule_lib.jar',
source_jars = ['my_skylark_rule_src.jar']
)
EOF

cat > java/com/google/foo/my_rule.bzl << EOF
result = provider()
def _impl(ctx):
javaInfo = JavaInfo(
output_jar = ctx.file.output_jar,
source_jars = ctx.files.source_jars,
use_ijar = True,
actions = ctx.actions
)
return [result(property = javaInfo)]
my_rule = rule(
implementation = _impl,
attrs = {
'output_jar' : attr.label(allow_single_file=True),
'source_jars' : attr.label_list(allow_files=['.jar'])
}
)
EOF

bazel build java/com/google/foo:my_skylark_rule >& "$TEST_log" && fail "Unexpected success"
expect_log "The value of use_ijar is True. Make sure the java_toolchain argument is valid."
}

function test_java_info_constructor_e2e() {
mkdir -p java/com/google/foo
touch java/com/google/foo/{BUILD,my_rule.bzl}
Expand Down

0 comments on commit 81216e3

Please sign in to comment.