Starlarkify ProtoInfo
The Starlark version needs to follow fields as they were exposed on ProtoInfoApi.
The change is slightly confusing, because native fields are sometimes named differently from Starlark ones. Here's the mapping:
Type | Native field | Starlark field
:------------------ | :--------------------- | :---
Artifact | directDescriptorSet | direct_descriptor_set
List<ProtoSource> | directSources | _direct_proto_sources (private)
List<Artifact> | directProtoSources | direct_sources = extractProtoSources(directSources)
PathFragment | directProtoSourceRoot | proto_source_root = directProtoSourceRoot.getSafePathString();
NestedSet<ProtoSource> | transitiveSources | _transitive_proto_sources (private)
NestedSet<Artifact> | transitiveProtoSources | transitive_imports, transitive_sources
NestedSet<String> | transitiveProtoSourceRoots | transitive_proto_path
NestedSet<Artifact> | strictImportableProto-SourcesForDependents | check_deps_sources
NestedSet<Artifact> | transitiveDescriptorSets | transitive_descriptor_sets
NestedSet<ProtoSource> | exportedSources | _exported_sources (private)
The fields `transitive_imports` and `transitive_sources` are duplicated in Starlark.
Native `directProtoSourceRoot` was interned using `ProtoCommon.memoryEfficientProtoSourceRoot`. There's no optimisation on `proto_source_root`, for now it doesn't seem necessary and I have ideas how to optimise `ProtoInfo` further without it.
The change introduces a slight regression in retained heap on benchmarked builds <0.1%. It's caused because of extra containers. That is in Starlark each instance needs two references and an Object array, whereas natively there's no need for references or arrays: `StarlarkInfo { ProtoInfo.class, Object[]{ f1, f2 } } > ProtoInfo { f1,f2 }`.
PiperOrigin-RevId: 511854620
Change-Id: I239aef427898e30e4f264f002e79b69eeaaa34db
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
index 8ffe46e..ded8f2c 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java
@@ -109,7 +109,6 @@
import com.google.devtools.build.lib.rules.proto.BazelProtoCommon;
import com.google.devtools.build.lib.rules.proto.BazelProtoLibraryRule;
import com.google.devtools.build.lib.rules.proto.ProtoConfiguration;
-import com.google.devtools.build.lib.rules.proto.ProtoInfo;
import com.google.devtools.build.lib.rules.proto.ProtoLangToolchainRule;
import com.google.devtools.build.lib.rules.python.PyCcLinkParamsProvider;
import com.google.devtools.build.lib.rules.python.PyInfo;
@@ -322,7 +321,6 @@
ProtoBootstrap bootstrap =
new ProtoBootstrap(
- ProtoInfo.PROVIDER,
BazelProtoCommon.INSTANCE,
new StarlarkAspectStub(),
new ProviderStub());
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
index e8a8388..ba111ba 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
@@ -852,7 +852,11 @@
}
private static boolean isProtoRule(ConfiguredTarget base) {
- return base.get(ProtoInfo.PROVIDER) != null;
+ try {
+ return base.get(ProtoInfo.PROVIDER) != null;
+ } catch (RuleErrorException e) {
+ return false;
+ }
}
/** Returns a mutable List of objc output files. */
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/BUILD b/src/main/java/com/google/devtools/build/lib/rules/proto/BUILD
index 42b6bb2..83f837b 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/BUILD
@@ -25,7 +25,6 @@
["*.java"],
),
deps = [
- "//src/main/java/com/google/devtools/build/docgen/annot",
"//src/main/java/com/google/devtools/build/lib/actions:artifacts",
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
"//src/main/java/com/google/devtools/build/lib/analysis:config/build_options",
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoCommon.java b/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoCommon.java
index e413803..ac9b40f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoCommon.java
@@ -14,77 +14,11 @@
package com.google.devtools.build.lib.rules.proto;
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.collect.nestedset.Depset;
import com.google.devtools.build.lib.starlarkbuildapi.proto.ProtoCommonApi;
-import com.google.devtools.build.lib.vfs.PathFragment;
-import net.starlark.java.annot.Param;
-import net.starlark.java.annot.StarlarkMethod;
-import net.starlark.java.eval.EvalException;
-import net.starlark.java.eval.StarlarkList;
-import net.starlark.java.eval.StarlarkThread;
/** Protocol buffers support for Starlark. */
public class BazelProtoCommon implements ProtoCommonApi {
public static final BazelProtoCommon INSTANCE = new BazelProtoCommon();
protected BazelProtoCommon() {}
-
- @StarlarkMethod(
- name = "ProtoSource",
- documented = false,
- parameters = {
- @Param(name = "source_file", doc = "The proto file."),
- @Param(name = "original_source_file", doc = "Original proto file."),
- @Param(name = "proto_path", doc = "Path to proto file."),
- },
- useStarlarkThread = true)
- public ProtoSource protoSource(
- Artifact sourceFile, Artifact originalSourceFile, String sourceRoot, StarlarkThread thread)
- throws EvalException {
- ProtoCommon.checkPrivateStarlarkificationAllowlist(thread);
- return new ProtoSource(sourceFile, originalSourceFile, PathFragment.create(sourceRoot));
- }
-
- @StarlarkMethod(
- name = "ProtoInfo",
- documented = false,
- parameters = {
- @Param(name = "direct_sources", doc = "Direct sources."),
- @Param(name = "proto_path", doc = "Proto path."),
- @Param(name = "transitive_sources", doc = "Transitive sources."),
- @Param(name = "transitive_proto_sources", doc = "Transitive proto sources."),
- @Param(name = "transitive_proto_path", doc = "Transitive proto path."),
- @Param(name = "check_deps_sources", doc = "Check deps sources."),
- @Param(name = "direct_descriptor_set", doc = "Direct descriptor set."),
- @Param(name = "transitive_descriptor_set", doc = "Transitive descriptor sets."),
- @Param(name = "exported_sources", doc = "Exported sources"),
- },
- useStarlarkThread = true)
- @SuppressWarnings("unchecked")
- public ProtoInfo protoInfo(
- StarlarkList<? extends ProtoSource> directSources,
- String directProtoSourceRoot,
- Depset transitiveProtoSources,
- Depset transitiveSources,
- Depset transitiveProtoSourceRoots,
- Depset strictImportableProtoSourcesForDependents,
- Artifact directDescriptorSet,
- Depset transitiveDescriptorSets,
- Depset exportedSources,
- StarlarkThread thread)
- throws EvalException {
- ProtoCommon.checkPrivateStarlarkificationAllowlist(thread);
- return new ProtoInfo(
- ((StarlarkList<ProtoSource>) directSources).getImmutableList(),
- PathFragment.create(directProtoSourceRoot),
- Depset.cast(transitiveSources, ProtoSource.class, "transitive_sources"),
- Depset.cast(transitiveProtoSources, Artifact.class, "transitive_proto_sources"),
- Depset.cast(transitiveProtoSourceRoots, String.class, "transitive_proto_path"),
- Depset.cast(
- strictImportableProtoSourcesForDependents, Artifact.class, "check_deps_sources"),
- directDescriptorSet,
- Depset.cast(transitiveDescriptorSets, Artifact.class, "transitive_descriptor_set"),
- Depset.cast(exportedSources, ProtoSource.class, "exported_sources"));
- }
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java
index 6ff397d..05f88ce 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java
@@ -81,7 +81,7 @@
declareGeneratedFiles,
ImmutableList.of(
/* actions */ ruleContext.getStarlarkRuleContext().actions(),
- /* proto_info */ protoTarget.get(ProtoInfo.PROVIDER),
+ /* proto_info */ protoTarget.get(ProtoInfo.PROVIDER.getKey()),
/* extension */ extension),
ImmutableMap.of());
try {
@@ -107,7 +107,7 @@
compile,
ImmutableList.of(
/* actions */ ruleContext.getStarlarkRuleContext().actions(),
- /* proto_info */ protoTarget.get(ProtoInfo.PROVIDER),
+ /* proto_info */ protoTarget.get(ProtoInfo.PROVIDER.getKey()),
/* proto_lang_toolchain_info */ protoLangToolchainInfo,
/* generated_files */ StarlarkList.immutableCopyOf(generatedFiles),
/* plugin_output */ pluginOutput == null ? Starlark.NONE : pluginOutput),
@@ -131,7 +131,7 @@
ruleContext.callStarlarkOrThrowRuleError(
filterSources,
ImmutableList.of(
- /* proto_info */ protoTarget.get(ProtoInfo.PROVIDER),
+ /* proto_info */ protoTarget.get(ProtoInfo.PROVIDER.getKey()),
/* proto_lang_toolchain_info */ protoLangToolchainInfo),
ImmutableMap.of()))
.get(0),
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoInfo.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoInfo.java
index 53437aa..8535898 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoInfo.java
@@ -14,170 +14,96 @@
package com.google.devtools.build.lib.rules.proto;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.actions.Artifact;
+import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.collect.nestedset.Depset;
+import com.google.devtools.build.lib.collect.nestedset.Depset.TypeException;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
+import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
+import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-import com.google.devtools.build.lib.packages.BuiltinProvider;
-import com.google.devtools.build.lib.packages.NativeInfo;
-import com.google.devtools.build.lib.starlarkbuildapi.ProtoInfoApi;
-import com.google.devtools.build.lib.starlarkbuildapi.proto.ProtoBootstrap;
-import com.google.devtools.build.lib.vfs.PathFragment;
+import com.google.devtools.build.lib.packages.Info;
+import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
+import com.google.devtools.build.lib.packages.StarlarkInfo;
+import com.google.devtools.build.lib.packages.StarlarkProviderWrapper;
import net.starlark.java.eval.EvalException;
-import net.starlark.java.eval.StarlarkThread;
+import net.starlark.java.eval.Sequence;
/**
* Configured target classes that implement this class can contribute .proto files to the
* compilation of proto_library rules.
*/
@Immutable
-public final class ProtoInfo extends NativeInfo implements ProtoInfoApi<Artifact> {
- /** Provider class for {@link ProtoInfo} objects. */
- public static class ProtoInfoProvider extends BuiltinProvider<ProtoInfo>
- implements ProtoInfoProviderApi {
- public ProtoInfoProvider() {
- super(ProtoBootstrap.PROTO_INFO_STARLARK_NAME, ProtoInfo.class);
- }
- }
-
+public final class ProtoInfo {
public static final ProtoInfoProvider PROVIDER = new ProtoInfoProvider();
- private static ImmutableList<Artifact> extractProtoSources(ImmutableList<ProtoSource> sources) {
- ImmutableList.Builder<Artifact> builder = ImmutableList.builder();
- for (ProtoSource source : sources) {
- builder.add(source.getSourceFile());
- }
- return builder.build();
- }
-
- private final ImmutableList<ProtoSource> directSources;
- private final ImmutableList<Artifact> directProtoSources;
- private final PathFragment directProtoSourceRoot;
- private final NestedSet<ProtoSource> transitiveSources;
- private final NestedSet<Artifact> transitiveProtoSources;
- private final NestedSet<String> transitiveProtoSourceRoots;
- private final NestedSet<Artifact> strictImportableProtoSourcesForDependents;
- private final Artifact directDescriptorSet;
- private final NestedSet<Artifact> transitiveDescriptorSets;
- private final NestedSet<ProtoSource> exportedSources;
-
- public ProtoInfo(
- ImmutableList<ProtoSource> directSources,
- PathFragment directProtoSourceRoot,
- NestedSet<ProtoSource> transitiveSources,
- NestedSet<Artifact> transitiveProtoSources,
- NestedSet<String> transitiveProtoSourceRoots,
- NestedSet<Artifact> strictImportableProtoSourcesForDependents,
- Artifact directDescriptorSet,
- NestedSet<Artifact> transitiveDescriptorSets,
- // Layering checks.
- NestedSet<ProtoSource> exportedSources) {
- this.directSources = directSources;
- this.directProtoSources = extractProtoSources(directSources);
- this.directProtoSourceRoot = ProtoCommon.memoryEfficientProtoSourceRoot(directProtoSourceRoot);
- this.transitiveSources = transitiveSources;
- this.transitiveProtoSources = transitiveProtoSources;
- this.transitiveProtoSourceRoots = transitiveProtoSourceRoots;
- this.strictImportableProtoSourcesForDependents = strictImportableProtoSourcesForDependents;
- this.directDescriptorSet = directDescriptorSet;
- this.transitiveDescriptorSets = transitiveDescriptorSets;
-
- // Layering checks.
- this.exportedSources = exportedSources;
- }
-
- /** The {@code .proto} source files in this {@code proto_library}'s {@code srcs}. */
- public ImmutableList<ProtoSource> getDirectSources() {
- return directSources;
- }
-
- @Override
- public BuiltinProvider<ProtoInfo> getProvider() {
+ public StarlarkProviderWrapper<ProtoInfo> getProvider() {
return PROVIDER;
}
- /** The proto source files that are used in compiling this {@code proto_library}. */
- @Override
- public ImmutableList<Artifact> getDirectProtoSources() {
- return directProtoSources;
+ /** Provider class for {@link ProtoInfo} objects. */
+ public static class ProtoInfoProvider extends StarlarkProviderWrapper<ProtoInfo> {
+ public ProtoInfoProvider() {
+ super(Label.parseCanonicalUnchecked("@_builtins//:common/proto/proto_info.bzl"), "ProtoInfo");
+ }
+
+ @Override
+ public ProtoInfo wrap(Info value) throws RuleErrorException {
+ try {
+ return new ProtoInfo((StarlarkInfo) value);
+ } catch (EvalException e) {
+ throw new RuleErrorException(e.getMessageWithStack());
+ } catch (TypeException e) {
+ throw new RuleErrorException(e.getMessage());
+ }
+ }
}
- @Override
- public ImmutableList<ProtoSource> getDirectProtoSourcesForStarlark(StarlarkThread thread)
- throws EvalException {
- ProtoCommon.checkPrivateStarlarkificationAllowlist(thread);
- return directSources;
- }
+ private final StarlarkInfo value;
+ private final NestedSet<Artifact> transitiveProtoSources;
- /**
- * The source root of the current library.
- *
- * <p>For Bazel, this is always a (logical) prefix of all direct sources. For Blaze, this is
- * currently a lie for {@code proto_library} targets with generated sources.
- */
- @Override
- public String getDirectProtoSourceRoot() {
- return directProtoSourceRoot.getSafePathString();
- }
-
- /** The proto sources in the transitive closure of this rule. */
- @Override
- public Depset /*<Artifact>*/ getTransitiveProtoSourcesForStarlark() {
- return Depset.of(Artifact.TYPE, getTransitiveProtoSources());
- }
-
- @Override
- public Depset getTransitiveSourcesForStarlark(StarlarkThread thread) throws EvalException {
- ProtoCommon.checkPrivateStarlarkificationAllowlist(thread);
- return Depset.of(ProtoSource.TYPE, transitiveSources);
- }
-
- /**
- * The {@code .proto} source files in this {@code proto_library}'s {@code srcs} and all of its
- * transitive dependencies.
- */
- public NestedSet<ProtoSource> getTransitiveSources() {
- return transitiveSources;
+ private ProtoInfo(StarlarkInfo value) throws EvalException, TypeException {
+ this.value = value;
+ transitiveProtoSources =
+ value.getValue("transitive_sources", Depset.class).getSet(Artifact.class);
}
public NestedSet<Artifact> getTransitiveProtoSources() {
return transitiveProtoSources;
}
- /**
- * The proto source roots of the transitive closure of this rule. These flags will be passed to
- * {@code protoc} in the specified order, via the {@code --proto_path} flag.
- */
- @Override
- public Depset /*<String>*/ getTransitiveProtoSourceRootsForStarlark() {
- return Depset.of(Depset.ElementType.STRING, transitiveProtoSourceRoots);
+ /** The {@code .proto} source files in this {@code proto_library}'s {@code srcs}. */
+ @VisibleForTesting
+ public ImmutableList<ProtoSource> getDirectSources() throws Exception {
+ ImmutableList.Builder<ProtoSource> directSources = new ImmutableList.Builder<>();
+ for (StarlarkInfo protoSource :
+ Sequence.cast(
+ value.getValue("_direct_proto_sources", Sequence.class),
+ StarlarkInfo.class,
+ "_direct_proto_sources")) {
+ directSources.add(ProtoSource.create(protoSource));
+ }
+ return directSources.build();
}
- public NestedSet<String> getTransitiveProtoSourceRoots() {
- return transitiveProtoSourceRoots;
+ /** The proto source files that are used in compiling this {@code proto_library}. */
+ @VisibleForTesting
+ public ImmutableList<Artifact> getDirectProtoSources() throws Exception {
+ return Sequence.cast(
+ value.getValue("direct_sources", Sequence.class), Artifact.class, "direct_sources")
+ .getImmutableList();
}
- @Deprecated
- @Override
- public Depset /*<Artifact>*/ getTransitiveImports() {
- return getTransitiveProtoSourcesForStarlark();
+ @VisibleForTesting
+ public NestedSet<String> getTransitiveProtoSourceRoots() throws Exception {
+ return value.getValue("transitive_proto_path", Depset.class).getSet(String.class);
}
- /**
- * Returns the set of source files importable by rules directly depending on the rule declaring
- * this provider if strict dependency checking is in effect.
- *
- * <p>(strict dependency checking: when a target can only include / import source files from its
- * direct dependencies, but not from transitive ones)
- */
- @Override
- public Depset /*<Artifact>*/ getStrictImportableProtoSourcesForDependentsForStarlark() {
- return Depset.of(Artifact.TYPE, strictImportableProtoSourcesForDependents);
- }
-
- public NestedSet<Artifact> getStrictImportableProtoSourcesForDependents() {
- return strictImportableProtoSourcesForDependents;
+ @VisibleForTesting
+ public NestedSet<Artifact> getStrictImportableProtoSourcesForDependents() throws Exception {
+ return value.getValue("check_deps_sources", Depset.class).getSet(Artifact.class);
}
/**
@@ -186,37 +112,27 @@
* (remember that proto-compiler reads all transitive .proto files, even when producing the
* direct-srcs descriptor set)
*/
- @Override
- public Artifact getDirectDescriptorSet() {
- return directDescriptorSet;
+ @VisibleForTesting
+ public Artifact getDirectDescriptorSet() throws Exception {
+ return value.getValue("direct_descriptor_set", Artifact.class);
}
- /**
- * Be careful while using this artifact - it is the parsing of the transitive set of .proto files.
- * It's possible to cause a O(n^2) behavior, where n is the length of a proto chain-graph.
- * (remember that proto-compiler reads all transitive .proto files, even when producing the
- * direct-srcs descriptor set)
- */
- @Override
- public Depset /*<Artifact>*/ getTransitiveDescriptorSetsForStarlark() {
- return Depset.of(Artifact.TYPE, transitiveDescriptorSets);
- }
-
- public NestedSet<Artifact> getTransitiveDescriptorSets() {
- return transitiveDescriptorSets;
- }
-
- @Override
- public Depset getExportedSourcesForStarlark(StarlarkThread thread) throws EvalException {
- ProtoCommon.checkPrivateStarlarkificationAllowlist(thread);
- return Depset.of(ProtoSource.TYPE, getExportedSources());
+ @VisibleForTesting
+ public NestedSet<Artifact> getTransitiveDescriptorSets() throws Exception {
+ return value.getValue("transitive_descriptor_sets", Depset.class).getSet(Artifact.class);
}
/**
* Returns a set of {@code .proto} sources that may be imported by {@code proto_library} targets
* directly depending on this {@code ProtoInfo}.
*/
- public NestedSet<ProtoSource> getExportedSources() {
- return exportedSources;
+ @VisibleForTesting
+ public NestedSet<ProtoSource> getExportedSources() throws Exception {
+ ImmutableList.Builder<ProtoSource> exportedSources = new ImmutableList.Builder<>();
+ for (StarlarkInfo protoSource :
+ value.getValue("_exported_sources", Depset.class).toList(StarlarkInfo.class)) {
+ exportedSources.add(ProtoSource.create(protoSource));
+ }
+ return NestedSetBuilder.wrap(Order.STABLE_ORDER, exportedSources.build());
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoLangToolchainProvider.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoLangToolchainProvider.java
index f7d3d88..1dc6e5c 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoLangToolchainProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoLangToolchainProvider.java
@@ -24,6 +24,7 @@
import com.google.devtools.build.lib.packages.StarlarkInfo;
import com.google.devtools.build.lib.packages.StarlarkProvider;
import com.google.devtools.build.lib.packages.StarlarkProviderIdentifier;
+import com.google.devtools.build.lib.packages.StructImpl;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.annotation.Nullable;
@@ -64,11 +65,11 @@
public abstract TransitiveInfoCollection runtime();
/**
- * Returns a list of {@link ProtoSource}s that are already provided by the protobuf runtime (i.e.
- * for which {@code <lang>_proto_library} should not generate bindings.
+ * Returns a list of {@code ProtoSourceInfos}s that are already provided by the protobuf runtime
+ * (i.e. for which {@code <lang>_proto_library} should not generate bindings.
*/
// Proto sources provided by the toolchain.
- public abstract ImmutableList<ProtoSource> providedProtoSources();
+ public abstract ImmutableList<StarlarkInfo> providedProtoSources();
// Proto compiler.
public abstract FilesToRunProvider protoc();
@@ -91,7 +92,7 @@
String pluginFormatFlag,
FilesToRunProvider pluginExecutable,
TransitiveInfoCollection runtime,
- ImmutableList<ProtoSource> providedProtoSources,
+ ImmutableList<StructImpl> providedProtoSources,
FilesToRunProvider protoc,
ImmutableList<String> protocOpts,
String progressMessage,
@@ -167,7 +168,7 @@
? null
: provider.getValue("runtime", TransitiveInfoCollection.class),
ImmutableList.copyOf(
- (StarlarkList<ProtoSource>) provider.getValue("provided_proto_sources")),
+ (StarlarkList<StarlarkInfo>) provider.getValue("provided_proto_sources")),
provider.getValue("proto_compiler", FilesToRunProvider.class),
ImmutableList.copyOf((StarlarkList<String>) provider.getValue("protoc_opts")),
provider.getValue("progress_message", String.class),
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSource.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSource.java
index 27f13b4..db38548 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSource.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoSource.java
@@ -14,79 +14,35 @@
package com.google.devtools.build.lib.rules.proto;
-import com.google.devtools.build.docgen.annot.DocCategory;
+import com.google.auto.value.AutoValue;
+import com.google.common.annotations.VisibleForTesting;
import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.collect.nestedset.Depset;
-import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.packages.StarlarkInfo;
import com.google.devtools.build.lib.vfs.PathFragment;
-import net.starlark.java.annot.StarlarkBuiltin;
-import net.starlark.java.annot.StarlarkMethod;
-import net.starlark.java.eval.EvalException;
-import net.starlark.java.eval.StarlarkThread;
import net.starlark.java.eval.StarlarkValue;
-/** Represents a single {@code .proto} source file. */
-@Immutable
-@StarlarkBuiltin(name = "ProtoSource", category = DocCategory.BUILTIN, documented = false)
-final class ProtoSource implements StarlarkValue {
- public static final Depset.ElementType TYPE = Depset.ElementType.of(ProtoSource.class);
+/** Represents a single {@code .proto} source file. Deserializer only used in tests */
+@AutoValue
+abstract class ProtoSource implements StarlarkValue {
+ @VisibleForTesting
+ abstract Artifact getSourceFile();
- private final Artifact sourceFile;
- private final Artifact originalSourceFile;
- private final PathFragment sourceRoot;
+ @VisibleForTesting
+ abstract Artifact getOriginalSourceFile();
- public ProtoSource(Artifact sourceFile, PathFragment sourceRoot) {
- this(sourceFile, sourceFile, sourceRoot);
+ @VisibleForTesting
+ abstract PathFragment getSourceRoot();
+
+ @VisibleForTesting
+ PathFragment getImportPath() {
+ return getSourceFile().getExecPath().relativeTo(getSourceRoot());
}
- ProtoSource(Artifact sourceFile, Artifact originalSourceFile, PathFragment sourceRoot) {
- this.sourceFile = sourceFile;
- this.originalSourceFile = originalSourceFile;
- this.sourceRoot = ProtoCommon.memoryEfficientProtoSourceRoot(sourceRoot);
- }
-
- public Artifact getSourceFile() {
- return sourceFile;
- }
-
- @StarlarkMethod(name = "source_file", documented = false, useStarlarkThread = true)
- public Artifact getSourceFileForStarlark(StarlarkThread thread) throws EvalException {
- ProtoCommon.checkPrivateStarlarkificationAllowlist(thread);
- return sourceFile;
- }
-
- /** Returns the original source file. Only for forbidding protos! */
- @StarlarkMethod(name = "original_source_file", documented = false, useStarlarkThread = true)
- public Artifact getOriginalSourceFileForStarlark(StarlarkThread thread) throws EvalException {
- ProtoCommon.checkPrivateStarlarkificationAllowlist(thread);
- return originalSourceFile;
- }
-
- Artifact getOriginalSourceFile() {
- return originalSourceFile;
- }
-
- public PathFragment getSourceRoot() {
- return sourceRoot;
- }
-
- @StarlarkMethod(name = "import_path", documented = false, useStarlarkThread = true)
- public String getImportPathForStarlark(StarlarkThread thread) throws EvalException {
- ProtoCommon.checkPrivateStarlarkificationAllowlist(thread);
- return getImportPath().getPathString();
- }
-
- public PathFragment getImportPath() {
- return sourceFile.getExecPath().relativeTo(sourceRoot);
- }
-
- @Override
- public String toString() {
- return "ProtoSource('" + getImportPath() + "')";
- }
-
- @Override
- public boolean isImmutable() {
- return true;
+ @VisibleForTesting
+ static ProtoSource create(StarlarkInfo protoSourceStruct) throws Exception {
+ return new AutoValue_ProtoSource(
+ protoSourceStruct.getValue("_source_file", Artifact.class),
+ protoSourceStruct.getValue("_original_source_file", Artifact.class),
+ PathFragment.create(protoSourceStruct.getValue("_proto_path", String.class)));
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/ProtoInfoApi.java b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/ProtoInfoApi.java
deleted file mode 100644
index f82333e..0000000
--- a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/ProtoInfoApi.java
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright 2018 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.starlarkbuildapi;
-
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.docgen.annot.DocCategory;
-import com.google.devtools.build.lib.collect.nestedset.Depset;
-import com.google.devtools.build.lib.starlarkbuildapi.core.ProviderApi;
-import com.google.devtools.build.lib.starlarkbuildapi.core.StructApi;
-import net.starlark.java.annot.StarlarkBuiltin;
-import net.starlark.java.annot.StarlarkMethod;
-import net.starlark.java.eval.EvalException;
-import net.starlark.java.eval.StarlarkThread;
-
-/** Info object propagating information about protocol buffer sources. */
-@StarlarkBuiltin(
- name = "ProtoInfo",
- category = DocCategory.PROVIDER,
- doc =
- "Encapsulates information provided by <a href=\""
- + "${link protocol-buffer#proto_library}\">proto_library.</a>"
- + "<p>"
- + "Please consider using `load(\"@rules_proto//proto:defs.bzl\", \"ProtoInfo\")` "
- + "to load this symbol from <a href=\"https://github.com/bazelbuild/rules_proto\">"
- + "rules_proto</a>."
- + "</p>")
-public interface ProtoInfoApi<FileT extends FileApi> extends StructApi {
- /** Provider class for {@link ProtoInfoApi} objects. */
- @StarlarkBuiltin(name = "Provider", documented = false, doc = "")
- interface ProtoInfoProviderApi extends ProviderApi {
- // Currently empty. ProtoInfo cannot be created from Starlark at the moment.
- }
-
- @StarlarkMethod(
- name = "transitive_imports",
- doc = "Transitive imports including weak dependencies.",
- structField = true)
- Depset /*<FileT>*/ getTransitiveImports();
-
- @StarlarkMethod(
- name = "transitive_sources",
- doc = "Proto sources for this rule and all its dependent protocol buffer rules.",
- structField = true)
- // TODO(bazel-team): The difference between transitive imports and transitive proto sources
- // should never be used by Starlark or by an Aspect. One of these two should be removed,
- // preferably soon, before Starlark users start depending on them.
- Depset /*<FileT>*/ getTransitiveProtoSourcesForStarlark();
-
- @StarlarkMethod(
- name = "direct_sources",
- doc = "Proto sources from the 'srcs' attribute.",
- structField = true)
- ImmutableList<FileT> getDirectProtoSources();
-
- @StarlarkMethod(name = "direct_proto_sources", documented = false, useStarlarkThread = true)
- ImmutableList<?> getDirectProtoSourcesForStarlark(StarlarkThread thread) throws EvalException;
-
- @StarlarkMethod(
- name = "check_deps_sources",
- doc =
- "Proto sources from the 'srcs' attribute. If the library is a proxy library "
- + "that has no sources, it contains the check_deps_sources "
- + "from this library's direct deps.",
- structField = true)
- Depset /*<FileT>*/ getStrictImportableProtoSourcesForDependentsForStarlark();
-
- @StarlarkMethod(
- name = "direct_descriptor_set",
- doc =
- "The <a href=\""
- + "https://github.com/google/protobuf/search?q=%22message+FileDescriptorSet%22+path%3A%2Fsrc\">FileDescriptorSet</a>"
- + " of the direct sources. If no srcs, contains an empty file.",
- structField = true)
- FileT getDirectDescriptorSet();
-
- @StarlarkMethod(
- name = "transitive_descriptor_sets",
- doc =
- "A set of <a href=\""
- + "https://github.com/google/protobuf/search?q=%22message+FileDescriptorSet%22+path%3A%2Fsrc\">FileDescriptorSet</a>"
- + " files of all dependent proto_library rules, and this one's. This is not the same"
- + " as passing --include_imports to proto-compiler. Will be empty if no"
- + " dependencies.",
- structField = true)
- Depset /*<FileT>*/ getTransitiveDescriptorSetsForStarlark();
-
- @StarlarkMethod(
- name = "transitive_proto_path",
- doc = "A set of proto source roots collected from the transitive closure of this rule.",
- structField = true)
- Depset /*<String>*/ getTransitiveProtoSourceRootsForStarlark();
-
- @StarlarkMethod(
- name = "proto_source_root",
- doc =
- "The directory relative to which the .proto files defined in the proto_library are "
- + "defined. For example, if this is 'a/b' and the rule has the file 'a/b/c/d.proto'"
- + " as a source, that source file would be imported as 'import c/d.proto'",
- structField = true)
- String getDirectProtoSourceRoot();
-
- @StarlarkMethod(name = "transitive_proto_sources", documented = false, useStarlarkThread = true)
- Depset getTransitiveSourcesForStarlark(StarlarkThread thread) throws EvalException;
-
- @StarlarkMethod(name = "exported_sources", documented = false, useStarlarkThread = true)
- Depset getExportedSourcesForStarlark(StarlarkThread thread) throws EvalException;
-}
diff --git a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/proto/ProtoBootstrap.java b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/proto/ProtoBootstrap.java
index cf33479..7e6f7d9 100644
--- a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/proto/ProtoBootstrap.java
+++ b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/proto/ProtoBootstrap.java
@@ -18,12 +18,12 @@
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.packages.semantics.BuildLanguageOptions;
-import com.google.devtools.build.lib.starlarkbuildapi.ProtoInfoApi.ProtoInfoProviderApi;
import com.google.devtools.build.lib.starlarkbuildapi.StarlarkAspectApi;
import com.google.devtools.build.lib.starlarkbuildapi.core.Bootstrap;
import com.google.devtools.build.lib.starlarkbuildapi.core.ContextAndFlagGuardedValue;
import com.google.devtools.build.lib.starlarkbuildapi.core.ProviderApi;
import net.starlark.java.eval.FlagGuardedValue;
+import net.starlark.java.eval.Starlark;
/** A {@link Bootstrap} for Starlark objects related to protocol buffers. */
public class ProtoBootstrap implements Bootstrap {
@@ -41,17 +41,14 @@
public static final String PROTO_COMMON_SECOND_NAME = "proto_common_do_not_use";
- private final ProtoInfoProviderApi protoInfoApiProvider;
private final Object protoCommon;
private final StarlarkAspectApi protoRegistryAspect;
private final ProviderApi protoRegistryProvider;
public ProtoBootstrap(
- ProtoInfoProviderApi protoInfoApiProvider,
Object protoCommon,
StarlarkAspectApi protoRegistryAspect,
ProviderApi protoRegistryProvider) {
- this.protoInfoApiProvider = protoInfoApiProvider;
this.protoCommon = protoCommon;
this.protoRegistryAspect = protoRegistryAspect;
this.protoRegistryProvider = protoRegistryProvider;
@@ -63,7 +60,7 @@
PROTO_INFO_STARLARK_NAME,
ContextAndFlagGuardedValue.onlyInAllowedReposOrWhenIncompatibleFlagIsFalse(
BuildLanguageOptions.INCOMPATIBLE_STOP_EXPORTING_LANGUAGE_MODULES,
- protoInfoApiProvider,
+ Starlark.NONE,
allowedRepositories));
builder.put(
PROTO_COMMON_NAME,
diff --git a/src/main/starlark/builtins_bzl/common/exports.bzl b/src/main/starlark/builtins_bzl/common/exports.bzl
index 3cc7d0e..9a56d28 100755
--- a/src/main/starlark/builtins_bzl/common/exports.bzl
+++ b/src/main/starlark/builtins_bzl/common/exports.bzl
@@ -24,6 +24,7 @@
load("@_builtins//:common/objc/linking_support.bzl", "linking_support")
load("@_builtins//:common/proto/proto_common.bzl", "proto_common_do_not_use")
load("@_builtins//:common/proto/proto_library.bzl", "proto_library")
+load("@_builtins//:common/proto/proto_info.bzl", "ProtoInfo")
load("@_builtins//:common/proto/proto_lang_toolchain_wrapper.bzl", "proto_lang_toolchain")
load("@_builtins//:common/python/py_internal.bzl", "py_internal")
load("@_builtins//:common/python/py_runtime_macro.bzl", "py_runtime")
@@ -43,6 +44,7 @@
"PyInfo": PyInfo,
"PyCcLinkParamsProvider": PyCcLinkParamsProvider,
"py_internal": py_internal,
+ "ProtoInfo": ProtoInfo,
}
# A list of Starlarkified native rules.
diff --git a/src/main/starlark/builtins_bzl/common/proto/proto_common.bzl b/src/main/starlark/builtins_bzl/common/proto/proto_common.bzl
index 7bd0ff5..908c3ac 100644
--- a/src/main/starlark/builtins_bzl/common/proto/proto_common.bzl
+++ b/src/main/starlark/builtins_bzl/common/proto/proto_common.bzl
@@ -35,7 +35,12 @@
return "--proto_path=%s" % path
def _Iimport_path_equals_fullpath(proto_source):
- return "-I%s=%s" % (proto_source.import_path(), proto_source.source_file().path)
+ return "-I%s=%s" % (_get_import_path(proto_source), proto_source._source_file.path)
+
+def _get_import_path(proto_source):
+ if proto_source._proto_path == "":
+ return proto_source._source_file.path
+ return proto_source._source_file.path[len(proto_source._proto_path) + 1:]
def _compile(
actions,
@@ -94,7 +99,7 @@
# For each import, include both the import as well as the import relativized against its
# protoSourceRoot. This ensures that protos can reference either the full path or the short
# path when including other protos.
- args.add_all(proto_info.transitive_proto_sources(), map_each = _Iimport_path_equals_fullpath)
+ args.add_all(proto_info._transitive_proto_sources, map_each = _Iimport_path_equals_fullpath)
# Example: `-Ia.proto=bazel-bin/target/third_party/pkg/_virtual_imports/subpkg/a.proto`
args.add_all(proto_info.direct_sources)
@@ -126,7 +131,7 @@
provided_proto_sources = proto_lang_toolchain_info.provided_proto_sources
provided_paths = {}
for src in provided_proto_sources:
- path = src.original_source_file().path
+ path = src._original_source_file.path
# For listed protos bundled with the Bazel tools repository, their exec paths start
# with external/bazel_tools/. This prefix needs to be removed first, because the protos in
@@ -137,7 +142,7 @@
provided_paths[path] = None
# Filter proto files
- proto_files = [src.original_source_file() for src in proto_info.direct_proto_sources()]
+ proto_files = [src._original_source_file for src in proto_info._direct_proto_sources]
excluded = []
included = []
for proto_file in proto_files:
diff --git a/src/main/starlark/builtins_bzl/common/proto/proto_info.bzl b/src/main/starlark/builtins_bzl/common/proto/proto_info.bzl
index a5e57be..b016c65 100644
--- a/src/main/starlark/builtins_bzl/common/proto/proto_info.bzl
+++ b/src/main/starlark/builtins_bzl/common/proto/proto_info.bzl
@@ -16,4 +16,49 @@
Definition of ProtoInfo provider.
"""
-ProtoInfo = _builtins.toplevel.ProtoInfo
+_warning = """ Don't use this field. It's intended for internal use and will be changed or removed
+ without warning."""
+
+ProtoInfo = provider(
+ doc = "Encapsulates information provided by a `proto_library.`",
+ fields = {
+ "direct_sources": "(list[File]) The `.proto` source files from the `srcs` attribute.",
+ "transitive_sources": """(depset[File]) The `.proto` source files from this rule and all
+ its dependent protocol buffer rules.""",
+ "direct_descriptor_set": """(File) The descriptor set of the direct sources. If no srcs,
+ contains an empty file.""",
+ "transitive_descriptor_sets": """(depset[File]) A set of descriptor set files of all
+ dependent `proto_library` rules, and this one's. This is not the same as passing
+ --include_imports to proto-compiler. Will be empty if no dependencies.""",
+ "proto_source_root": """(str) The directory relative to which the `.proto` files defined in
+ the `proto_library` are defined. For example, if this is `a/b` and the rule has the
+ file `a/b/c/d.proto` as a source, that source file would be imported as
+ `import c/d.proto`""",
+ "transitive_proto_path": """(depset(str) A set of `proto_source_root`s collected from the
+ transitive closure of this rule.""",
+ "check_deps_sources": """(depset[File]) The `.proto` sources from the 'srcs' attribute.
+ If the library is a proxy library that has no sources, it contains the
+ `check_deps_sources` from this library's direct deps.""",
+
+ # Deprecated fields:
+ "transitive_imports": """(depset[File]) Deprecated: use `transitive_sources` instead.""",
+
+ # Internal fields:
+ "_direct_proto_sources": """(list[ProtoSourceInfo]) The `ProtoSourceInfo`s from the `srcs`
+ attribute.""" + _warning,
+ "_transitive_proto_sources": """(depset[ProtoSourceInfo]) The `ProtoSourceInfo`s from this
+ rule and all its dependent protocol buffer rules.""" + _warning,
+ "_exported_sources": """(depset[ProtoSourceInfo]) A set of `ProtoSourceInfo`s that may be
+ imported by another `proto_library` depending on this one.""" + _warning,
+ },
+)
+
+ProtoSourceInfo = provider(
+ doc = "Represents a single `.proto` source file.",
+ fields = {
+ "_source_file": """(File) The `.proto` file. Possibly virtual to handle additional/stripped
+ path prefix.""" + _warning,
+ "_original_source_file": "(File) The original `.proto` file." + _warning,
+ "_proto_path": "(str) The root of the virtual location." + _warning,
+ },
+)
diff --git a/src/main/starlark/builtins_bzl/common/proto/proto_lang_toolchain.bzl b/src/main/starlark/builtins_bzl/common/proto/proto_lang_toolchain.bzl
index 0649525..0981e72 100644
--- a/src/main/starlark/builtins_bzl/common/proto/proto_lang_toolchain.bzl
+++ b/src/main/starlark/builtins_bzl/common/proto/proto_lang_toolchain.bzl
@@ -19,7 +19,7 @@
load(":common/proto/proto_semantics.bzl", "semantics")
def _rule_impl(ctx):
- provided_proto_sources = depset(transitive = [bp[ProtoInfo].transitive_proto_sources() for bp in ctx.attr.blacklisted_protos]).to_list()
+ provided_proto_sources = depset(transitive = [bp[ProtoInfo]._transitive_proto_sources for bp in ctx.attr.blacklisted_protos]).to_list()
flag = ctx.attr.command_line
if flag.find("$(PLUGIN_OUT)") > -1:
diff --git a/src/main/starlark/builtins_bzl/common/proto/proto_library.bzl b/src/main/starlark/builtins_bzl/common/proto/proto_library.bzl
index 8f667f6..f497a77 100644
--- a/src/main/starlark/builtins_bzl/common/proto/proto_library.bzl
+++ b/src/main/starlark/builtins_bzl/common/proto/proto_library.bzl
@@ -18,7 +18,7 @@
load(":common/proto/proto_semantics.bzl", "semantics")
load(":common/proto/proto_common.bzl", proto_common = "proto_common_do_not_use")
-load(":common/proto/proto_info.bzl", "ProtoInfo")
+load(":common/proto/proto_info.bzl", "ProtoInfo", "ProtoSourceInfo")
load(":common/paths.bzl", "paths")
def _check_srcs_package(target_package, srcs):
@@ -90,7 +90,7 @@
]
def _create_proto_sources(ctx, srcs, import_prefix, strip_import_prefix):
- """Transforms Files in srcs to ProtoSources, optionally symlinking them to _virtual_imports.
+ """Transforms Files in srcs to ProtoSourceInfos, optionally symlinking them to _virtual_imports.
Returns:
A pair proto_path, directs_sources.
@@ -112,7 +112,7 @@
else:
# source_root == ''|'bazel-out/foo/k8-fastbuild/bin' / 'external/repo'
source_root = _join(src.root.path, ctx.label.workspace_root)
- direct_sources.append(_builtins.toplevel.proto_common.ProtoSource(src, src, source_root))
+ direct_sources.append(ProtoSourceInfo(_source_file = src, _original_source_file = src, _proto_path = source_root))
return ctx.label.workspace_root if ctx.label.workspace_root else ".", direct_sources
@@ -155,7 +155,7 @@
target_file = src,
progress_message = "Symlinking virtual .proto sources for %{label}",
)
- direct_sources.append(_builtins.toplevel.proto_common.ProtoSource(virtual_src, src, proto_path))
+ direct_sources.append(ProtoSourceInfo(_source_file = virtual_src, _original_source_file = src, _proto_path = proto_path))
return proto_path, direct_sources
def _create_proto_info(ctx, direct_sources, deps, exports, proto_path, descriptor_set):
@@ -164,11 +164,11 @@
# Construct ProtoInfo
transitive_proto_sources = depset(
direct = direct_sources,
- transitive = [dep.transitive_proto_sources() for dep in deps],
+ transitive = [dep._transitive_proto_sources for dep in deps],
order = "preorder",
)
transitive_sources = depset(
- direct = [src.source_file() for src in direct_sources],
+ direct = [src._source_file for src in direct_sources],
transitive = [dep.transitive_sources for dep in deps],
order = "preorder",
)
@@ -177,7 +177,7 @@
transitive = [dep.transitive_proto_path for dep in deps],
)
if direct_sources:
- check_deps_sources = depset(direct = [src.source_file() for src in direct_sources])
+ check_deps_sources = depset(direct = [src._source_file for src in direct_sources])
else:
check_deps_sources = depset(transitive = [dep.check_deps_sources for dep in deps])
@@ -190,22 +190,24 @@
if direct_sources:
exported_sources = depset(direct = direct_sources)
else:
- exported_sources = depset(transitive = [dep.exported_sources() for dep in deps])
+ exported_sources = depset(transitive = [dep._exported_sources for dep in deps])
- return _builtins.toplevel.proto_common.ProtoInfo(
- direct_sources,
- proto_path,
- transitive_sources,
- transitive_proto_sources,
- transitive_proto_path,
- check_deps_sources,
- descriptor_set,
- transitive_descriptor_sets,
- exported_sources,
+ return ProtoInfo(
+ direct_sources = [src._source_file for src in direct_sources],
+ transitive_sources = transitive_sources,
+ direct_descriptor_set = descriptor_set,
+ transitive_descriptor_sets = transitive_descriptor_sets,
+ proto_source_root = proto_path,
+ transitive_proto_path = transitive_proto_path,
+ check_deps_sources = check_deps_sources,
+ transitive_imports = transitive_sources,
+ _direct_proto_sources = direct_sources,
+ _transitive_proto_sources = transitive_proto_sources,
+ _exported_sources = exported_sources,
)
def _get_import_path(proto_source):
- return proto_source.import_path()
+ return paths.relativize(proto_source._source_file.path, proto_source._proto_path)
def _write_descriptor_set(ctx, direct_sources, deps, exports, proto_info, descriptor_set):
"""Writes descriptor set."""
@@ -225,7 +227,7 @@
if direct_sources:
strict_importable_sources = depset(
direct = direct_sources,
- transitive = [dep.exported_sources() for dep in deps],
+ transitive = [dep._exported_sources for dep in deps],
)
else:
strict_importable_sources = None
@@ -243,7 +245,7 @@
strict_public_imports_mode = ctx.fragments.proto.strict_public_imports()
strict_imports = strict_public_imports_mode != "OFF" and strict_public_imports_mode != "DEFAULT"
if strict_imports:
- public_import_protos = depset(transitive = [export.exported_sources() for export in exports])
+ public_import_protos = depset(transitive = [export._exported_sources for export in exports])
if not public_import_protos:
# This line is necessary to trigger the check.
args.add("--allowed_public_imports=")
diff --git a/src/test/java/com/google/devtools/build/lib/rules/proto/BUILD b/src/test/java/com/google/devtools/build/lib/rules/proto/BUILD
index bac7bd3..1deb3e6 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/proto/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/rules/proto/BUILD
@@ -43,7 +43,7 @@
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/rules/proto",
- "//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
+ "//src/main/java/net/starlark/java/syntax",
"//src/test/java/com/google/devtools/build/lib/analysis/util",
"//src/test/java/com/google/devtools/build/lib/packages:testutil",
"//src/test/java/com/google/devtools/build/lib/testutil:TestConstants",
diff --git a/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoLangToolchainTest.java b/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoLangToolchainTest.java
index 23daa19..3c1ff64 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoLangToolchainTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoLangToolchainTest.java
@@ -17,15 +17,18 @@
import static com.google.common.truth.Truth.assertThat;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import com.google.common.eventbus.EventBus;
import com.google.devtools.build.lib.analysis.FilesToRunProvider;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.packages.StarlarkInfo;
+import com.google.devtools.build.lib.packages.StarlarkProvider;
+import com.google.devtools.build.lib.packages.StructImpl;
import com.google.devtools.build.lib.packages.util.MockProtoSupport;
import com.google.devtools.build.lib.testutil.TestConstants;
-import com.google.devtools.build.lib.vfs.PathFragment;
+import net.starlark.java.syntax.Location;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -232,12 +235,22 @@
FilesToRunProvider protoCompiler =
getConfiguredTarget("//net/proto2/compiler/public:protocol_compiler")
.getProvider(FilesToRunProvider.class);
- ImmutableList<ProtoSource> providedProtoSources =
+ StarlarkProvider provider =
+ StarlarkProvider.builder(Location.BUILTIN)
+ .setExported(
+ new StarlarkProvider.Key(
+ Label.parseCanonicalUnchecked("@_builtins//:common/proto/protoinfo.bzl"),
+ "ProtoSourceInfo"))
+ .build();
+ ImmutableList<StructImpl> providedProtoSources =
ImmutableList.of(
- new ProtoSource(
- getSourceArtifact("a.proto"),
- getSourceArtifact("_virtual_imports/b/a.proto"),
- PathFragment.create("b")));
+ StarlarkInfo.create(
+ provider,
+ ImmutableMap.of(
+ "original_source_file", getSourceArtifact("a.proto"),
+ "source_file", getSourceArtifact("_virtual_imports/b/a.proto"),
+ "proto_path", "b"),
+ Location.BUILTIN));
StarlarkInfo starlarkProvider =
ProtoLangToolchainProvider.create(
/* outReplacementFormatFlag= */ "outReplacementFormatFlag",