aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar ajmichael <ajmichael@google.com>2017-05-23 23:43:00 +0200
committerGravatar Irina Iancu <elenairina@google.com>2017-05-24 14:37:38 +0200
commit0271796ab5f51e8da43ca5582c76d81843c54275 (patch)
tree01fd83313574e9b2a07463c604f15a9c692e06ba /src/main/java/com/google/devtools/build
parent55d74ab5a25a242b7cdf00eab19c910a0f5acadc (diff)
Improve error messages for malformed Android SDK/NDK.
Currently, if the user has an SDK/NDK that is missing required directories, we print out an InconsistentFileSystemException. This CL will give a better error, indicating which directory is missing (or is not a directory). Implementation is roughly taken from NewLocalRepositoryFunction. Followup to https://github.com/bazelbuild/bazel/issues/2739. RELNOTES: None PiperOrigin-RevId: 156913532
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryUtils.java32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryUtils.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryUtils.java
index ee65d2aade..4e5f0d0df4 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryUtils.java
@@ -17,6 +17,8 @@ import com.google.common.collect.ImmutableSortedSet;
import com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryFunctionException;
import com.google.devtools.build.lib.skyframe.DirectoryListingValue;
import com.google.devtools.build.lib.skyframe.Dirents;
+import com.google.devtools.build.lib.skyframe.FileSymlinkException;
+import com.google.devtools.build.lib.skyframe.FileValue;
import com.google.devtools.build.lib.skyframe.InconsistentFilesystemException;
import com.google.devtools.build.lib.vfs.Dirent;
import com.google.devtools.build.lib.vfs.Path;
@@ -34,15 +36,41 @@ import java.util.regex.Pattern;
final class AndroidRepositoryUtils {
private static final Pattern PLATFORMS_API_LEVEL_PATTERN = Pattern.compile("android-(\\d+)");
- /** Gets a DirectoryListingValue for {@code dirPath} or returns null. */
+ /**
+ * Gets a {@link DirectoryListingValue} for {@code dirPath} or returns null.
+ *
+ * <p>First, we get a {@link FileValue} to check the the {@code dirPath} exists and is a
+ * directory. If not, we throw an exception.
+ */
static DirectoryListingValue getDirectoryListing(Path root, PathFragment dirPath, Environment env)
throws RepositoryFunctionException, InterruptedException {
+ RootedPath rootedPath = RootedPath.toRootedPath(root, dirPath);
try {
+ FileValue dirFileValue =
+ (FileValue)
+ env.getValueOrThrow(
+ FileValue.key(rootedPath),
+ IOException.class,
+ FileSymlinkException.class,
+ InconsistentFilesystemException.class);
+ if (dirFileValue == null) {
+ return null;
+ }
+ if (!dirFileValue.exists() || !dirFileValue.isDirectory()) {
+ throw new RepositoryFunctionException(
+ new IOException(
+ String.format(
+ "Expected directory at %s but it is not a directory or it does not exist.",
+ rootedPath.asPath().getPathString())),
+ Transience.PERSISTENT);
+ }
return (DirectoryListingValue)
env.getValueOrThrow(
DirectoryListingValue.key(RootedPath.toRootedPath(root, dirPath)),
InconsistentFilesystemException.class);
- } catch (InconsistentFilesystemException e) {
+ } catch (IOException e) {
+ throw new RepositoryFunctionException(e, Transience.PERSISTENT);
+ } catch (FileSymlinkException | InconsistentFilesystemException e) {
throw new RepositoryFunctionException(new IOException(e), Transience.PERSISTENT);
}
}