aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/android
diff options
context:
space:
mode:
authorGravatar Michael Case <mikecase@google.com>2018-06-05 17:47:19 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-06-05 17:50:28 -0700
commit5105350be955422169de1f22bb99f928c1f4c2ae (patch)
tree1b1d48dda99f14a5bc6a02355d8b479cced761c2 /third_party/android
parent8a141854d81a9135a3658255c5813c5277364d01 (diff)
Moves generated android_sdk() and android_ndk() repo rules out of WORKSPACE.
These rules currently get written by configure.py script to WORKSPACE file which is not ideal since (1) WORKSPACE file is tracked by git and (2) we require users to manually delete the rules in order to update/regenerate them. Moving these rules into an external repo that is generated based on several ENV variables set by the configure.py script. Modifying any of these ENV variables will cause the rules to be updated. PiperOrigin-RevId: 199388460
Diffstat (limited to 'third_party/android')
-rw-r--r--third_party/android/BUILD0
-rw-r--r--third_party/android/android.bzl.tpl9
-rw-r--r--third_party/android/android_configure.BUILD.tpl0
-rw-r--r--third_party/android/android_configure.bzl87
4 files changed, 96 insertions, 0 deletions
diff --git a/third_party/android/BUILD b/third_party/android/BUILD
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/third_party/android/BUILD
diff --git a/third_party/android/android.bzl.tpl b/third_party/android/android.bzl.tpl
new file mode 100644
index 0000000000..e6ed4994f3
--- /dev/null
+++ b/third_party/android/android.bzl.tpl
@@ -0,0 +1,9 @@
+"""Set up configurable Android SDK and NDK dependencies."""
+
+def android_workspace():
+ # String for replacement in Bazel template.
+ # These will either be replaced by android_sdk_repository if various ENV
+ # variables are set when `local_config_android` repo_rule is run, or they
+ # will be replaced by noops otherwise.
+ MAYBE_ANDROID_SDK_REPOSITORY
+ MAYBE_ANDROID_NDK_REPOSITORY
diff --git a/third_party/android/android_configure.BUILD.tpl b/third_party/android/android_configure.BUILD.tpl
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/third_party/android/android_configure.BUILD.tpl
diff --git a/third_party/android/android_configure.bzl b/third_party/android/android_configure.bzl
new file mode 100644
index 0000000000..da09bdf39e
--- /dev/null
+++ b/third_party/android/android_configure.bzl
@@ -0,0 +1,87 @@
+"""Repository rule for Android SDK and NDK autoconfiguration.
+
+`android_configure` depends on the following environment variables:
+
+ * `ANDROID_NDK_HOME`: Location of Android NDK root.
+ * `ANDROID_SDK_HOME`: Location of Android SDK root.
+ * `ANDROID_SDK_API_LEVEL`: Desired Android SDK API version.
+ * `ANDROID_NDK_API_LEVEL`: Desired Android NDK API version.
+ * `ANDROID_BUILD_TOOLS_VERSION`: Desired Android build tools version.
+"""
+
+# TODO(mikecase): Move logic for getting default values for the env variables
+# from configure.py script into this rule.
+
+_ANDROID_NDK_HOME = "ANDROID_NDK_HOME"
+_ANDROID_SDK_HOME = "ANDROID_SDK_HOME"
+_ANDROID_NDK_API_VERSION = "ANDROID_NDK_API_LEVEL"
+_ANDROID_SDK_API_VERSION = "ANDROID_SDK_API_LEVEL"
+_ANDROID_BUILD_TOOLS_VERSION = "ANDROID_BUILD_TOOLS_VERSION"
+
+_ANDROID_SDK_REPO_TEMPLATE = """
+ native.android_sdk_repository(
+ name="androidsdk",
+ path="%s",
+ api_level=%s,
+ build_tools_version="%s",
+ )
+"""
+
+_ANDROID_NDK_REPO_TEMPLATE = """
+ native.android_ndk_repository(
+ name="androidndk",
+ path="%s",
+ api_level=%s,
+ )
+"""
+
+def _android_autoconf_impl(repository_ctx):
+ """Implementation of the android_autoconf repository rule."""
+ sdk_home = repository_ctx.os.environ.get(_ANDROID_SDK_HOME)
+ sdk_api_level = repository_ctx.os.environ.get(_ANDROID_SDK_API_VERSION)
+ build_tools_version = repository_ctx.os.environ.get(
+ _ANDROID_BUILD_TOOLS_VERSION)
+ ndk_home = repository_ctx.os.environ.get(_ANDROID_NDK_HOME)
+ ndk_api_level = repository_ctx.os.environ.get(_ANDROID_NDK_API_VERSION)
+
+ sdk_rule = "pass"
+ if all([sdk_home, sdk_api_level, build_tools_version]):
+ sdk_rule = _ANDROID_SDK_REPO_TEMPLATE % (
+ sdk_home, sdk_api_level, build_tools_version)
+
+ ndk_rule = "pass"
+ if all([ndk_home, ndk_api_level]):
+ ndk_rule = _ANDROID_NDK_REPO_TEMPLATE % (ndk_home, ndk_api_level)
+
+ repository_ctx.template(
+ "BUILD",
+ Label("//third_party/android:android_configure.BUILD.tpl"))
+ repository_ctx.template(
+ "android.bzl",
+ Label("//third_party/android:android.bzl.tpl"),
+ substitutions={
+ "MAYBE_ANDROID_SDK_REPOSITORY": sdk_rule,
+ "MAYBE_ANDROID_NDK_REPOSITORY": ndk_rule,
+ })
+
+android_configure = repository_rule(
+ implementation = _android_autoconf_impl,
+ environ = [
+ _ANDROID_SDK_API_VERSION,
+ _ANDROID_NDK_API_VERSION,
+ _ANDROID_BUILD_TOOLS_VERSION,
+ _ANDROID_NDK_HOME,
+ _ANDROID_SDK_HOME,
+ ],
+)
+"""Writes Android SDK and NDK rules.
+
+Add the following to your WORKSPACE FILE:
+
+```python
+android_configure(name = "local_config_android")
+```
+
+Args:
+ name: A unique name for this workspace rule.
+"""