Bug 1578501 [wpt PR 18803] - WebKit export of https://bugs.webkit.org/show_bug.cgi...
[gecko.git] / build / moz.configure / android-sdk.configure
blob551a1cc1bdd6fe06ac4d4233086dba411d682fc4
1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 # Ensure Android SDK and build-tools versions depending on mobile target.
10 @depends(host, mozbuild_state_path, '--help')
11 @imports('os')
12 def default_android_sdk_root(host, mozbuild_state_path, _):
13     sdk_basename = {
14         'Darwin': 'android-sdk-macosx',
15         'Linux': 'android-sdk-linux',
16         'WINNT': 'android-sdk-windows',
17     }.get(host.kernel)
18     if sdk_basename:
19         path = os.path.join(mozbuild_state_path, sdk_basename)
20         if os.path.isdir(path):
21             return path
24 option('--with-android-sdk', nargs=1,
25        default=default_android_sdk_root,
26        help='location where the Android SDK can be found (like ~/.mozbuild/android-sdk-linux){|}')
29 @depends('--with-android-sdk')
30 @imports(_from='os.path', _import='isdir')
31 def android_sdk_root(value):
32     if value:
33         if not isdir(value[0]):
34             die("The path you specified with --with-android-sdk (%s) is not "
35                 "a directory" % value[0])
36         return value[0]
38     die("You must specify --with-android-sdk=/path/to/sdk when targeting Android, "
39         "or try |mach bootstrap|.")
42 @depends('--help')
43 def android_sdk_version(_):
44     return namespace(build_tools_versions=['28.0.3'], target_sdk_version='28')
47 @depends(android_sdk_root, android_sdk_version)
48 @checking('for Android build-tools')
49 @imports(_from='os.path', _import='exists')
50 @imports(_from='os.path', _import='isdir')
51 def android_build_tools(sdk_root, sdk_version):
52     android_build_tools_base = os.path.join(sdk_root, 'build-tools')
53     versions = sdk_version.build_tools_versions
54     for version in versions:
55         if isdir(os.path.join(android_build_tools_base, version)):
56             tools = os.path.join(android_build_tools_base, version)
57             for zipalign in ('zipalign', 'zipalign.exe'):
58                 if exists(os.path.join(tools, zipalign)):
59                     return [tools]
61     die("You must install the Android build-tools version %s.  "
62         "Try |mach bootstrap|.  (Looked for %s/%s)" %
63         (versions[0], android_build_tools_base, versions[0]))
66 @depends(android_sdk_root)
67 @checking('for Android tools')
68 @imports(_from='os.path', _import='isdir')
69 def android_tools(sdk_root):
70     tools = os.path.join(sdk_root, 'tools')
71     if isdir(tools):
72         return tools
74     die("You must install the Android tools.  Try |mach bootstrap|")
77 @depends(android_sdk_root)
78 @checking('for Android platform-tools')
79 @imports(_from='os.path', _import='exists')
80 @imports(_from='os.path', _import='isdir')
81 def android_platform_tools(sdk_root):
82     tools = os.path.join(sdk_root, 'platform-tools')
83     for adb in ('adb', 'adb.exe'):
84         if exists(os.path.join(tools, adb)):
85             return [tools]
87     die("You must install the Android platform-tools.  Try |mach bootstrap|.  (Looked for %s)" %
88         tools)
91 @depends(android_sdk_root)
92 def android_emulator_path(sdk_root):
93     return [os.path.join(sdk_root, 'emulator')]
96 @template
97 def check_android_tools(tool, tool_dir):
98     check = check_prog(tool.upper(), (tool, tool + '.exe'), paths=tool_dir,
99                        allow_missing=True)
101     @depends(check)
102     def require_tool(result):
103         if result is None:
104             die('The program %s was not found.  Try |mach bootstrap|' % tool)
105         return result
107     return require_tool
110 check_android_tools('zipalign', android_build_tools)
111 check_android_tools('adb', android_platform_tools)
112 check_android_tools('emulator', android_emulator_path)
114 set_config('ANDROID_SDK_ROOT', android_sdk_root)
115 set_config('ANDROID_TOOLS', android_tools)
117 set_config('ANDROID_TARGET_SDK', android_sdk_version.target_sdk_version)
118 add_old_configure_assignment('ANDROID_TARGET_SDK', android_sdk_version.target_sdk_version)