Bug 1515004 - Move --with-android-sdk to moz.configure. r=nalexander
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Fri, 01 Feb 2019 21:12:51 +0000
changeset 456499 b2a43f0c9d787e844577c8cceca94c35e8b05a5b
parent 456498 52f541c1147efcba8febe1c26a51181bb0901233
child 456500 a2e4f48c810b48c3b542fb67df5606f4d9055639
push id111656
push userdvarga@mozilla.com
push dateSat, 02 Feb 2019 09:51:54 +0000
treeherdermozilla-inbound@d8cebb3b46cf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1515004
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1515004 - Move --with-android-sdk to moz.configure. r=nalexander Since ./mach bootstrap installs Android SDK into ~/.mozbuild, we should detect this location as default SDK install path. Also, --with-android-max-sdk and --with-android-min-sdk are still in android.m4 because confvars.sh sets MOZ_ANDROID_MIN_SDK_VERSION. Differential Revision: https://phabricator.services.mozilla.com/D15463
build/autoconf/android.m4
build/moz.configure/android-sdk.configure
build/moz.configure/old.configure
mobile/android/moz.configure
old-configure.in
--- a/build/autoconf/android.m4
+++ b/build/autoconf/android.m4
@@ -86,96 +86,19 @@ if test "$OS_TARGET" = "Android"; then
     fi
 fi
 AC_SUBST_LIST([STLPORT_LIBS])
 
 ])
 
 
 dnl Configure an Android SDK.
