Skip to content

Commit

Permalink
Make --incompatible_depset_for_java_output_source_jars a no-op and …
Browse files Browse the repository at this point in the history
…move it to the graveyard

Closes #18966

RELNOTES: `--incompatible_depset_for_java_output_source_jars` is a no-op
PiperOrigin-RevId: 585740794
Change-Id: I8d13ed089eb3fa1398086008e572e11eb46f108b
  • Loading branch information
hvadehra authored and copybara-github committed Nov 27, 2023
1 parent c8afa82 commit 106aec6
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,15 @@ public static final class AllCommandGraveyardOptions extends OptionsBase {
effectTags = {OptionEffectTag.UNKNOWN},
help = "Do not use.")
public String javaOptimizationMode;

@Option(
name = "incompatible_depset_for_java_output_source_jars",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE},
help = "No-op.")
public boolean incompatibleDepsetForJavaOutputSourceJars;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,17 +565,6 @@ public final class BuildLanguageOptions extends OptionsBase {
+ "returns a depset instead.")
public boolean incompatibleDepsetForLibrariesToLinkGetter;

@Option(
name = "incompatible_depset_for_java_output_source_jars",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.STARLARK_SEMANTICS,
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE},
help =
"When true, Bazel no longer returns a list from java_info.java_output[0].source_jars but "
+ "returns a depset instead.")
public boolean incompatibleDepsetForJavaOutputSourceJars;

