diff options
author | Irina Iancu <elenairina@google.com> | 2017-02-23 10:47:58 +0000 |
---|---|---|
committer | Yue Gan <yueg@google.com> | 2017-02-23 11:33:51 +0000 |
commit | 10390f2dac277baeaaff48fbfd663ce687ec92e1 (patch) | |
tree | 1b9aa5f2fbdcb2527c1b22ad5a204ebc28e29f7c /src/main/java/com/google/devtools/build/lib/rules | |
parent | 57784449266907508de1f23e7c72f5b633c9bd76 (diff) |
Add ProtoJavaApiInfoAspectProvider to JavaProvider.
Also moved ProtoJavaApiInfo*Provider to package
com.google.devtools.build.lib.rules.java to avoid a dependency cycle.
--
PiperOrigin-RevId: 148324664
MOS_MIGRATED_REVID=148324664
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules')
4 files changed, 240 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java index 050aeca6d7..b9fcd8da27 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibrary.java @@ -21,6 +21,7 @@ import com.google.devtools.build.lib.analysis.OutputGroupProvider; import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.RunfilesProvider; +import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; @@ -153,6 +154,16 @@ public class JavaLibrary implements RuleConfiguredTargetFactory { } }; + ProtoJavaApiInfoAspectProvider.Builder protoAspectBuilder = + ProtoJavaApiInfoAspectProvider.builder(); + for (TransitiveInfoCollection dep : common.getDependencies()) { + ProtoJavaApiInfoAspectProvider protoProvider = + JavaProvider.getProvider(ProtoJavaApiInfoAspectProvider.class, dep); + if (protoProvider != null) { + protoAspectBuilder.addTransitive(protoProvider); + } + } + RuleConfiguredTargetBuilder builder = new RuleConfiguredTargetBuilder(ruleContext); @@ -188,6 +199,7 @@ public class JavaLibrary implements RuleConfiguredTargetFactory { JavaProvider javaProvider = JavaProvider.Builder.create() .addProvider(JavaCompilationArgsProvider.class, compilationArgsProvider) .addProvider(JavaSourceJarsProvider.class, sourceJarsProvider) + .addProvider(ProtoJavaApiInfoAspectProvider.class, protoAspectBuilder.build()) .build(); builder .addSkylarkTransitiveInfo(JavaSkylarkApiProvider.NAME, skylarkApiProvider.build()) diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaProvider.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaProvider.java index 434cf2ac70..d4b2b997b3 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaProvider.java @@ -39,7 +39,8 @@ public final class JavaProvider extends SkylarkClassObject implements Transitive private static final Set<Class<? extends TransitiveInfoProvider>> ALLOWED_PROVIDERS = ImmutableSet.of( JavaCompilationArgsProvider.class, - JavaSourceJarsProvider.class); + JavaSourceJarsProvider.class, + ProtoJavaApiInfoAspectProvider.class); private final TransitiveInfoProviderMap providers; @@ -63,6 +64,8 @@ public final class JavaProvider extends SkylarkClassObject implements Transitive JavaProvider.fetchProvidersFromList(providers, JavaCompilationArgsProvider.class); List<JavaSourceJarsProvider> javaSourceJarsProviders = JavaProvider.fetchProvidersFromList(providers, JavaSourceJarsProvider.class); + List<ProtoJavaApiInfoAspectProvider> protoJavaApiInfoAspectProviders = + JavaProvider.fetchProvidersFromList(providers, ProtoJavaApiInfoAspectProvider.class); return JavaProvider.Builder.create() .addProvider( @@ -70,6 +73,9 @@ public final class JavaProvider extends SkylarkClassObject implements Transitive JavaCompilationArgsProvider.merge(javaCompilationArgsProviders)) .addProvider( JavaSourceJarsProvider.class, JavaSourceJarsProvider.merge(javaSourceJarsProviders)) + .addProvider( + ProtoJavaApiInfoAspectProvider.class, + ProtoJavaApiInfoAspectProvider.merge(protoJavaApiInfoAspectProviders)) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/ProtoJavaApiInfoAspectProvider.java b/src/main/java/com/google/devtools/build/lib/rules/java/ProtoJavaApiInfoAspectProvider.java new file mode 100644 index 0000000000..764a6bc006 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/java/ProtoJavaApiInfoAspectProvider.java @@ -0,0 +1,70 @@ +// Copyright 2014 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.rules.java; + +import com.google.auto.value.AutoValue; +import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; +import com.google.devtools.build.lib.collect.nestedset.NestedSet; +import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; +import javax.annotation.concurrent.Immutable; + +/** + * A {@link TransitiveInfoProvider} that aggregates {@link ProtoJavaApiInfoProvider} for propogation + * in an aspect. + */ +@Immutable +@AutoValue +public abstract class ProtoJavaApiInfoAspectProvider implements TransitiveInfoProvider { + + public static Builder builder() { + return new AutoValue_ProtoJavaApiInfoAspectProvider.Builder(); + } + + public static ProtoJavaApiInfoAspectProvider merge( + Iterable<ProtoJavaApiInfoAspectProvider> providers) { + ProtoJavaApiInfoAspectProvider.Builder protoBuilder = ProtoJavaApiInfoAspectProvider.builder(); + for (ProtoJavaApiInfoAspectProvider provider : providers) { + protoBuilder.addTransitive(provider); + } + return protoBuilder.build(); + } + + public abstract NestedSet<ProtoJavaApiInfoProvider> getProviders(); + + /** A builder for {@link ProtoJavaApiInfoProvider}. */ + @AutoValue.Builder + public abstract static class Builder { + + private final NestedSetBuilder<ProtoJavaApiInfoProvider> providers = + NestedSetBuilder.stableOrder(); + + public Builder add(ProtoJavaApiInfoProvider provider) { + providers.add(provider); + return this; + } + + public Builder addTransitive(ProtoJavaApiInfoAspectProvider provider) { + providers.addTransitive(provider.getProviders()); + return this; + } + + abstract Builder setProviders(NestedSet<ProtoJavaApiInfoProvider> providers); + + abstract ProtoJavaApiInfoAspectProvider autoBuild(); + + public ProtoJavaApiInfoAspectProvider build() { + return setProviders(providers.build()).autoBuild(); + } + } +} diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/ProtoJavaApiInfoProvider.java b/src/main/java/com/google/devtools/build/lib/rules/java/ProtoJavaApiInfoProvider.java new file mode 100644 index 0000000000..b43c112960 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/java/ProtoJavaApiInfoProvider.java @@ -0,0 +1,151 @@ +// Copyright 2014 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.rules.java; + +import com.google.auto.value.AutoValue; +import com.google.common.collect.ImmutableMap; +import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; +import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; +import java.util.Map; + +/** + * An object that provides information about API versions used by a proto library. + */ +@Immutable +@AutoValue +public abstract class ProtoJavaApiInfoProvider implements TransitiveInfoProvider { + + public static ProtoJavaApiInfoProvider create( + JavaCompilationArgs javaCompilationContext, + JavaCompilationArgs transitiveJavaCompilationArgs, + JavaCompilationArgs transitiveJavaRpcLibs, + JavaCompilationArgs transitiveJavaCompilationArgss1, + JavaCompilationArgs transitiveJavaCompilationArgssMutable, + JavaCompilationArgs transitiveJavaCompilationArgssImmutable, + JavaCompilationArgs javaCompilationArgs1, + JavaCompilationArgs javaCompilationArgsMutable, + JavaCompilationArgs javaCompilationArgsImmutable, + Map<Artifact, Artifact> compileTimeJarToRuntimeJar, + boolean mixedApiVersions, + int apiVersion, + boolean supportsProto1, + boolean supportsProto2Mutable, + boolean hasProto1OnlyDependency) { + return new AutoValue_ProtoJavaApiInfoProvider( + javaCompilationContext, + transitiveJavaCompilationArgs, + transitiveJavaRpcLibs, + transitiveJavaCompilationArgss1, + transitiveJavaCompilationArgssMutable, + transitiveJavaCompilationArgssImmutable, + javaCompilationArgs1, + javaCompilationArgsMutable, + javaCompilationArgsImmutable, + mixedApiVersions, + apiVersion, + supportsProto1, + supportsProto2Mutable, + hasProto1OnlyDependency, + ImmutableMap.copyOf(compileTimeJarToRuntimeJar)); + } + + /** + * Returns the Java artifacts created for this target. This method should only be called on + * recursive visitations if {@code hasProtoLibraryShellInDeps()} returns {@code false}. + */ + // TODO(bazel-team): this is mostly used by the tests + public abstract JavaCompilationArgs getJavaCompilationContext(); + + /** + * Returns the the transitive Java artifacts created for this target. + */ + // TODO(bazel-team): this is mostly used by the tests + public abstract JavaCompilationArgs getTransitiveJavaCompilationArgs(); + + /** + * Returns the Java RPC library if any dependencies need it, null otherwise. + */ + public abstract JavaCompilationArgs getTransitiveJavaRpcLibs(); + + /** + * Returns the artifacts for java compilation (API version 1) from the transitive + * closure (excluding this target). + */ + public abstract JavaCompilationArgs getTransitiveJavaCompilationArgs1(); + + /** + * Returns the artifacts for java compilation (API version 2, code for mutable API) + * from the transitive closure (excluding this target). + */ + public abstract JavaCompilationArgs getTransitiveJavaCompilationArgsMutable(); + + /** + * Returns the artifacts for java compilation (API version 2, code for immutable API) + * from the transitive closure (excluding this target). + */ + public abstract JavaCompilationArgs getTransitiveJavaCompilationArgsImmutable(); + + /** + * Returns the artifacts for java compilation (API version 1) for only this target. + */ + public abstract JavaCompilationArgs getJavaCompilationArgs1(); + + /** + * Returns the artifacts for java compilation (API version 2, code for mutable API) + * for only this target. + */ + public abstract JavaCompilationArgs getJavaCompilationArgsMutable(); + + /** + * Returns the artifacts for java compilation (API version 2, code for immutable API) + * for only this target. + */ + public abstract JavaCompilationArgs getJavaCompilationArgsImmutable(); + + /** + * Returns true if the transitive closure contains libraries with API versions other than the one + * specified in this target. Building in mixed mode will add implicit deps for all the api_version + * and might generate adapter code that has some runtime overhead. + */ + public abstract boolean hasMixedApiVersions(); + + /** Returns the API version. */ + public abstract int getApiVersion(); + + /** + * Returns true if this target support proto1 API. + */ + public abstract boolean supportsProto1(); + + /** + * Returns true if this target support proto2 mutable API. + */ + public abstract boolean supportsProto2Mutable(); + + /** + * Returns true if this target has a dependency (can be recursively) that only + * supports proto1 API but not proto2 mutable API. + */ + public abstract boolean hasProto1OnlyDependency(); + + /** + * Returns the runtime jar artifact output created by this proto_libary rule. + */ + public Artifact getRuntimeJarFor(Artifact compileTimeJar) { + return getCompileTimeJarToRuntimeJar().get(compileTimeJar); + } + + abstract ImmutableMap<Artifact, Artifact> getCompileTimeJarToRuntimeJar(); +} |