Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 625722242
Change-Id: I74cc04a29cb230f9c6ad771c063a3ecc4a596891
  • Loading branch information
brandjon authored and copybara-github committed Apr 17, 2024
1 parent cf5951e commit 32def70
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 150 deletions.

This file was deleted.

10 changes: 0 additions & 10 deletions src/main/java/com/google/devtools/build/lib/packages/Rule.java
Original file line number Diff line number Diff line change
Expand Up @@ -903,16 +903,6 @@ public SetMultimap<Attribute, Label> getTransitions(DependencyFilter filter) {
return transitions;
}

/**
* Check if this rule is valid according to the validityPredicate of its RuleClass.
*/
void checkValidityPredicate(EventHandler eventHandler) {
PredicateWithMessage<Rule> predicate = ruleClass.getValidityPredicate();
if (!predicate.apply(this)) {
reportError(predicate.getErrorReason(this), eventHandler);
}
}

/**
* Collects the output files (both implicit and explicit). Must be called before the output
* accessors methods can be used, and must be called only once.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package com.google.devtools.build.lib.packages;

import static com.google.common.collect.Streams.stream;
import static com.google.devtools.build.lib.packages.Attribute.attr;
import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
import static com.google.devtools.build.lib.packages.Type.BOOLEAN;
Expand Down Expand Up @@ -165,66 +164,6 @@ public class RuleClass implements RuleClassData {

public static final String APPLICABLE_METADATA_ATTR_ALT = "applicable_licenses";

/** A constraint for the package name of the Rule instances. */
public static class PackageNameConstraint implements PredicateWithMessage<Rule> {

public static final int ANY_SEGMENT = 0;

private final int pathSegment;

private final Set<String> values;

/**
* The pathSegment-th segment of the package must be one of the specified values. The path
* segment indexing starts from 1.
*/
public PackageNameConstraint(int pathSegment, String... values) {
this.values = ImmutableSet.copyOf(values);
this.pathSegment = pathSegment;
}

@Override
public boolean apply(Rule input) {
PathFragment path = input.getLabel().getPackageFragment();
if (pathSegment == ANY_SEGMENT) {
return stream(path.segments()).anyMatch(values::contains);
} else {
return path.segmentCount() >= pathSegment
&& values.contains(path.getSegment(pathSegment - 1));
}
}

@Override
public String getErrorReason(Rule param) {
if (pathSegment == ANY_SEGMENT) {
return param.getRuleClass()
+ " rules have to be under a "
+ StringUtil.joinEnglishList(values, "or", "'")
+ " directory";
} else if (pathSegment == 1) {
return param.getRuleClass()
+ " rules are only allowed in "
+ StringUtil.joinEnglishList(Iterables.transform(values, s -> "//" + s), "or");
} else {
return param.getRuleClass()
+ " rules are only allowed in packages which "
+ StringUtil.ordinal(pathSegment)
+ " is "
+ StringUtil.joinEnglishList(values, "or");
}
}

@VisibleForTesting
public int getPathSegment() {
return pathSegment;
}

@VisibleForTesting
public Collection<String> getValues() {
return values;
}
}

