diff options
author | tomlu <tomlu@google.com> | 2018-05-23 08:02:04 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-05-23 08:03:54 -0700 |
commit | b8c51205bfd91fdeb98f7879bda05f0c53b58e0b (patch) | |
tree | 0cbd362d968816023079020b8c9f07eabe7030a7 /src/main/java/com/google/devtools/build | |
parent | 24be509e3a40a0ac661edaf825f6dcd5d9a94d47 (diff) |
Rollforward of CL/197136304:
Remove java support from proto_library.
NEW: Allow java_* rules to depend on proto_libraries via runtime_deps and exports. This should avoid the breakage that caused the original rollback. The edges are no-ops and could be removed.
*** Reason for rollback ***
Targets in the repository are still able to depend on proto_library rules
even after the --noemit_proto_java_outputs flag flip. Removal of the Java
support from proto_library breaks them.
PiperOrigin-RevId: 197725926
Diffstat (limited to 'src/main/java/com/google/devtools/build')
6 files changed, 0 insertions, 138 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD index a1541bf70b..3704699f2d 100644 --- a/src/main/java/com/google/devtools/build/lib/BUILD +++ b/src/main/java/com/google/devtools/build/lib/BUILD @@ -911,7 +911,6 @@ java_library( "rules/java/ProguardSpecProvider.java", "rules/java/ProtoJavaApiInfoAspectProvider.java", "rules/java/ProtoJavaApiInfoProvider.java", - "rules/java/proto/ActionReuser.java", "rules/java/proto/JavaLiteProtoAspect.java", "rules/java/proto/JavaLiteProtoLibrary.java", "rules/java/proto/JavaProtoAspect.java", diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java index 4d95e44430..a634a10eed 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java @@ -74,7 +74,6 @@ import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.PathFragment; import java.io.File; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import javax.annotation.Nullable; @@ -120,10 +119,6 @@ public class BazelJavaSemantics implements JavaSemantics { public void checkForProtoLibraryAndJavaProtoLibraryOnSameProto( RuleContext ruleContext, JavaCommon javaCommon) {} - @Override - public void checkProtoDeps( - RuleContext ruleContext, Collection<? extends TransitiveInfoCollection> deps) {} - private static final String JUNIT4_RUNNER = "org.junit.runner.JUnitCore"; @Nullable diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java index a7d80cc300..66f584428a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java @@ -627,8 +627,6 @@ public class JavaCommon { javaTargetAttributes.addSourceArtifacts(extraSrcs); processRuntimeDeps(javaTargetAttributes); - semantics.checkProtoDeps(ruleContext, targetsTreatedAsDeps(ClasspathType.BOTH)); - if (disallowDepsWithoutSrcs(ruleContext.getRule().getRuleClass()) && ruleContext.attributes().get("srcs", BuildType.LABEL_LIST).isEmpty() && ruleContext.getRule().isAttributeValueExplicitlySpecified("deps")) { diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaSemantics.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaSemantics.java index a95e338b7c..90972d2315 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaSemantics.java @@ -47,7 +47,6 @@ import com.google.devtools.build.lib.util.FileType; import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.vfs.PathFragment; import java.io.File; -import java.util.Collection; import java.util.List; import java.util.stream.Collectors; import javax.annotation.Nullable; @@ -256,8 +255,6 @@ public interface JavaSemantics { void checkForProtoLibraryAndJavaProtoLibraryOnSameProto( RuleContext ruleContext, JavaCommon javaCommon); - void checkProtoDeps(RuleContext ruleContext, Collection<? extends TransitiveInfoCollection> deps); - /** * Returns the main class of a Java binary. */ diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/ActionReuser.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/ActionReuser.java deleted file mode 100644 index 8f4479eecb..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/ActionReuser.java +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2017 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.proto; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.getOnlyElement; -import static com.google.common.collect.Iterables.isEmpty; -import static com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode.TARGET; -import static com.google.devtools.build.lib.rules.java.JavaCompilationArgs.ClasspathType.BOTH; -import static com.google.devtools.build.lib.rules.java.proto.JplCcLinkParams.createCcLinkParamsStore; -import static com.google.devtools.build.lib.rules.java.proto.StrictDepsUtils.createNonStrictCompilationArgsProvider; - -import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.ConfiguredAspect; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.TransitiveInfoProviderMap; -import com.google.devtools.build.lib.analysis.TransitiveInfoProviderMapBuilder; -import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.collect.nestedset.Order; -import com.google.devtools.build.lib.rules.java.JavaCompilationArgs; -import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider; -import com.google.devtools.build.lib.rules.java.JavaCompilationArtifacts; -import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider; -import com.google.devtools.build.lib.rules.java.JavaSkylarkApiProvider; -import com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider; -import com.google.devtools.build.lib.rules.java.ProtoJavaApiInfoProvider; - -public class ActionReuser { - - /** - * If the underlying proto_library rule already registers the compile actions we need, just reuse - * them. This will preserve memory. - * - * <p>TODO(b/36191931): Delete when it's time. - */ - public static boolean reuseExistingActions( - ConfiguredTarget base, RuleContext ruleContext, ConfiguredAspect.Builder aspect) { - ProtoJavaApiInfoProvider javaApi = base.getProvider(ProtoJavaApiInfoProvider.class); - if (javaApi == null) { - return false; - } - - JavaCompilationArtifacts directJars = javaApi.getJavaCompilationArtifactsImmutable(); - if (isEmpty(directJars.getCompileTimeJars()) || javaApi.sourceJarImmutable() == null) { - return false; - } - - JavaCompilationArgs.Builder transitiveJars = - JavaCompilationArgs.builder() - .addTransitiveArgs(javaApi.getTransitiveJavaCompilationArgsImmutable(), BOTH) - .addTransitiveArgs(javaApi.getTransitiveProtoRuntimeImmutable(), BOTH) - .merge(directJars); - - Artifact outputJar = getOnlyElement(directJars.getRuntimeJars()); - Artifact compileTimeJar = getOnlyElement(directJars.getCompileTimeJars()); - Artifact sourceJar = checkNotNull(javaApi.sourceJarImmutable()); - - JavaCompilationArgsProvider compilationArgsProvider = - JavaCompilationArgsProvider.create( - JavaCompilationArgs.builder().merge(directJars).build(), - transitiveJars.build(), - NestedSetBuilder.create( - Order.STABLE_ORDER, directJars.getCompileTimeDependencyArtifact())); - - TransitiveInfoProviderMapBuilder javaProvidersBuilder = - new TransitiveInfoProviderMapBuilder() - .add(createOutputJarProvider(outputJar, compileTimeJar, sourceJar)) - .add(createSrcJarProvider(sourceJar)) - .add(compilationArgsProvider) - .add(createCcLinkParamsStore(ruleContext, javaApi.getProtoRuntimeImmutable())); - - Iterable<JavaProtoLibraryAspectProvider> javaProtoLibraryAspectProviders = - ruleContext.getPrerequisites("deps", TARGET, JavaProtoLibraryAspectProvider.class); - - NestedSetBuilder<Artifact> transitiveOutputJars = NestedSetBuilder.stableOrder(); - for (JavaProtoLibraryAspectProvider provider : javaProtoLibraryAspectProviders) { - transitiveOutputJars.addTransitive(provider.getJars()); - } - transitiveOutputJars.add(outputJar); - - TransitiveInfoProviderMap javaProviders = javaProvidersBuilder.build(); - aspect - .addSkylarkTransitiveInfo( - JavaSkylarkApiProvider.PROTO_NAME.getLegacyId(), - JavaSkylarkApiProvider.fromProviderMap(javaProviders)) - .addProviders( - new JavaProtoLibraryAspectProvider( - javaProviders, - transitiveOutputJars.build(), - createNonStrictCompilationArgsProvider( - javaProtoLibraryAspectProviders, - compilationArgsProvider, - javaApi.getProtoRuntimeImmutable()))); - return true; - } - - private static JavaRuleOutputJarsProvider createOutputJarProvider( - Artifact outputJar, Artifact compileTimeJar, Artifact sourceJar) { - return JavaRuleOutputJarsProvider.builder() - .addOutputJar(outputJar, compileTimeJar, ImmutableList.of(sourceJar)) - .build(); - } - - private static JavaSourceJarsProvider createSrcJarProvider(Artifact sourceJar) { - return JavaSourceJarsProvider.create( - NestedSetBuilder.emptySet(Order.STABLE_ORDER), - NestedSetBuilder.<Artifact>stableOrder().add(sourceJar).build()); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java index 4a4eab01e0..0e59ce8367 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java @@ -106,10 +106,6 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe JavaProtoAspectCommon aspectCommon = JavaProtoAspectCommon.getSpeedInstance(ruleContext, javaSemantics, rpcSupport); Impl impl = new Impl(ruleContext, supportData, aspectCommon, rpcSupport); - if (impl.shouldGenerateCode() - && ActionReuser.reuseExistingActions(ctadBase.getConfiguredTarget(), ruleContext, aspect)) { - return aspect.build(); - } impl.addProviders(aspect); return aspect.build(); } |