Bug 1880227 - Migrate Focus docs into Sphinx. r=owlish,geckoview-reviewers,android...
[gecko.git] / build / moz.configure / android-sdk.configure
blob7607ed2135b8b26e0a6c2e8afc055f5e5e8cdc40
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, toolchains_base_dir, "--help")
11 @imports(_from="os.path", _import="isdir")
12 def default_android_sdk_root(host, toolchains_base_dir, _):
13     sdk_basename = {
14         "Darwin": "android-sdk-macosx",
15         "Linux": "android-sdk-linux",
16         "WINNT": "android-sdk-windows",
17     }.get(host.kernel, "android-sdk")
18     for sdk_basename in (sdk_basename, "android-sdk"):
19         path = os.path.join(toolchains_base_dir, sdk_basename)
20         if isdir(path):
21             return path
24 option(
25     "--with-android-sdk",
26     nargs=1,
27     default=default_android_sdk_root,
28     help="location where the Android SDK can be found (like ~/.mozbuild/android-sdk-linux){|}",
32 @depends("--with-android-sdk")
33 @imports(_from="os.path", _import="isdir")
34 def android_sdk_root(value):
35     if value:
36         if not isdir(value[0]):
37             die(
38                 "The path you specified with --with-android-sdk (%s) is not "
39                 "a directory" % value[0]
40             )
41         return value[0]
43     die(
44         "You must specify --with-android-sdk=/path/to/sdk when targeting Android, "
45         "or try |mach bootstrap|."
46     )
49 @dependable
50 def android_sdk_version():
51     # We support Android SDK version 21 and up by default.
52     # See the --enable-android-min-sdk option below.
53     #
54     # Warning: Before increasing the with-android-min-sdk value, please note several places in
55     # and out of tree have to be changed. Otherwise, places like Treeherder or archive.mozilla.org
56     # will advertise a bad API level. This may confuse people. As an example, please look at
57     # bug 1384482.
58     # If you think you can't handle the whole set of changes, please reach out to the Release
59     # Engineering team.
60     return namespace(
61         build_tools_version="34.0.0",
62         target_sdk_version="34",
63         min_sdk_version="21",
64     )
67 option(
68     "--with-android-min-sdk",
69     default=android_sdk_version.min_sdk_version,
70     help="Impose a minimum Firefox for Android SDK version",
74 @depends("--with-android-min-sdk", android_sdk_version.target_sdk_version)
75 @imports(_from="__builtin__", _import="ValueError")
76 def valid_android_min_sdk(min_sdk_version, target_sdk_version):
77     if not min_sdk_version:
78         die("--without-android-min-sdk is not a valid option")
79     try:
80         if int(min_sdk_version[0]) > int(target_sdk_version):
81             die(
82                 "--with-android-min-sdk is expected to be less than {}".format(
83                     target_sdk_version
84                 )
85             )
86     except ValueError:
87         die("--with-android-min-sdk takes a numerical value")
88     return min_sdk_version[0]
91 set_config("MOZ_ANDROID_MIN_SDK_VERSION", valid_android_min_sdk)
94 @depends(android_sdk_root, android_sdk_version)
95 @checking("for Android build-tools")
96 @imports(_from="os.path", _import="exists")
97 @imports(_from="os.path", _import="isdir")
98 def android_build_tools(sdk_root, sdk_version):
99     android_build_tools_base = os.path.join(sdk_root, "build-tools")
100     version = sdk_version.build_tools_version
101     if isdir(os.path.join(android_build_tools_base, version)):
102         tools = os.path.join(android_build_tools_base, version)
103         for zipalign in ("zipalign", "zipalign.exe"):
104             if exists(os.path.join(tools, zipalign)):
105                 return [tools]
107     die(
108         "You must install the Android build-tools version %s.  "
109         "Try |mach bootstrap|.  (Looked for %s/%s)"
110         % (version, android_build_tools_base, version)
111     )
114 @depends(android_sdk_root)
115 @checking("for Android platform-tools")
116 @imports(_from="os.path", _import="exists")
117 @imports(_from="os.path", _import="isdir")
118 def android_platform_tools(sdk_root):
119     tools = os.path.join(sdk_root, "platform-tools")
120     for adb in ("adb", "adb.exe"):
121         if exists(os.path.join(tools, adb)):
122             return [tools]
124     die(
125         "You must install the Android platform-tools.  Try |mach bootstrap|.  (Looked for %s)"
126         % tools
127     )
130 @depends(android_sdk_root)
131 def android_emulator_path(sdk_root):
132     return [os.path.join(sdk_root, "emulator")]
135 @template
136 def check_android_tools(tool, tool_dir):
137     check = check_prog(
138         tool.upper(), (tool, tool + ".exe"), paths=tool_dir, allow_missing=True
139     )
141     @depends(check)
142     def require_tool(result):
143         if result is None:
144             die("The program %s was not found.  Try |mach bootstrap|" % tool)
145         return result
147     return require_tool
150 check_android_tools("zipalign", android_build_tools)
151 check_android_tools("adb", android_platform_tools)
152 check_android_tools("emulator", android_emulator_path)
154 set_config("ANDROID_SDK_ROOT", android_sdk_root)
156 set_config("ANDROID_BUILD_TOOLS_VERSION", android_sdk_version.build_tools_version)
157 set_config("ANDROID_TARGET_SDK", android_sdk_version.target_sdk_version)