Skip to content

Commit

Permalink
Remove native proto_library implementation.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 425894387
  • Loading branch information
comius authored and copybara-github committed Feb 2, 2022
1 parent a0fe0d8 commit 76c8c3a
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 803 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ abstract class ParametrizedMapFn<T> implements MapFn<T> {
public abstract int maxInstancesAllowed();
}

/**
* Use this map function when your map function needs to capture per-rule information.
*
* <p>Use of this class prevents sharing sub-computations over shared NestedSets, since the map
* function is per-target. This will make your action key computations become O(N^2). Please avoid
* if possible.
*/
interface CapturingMapFn<T> extends MapFn<T> {}

/** Expands the object into the command line as a string. */
String expandToCommandLine();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.google.common.collect.Multiset;
import com.google.devtools.build.lib.actions.CommandLineExpansionException;
import com.google.devtools.build.lib.actions.CommandLineItem;
import com.google.devtools.build.lib.actions.CommandLineItem.MapFn;
import com.google.devtools.build.lib.util.Fingerprint;
import com.google.devtools.build.lib.vfs.DigestHashFunction;
import java.util.HashSet;
Expand All @@ -45,10 +44,6 @@ public <T> void addNestedSetToFingerprint(Fingerprint fingerprint, NestedSet<T>
public <T> void addNestedSetToFingerprint(
CommandLineItem.MapFn<? super T> mapFn, Fingerprint fingerprint, NestedSet<T> nestedSet)
throws CommandLineExpansionException, InterruptedException {
if (mapFn instanceof CommandLineItem.CapturingMapFn) {
addNestedSetToFingerprintSlow(mapFn, fingerprint, nestedSet);
return;
}
// Only top-level nested sets can be empty, so we can bail here
if (nestedSet.isEmpty()) {
fingerprint.addInt(EMPTY_SET_DIGEST);
Expand All @@ -60,14 +55,6 @@ public <T> void addNestedSetToFingerprint(
addToFingerprint(mapFn, fingerprint, digestMap, children);
}

private <T> void addNestedSetToFingerprintSlow(
MapFn<? super T> mapFn, Fingerprint fingerprint, NestedSet<T> nestedSet)
throws CommandLineExpansionException, InterruptedException {
for (T object : nestedSet.toList()) {
addToFingerprint(mapFn, fingerprint, object);
}
}

public void clear() {
mapFnToDigestMap = createMap();
seenMapFns.clear();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,27 @@
package com.google.devtools.build.lib.rules.proto;

import static com.google.devtools.build.lib.packages.Attribute.attr;
import static com.google.devtools.build.lib.packages.BuildType.LABEL;
import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
import static com.google.devtools.build.lib.packages.Type.STRING;

import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.packages.Attribute;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.util.FileType;

/**
* Rule definition for the proto_library rule.
*
* <p>This rule is implemented in Starlark. This class remains only for doc-gen purposes.
*/
public final class BazelProtoLibraryRule implements RuleDefinition {

private static final Label DEFAULT_PROTO_COMPILER =
Label.parseAbsoluteUnchecked("@com_google_protobuf//:protoc");
private static final Attribute.LabelLateBoundDefault<?> PROTO_COMPILER =
Attribute.LabelLateBoundDefault.fromTargetConfiguration(
ProtoConfiguration.class,
DEFAULT_PROTO_COMPILER,
(rule, attributes, protoConfig) ->
protoConfig.protoCompiler() != null
? protoConfig.protoCompiler()
: DEFAULT_PROTO_COMPILER);

@Override
public RuleClass build(RuleClass.Builder builder, final RuleDefinitionEnvironment env) {

return builder
.requiresConfigurationFragments(ProtoConfiguration.class)
.setOutputToGenfiles()
.add(
attr(":proto_compiler", LABEL)
.cfg(ExecutionTransitionFactory.create())
.exec()
.value(PROTO_COMPILER))
/* <!-- #BLAZE_RULE(proto_library).ATTRIBUTE(deps) -->
The list of other <code>proto_library</code> rules that the target depends upon.
A <code>proto_library</code> may only depend on other
Expand Down Expand Up @@ -114,7 +95,7 @@ public Metadata getMetadata() {
return RuleDefinition.Metadata.builder()
.name("proto_library")
.ancestors(BaseRuleClasses.NativeActionCreatingRule.class)
.factoryClass(BazelProtoLibrary.class)
.factoryClass(BaseRuleClasses.EmptyRuleConfiguredTargetFactory.class)
.build();
}
}
Expand Down
Loading

0 comments on commit 76c8c3a

Please sign in to comment.