Add //external:has_androidsdk config_setting.
This will be used to add some tests and targets to the Bazel codebase that build and run successfully when android_sdk_repository is in the WORKSPACE and silently skip if it is not.
Example deps of a library that links against dx.jar:
```
deps = select({
"//external:has_androidsdk": ["//external:android/dx_jar_import"],
"//conditions:default": [],
}),
```
Also adds tests that config_setting works as expected when propagated through an alias or bind rule.
RELNOTES: None
PiperOrigin-RevId: 157627472
diff --git a/tools/android/BUILD.tools b/tools/android/BUILD.tools
index 2c2e10f..7effede 100644
--- a/tools/android/BUILD.tools
+++ b/tools/android/BUILD.tools
@@ -240,3 +240,29 @@
rule to your WORKSPACE. ; \
exit 1 """,
)
+
+# //external:has_androidsdk is bound to either
+# @bazel_tools//tools/android:always_true or
+# @bazel_tools//tools/android:always_false depending on whether
+# android_sdk_repository has run. This allows targets to depend on targets from
+# @androidsdk if and only if the user has an android_sdk_repository set up.
+
+config_feature_flag(
+ name = "true",
+ default_value = "true",
+ allowed_values = ["true", "false"],
+)
+
+config_setting(
+ name = "always_true",
+ flag_values = {
+ ":true": "true"
+ },
+)
+
+config_setting(
+ name = "always_false",
+ flag_values = {
+ ":true": "false",
+ },
+)