Skip to content

Commit

Permalink
Improve package loading error message on directories without BUILD files
Browse files Browse the repository at this point in the history
Let's print an actionable for the user and inform that BUILD files turn directories into packages.

Fixes #9364

Closes #9385.

Change-Id: Ia19133d2bfb0e71fdd03043592f525afddff740d
PiperOrigin-RevId: 269350796
  • Loading branch information
jin authored and copybara-github committed Sep 16, 2019
1 parent 4ace465 commit 5858c5a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ public SkyValue compute(SkyKey skyKey, Environment env)
*/
public static String explainNoBuildFileValue(PackageIdentifier packageKey, Environment env)
throws InterruptedException {
String educationalMessage = "Add a BUILD file to a directory to mark it as a package.";
if (packageKey.getRepository().isMain()) {
PathPackageLocator pkgLocator = PrecomputedValue.PATH_PACKAGE_LOCATOR.get(env);
StringBuilder message = new StringBuilder();
message.append("BUILD file not found in any of the following directories.");
message.append("BUILD file not found in any of the following directories. ");
message.append(educationalMessage);
for (Root root : pkgLocator.getPathEntries()) {
message
.append("\n - ")
Expand All @@ -127,7 +129,9 @@ public static String explainNoBuildFileValue(PackageIdentifier packageKey, Envir
return "BUILD file not found in directory '"
+ packageKey.getPackageFragment()
+ "' of external repository "
+ packageKey.getRepository();
+ packageKey.getRepository()
+ ". "
+ educationalMessage;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public void testMissingDependency() throws Exception {
.containsExactly(
new LoadingFailedCause(
causeLabel,
"no such package 'bar': BUILD file not found in any of the following directories.\n"
"no such package 'bar': BUILD file not found in any of the following "
+ "directories. Add a BUILD file to a directory to mark it as a package.\n"
+ " - /workspace/bar"));
}

Expand Down

0 comments on commit 5858c5a

Please sign in to comment.