Add new skyframe function to lookup the repository given a path, and use that
to report invalid package references. Fixes #1592.
--
MOS_MIGRATED_REVID=137164164
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 54ccc3e..7e1fca4 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
@@ -15,6 +15,7 @@
package com.google.devtools.build.lib.packages;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@@ -475,11 +476,23 @@
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,
+ new Predicate<Rule>() {
+ @Override
+ public boolean apply(@Nullable Rule rule) {
+ return rule.getRuleClass().equals(ruleClass);
+ }
+ });
+ }
+
/**
* Returns this package's workspace name.
*
- * <p>Package-private to encourage callers to get their workspace name from a rule, not a
- * package.</p>
+ * <p>Package-private to encourage callers to get their workspace name from a rule, not a package.
*/
public String getWorkspaceName() {
return workspaceName;