Fixes bug where using portable_proto_filters along with proto files in deps (as oposed to proto_library targets) would result in a crash.
MOS_MIGRATED_REVID=145283582
@@ -49,6 +49,11 @@ final class ProtoAttributes {
private static final ImmutableSet<String> UPPERCASE_SEGMENTS =
ImmutableSet.of("url", "http", "https");
+ @VisibleForTesting
+ static final String FILES_NOT_ALLOWED_ERROR =
+ "Using files and filegroups in objc_proto_library with portable_proto_filters is not "
+ + "allowed. Please wrap the files inside a proto_library target.";
+
@VisibleForTesting
static final String FILES_DEPRECATED_WARNING =
"Using files and filegroups in objc_proto_library is deprecated";
@@ -104,13 +109,13 @@ final class ProtoAttributes {
PrerequisiteArtifacts prerequisiteArtifacts =
ruleContext.getPrerequisiteArtifacts("deps", Mode.TARGET);
ImmutableList<Artifact> protos = prerequisiteArtifacts.filter(FileType.of(".proto")).list();
- if (!protos.isEmpty()) {
- ruleContext.attributeWarning("deps", FILES_DEPRECATED_WARNING);
- }
if (ruleContext
.attributes()
.isAttributeValueExplicitlySpecified(ObjcProtoLibraryRule.PORTABLE_PROTO_FILTERS_ATTR)) {
+ if (!protos.isEmpty()) {
+ ruleContext.throwWithAttributeError("deps", FILES_NOT_ALLOWED_ERROR);
+ }
if (getProtoFiles().isEmpty() && !hasObjcProtoLibraryDependencies()) {
ruleContext.throwWithRuleError(NO_PROTOS_ERROR);
}
@@ -129,6 +134,9 @@ final class ProtoAttributes {
}
} else {
+ if (!protos.isEmpty()) {
+ ruleContext.attributeWarning("deps", FILES_DEPRECATED_WARNING);
+ }
if (getProtoFiles().isEmpty()) {
ruleContext.throwWithRuleError(NO_PROTOS_ERROR);
}
