Skip to content

Commit

Permalink
Removes toRuleTags ValidityPredicate parameter.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 567290365
Change-Id: Iff140a2953709d17140161b69f56ae158a9bb989
  • Loading branch information
aoeui authored and copybara-github committed Sep 21, 2023
1 parent e51f26e commit 80e7023
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1949,9 +1949,7 @@ private void validateDirectPrerequisiteType(
String ruleClass = prerequisite.getRuleClass();
if (!ruleClass.isEmpty()) {
String reason =
attribute
.getValidityPredicate()
.checkValid(target.getAssociatedRule(), ruleClass, prerequisite.getRuleTags());
attribute.getValidityPredicate().checkValid(target.getAssociatedRule(), ruleClass);
if (reason != null) {
reportBadPrerequisite(attribute, prerequisite, reason, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,13 @@ public interface ValidityPredicate {
/**
* This method should return null if the edge is valid, or a suitable error message if it is
* not. Note that warnings are not supported.
*
* @param toRuleTags the tags of the rule, used as a workaround in {@code J2ObjcLibraryBaseRule}
* and should probably be deleted.
*/
@Nullable
String checkValid(Rule from, String toRuleClass, Set<String> toRuleTags);
String checkValid(Rule from, String toRuleClass);
}

@SerializationConstant
public static final ValidityPredicate ANY_EDGE = (from, toRuleClass, toRuleTags) -> null;
public static final ValidityPredicate ANY_EDGE = (from, toRuleClass) -> null;

/** A predicate class to check if the value of the attribute comes from a predefined set. */
public static class AllowedValueSet implements PredicateWithMessage<Object> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@
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.packages.Attribute.ValidityPredicate;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
import com.google.devtools.build.lib.rules.cpp.CppRuleClasses;
import java.util.Set;
import javax.annotation.Nullable;

/**
* Abstract rule definition for j2objc_library.
Expand Down Expand Up @@ -95,22 +91,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
The list of additional JRE emulation libraries required by all Java code translated by this
<code>j2objc_library</code> rule. Only core JRE functionality is linked by default.
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(
attr("jre_deps", LABEL_LIST)
.allowedRuleClasses("objc_library")
.allowedFileTypes()
.validityPredicate(
new ValidityPredicate() {
@Override
@Nullable
public String checkValid(
Rule from, String toRuleClass, Set<String> toRuleTags) {
if (!toRuleTags.contains("j2objc_jre_lib")) {
return "Only J2ObjC JRE libraries are allowed";
}
return null;
}
}))
.add(attr("jre_deps", LABEL_LIST).allowedRuleClasses("objc_library").allowedFileTypes())
.addToolchainTypes(CppRuleClasses.ccToolchainTypeRequirement(env))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ public void testValidityChecker() throws Exception {
ValidityPredicate checker =
new ValidityPredicate() {
@Override
public String checkValid(Rule from, String toRuleClass, Set<String> toRuleTags) {
public String checkValid(Rule from, String toRuleClass) {
assertThat(from.getName()).isEqualTo("top");
switch (toRuleClass) {
case "dep1class":
Expand All @@ -1144,13 +1144,13 @@ public String checkValid(Rule from, String toRuleClass, Set<String> toRuleTags)
topClass
.getAttributeByName("deps")
.getValidityPredicate()
.checkValid(topRule, dep1.getRuleClass(), dep1.getRuleTags()))
.checkValid(topRule, dep1.getRuleClass()))
.isEqualTo("pear");
assertThat(
topClass
.getAttributeByName("deps")
.getValidityPredicate()
.checkValid(topRule, dep2.getRuleClass(), dep2.getRuleTags()))
.checkValid(topRule, dep2.getRuleClass()))
.isNull();
}

Expand Down

0 comments on commit 80e7023

Please sign in to comment.