/** Possible values for setting whether a rule uses toolchain resolution. */
public enum ToolchainResolutionMode {
/** The rule should use toolchain resolution. */
Expand Down Expand Up @@ -783,7 +722,6 @@ public String toString() {
private ImplicitOutputsFunction implicitOutputsFunction = SafeImplicitOutputsFunction.NONE;
@Nullable private TransitionFactory<RuleTransitionData> transitionFactory;
private ConfiguredTargetFactory<?, ?, ?> configuredTargetFactory = null;
private PredicateWithMessage<Rule> validityPredicate = PredicatesWithMessage.alwaysTrue();
private final AdvertisedProviderSet.Builder advertisedProviders =
AdvertisedProviderSet.builder();
private StarlarkCallable configuredTargetFunction = null;
Expand Down Expand Up @@ -850,9 +788,6 @@ public Builder(String name, RuleClassType type, boolean starlark, RuleClass... p
Preconditions.checkArgument(starlarkParent.isExtendable());
}
for (RuleClass parent : parents) {
if (parent.getValidityPredicate() != PredicatesWithMessage.<Rule>alwaysTrue()) {
setValidityPredicate(parent.getValidityPredicate());
}
configurationFragmentPolicy.includeConfigurationFragmentsFrom(
parent.getConfigurationFragmentPolicy());
supportsConstraintChecking = parent.supportsConstraintChecking;
Expand Down Expand Up @@ -997,7 +932,6 @@ public RuleClass build(String name, String key) {
implicitOutputsFunction,
transitionFactory,
configuredTargetFactory,
validityPredicate,
advertisedProviders.build(),
configuredTargetFunction,
externalBindingsFunction,
Expand Down Expand Up @@ -1213,12 +1147,6 @@ public Builder factory(ConfiguredTargetFactory<?, ?, ?> factory) {
return this;
}

@CanIgnoreReturnValue
public Builder setValidityPredicate(PredicateWithMessage<Rule> predicate) {
this.validityPredicate = predicate;
return this;
}

/**
* State that the rule class being built possibly supplies the specified provider to its direct
* dependencies.
Expand Down Expand Up @@ -1747,9 +1675,6 @@ public Attribute.Builder<?> copy(String name) {
/** The factory that creates configured targets from this rule. */
private final ConfiguredTargetFactory<?, ?, ?> configuredTargetFactory;

/** The constraint the package name of the rule instance must fulfill */
private final PredicateWithMessage<Rule> validityPredicate;

/** The list of transitive info providers this class advertises to aspects. */
private final AdvertisedProviderSet advertisedProviders;

Expand Down Expand Up @@ -1855,7 +1780,6 @@ public Attribute.Builder<?> copy(String name) {
ImplicitOutputsFunction implicitOutputsFunction,
@Nullable TransitionFactory<RuleTransitionData> transitionFactory,
ConfiguredTargetFactory<?, ?, ?> configuredTargetFactory,
PredicateWithMessage<Rule> validityPredicate,
AdvertisedProviderSet advertisedProviders,
@Nullable StarlarkCallable configuredTargetFunction,
Function<? super Rule, Map<String, Label>> externalBindingsFunction,
Expand Down Expand Up @@ -1893,7 +1817,6 @@ public Attribute.Builder<?> copy(String name) {
this.implicitOutputsFunction = implicitOutputsFunction;
this.transitionFactory = transitionFactory;
this.configuredTargetFactory = configuredTargetFactory;
this.validityPredicate = validityPredicate;
this.advertisedProviders = advertisedProviders;
this.configuredTargetFunction = configuredTargetFunction;
this.externalBindingsFunction = externalBindingsFunction;
Expand Down Expand Up @@ -2084,10 +2007,6 @@ List<String> getNonConfigurableAttributes() {
return nonConfigurableAttributes;
}

public PredicateWithMessage<Rule> getValidityPredicate() {
return validityPredicate;
}

/**
* Returns the set of advertised transitive info providers.
*
Expand Down Expand Up @@ -2152,7 +2071,6 @@ <T> Rule createRule(
checkForDuplicateLabels(rule, eventHandler);

checkForValidSizeAndTimeoutValues(rule, eventHandler);
rule.checkValidityPredicate(eventHandler);
return rule;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ private static RuleClass createRuleClassA() throws LabelSyntaxException {
SafeImplicitOutputsFunction.NONE,
null,
DUMMY_CONFIGURED_TARGET_FACTORY,
PredicatesWithMessage.alwaysTrue(),
AdvertisedProviderSet.EMPTY,
null,
ImmutableSet.of(),
Expand Down Expand Up @@ -144,7 +143,6 @@ private static RuleClass createRuleClassB(RuleClass ruleClassA) {
SafeImplicitOutputsFunction.NONE,
null,
DUMMY_CONFIGURED_TARGET_FACTORY,
PredicatesWithMessage.alwaysTrue(),
AdvertisedProviderSet.EMPTY,
null,
ImmutableSet.of(),
Expand Down Expand Up @@ -295,7 +293,6 @@ public void testDuplicatedDeps() throws Exception {
SafeImplicitOutputsFunction.NONE,
null,
DUMMY_CONFIGURED_TARGET_FACTORY,
PredicatesWithMessage.alwaysTrue(),
AdvertisedProviderSet.EMPTY,
null,
ImmutableSet.of(),
Expand Down Expand Up @@ -338,7 +335,6 @@ public void testDuplicatedDepsWithinSingleSelectConditionError() throws Exceptio
SafeImplicitOutputsFunction.NONE,
null,
DUMMY_CONFIGURED_TARGET_FACTORY,
PredicatesWithMessage.alwaysTrue(),
AdvertisedProviderSet.EMPTY,
null,
ImmutableSet.of(),
Expand Down Expand Up @@ -375,7 +371,6 @@ public void testDuplicatedDepsWithinConditionMultipleSelectsErrors() throws Exce
SafeImplicitOutputsFunction.NONE,
null,
DUMMY_CONFIGURED_TARGET_FACTORY,
PredicatesWithMessage.alwaysTrue(),
AdvertisedProviderSet.EMPTY,
null,
ImmutableSet.of(),
Expand Down Expand Up @@ -424,7 +419,6 @@ public void testSameDepAcrossMultipleSelectsNoDuplicateNoError() throws Exceptio
SafeImplicitOutputsFunction.NONE,
null,
DUMMY_CONFIGURED_TARGET_FACTORY,
PredicatesWithMessage.alwaysTrue(),
AdvertisedProviderSet.EMPTY,
null,
ImmutableSet.of(),
Expand Down Expand Up @@ -467,7 +461,6 @@ public void testSameDepAcrossMultipleSelectsIsDuplicateNoError() throws Exceptio
SafeImplicitOutputsFunction.NONE,
null,
DUMMY_CONFIGURED_TARGET_FACTORY,
PredicatesWithMessage.alwaysTrue(),
AdvertisedProviderSet.EMPTY,
null,
ImmutableSet.of(),
Expand Down Expand Up @@ -510,7 +503,6 @@ public void testSameDepAcrossConditionsInSelectNoError() throws Exception {
SafeImplicitOutputsFunction.NONE,
null,
DUMMY_CONFIGURED_TARGET_FACTORY,
PredicatesWithMessage.alwaysTrue(),
AdvertisedProviderSet.EMPTY,
null,
ImmutableSet.of(),
Expand Down Expand Up @@ -608,7 +600,6 @@ public void testImplicitOutputs() throws Exception {
"foo-%{name}.bar", "lib%{name}-wazoo-%{name}.mumble", "stuff-%{outs}-bar"),
null,
DUMMY_CONFIGURED_TARGET_FACTORY,
PredicatesWithMessage.alwaysTrue(),
AdvertisedProviderSet.EMPTY,
null,
ImmutableSet.of(),
Expand Down Expand Up @@ -644,7 +635,6 @@ public void testImplicitOutsWithBasenameDirname() throws Exception {
ImplicitOutputsFunction.fromTemplates("%{dirname}lib%{basename}.bar"),
null,
DUMMY_CONFIGURED_TARGET_FACTORY,
PredicatesWithMessage.alwaysTrue(),
AdvertisedProviderSet.EMPTY,
null,
ImmutableSet.of(),
Expand Down Expand Up @@ -675,7 +665,6 @@ private static RuleClass getRuleClassWithComputedDefault(Attribute computedDefau
ImplicitOutputsFunction.fromTemplates("empty"),
null,
DUMMY_CONFIGURED_TARGET_FACTORY,
PredicatesWithMessage.alwaysTrue(),
AdvertisedProviderSet.EMPTY,
null,
ImmutableSet.of(),
Expand Down Expand Up @@ -844,7 +833,6 @@ public void testOutputsAreOrdered() throws Exception {
ImplicitOutputsFunction.fromTemplates("first-%{name}", "second-%{name}", "out-%{outs}"),
null,
DUMMY_CONFIGURED_TARGET_FACTORY,
PredicatesWithMessage.alwaysTrue(),
AdvertisedProviderSet.EMPTY,
null,
ImmutableSet.of(),
Expand Down Expand Up @@ -882,7 +870,6 @@ public void testSubstitutePlaceholderIntoTemplate() throws Exception {
SafeImplicitOutputsFunction.NONE,
null,
DUMMY_CONFIGURED_TARGET_FACTORY,
PredicatesWithMessage.alwaysTrue(),
AdvertisedProviderSet.EMPTY,
null,
ImmutableSet.of(),
Expand Down Expand Up @@ -1032,7 +1019,6 @@ private static RuleClass newRuleClass(
ImplicitOutputsFunction implicitOutputsFunction,
TransitionFactory<RuleTransitionData> transitionFactory,
ConfiguredTargetFactory<?, ?, ?> configuredTargetFactory,
PredicateWithMessage<Rule> validityPredicate,
AdvertisedProviderSet advertisedProviders,
@Nullable StarlarkFunction configuredTargetFunction,
Set<Class<? extends Fragment>> allowedConfigurationFragments,
Expand Down Expand Up @@ -1061,7 +1047,6 @@ private static RuleClass newRuleClass(
implicitOutputsFunction,
transitionFactory,
configuredTargetFactory,
validityPredicate,
advertisedProviders,
configuredTargetFunction,
NO_EXTERNAL_BINDINGS,
Expand Down Expand Up @@ -1101,7 +1086,6 @@ private static RuleClass createParentRuleClass() {
SafeImplicitOutputsFunction.NONE,
null,
DUMMY_CONFIGURED_TARGET_FACTORY,
PredicatesWithMessage.alwaysTrue(),
AdvertisedProviderSet.EMPTY,
null,
ImmutableSet.of(DummyFragment.class),
Expand Down

0 comments on commit 32def70

Please sign in to comment.