Pass through information about package lookup failure into import lookup.
This fixes 'Misleading error message "file must have a corresponding package"' '#7094.
PiperOrigin-RevId: 235806611
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupValue.java
index 7ab319c..302d6db 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupValue.java
@@ -26,6 +26,7 @@
import com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
+import javax.annotation.Nonnull;
/**
* A value that represents the result of looking for the existence of a package that owns a
@@ -45,6 +46,14 @@
/** If there is a containing package, returns its package root */
public abstract Root getContainingPackageRoot();
+ /**
+ * If there is not a containing package, returns a reason why (this is usually the reason the
+ * outer-most directory isn't a package).
+ */
+ public String getReasonForNoContainingPackage() {
+ throw new IllegalStateException();
+ }
+
public static Key key(PackageIdentifier id) {
Preconditions.checkArgument(!id.getPackageFragment().isAbsolute(), id);
Preconditions.checkArgument(!id.getRepository().isDefault(), id);
@@ -112,7 +121,15 @@
/** Value indicating there is no containing package. */
public static class NoContainingPackage extends ContainingPackageLookupValue {
- private NoContainingPackage() {}
+ private final String reason;
+
+ private NoContainingPackage() {
+ this.reason = null;
+ }
+
+ NoContainingPackage(@Nonnull String reason) {
+ this.reason = reason;
+ }
@Override
public boolean hasContainingPackage() {
@@ -133,6 +150,11 @@
public String toString() {
return getClass().getName();
}
+
+ @Override
+ public String getReasonForNoContainingPackage() {
+ return reason;
+ }
}
/** A successful lookup value. */