From f2ad683c0873991fd1cbca0fe32b7c81fdc9d26a Mon Sep 17 00:00:00 2001 From: Carmi Grushko Date: Thu, 3 Nov 2016 18:34:58 +0000 Subject: Make ProtoSourceFileBlacklist take an explicit list of .proto files to blacklist. This is intead of taking an attribute name and reading it inside of the class. Motivation: using proto_lang_toolchain() rules means there's no longer an attribute that points at the blacklist. Instead, we have an attribute that points at the toolchain, which itself points at the blacklist. -- MOS_MIGRATED_REVID=138096096 --- .../build/lib/rules/java/proto/JavaProtoAspect.java | 6 +++++- .../build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java | 6 +++++- .../devtools/build/lib/rules/objc/ProtoAttributes.java | 4 ++-- .../build/lib/rules/proto/ProtoSourceFileBlacklist.java | 15 +++------------ 4 files changed, 15 insertions(+), 16 deletions(-) (limited to 'src/main/java') 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 b4bcb8bada..daa56daa12 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 @@ -252,7 +252,11 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe } ProtoSourceFileBlacklist protoBlackList = - new ProtoSourceFileBlacklist(ruleContext, PROTO_SOURCE_FILE_BLACKLIST_ATTR); + new ProtoSourceFileBlacklist( + ruleContext, + ruleContext + .getPrerequisiteArtifacts(PROTO_SOURCE_FILE_BLACKLIST_ATTR, Mode.HOST) + .list()); return protoBlackList.checkSrcs(supportData.getDirectProtoSources(), "java_proto_library"); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java index 0c80f2779a..560051505f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AbstractJ2ObjcProtoAspect.java @@ -132,7 +132,11 @@ public abstract class AbstractJ2ObjcProtoAspect extends NativeAspectClass // Avoid pulling in any generated files from blacklisted protos. ProtoSourceFileBlacklist protoBlacklist = - new ProtoSourceFileBlacklist(ruleContext, PROTO_SOURCE_FILE_BLACKLIST_ATTR); + new ProtoSourceFileBlacklist( + ruleContext, + ruleContext + .getPrerequisiteArtifacts(PROTO_SOURCE_FILE_BLACKLIST_ATTR, Mode.HOST) + .list()); ImmutableList filteredProtoSources = ImmutableList.copyOf( protoBlacklist.filter(protoSources)); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ProtoAttributes.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ProtoAttributes.java index 6b5c42101a..25f1469dbf 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ProtoAttributes.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ProtoAttributes.java @@ -228,14 +228,14 @@ final class ProtoAttributes { */ Iterable filterWellKnownProtos(Iterable protoFiles) { ProtoSourceFileBlacklist wellKnownProtoBlacklist = - new ProtoSourceFileBlacklist(ruleContext, ObjcRuleClasses.PROTOBUF_WELL_KNOWN_TYPES); + new ProtoSourceFileBlacklist(ruleContext, getWellKnownTypeProtos()); return wellKnownProtoBlacklist.filter(protoFiles); } /** Returns whether the given proto is a well known proto or not. */ boolean isProtoWellKnown(Artifact protoFile) { ProtoSourceFileBlacklist wellKnownProtoBlacklist = - new ProtoSourceFileBlacklist(ruleContext, ObjcRuleClasses.PROTOBUF_WELL_KNOWN_TYPES); + new ProtoSourceFileBlacklist(ruleContext, getWellKnownTypeProtos()); return wellKnownProtoBlacklist.isBlacklisted(protoFile); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSourceFileBlacklist.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSourceFileBlacklist.java index f324ce5fb3..6ba951753d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSourceFileBlacklist.java +++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSourceFileBlacklist.java @@ -25,7 +25,6 @@ import com.google.common.base.Predicates; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.packages.Attribute; @@ -56,14 +55,13 @@ public class ProtoSourceFileBlacklist { /** * Creates a proto source file blacklist. + * * @param ruleContext the proto rule context. - * @param blacklistAttribute the attribute that points to a filegroup containing the blacklisted + * @param blacklistProtoFiles a list of blacklisted .proto files. The list will be iterated. * protos. */ - public ProtoSourceFileBlacklist(RuleContext ruleContext, String blacklistAttribute) { + public ProtoSourceFileBlacklist(RuleContext ruleContext, Iterable blacklistProtoFiles) { this.ruleContext = ruleContext; - Iterable blacklistProtoFiles = - ruleContext.getPrerequisiteArtifacts(blacklistAttribute, Mode.HOST).list(); ImmutableSet.Builder blacklistProtoFilePathsBuilder = new ImmutableSet.Builder<>(); for (Artifact blacklistProtoFile : blacklistProtoFiles) { @@ -118,13 +116,6 @@ public class ProtoSourceFileBlacklist { return blacklisted.isEmpty(); } - /** - * Returns blacklisted protos from the given protos. - */ - private Iterable blacklisted(Iterable protoFiles) { - return ImmutableSet.copyOf(Iterables.filter(protoFiles, isBlacklistProto)); - } - /** * Returns whether the given proto file is blacklisted. */ -- cgit v1.2.3