github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/third_party/android/android_configure.bzl (about) 1 """Repository rule for Android SDK and NDK autoconfiguration. 2 3 `android_configure` depends on the following environment variables: 4 5 * `ANDROID_NDK_HOME`: Location of Android NDK root. 6 * `ANDROID_SDK_HOME`: Location of Android SDK root. 7 * `ANDROID_SDK_API_LEVEL`: Desired Android SDK API version. 8 * `ANDROID_NDK_API_LEVEL`: Desired Android NDK API version. 9 * `ANDROID_BUILD_TOOLS_VERSION`: Desired Android build tools version. 10 """ 11 12 # TODO(mikecase): Move logic for getting default values for the env variables 13 # from configure.py script into this rule. 14 15 _ANDROID_NDK_HOME = "ANDROID_NDK_HOME" 16 _ANDROID_SDK_HOME = "ANDROID_SDK_HOME" 17 _ANDROID_NDK_API_VERSION = "ANDROID_NDK_API_LEVEL" 18 _ANDROID_SDK_API_VERSION = "ANDROID_SDK_API_LEVEL" 19 _ANDROID_BUILD_TOOLS_VERSION = "ANDROID_BUILD_TOOLS_VERSION" 20 21 _ANDROID_SDK_REPO_TEMPLATE = """ 22 native.android_sdk_repository( 23 name="androidsdk", 24 path="%s", 25 api_level=%s, 26 build_tools_version="%s", 27 ) 28 """ 29 30 _ANDROID_NDK_REPO_TEMPLATE = """ 31 native.android_ndk_repository( 32 name="androidndk", 33 path="%s", 34 api_level=%s, 35 ) 36 """ 37 38 def _android_autoconf_impl(repository_ctx): 39 """Implementation of the android_autoconf repository rule.""" 40 sdk_home = repository_ctx.os.environ.get(_ANDROID_SDK_HOME) 41 sdk_api_level = repository_ctx.os.environ.get(_ANDROID_SDK_API_VERSION) 42 build_tools_version = repository_ctx.os.environ.get( 43 _ANDROID_BUILD_TOOLS_VERSION, 44 ) 45 ndk_home = repository_ctx.os.environ.get(_ANDROID_NDK_HOME) 46 ndk_api_level = repository_ctx.os.environ.get(_ANDROID_NDK_API_VERSION) 47 48 sdk_rule = "pass" 49 if all([sdk_home, sdk_api_level, build_tools_version]): 50 sdk_rule = _ANDROID_SDK_REPO_TEMPLATE % ( 51 sdk_home, 52 sdk_api_level, 53 build_tools_version, 54 ) 55 56 ndk_rule = "pass" 57 if all([ndk_home, ndk_api_level]): 58 ndk_rule = _ANDROID_NDK_REPO_TEMPLATE % (ndk_home, ndk_api_level) 59 60 repository_ctx.template( 61 "BUILD", 62 Label("//third_party/android:android_configure.BUILD.tpl"), 63 ) 64 repository_ctx.template( 65 "android.bzl", 66 Label("//third_party/android:android.bzl.tpl"), 67 substitutions = { 68 "MAYBE_ANDROID_SDK_REPOSITORY": sdk_rule, 69 "MAYBE_ANDROID_NDK_REPOSITORY": ndk_rule, 70 }, 71 ) 72 73 android_configure = repository_rule( 74 implementation = _android_autoconf_impl, 75 environ = [ 76 _ANDROID_SDK_API_VERSION, 77 _ANDROID_NDK_API_VERSION, 78 _ANDROID_BUILD_TOOLS_VERSION, 79 _ANDROID_NDK_HOME, 80 _ANDROID_SDK_HOME, 81 ], 82 ) 83 """Writes Android SDK and NDK rules. 84 85 Add the following to your WORKSPACE FILE: 86 87 ```python 88 android_configure(name = "local_config_android") 89 ``` 90 91 Args: 92 name: A unique name for this workspace rule. 93 """