Skip to content

Commit

Permalink
Remove JavaStrictCompilationArgsProvider.
Browse files Browse the repository at this point in the history
The JavaStrictCompilationArgsProvider was introduced for a migration in times when a java_*_proto_library could be either strict/nonstrict. See unknown commit for migration plan.

With removal of special attribute on java_*_proto_library (attribute strict_deps, flag experimental_java_proto_library_enforce_strict_deps) and addition of a global configuration flag (experimental_jlpl_enforce_strict_deps), that only allows all such targets to be strict or non-strict, this can be merged into a single provider.

Note that most of java_* rules took strict version over non-strict, and generated identical strict/non-strict version of the provider. The last place where different providers are generated is java_lite_proto_library. The latter provides a non-strict using a custom provider JavaProtoLibraryAspectProvider)

PiperOrigin-RevId: 358784793
  • Loading branch information
comius authored and copybara-github committed Feb 22, 2021
1 parent 7a0f36e commit f40a89b
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ java_library(
"JavaSourceInfoProvider.java",
"JavaSourceJarsProvider.java",
"JavaStarlarkCommon.java",
"JavaStrictCompilationArgsProvider.java",
"JavaTargetAttributes.java",
"JavaToolchainProvider.java",
"JavaToolchainTool.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,6 @@ public static String javaLibraryPath(Collection<Artifact> sharedLibraries, Strin
*/
public JavaCompilationArgsProvider collectJavaCompilationArgs(
boolean isNeverLink, boolean srcLessDepsExport) {
return collectJavaCompilationArgs(
isNeverLink, srcLessDepsExport, /* javaProtoLibraryStrictDeps= */ false);
}

public JavaCompilationArgsProvider collectJavaCompilationArgs(
boolean isNeverLink, boolean srcLessDepsExport, boolean javaProtoLibraryStrictDeps) {
return collectJavaCompilationArgs(
/* isNeverLink= */ isNeverLink,
/* srcLessDepsExport= */ srcLessDepsExport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ public static JavaCompilationArgsProvider legacyFromTargets(
for (TransitiveInfoCollection info : infos) {
JavaCompilationArgsProvider provider = null;

JavaStrictCompilationArgsProvider strictCompilationArgsProvider =
JavaInfo.getProvider(JavaStrictCompilationArgsProvider.class, info);
if (strictCompilationArgsProvider != null) {
provider = strictCompilationArgsProvider.getJavaCompilationArgsProvider();
}
if (provider == null) {
provider = JavaInfo.getProvider(JavaCompilationArgsProvider.class, info);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ private static <T> T nullIfNone(Object object, Class<T> type) {
JavaGenJarsProvider.class,
JavaExportsProvider.class,
JavaCompilationInfoProvider.class,
JavaStrictCompilationArgsProvider.class,
JavaSourceInfoProvider.class);

private final TransitiveInfoProviderMap providers;
Expand Down Expand Up @@ -118,8 +117,6 @@ public TransitiveInfoProviderMap getProviders() {
public static JavaInfo merge(List<JavaInfo> providers) {
List<JavaCompilationArgsProvider> javaCompilationArgsProviders =
JavaInfo.fetchProvidersFromList(providers, JavaCompilationArgsProvider.class);
List<JavaStrictCompilationArgsProvider> javaStrictCompilationArgsProviders =
JavaInfo.fetchProvidersFromList(providers, JavaStrictCompilationArgsProvider.class);
List<JavaSourceJarsProvider> javaSourceJarsProviders =
JavaInfo.fetchProvidersFromList(providers, JavaSourceJarsProvider.class);
List<JavaPluginInfoProvider> javaPluginInfoProviders =
Expand All @@ -142,9 +139,6 @@ public static JavaInfo merge(List<JavaInfo> providers) {
.addProvider(
JavaCompilationArgsProvider.class,
JavaCompilationArgsProvider.merge(javaCompilationArgsProviders))
.addProvider(
JavaStrictCompilationArgsProvider.class,
JavaStrictCompilationArgsProvider.merge(javaStrictCompilationArgsProviders))
.addProvider(
JavaSourceJarsProvider.class, JavaSourceJarsProvider.merge(javaSourceJarsProviders))
.addProvider(
Expand Down Expand Up @@ -561,16 +555,6 @@ public <P extends TransitiveInfoProvider> Builder addProvider(
}

public JavaInfo build() {
// TODO(twerth): Clean up after we remove java_proto_library.strict_deps.
// Instead of teaching every (potential Starlark) caller to also create the provider for
// strict deps we wrap the non strict provider instead.
if (!providerMap.contains(JavaStrictCompilationArgsProvider.class)
&& providerMap.contains(JavaCompilationArgsProvider.class)) {
JavaStrictCompilationArgsProvider javaStrictCompilationArgsProvider =
new JavaStrictCompilationArgsProvider(
providerMap.getProvider(JavaCompilationArgsProvider.class));
addProvider(JavaStrictCompilationArgsProvider.class, javaStrictCompilationArgsProvider);
}
return new JavaInfo(
providerMap.build(),
runtimeJars,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,7 @@ final ConfiguredTarget init(
javaArtifacts, attributes, neverLink, helper.getBootclasspathOrDefault()));

JavaCompilationArgsProvider javaCompilationArgs =
common.collectJavaCompilationArgs(
neverLink, /* srcLessDepsExport= */ false, /* javaProtoLibraryStrictDeps= */ false);
JavaStrictCompilationArgsProvider strictJavaCompilationArgs =
new JavaStrictCompilationArgsProvider(
common.collectJavaCompilationArgs(
neverLink, /* srcLessDepsExport= */ false, /* javaProtoLibraryStrictDeps= */ true));
common.collectJavaCompilationArgs(neverLink, /* srcLessDepsExport= */ false);
NestedSet<LibraryToLink> transitiveJavaNativeLibraries =
common.collectTransitiveJavaNativeLibraries();

Expand Down Expand Up @@ -185,7 +180,6 @@ final ConfiguredTarget init(
JavaInfo javaInfo =
javaInfoBuilder
.addProvider(JavaCompilationArgsProvider.class, compilationArgsProvider)
.addProvider(JavaStrictCompilationArgsProvider.class, strictJavaCompilationArgs)
.addProvider(JavaSourceJarsProvider.class, sourceJarsProvider)
.addProvider(JavaRuleOutputJarsProvider.class, ruleOutputJarsProvider)
// TODO(bazel-team): this should only happen for java_plugin
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import com.google.devtools.build.lib.rules.java.JavaInfo;
import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider;
import com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider;
import com.google.devtools.build.lib.rules.java.JavaStrictCompilationArgsProvider;
import com.google.devtools.build.lib.rules.java.ProguardLibrary;
import com.google.devtools.build.lib.rules.java.ProguardSpecProvider;

Expand All @@ -59,7 +58,10 @@ public ConfiguredTarget create(final RuleContext ruleContext)
ruleContext.getPrerequisites("deps", JavaProtoLibraryAspectProvider.class);

JavaCompilationArgsProvider dependencyArgsProviders =
constructJcapFromAspectDeps(ruleContext, javaProtoLibraryAspectProviders);
constructJcapFromAspectDeps(
ruleContext,
javaProtoLibraryAspectProviders,
ruleContext.getFragment(JavaConfiguration.class).isJlplStrictDepsEnforced());

// We assume that the runtime jars will not have conflicting artifacts
// with the same root relative path
Expand All @@ -83,14 +85,6 @@ public ConfiguredTarget create(final RuleContext ruleContext)
JavaInfo.Builder javaInfoBuilder =
JavaInfo.Builder.create()
.addProvider(JavaCompilationArgsProvider.class, dependencyArgsProviders);
if (ruleContext.getFragment(JavaConfiguration.class).isJlplStrictDepsEnforced()) {
JavaStrictCompilationArgsProvider strictDependencyArgsProviders =
new JavaStrictCompilationArgsProvider(
constructJcapFromAspectDeps(
ruleContext, javaProtoLibraryAspectProviders, /* alwaysStrict= */ true));
javaInfoBuilder.addProvider(
JavaStrictCompilationArgsProvider.class, strictDependencyArgsProviders);
}
JavaInfo javaInfo =
javaInfoBuilder
.addProvider(JavaSourceJarsProvider.class, sourceJarsProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.google.devtools.build.lib.rules.java.JavaInfo;
import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider;
import com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider;
import com.google.devtools.build.lib.rules.java.JavaStrictCompilationArgsProvider;

/** Implementation of the java_proto_library rule. */
public class JavaProtoLibrary implements RuleConfiguredTargetFactory {
Expand All @@ -54,11 +53,8 @@ public ConfiguredTarget create(final RuleContext ruleContext)
ruleContext.getPrerequisites("deps", JavaProtoLibraryAspectProvider.class);

JavaCompilationArgsProvider dependencyArgsProviders =
constructJcapFromAspectDeps(ruleContext, javaProtoLibraryAspectProviders);
JavaStrictCompilationArgsProvider strictDependencyArgsProviders =
new JavaStrictCompilationArgsProvider(
constructJcapFromAspectDeps(
ruleContext, javaProtoLibraryAspectProviders, /* alwaysStrict= */ true));
constructJcapFromAspectDeps(
ruleContext, javaProtoLibraryAspectProviders, /* alwaysStrict= */ true);

// We assume that the runtime jars will not have conflicting artifacts
// with the same root relative path
Expand All @@ -82,7 +78,6 @@ public ConfiguredTarget create(final RuleContext ruleContext)
JavaInfo javaInfo =
JavaInfo.Builder.create()
.addProvider(JavaCompilationArgsProvider.class, dependencyArgsProviders)
.addProvider(JavaStrictCompilationArgsProvider.class, strictDependencyArgsProviders)
.addProvider(JavaSourceJarsProvider.class, sourceJarsProvider)
.addProvider(JavaRuleOutputJarsProvider.class, JavaRuleOutputJarsProvider.EMPTY)
.build();
Expand Down

0 comments on commit f40a89b

Please sign in to comment.