Minor tidying of Package's rule lookup methods
Declare bankruptcy on Package#getRule(String)'s @VisibleForTesting, it might
have been true at some point but it's not now.
Package#getRulesMatchingRuleClass is only used in one place, so inline it there
to declutter Package's api.
PiperOrigin-RevId: 281745778
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Package.java b/src/main/java/com/google/devtools/build/lib/packages/Package.java
index a6b0508..c993959 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Package.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Package.java
@@ -528,17 +528,10 @@
* for walking through the dependency graph of a target.
* Fails if the target is not a Rule.
*/
- @VisibleForTesting // Should be package-private
public Rule getRule(String targetName) {
return (Rule) targets.get(targetName);
}
- /** Returns all rules in the package that match the given rule class. */
- public Iterable<Rule> getRulesMatchingRuleClass(final String ruleClass) {
- Iterable<Rule> targets = getTargets(Rule.class);
- return Iterables.filter(targets, rule -> rule.getRuleClass().equals(ruleClass));
- }
-
/**
* Returns this package's workspace name.
*/
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunction.java
index 94b54d5..0e87677 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunction.java
@@ -195,7 +195,9 @@
// Find all local_repository rules in the WORKSPACE, and check if any have a "path" attribute
// the same as the requested directory.
Iterable<Rule> localRepositories =
- externalPackage.getRulesMatchingRuleClass(LocalRepositoryRule.NAME);
+ Iterables.filter(
+ externalPackage.getTargets(Rule.class),
+ rule -> LocalRepositoryRule.NAME.equals(rule.getRuleClass()));
Rule rule =
Iterables.find(
localRepositories,