From 3bed84ff177c7cbfd0c8d315829cc9dcb35fcf70 Mon Sep 17 00:00:00 2001 From: Adam Michael Date: Fri, 10 Feb 2017 20:06:16 +0000 Subject: 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 --- .../bazel/rules/android/AndroidSdkRepositoryTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/test/java/com/google') diff --git a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryTest.java b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryTest.java index 0f33d2dd2f..6024b1f256 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryTest.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.bazel.rules.android; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.Artifact; @@ -22,6 +23,7 @@ import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.FilesToRunProvider; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; +import com.google.devtools.build.lib.packages.BuildFileNotFoundException; import com.google.devtools.build.lib.testutil.TestRuleClassProvider; import com.google.devtools.build.lib.vfs.FileSystemUtils; import org.junit.Before; @@ -42,6 +44,7 @@ public class AndroidSdkRepositoryTest extends BuildViewTestCase { @Before public void setup() throws Exception { scratch.setWorkingDir("/sdk"); + scratch.dir("platforms/android-24"); scratch.dir("platforms/android-25"); scratch.file("extras/google/m2repository/com/google/android/foo/1.0.0/foo.pom", "", @@ -127,4 +130,20 @@ public class AndroidSdkRepositoryTest extends BuildViewTestCase { .getFilesToRun()) .isEmpty(); } + + @Test + public void testMissingApiLevel() throws Exception { + scratch.deleteFile("/sdk/platforms/android-25"); + try { + invalidatePackages(); + getTarget("@androidsdk//:files"); + fail("android_sdk_repository should have failed due to missing SDK api level."); + } catch (BuildFileNotFoundException e) { + assertThat(e.getMessage()) + .contains( + "Android SDK api level 25 was requested but it is not installed in the Android SDK " + + "at /sdk. The api levels found were [24]. Please choose an available api level " + + "or install api level 25 from the Android SDK Manager."); + } + } } -- cgit v1.2.3