aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar cushon <cushon@google.com>2018-03-28 08:23:33 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-28 08:25:27 -0700
commit1e00497c61323d1b7f0992b21887474283ebe0cb (patch)
tree7ed8a5e406ab21fbd7aead63544c31130a44e8c9
parentb0440164eda858fa0e14f623780a00b30e20ebf7 (diff)
Add a skylark-compatible alternative to MessageBundleProvider
PiperOrigin-RevId: 190775527
-rw-r--r--src/main/java/com/google/devtools/build/lib/BUILD2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java15
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/MessageBundleInfo.java86
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/MessageBundleProvider.java38
4 files changed, 95 insertions, 46 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD
index 46e523d728..ae9db41e53 100644
--- a/src/main/java/com/google/devtools/build/lib/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/BUILD
@@ -964,7 +964,7 @@ java_library(
"rules/java/JavaTargetAttributes.java",
"rules/java/JavaToolchainProvider.java",
"rules/java/JavaUtil.java",
- "rules/java/MessageBundleProvider.java",
+ "rules/java/MessageBundleInfo.java",
"rules/java/NativeLibraryNestedSetBuilder.java",
"rules/java/OneVersionCheckActionBuilder.java",
"rules/java/ProtoJavaApiInfoAspectProvider.java",
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 4774ef895b..3b34318e64 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
@@ -746,14 +746,15 @@ public class JavaCommon {
javaInfoBuilder.addProvider(JavaGenJarsProvider.class, genJarsProvider);
}
- /**
- * Processes the sources of this target, adding them as messages or proper
- * sources.
- */
+ /** Processes the sources of this target, adding them as messages or proper sources. */
private void processSrcs(JavaTargetAttributes.Builder attributes) {
- for (MessageBundleProvider srcItem : ruleContext.getPrerequisites(
- "srcs", Mode.TARGET, MessageBundleProvider.class)) {
- attributes.addMessages(srcItem.getMessages());
+ List<? extends TransitiveInfoCollection> srcs =
+ ruleContext.getPrerequisites("srcs", Mode.TARGET);
+ for (TransitiveInfoCollection src : srcs) {
+ ImmutableList<Artifact> messages = MessageBundleInfo.getMessages(src);
+ if (messages != null) {
+ attributes.addMessages(messages);
+ }
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/MessageBundleInfo.java b/src/main/java/com/google/devtools/build/lib/rules/java/MessageBundleInfo.java
new file mode 100644
index 0000000000..793ed26a04
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/MessageBundleInfo.java
@@ -0,0 +1,86 @@
+// 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.common.collect.ImmutableList;
+import com.google.devtools.build.lib.actions.Artifact;
+import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
+import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.events.Location;
+import com.google.devtools.build.lib.packages.NativeInfo;
+import com.google.devtools.build.lib.packages.NativeProvider;
+import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
+import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
+import com.google.devtools.build.lib.syntax.FunctionSignature;
+import com.google.devtools.build.lib.syntax.SkylarkList;
+import com.google.devtools.build.lib.syntax.SkylarkType;
+import javax.annotation.Nullable;
+
+/** Marks configured targets that are able to supply message bundles to their dependents. */
+@AutoCodec
+@Immutable
+public final class MessageBundleInfo extends NativeInfo {
+
+ public static final String SKYLARK_NAME = "MessageBundleInfo";
+
+ private static final SkylarkType LIST_OF_ARTIFACTS =
+ SkylarkType.Combination.of(SkylarkType.SEQUENCE, SkylarkType.of(Artifact.class));
+
+ private static final FunctionSignature.WithValues<Object, SkylarkType> SIGNATURE =
+ FunctionSignature.WithValues.create(
+ FunctionSignature.namedOnly("messages"),
+ /*defaultValues=*/ null,
+ /*types=*/ ImmutableList.of(LIST_OF_ARTIFACTS));
+
+ public static final NativeProvider<MessageBundleInfo> PROVIDER =
+ new NativeProvider<MessageBundleInfo>(MessageBundleInfo.class, SKYLARK_NAME, SIGNATURE) {
+ @Override
+ @SuppressWarnings("unchecked")
+ protected MessageBundleInfo createInstanceFromSkylark(Object[] args, Location loc) {
+ return new MessageBundleInfo(ImmutableList.copyOf((SkylarkList<Artifact>) args[0]), loc);
+ }
+ };
+
+ private final ImmutableList<Artifact> messages;
+
+ public static MessageBundleInfo create(ImmutableList<Artifact> messages) {
+ return new MessageBundleInfo(messages, null);
+ }
+
+ @VisibleForSerialization
+ @AutoCodec.Instantiator
+ MessageBundleInfo(ImmutableList<Artifact> messages, Location location) {
+ super(PROVIDER, location);
+ this.messages = ImmutableList.copyOf(messages);
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+
+ public ImmutableList<Artifact> getMessages() {
+ return messages;
+ }
+
+ @Nullable
+ public static ImmutableList<Artifact> getMessages(TransitiveInfoCollection info) {
+ MessageBundleInfo messageBundleInfo =
+ (MessageBundleInfo) info.get(MessageBundleInfo.PROVIDER.getKey());
+ if (messageBundleInfo != null) {
+ return messageBundleInfo.getMessages();
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/MessageBundleProvider.java b/src/main/java/com/google/devtools/build/lib/rules/java/MessageBundleProvider.java
deleted file mode 100644
index 284e03ec1a..0000000000
--- a/src/main/java/com/google/devtools/build/lib/rules/java/MessageBundleProvider.java
+++ /dev/null
@@ -1,38 +0,0 @@
-// 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.ImmutableList;
-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 com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
-
-/** Marks configured targets that are able to supply message bundles to their dependents. */
-@AutoCodec
-@AutoValue
-@Immutable
-public abstract class MessageBundleProvider implements TransitiveInfoProvider {
- @AutoCodec.Instantiator
- public static MessageBundleProvider create(ImmutableList<Artifact> messages) {
- return new AutoValue_MessageBundleProvider(messages);
- }
-
- /** The set of XML source files containing the message definitions. */
- public abstract ImmutableList<Artifact> getMessages();
-
- MessageBundleProvider() {}
-}