Skip to content

Commit

Permalink
Fixes bug where using portable_proto_filters along with proto files i…
Browse files Browse the repository at this point in the history
…n deps (as oposed to proto_library targets) would result in a crash.

--
PiperOrigin-RevId: 145283582
MOS_MIGRATED_REVID=145283582
  • Loading branch information
sergiocampama authored and katre committed Jan 23, 2017
1 parent 50c13ce commit 3fc4410
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -104,13 +109,13 @@ public void validate() throws RuleErrorException {
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);
}
Expand All @@ -129,6 +134,9 @@ public void validate() throws RuleErrorException {
}

} else {
if (!protos.isEmpty()) {
ruleContext.attributeWarning("deps", FILES_DEPRECATED_WARNING);
}
if (getProtoFiles().isEmpty()) {
ruleContext.throwWithRuleError(NO_PROTOS_ERROR);
}
Expand Down

0 comments on commit 3fc4410

Please sign in to comment.