File: android_configure.bzl

package info (click to toggle)
tensorflow 2.14.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 359,396 kB
  • sloc: cpp: 2,418,453; python: 736,954; java: 20,254; ansic: 18,962; sh: 9,279; pascal: 7,941; objc: 1,584; xml: 988; ada: 727; cs: 273; perl: 150; makefile: 92
file content (96 lines) | stat: -rw-r--r-- 2,896 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"""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 = ""
    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 = ""
    if all([ndk_home, ndk_api_level]):
        ndk_rule = _ANDROID_NDK_REPO_TEMPLATE % (ndk_home, ndk_api_level)

    if ndk_rule == "" and sdk_rule == "":
        sdk_rule = "pass"

    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.
"""