diff options
author | 2017-02-10 20:06:16 +0000 | |
---|---|---|
committer | 2017-02-13 11:32:37 +0000 | |
commit | 3bed84ff177c7cbfd0c8d315829cc9dcb35fcf70 (patch) | |
tree | c7494b92344f3ac6471c468b6b5b82afc75a78c4 /src/main | |
parent | d0ae210dec266be180fa95efb903b54b5c878096 (diff) |
Make android_sdk_repository fail if api_level requested is not installed.
This could have prevented https://github.com/bazelbuild/bazel/issues/2500.
--
PiperOrigin-RevId: 147182987
MOS_MIGRATED_REVID=147182987
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java index 4fa4f8f859..e06a8933d5 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java @@ -114,17 +114,31 @@ public class AndroidSdkRepositoryFunction extends RepositoryFunction { Transience.PERSISTENT); } - String defaultApiLevel; + Integer defaultApiLevel; if (attributes.isAttributeValueExplicitlySpecified("api_level")) { try { - defaultApiLevel = attributes.get("api_level", Type.INTEGER).toString(); + defaultApiLevel = attributes.get("api_level", Type.INTEGER); } catch (EvalException e) { throw new RepositoryFunctionException(e, Transience.PERSISTENT); } + if (!apiLevels.contains(defaultApiLevel)) { + throw new RepositoryFunctionException( + new EvalException( + rule.getLocation(), + String.format( + "Android SDK api level %s was requested but it is not installed in the Android " + + "SDK at %s. The api levels found were %s. Please choose an available api " + + "level or install api level %s from the Android SDK Manager.", + defaultApiLevel, + androidSdkPath, + apiLevels.toString(), + defaultApiLevel)), + Transience.PERSISTENT); + } } else { // If the api_level attribute is not explicitly set, we select the highest api level that is // available in the SDK. - defaultApiLevel = String.valueOf(apiLevels.first()); + defaultApiLevel = apiLevels.first(); } String buildToolsDirectory; @@ -189,7 +203,7 @@ public class AndroidSdkRepositoryFunction extends RepositoryFunction { .replace("%build_tools_version%", buildToolsVersion) .replace("%build_tools_directory%", buildToolsDirectory) .replace("%api_levels%", Iterables.toString(apiLevels)) - .replace("%default_api_level%", defaultApiLevel) + .replace("%default_api_level%", String.valueOf(defaultApiLevel)) .replace("%system_image_dirs%", systemImageDirsList); // All local maven repositories that are shipped in the Android SDK. |