Expose write_descriptor_set to builtins.
I believe this call can be completely rewritten to Starlark. I'm keeping it natively for the moment to focus on Starlarkifying outer layer of the proto_library rule.
@@ -17,6 +17,7 @@ package com.google.devtools.build.lib.rules.proto;
import com.google.devtools.build.lib.analysis.starlark.StarlarkRuleContext;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.packages.BazelModuleContext;
+import com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder.Services;
import com.google.devtools.build.lib.starlarkbuildapi.proto.ProtoCommonApi;
import net.starlark.java.annot.Param;
import net.starlark.java.annot.StarlarkMethod;
@@ -52,4 +53,26 @@ public class BazelProtoCommon implements ProtoCommonApi {
.getFragment(ProtoConfiguration.class)
.generatedProtosInVirtualImports());
}
+
+ @StarlarkMethod(
+ name = "write_descriptor_set",
+ documented = false,
+ parameters = {
+ @Param(name = "ctx", doc = "The rule context"),
+ @Param(name = "proto_info", doc = "The ProtoInfo")
+ },
+ useStarlarkThread = true)
+ public void writeDescriptorSet(
+ StarlarkRuleContext ruleContext, ProtoInfo protoInfo, StarlarkThread thread)
+ throws EvalException {
+ Label label =
+ ((BazelModuleContext) Module.ofInnermostEnclosingStarlarkFunction(thread).getClientData())
+ .label();
+ if (!label.getPackageIdentifier().getRepository().toString().equals("@_builtins")) {
+ throw Starlark.errorf("Rule in '%s' cannot use private API", label.getPackageName());
+ }
+
+ ProtoCompileActionBuilder.writeDescriptorSet(
+ ruleContext.getRuleContext(), protoInfo, Services.ALLOW);
+ }
}