-dnl Arg 1: target SDK version, like 23.
-dnl Arg 2: list of build-tools versions, like "23.0.3 23.0.1".
 AC_DEFUN([MOZ_ANDROID_SDK],
 [
 
-MOZ_ARG_WITH_STRING(android-sdk,
-[  --with-android-sdk=DIR
-                          location where the Android SDK can be found (like ~/.mozbuild/android-sdk-linux)],
-    android_sdk_root=$withval)
-
-android_sdk_root=${withval%/platforms/android-*}
-
-case "$target" in
-*-android*|*-linuxandroid*)
-    if test -z "$android_sdk_root" ; then
-        AC_MSG_ERROR([You must specify --with-android-sdk=/path/to/sdk when targeting Android.])
-    fi
-
-    # We were given an old-style
-    # --with-android-sdk=/path/to/sdk/platforms/android-*.  We could warn, but
-    # we'll get compliance by forcing the issue.
-    if test -e "$withval"/source.properties ; then
-        AC_MSG_ERROR([Including platforms/android-* in --with-android-sdk arguments is deprecated.  Use --with-android-sdk=$android_sdk_root.])
-    fi
-
-    android_target_sdk=$1
-
-    AC_MSG_CHECKING([for Android build-tools])
-    android_build_tools_base="$android_sdk_root"/build-tools
-    for version in $2; do
-        android_build_tools="$android_build_tools_base"/$version
-        if test -d "$android_build_tools" -a -f "$android_build_tools/zipalign"; then
-            AC_MSG_RESULT([$android_build_tools])
-            break
-        fi
-    done
-
-    MOZ_PATH_PROG(ZIPALIGN, zipalign, :, [$android_build_tools])
-    if test -z "$ZIPALIGN" -o "$ZIPALIGN" = ":"; then
-      AC_MSG_ERROR([The program zipalign was not found.  Try |mach bootstrap|.])
-    fi
-
-    android_platform_tools="$android_sdk_root"/platform-tools
-    AC_MSG_CHECKING([for Android platform-tools])
-    if test -d "$android_platform_tools" -a -f "$android_platform_tools/adb"; then
-        AC_MSG_RESULT([$android_platform_tools])
-    else
-        AC_MSG_ERROR([You must install the Android platform-tools.  Try |mach bootstrap|.  (Looked for $android_platform_tools)])
-    fi
-
-    MOZ_PATH_PROG(ADB, adb, :, [$android_platform_tools])
-    if test -z "$ADB" -o "$ADB" = ":"; then
-      AC_MSG_ERROR([The program adb was not found.  Try |mach bootstrap|.])
-    fi
-
-    android_tools="$android_sdk_root"/tools
-    AC_MSG_CHECKING([for Android tools])
-    if test -d "$android_tools" -a -f "$android_tools/emulator"; then
-        AC_MSG_RESULT([$android_tools])
-    else
-        AC_MSG_ERROR([You must install the Android tools.  Try |mach bootstrap|.  (Looked for $android_tools)])
-    fi
-
-    dnl Android Tools 26 changes emulator path.
-    dnl Although android_sdk_root/tools still has emulator command,
-    dnl it doesn't work correctly
-    MOZ_PATH_PROG(EMULATOR, emulator, :, [$android_sdk_root/emulator:$android_tools])
-    if test -z "$EMULATOR" -o "$EMULATOR" = ":"; then
-        AC_MSG_ERROR([The program emulator was not found.  Try |mach bootstrap|.])
-    fi
-
-    ANDROID_TARGET_SDK="${android_target_sdk}"
-    ANDROID_SDK_ROOT="${android_sdk_root}"
-    ANDROID_TOOLS="${android_tools}"
-    AC_SUBST(ANDROID_TARGET_SDK)
-    AC_SUBST(ANDROID_SDK_ROOT)
-    AC_SUBST(ANDROID_TOOLS)
-    ;;
-esac
-
 MOZ_ARG_WITH_STRING(android-min-sdk,
 [  --with-android-min-sdk=[VER]     Impose a minimum Firefox for Android SDK version],
 [ MOZ_ANDROID_MIN_SDK_VERSION=$withval ])
 
 MOZ_ARG_WITH_STRING(android-max-sdk,
 [  --with-android-max-sdk=[VER]     Impose a maximum Firefox for Android SDK version],
 [ MOZ_ANDROID_MAX_SDK_VERSION=$withval ])
 
new file mode 100644
--- /dev/null
+++ b/build/moz.configure/android-sdk.configure
@@ -0,0 +1,116 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Ensure Android SDK and build-tools versions depending on mobile target.
+
+
+@depends(host, '--help')
+@imports('os')
+def default_android_sdk_root(host, _):
+    mozbuild_state_dir = os.environ.get('MOZBUILD_STATE_PATH',
+                                        os.path.expanduser(os.path.join('~', '.mozbuild')))
+    sdk_basename = {
+        'Darwin': 'android-sdk-macosx',
+        'Linux': 'android-sdk-linux',
+        'WINNT': 'android-sdk-windows',
+    }.get(host.kernel)
+    if sdk_basename is None:
+        log.warning("%s is unsupported host" % host.kernel)
+        return None
+    return os.path.join(mozbuild_state_dir, sdk_basename)
+
+
+option('--with-android-sdk', nargs=1,
+       default=default_android_sdk_root,
+       help='location where the Android SDK can be found (like ~/.mozbuild/android-sdk-linux){|}')
+
+
+@depends('--with-android-sdk')
+@imports(_from='os.path', _import='isdir')
+def android_sdk_root(value):
+    if value and isdir(value[0]):
+        return value[0]
+
+    die("You must specify --with-android-sdk=/path/to/sdk when targeting Android, "
+        "or try |mach bootstrap|.")
+
+
+@depends('--help')
+def android_sdk_version(_):
+    return namespace(build_tools_versions=['27.0.3'], target_sdk_version='28')
+
+
+@depends(android_sdk_root, android_sdk_version)
+@checking('for Android build-tools')
+@imports(_from='os.path', _import='exists')
+@imports(_from='os.path', _import='isdir')
+def android_build_tools(sdk_root, sdk_version):
+    android_build_tools_base = os.path.join(sdk_root, 'build-tools')
+    for version in sdk_version.build_tools_versions:
+        if isdir(os.path.join(android_build_tools_base, version)):
+            tools = os.path.join(android_build_tools_base, version)
+            for zipalign in ('zipalign', 'zipalign.exe'):
+                if exists(os.path.join(tools, zipalign)):
+                    return [tools]
+
+    die("You must install the Android build-tools version %s.  "
+        "Try |mach bootstrap|.  (Looked for %s/%s)" %
+        (versions[0], android_build_tools_base, versions[0]))
+
+
+@depends(android_sdk_root)
+@checking('for Android tools')
+@imports(_from='os.path', _import='isdir')
+def android_tools(sdk_root):
+    tools = os.path.join(sdk_root, 'tools')
+    if isdir(tools):
+        return tools
+
+    die("You must install the Android tools.  Try |mach bootstrap|")
+
+
+@depends(android_sdk_root)
+@checking('for Android platform-tools')
+@imports(_from='os.path', _import='exists')
+@imports(_from='os.path', _import='isdir')
+def android_platform_tools(sdk_root):
+    tools = os.path.join(sdk_root, 'platform-tools')
+    for adb in ('adb', 'adb.exe'):
+        if exists(os.path.join(tools, adb)):
+            return [tools]
+
+    die("You must install the Android platform-tools.  Try |mach bootstrap|.  (Looked for %s)" %
+        tools)
+
+
+@depends(android_sdk_root)
+def android_emulator_path(sdk_root):
+    return [os.path.join(sdk_root, 'emulator')]
+
+
+@template
+def check_android_tools(tool, tool_dir):
+    check = check_prog(tool.upper(), (tool, tool + '.exe'), paths=tool_dir,
+                       allow_missing=True)
+
+    @depends(check)
+    def require_tool(result):
+        if result is None:
+            die('The program %s was not found.  Try |mach bootstrap|' % tool)
+        return result
+
+    return require_tool
+
+
+check_android_tools('zipalign', android_build_tools)
+check_android_tools('adb', android_platform_tools)
+check_android_tools('emulator', android_emulator_path)
+
+set_config('ANDROID_SDK_ROOT', android_sdk_root)
+set_config('ANDROID_TOOLS', android_tools)
+
+set_config('ANDROID_TARGET_SDK', android_sdk_version.target_sdk_version)
+add_old_configure_assignment('ANDROID_TARGET_SDK', android_sdk_version.target_sdk_version)
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -224,17 +224,16 @@ def old_configure_options(*options):
     '--enable-xul',
     '--enable-zipwriter',
     '--includedir',
     '--libdir',
     '--prefix',
     '--with-android-distribution-directory',
     '--with-android-max-sdk',
     '--with-android-min-sdk',
-    '--with-android-sdk',
     '--with-app-basename',
     '--with-app-name',
     '--with-arch',
     '--with-branding',
     '--with-cross-lib',
     '--with-debug-label',
     '--with-distribution-id',
     '--with-doc-include-dirs',
--- a/mobile/android/moz.configure
+++ b/mobile/android/moz.configure
@@ -117,16 +117,17 @@ def check_target(target):
     if target.os != 'Android':
         log.error('You must specify --target=arm-linux-androideabi (or some '
                   'other valid Android target) when building mobile/android.')
         die('See https://developer.mozilla.org/docs/Mozilla/Developer_guide/'
             'Build_Instructions/Simple_Firefox_for_Android_build '
             'for more information about the necessary options.')
 
 include('../../toolkit/moz.configure')
+include('../../build/moz.configure/android-sdk.configure')
 include('../../build/moz.configure/java.configure')
 include('gradle.configure')
 
 # Must come after the ../../toolkit/moz.configure.
 @depends('MOZ_INSTALL_TRACKING', google_play_services, '--with-adjust-sdk-keyfile')
 def check_install_tracking(install_tracking,
                            google_play_services,
                            adjust_sdk_keyfile):
--- a/old-configure.in
+++ b/old-configure.in
@@ -1791,17 +1791,17 @@ AC_SUBST(MOZ_XULRUNNER)
 
 dnl ========================================================
 dnl Ensure Android SDK and build-tools versions depending on
 dnl mobile target.
 dnl ========================================================
 
 case "$MOZ_BUILD_APP" in
 mobile/android)
-    MOZ_ANDROID_SDK(28, 27.0.3)
+    MOZ_ANDROID_SDK
     ;;
 esac
 
 dnl ========================================================
 dnl =
 dnl = Toolkit Options
 dnl =
 dnl ========================================================