Make a 'did you mean' suggestion when referencing a non-existent label.
It works for both labels on the command-line and labels in BUILD files.
--
MOS_MIGRATED_REVID=123967347
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 8a666b0..cbfeb5b 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
@@ -34,6 +34,7 @@
import com.google.devtools.build.lib.packages.AttributeMap.AcceptsLabelAttribute;
import com.google.devtools.build.lib.packages.License.DistributionType;
import com.google.devtools.build.lib.util.Preconditions;
+import com.google.devtools.build.lib.util.SpellChecker;
import com.google.devtools.build.lib.vfs.Canonicalizer;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -528,7 +529,12 @@
suffix = "; however, a source file of this name exists. (Perhaps add "
+ "'exports_files([\"" + targetName + "\"])' to " + name + "/BUILD?)";
} else {
- suffix = "";
+ String suggestion = SpellChecker.suggest(targetName, targets.keySet());
+ if (suggestion != null) {
+ suffix = " (did you mean '" + suggestion + "'?)";
+ } else {
+ suffix = "";
+ }
}
throw makeNoSuchTargetException(targetName, suffix);