Skip to content

Commit

Permalink
Add flag --incompatible_blacklisted_protos_requires_proto_info
Browse files Browse the repository at this point in the history
This change adds a new incompatible flag that makes ProtoInfo mandatory
for skipping code-gen for some proto sources (e.g. WKPs that are already
provided by the proto runtime). Flipping this flag will allow us to get rid of
ProtoInfo#getOriginal{Direct,Transitive}ProtoSources().

https://docs.google.com/document/d/1UmF_P4NDVl6Nw4JsHoHYp74iCdEQNh1O3-SVAX1CdjU/edit#

RELNOTES: Adds --incompatible_blacklisted_protos_requires_proto_info to indicate whether proto_lang_toolchain.blacklisted_protos requires ProtoInfo.

Closes #11617.

PiperOrigin-RevId: 319386644
  • Loading branch information
Yannic authored and copybara-github committed Jul 2, 2020
1 parent ea6e9ee commit c01c1f1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ public static class Options extends FragmentOptions {
+ "the Starlark rules instead at https://github.com/bazelbuild/rules_proto")
public boolean loadProtoRulesFromBzl;

@Option(
name = "incompatible_blacklisted_protos_requires_proto_info",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
},
help =
"If enabled, 'proto_lang_toolchain.blacklisted_protos' requires provider 'ProtoInfo'")
public boolean blacklistedProtosRequiresProtoInfo;

@Override
public FragmentOptions getHost() {
Options host = (Options) super.getHost();
Expand All @@ -203,6 +216,7 @@ public FragmentOptions getHost() {
host.experimentalJavaProtoAddAllowedPublicImports =
experimentalJavaProtoAddAllowedPublicImports;
host.generatedProtosInVirtualImports = generatedProtosInVirtualImports;
host.blacklistedProtosRequiresProtoInfo = blacklistedProtosRequiresProtoInfo;
return host;
}
}
Expand Down Expand Up @@ -300,4 +314,8 @@ public boolean generatedProtosInVirtualImports() {
public boolean loadProtoRulesFromBzl() {
return options.loadProtoRulesFromBzl;
}

public boolean blacklistedProtosRequiresProtoInfo() {
return options.blacklistedProtosRequiresProtoInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ public ConfiguredTarget create(RuleContext ruleContext)
for (TransitiveInfoCollection protos :
ruleContext.getPrerequisites("blacklisted_protos", TARGET)) {
ProtoInfo protoInfo = protos.get(ProtoInfo.PROVIDER);
// TODO(cushon): it would be nice to make this mandatory and stop adding files to build too
if (protoInfo == null
&& ruleContext
.getFragment(ProtoConfiguration.class)
.blacklistedProtosRequiresProtoInfo()) {
ruleContext.ruleError(
"'" + ruleContext.getLabel() + "' does not have mandatory provider 'ProtoInfo'.");
}
if (protoInfo != null) {
blacklistedProtos.addTransitive(protoInfo.getOriginalTransitiveProtoSources());
} else {
Expand Down

0 comments on commit c01c1f1

Please sign in to comment.