diff options
author | 2017-05-05 05:15:02 +0200 | |
---|---|---|
committer | 2017-05-05 15:27:26 +0200 | |
commit | 71ed1ee7c796b6cc0366ed4d39963b9542ac6e58 (patch) | |
tree | e42096edbd6db3fffd9b0e6ed746ef86f4becea1 | |
parent | 14747a8bf2d35846d75ac9058e1b514a89f68f07 (diff) |
Improve error message when building Android rules without an SDK.
Fixes https://github.com/bazelbuild/bazel/issues/509.
Example output:
```
$ bazel build //:all
INFO: Found 1 target...
ERROR: /usr/local/google/home/ajmichael/.cache/bazel/_bazel_ajmichael/7fcc7480abc634522e5c0cfe6b85b583/external/bazel_tools/tools/android/BUILD:236:1: Executing genrule @bazel_tools//tools/android:no_android_sdk_repository_error failed: Process exited with status 1 [sandboxed].
This build requires an Android SDK. Please add the android_sdk_repository rule to your WORKSPACE.
Use --strategy=Genrule=standalone to disable sandboxing for the failing actions.
Target //:lib failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.327s, Critical Path: 0.10s
```
RELNOTES: Attempting to build an Android target without setting up android_sdk_repository will now produce a helpful error message.
PiperOrigin-RevId: 155158667
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/bazel/rules/android/android.WORKSPACE | 3 | ||||
-rw-r--r-- | tools/android/BUILD.tools | 31 |
2 files changed, 33 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/android.WORKSPACE b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/android.WORKSPACE index c25c571698..51fdfef483 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/android.WORKSPACE +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/android.WORKSPACE @@ -1,4 +1,5 @@ -bind(name = "android/sdk") +bind(name = "android/sdk", actual = "@bazel_tools//tools/android:poison_pill_android_sdk") +bind(name = "android/dx_jar_import", actual = "@bazel_tools//tools/android:no_android_sdk_repository_error") bind(name = "android/crosstool", actual = "@bazel_tools//tools/cpp:toolchain") bind(name = "android_sdk_for_testing", actual = "//:dummy") bind(name = "android_ndk_for_testing", actual = "//:dummy") diff --git a/tools/android/BUILD.tools b/tools/android/BUILD.tools index 782fea920e..8c7bc618a3 100644 --- a/tools/android/BUILD.tools +++ b/tools/android/BUILD.tools @@ -210,3 +210,34 @@ alias( name = "databinding_annotation_processor", actual = "@android_databinding//:annotation_processor", ) + +# This is the default binding of //external:android/sdk. If someone attempts to +# build a rule that depends on //external:android/sdk without setting up +# android_sdk_repository in their WORKSPACE, the genrule will fail with a +# helpful error message. +android_sdk( + name = "poison_pill_android_sdk", + proguard = ":error_message", + aapt = ":error_message", + dx = ":error_message", + main_dex_list_creator = ":error_message", + adb = ":error_message", + framework_aidl = ":error_message", + aidl = ":error_message", + android_jar = ":error_message.jar", + shrinked_android_jar = ":error_message.jar", + annotations_jar = ":error_message.jar", + main_dex_classes = ":error_message", + apksigner = ":error_message", + zipalign = ":error_message", + resource_extractor = "error_message", +) + +genrule( + name = "no_android_sdk_repository_error", + outs = ["error_message", "error_message.jar"], + cmd = """echo \ + This build requires an Android SDK. Please add the android_sdk_repository \ + rule to your WORKSPACE. ; \ + exit 1 """, +) |