@Option(
name = "incompatible_java_common_parameters",
defaultValue = "true",
Expand Down Expand Up @@ -805,9 +794,6 @@ public StarlarkSemantics toStarlarkSemantics() {
.setBool(
INCOMPATIBLE_DEPSET_FOR_LIBRARIES_TO_LINK_GETTER,
incompatibleDepsetForLibrariesToLinkGetter)
.setBool(
INCOMPATIBLE_DEPSET_FOR_JAVA_OUTPUT_SOURCE_JARS,
incompatibleDepsetForJavaOutputSourceJars)
.setBool(INCOMPATIBLE_REQUIRE_LINKER_INPUT_CC_API, incompatibleRequireLinkerInputCcApi)
.set(MAX_COMPUTATION_STEPS, maxComputationSteps)
.set(NESTED_SET_DEPTH_LIMIT, nestedSetDepthLimit)
Expand Down Expand Up @@ -880,8 +866,6 @@ public StarlarkSemantics toStarlarkSemantics() {
"+incompatible_always_check_depset_elements";
public static final String INCOMPATIBLE_DEPSET_FOR_LIBRARIES_TO_LINK_GETTER =
"+incompatible_depset_for_libraries_to_link_getter";
public static final String INCOMPATIBLE_DEPSET_FOR_JAVA_OUTPUT_SOURCE_JARS =
"+incompatible_depset_for_java_output_source_jars";
public static final String INCOMPATIBLE_DISABLE_TARGET_PROVIDER_FIELDS =
"-incompatible_disable_target_provider_fields";
public static final String INCOMPATIBLE_DISALLOW_EMPTY_GLOB = "-incompatible_disallow_empty_glob";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.packages.StructImpl;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
import com.google.devtools.build.lib.rules.java.JavaInfo.JavaInfoInternalProvider;
import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.JavaOutput;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant;
Expand All @@ -44,7 +43,6 @@
import net.starlark.java.eval.EvalException;
import net.starlark.java.eval.Sequence;
import net.starlark.java.eval.Starlark;
import net.starlark.java.eval.StarlarkList;
import net.starlark.java.eval.StarlarkSemantics;

/** Provides information about jar files produced by a Java rule. */
Expand Down Expand Up @@ -146,12 +144,8 @@ public ImmutableList<Artifact> getSourceJarsAsList() {

@Nullable
@Override
public Object getSrcJarsStarlark(StarlarkSemantics semantics) {
if (semantics.getBool(BuildLanguageOptions.INCOMPATIBLE_DEPSET_FOR_JAVA_OUTPUT_SOURCE_JARS)) {
return Depset.of(Artifact.class, getSourceJars());
} else {
return StarlarkList.immutableCopyOf(getSourceJarsAsList());
}
public Depset getSrcJarsStarlark(StarlarkSemantics semantics) {
return Depset.of(Artifact.class, getSourceJars());
}

public static JavaOutput fromStarlarkJavaOutput(StructImpl struct) throws EvalException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,6 @@ public boolean isLegacyGoogleApiEnabled(StarlarkThread thread) throws EvalExcept
return thread.getSemantics().getBool(BuildLanguageOptions.EXPERIMENTAL_GOOGLE_LEGACY_API);
}

@Override
public boolean isDepsetForJavaOutputSourceJarsEnabled(StarlarkThread thread)
throws EvalException {
checkPrivateAccess(thread);
return thread
.getSemantics()
.getBool(BuildLanguageOptions.INCOMPATIBLE_DEPSET_FOR_JAVA_OUTPUT_SOURCE_JARS);
}

@Override
public boolean isJavaInfoMergeRuntimeModuleFlagsEnabled(StarlarkThread thread)
throws EvalException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,12 +694,6 @@ void checkJavaToolchainIsDeclaredOnRuleForStarlark(
StarlarkActionFactoryT actions, StarlarkThread thread)
throws EvalException, LabelSyntaxException;

@StarlarkMethod(
name = "_incompatible_depset_for_java_output_source_jars",
documented = false,
useStarlarkThread = true)
boolean isDepsetForJavaOutputSourceJarsEnabled(StarlarkThread thread) throws EvalException;

@StarlarkMethod(
name = "_incompatible_java_info_merge_runtime_module_flags",
documented = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.devtools.build.lib.starlarkbuildapi.java;

import com.google.devtools.build.lib.collect.nestedset.Depset;
import com.google.devtools.build.lib.starlarkbuildapi.FileApi;
import com.google.devtools.build.lib.starlarkbuildapi.core.StructApi;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -116,7 +117,7 @@ public interface JavaOutputApi<FileT extends FileApi> extends StructApi {
useStarlarkSemantics = true,
structField = true)
@Nullable
Object getSrcJarsStarlark(StarlarkSemantics semantics);
Depset getSrcJarsStarlark(StarlarkSemantics semantics);

@Override
default String toProto() throws EvalException {
Expand Down
2 changes: 1 addition & 1 deletion src/main/starlark/builtins_bzl/common/java/java_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def _javainfo_init_base(
native_headers_jar = native_headers_jar,
manifest_proto = manifest_proto,
jdeps = jdeps,
source_jars = depset(source_jars) if _java_common_internal._incompatible_depset_for_java_output_source_jars() else source_jars,
source_jars = depset(source_jars),
source_jar = source_jar, # deprecated
)]
result = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -983,39 +983,8 @@ public void starlarkJavaOutputsCanBeAddedToJavaPluginInfo() throws Exception {
assertThat(pluginInfo.getJavaOutputs().get(0).getClassJar()).isEqualTo(classJar);
}

@Test
public void javaOutputSourceJarsReturnsListWithIncompatibleFlagDisabled() throws Exception {
setBuildLanguageOptions("--noincompatible_depset_for_java_output_source_jars");
scratch.file(
"foo/extension.bzl",
"MyInfo = provider()",
"",
"def _impl(ctx):",
" return MyInfo(source_jars = ctx.attr.dep[JavaInfo].java_outputs[0].source_jars)",
"",
"my_rule = rule(",
" implementation = _impl,",
" attrs = {'dep' : attr.label()}",
")");
scratch.file(
"foo/BUILD",
"load(':extension.bzl', 'my_rule')",
"java_library(name = 'lib')",
"my_rule(name = 'my_starlark_rule', dep = ':lib')");

ConfiguredTarget target = getConfiguredTarget("//foo:my_starlark_rule");

StarlarkInfo info =
(StarlarkInfo)
target.get(
new StarlarkProvider.Key(Label.parseCanonical("//foo:extension.bzl"), "MyInfo"));
assertThat(info).isNotNull();
assertThat(info.getValue("source_jars")).isInstanceOf(StarlarkList.class);
}

@Test
public void javaOutputSourceJarsReturnsDepsetWithIncompatibleFlagEnabled() throws Exception {
setBuildLanguageOptions("--incompatible_depset_for_java_output_source_jars");
scratch.file(
"foo/extension.bzl",
"MyInfo = provider()",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3612,7 +3612,6 @@ public void testNoArgsPrivateAPIsAreIndeedPrivate(String module, String api) thr
"{api: check_provider_instances}",
"{api: _google_legacy_api_enabled}",
"{api: _check_java_toolchain_is_declared_on_rule}",
"{api: _incompatible_depset_for_java_output_source_jars}",
"{api: wrap_java_info}",
"{api: intern_javac_opts}",
})
Expand Down

0 comments on commit 106aec6

Please sign in to comment.