gecko-dev/mobile/android/mach_commands.py

159 строки
6.8 KiB
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/.
from __future__ import absolute_import, print_function, unicode_literals
import argparse
import logging
Bug 1098239 - Rewrite mobile/android Gradle integration. r=me This is a big patch, but it's essentially NPOTB. The part that is POTB is ... removing Gradle integration from the build. I've implemented |mach gradle-install| as a substitute for the build system stuff; it's just so much easier to iterate on a mach command than a moz.build and Makefile.in. I'm landing this with self-review because this lessens the impact of the Gradle integration on the build system and because I am the only person who understands either the old or the new system. You'll need to run |mach gradle-install| at top level to configure the new Gradle integration. But |mach gradle ...| does the right thing configuration steps too. This patch rewrites most of the Gradle integration. The major changes are: * all .gradle files move into mobile/android/gradle; * all the Gradle projects live in the object directory; * mozconfig exposed to all build.gradle files; * simplification of Android configuration between build.gradle files; * support for user-specified version of build tools; * first steps towards supporting builds from the source directory; * bumps Gradle to 2.2.1; * bumps the Android-Gradle plugin to 0.14.4. This is seemingly a step backwards given that we'd prefer to ship the .idea directory in the source directory. But in fact we get closer to that; it's possible to run ./gradlew in the source directory and get a reasonable build. We'll progress with this in time. The win right now is that the projects are nested, which makes importing work better on Linux machines. Unfortunately IntelliJ 13 and 14 now have conflicting Android-Gradle plugin version requirements, so we now only support IntelliJ 14.0.2 and above. --HG-- rename : mobile/android/base/gradle_AndroidManifest.xml => mobile/android/gradle/base/AndroidManifest.xml rename : mobile/android/base/gradle_AndroidManifest.xml => mobile/android/gradle/branding/AndroidManifest.xml rename : mobile/android/gradle/omnijar/gradle_AndroidManifest.xml => mobile/android/gradle/omnijar/AndroidManifest.xml rename : mobile/android/base/gradle_AndroidManifest.xml => mobile/android/gradle/preprocessed_code/AndroidManifest.xml rename : mobile/android/base/gradle_AndroidManifest.xml => mobile/android/gradle/preprocessed_resources/AndroidManifest.xml rename : mobile/android/thirdparty/gradle_AndroidManifest.xml => mobile/android/gradle/thirdparty/AndroidManifest.xml
2014-12-23 06:49:04 +03:00
import os
import mozpack.path as mozpath
from mozbuild.base import (
MachCommandBase,
MachCommandConditions as conditions,
)
from mach.decorators import (
CommandArgument,
CommandProvider,
Command,
)
# NOTE python/mach/mach/commands/commandinfo.py references this function
# by name. If this function is renamed or removed, that file should
# be updated accordingly as well.
def REMOVED(cls):
"""Command no longer exists! Use the Gradle configuration rooted in the top source directory instead.
See https://developer.mozilla.org/en-US/docs/Simple_Firefox_for_Android_build#Developing_Firefox_for_Android_in_Android_Studio_or_IDEA_IntelliJ.
"""
return False
@CommandProvider
class MachCommands(MachCommandBase):
@Command('android', category='devenv',
description='Run the Android package manager tool.',
conditions=[conditions.is_android])
@CommandArgument('args', nargs=argparse.REMAINDER)
def android(self, args):
# Avoid logging the command
self.log_manager.terminal_handler.setLevel(logging.CRITICAL)
return self.run_process(
[os.path.join(self.substs['ANDROID_TOOLS'], 'android')] + args,
pass_thru=True, # Allow user to run gradle interactively.
ensure_exit_code=False, # Don't throw on non-zero exit code.
cwd=mozpath.join(self.topsrcdir))
@Command('gradle', category='devenv',
description='Run gradle.',
conditions=[conditions.is_android])
@CommandArgument('args', nargs=argparse.REMAINDER)
def gradle(self, args):
# Avoid logging the command
self.log_manager.terminal_handler.setLevel(logging.CRITICAL)
# We force the Gradle JVM to run with the UTF-8 encoding, since we
# filter strings.xml, which is really UTF-8; the ellipsis character is
# replaced with ??? in some encodings (including ASCII). It's not yet
# possible to filter with encodings in Gradle
# (https://github.com/gradle/gradle/pull/520) and it's challenging to
# do our filtering with Gradle's Ant support. Moreover, all of the
# Android tools expect UTF-8: see
# http://tools.android.com/knownissues/encoding. See
# http://stackoverflow.com/a/21267635 for discussion of this approach.
return self.run_process([self.substs['GRADLE']] + args,
append_env={'GRADLE_OPTS': '-Dfile.encoding=utf-8'},
pass_thru=True, # Allow user to run gradle interactively.
ensure_exit_code=False, # Don't throw on non-zero exit code.
cwd=mozpath.join(self.topsrcdir))
Bug 1098239 - Rewrite mobile/android Gradle integration. r=me This is a big patch, but it's essentially NPOTB. The part that is POTB is ... removing Gradle integration from the build. I've implemented |mach gradle-install| as a substitute for the build system stuff; it's just so much easier to iterate on a mach command than a moz.build and Makefile.in. I'm landing this with self-review because this lessens the impact of the Gradle integration on the build system and because I am the only person who understands either the old or the new system. You'll need to run |mach gradle-install| at top level to configure the new Gradle integration. But |mach gradle ...| does the right thing configuration steps too. This patch rewrites most of the Gradle integration. The major changes are: * all .gradle files move into mobile/android/gradle; * all the Gradle projects live in the object directory; * mozconfig exposed to all build.gradle files; * simplification of Android configuration between build.gradle files; * support for user-specified version of build tools; * first steps towards supporting builds from the source directory; * bumps Gradle to 2.2.1; * bumps the Android-Gradle plugin to 0.14.4. This is seemingly a step backwards given that we'd prefer to ship the .idea directory in the source directory. But in fact we get closer to that; it's possible to run ./gradlew in the source directory and get a reasonable build. We'll progress with this in time. The win right now is that the projects are nested, which makes importing work better on Linux machines. Unfortunately IntelliJ 13 and 14 now have conflicting Android-Gradle plugin version requirements, so we now only support IntelliJ 14.0.2 and above. --HG-- rename : mobile/android/base/gradle_AndroidManifest.xml => mobile/android/gradle/base/AndroidManifest.xml rename : mobile/android/base/gradle_AndroidManifest.xml => mobile/android/gradle/branding/AndroidManifest.xml rename : mobile/android/gradle/omnijar/gradle_AndroidManifest.xml => mobile/android/gradle/omnijar/AndroidManifest.xml rename : mobile/android/base/gradle_AndroidManifest.xml => mobile/android/gradle/preprocessed_code/AndroidManifest.xml rename : mobile/android/base/gradle_AndroidManifest.xml => mobile/android/gradle/preprocessed_resources/AndroidManifest.xml rename : mobile/android/thirdparty/gradle_AndroidManifest.xml => mobile/android/gradle/thirdparty/AndroidManifest.xml
2014-12-23 06:49:04 +03:00
@Command('gradle-install', category='devenv',
conditions=[REMOVED])
def gradle_install(self):
pass
@CommandProvider
class AndroidEmulatorCommands(MachCommandBase):
"""
Run the Android emulator with one of the AVDs used in the Mozilla
automated test environment. If necessary, the AVD is fetched from
the tooltool server and installed.
"""
@Command('android-emulator', category='devenv',
conditions=[],
description='Run the Android emulator with an AVD from test automation.')
@CommandArgument('--version', metavar='VERSION', choices=['2.3', '4.3', 'x86'],
help='Specify Android version to run in emulator. One of "2.3", "4.3", or "x86".',
default='4.3')
@CommandArgument('--wait', action='store_true',
help='Wait for emulator to be closed.')
@CommandArgument('--force-update', action='store_true',
help='Update AVD definition even when AVD is already installed.')
@CommandArgument('--verbose', action='store_true',
help='Log informative status messages.')
def emulator(self, version, wait=False, force_update=False, verbose=False):
from mozrunner.devices.android_device import AndroidEmulator
emulator = AndroidEmulator(version, verbose, substs=self.substs, device_serial='emulator-5554')
if emulator.is_running():
# It is possible to run multiple emulators simultaneously, but:
# - if more than one emulator is using the same avd, errors may
# occur due to locked resources;
# - additional parameters must be specified when running tests,
# to select a specific device.
# To avoid these complications, allow just one emulator at a time.
self.log(logging.ERROR, "emulator", {},
"An Android emulator is already running.\n"
"Close the existing emulator and re-run this command.")
return 1
if not emulator.is_available():
self.log(logging.WARN, "emulator", {},
"Emulator binary not found.\n"
"Install the Android SDK and make sure 'emulator' is in your PATH.")
return 2
if not emulator.check_avd(force_update):
self.log(logging.INFO, "emulator", {},
"Fetching and installing AVD. This may take a few minutes...")
emulator.update_avd(force_update)
self.log(logging.INFO, "emulator", {},
"Starting Android emulator running %s..." %
emulator.get_avd_description())
emulator.start()
if emulator.wait_for_start():
self.log(logging.INFO, "emulator", {},
"Android emulator is running.")
else:
# This is unusual but the emulator may still function.
self.log(logging.WARN, "emulator", {},
"Unable to verify that emulator is running.")
if conditions.is_android(self):
self.log(logging.INFO, "emulator", {},
"Use 'mach install' to install or update Firefox on your emulator.")
else:
self.log(logging.WARN, "emulator", {},
"No Firefox for Android build detected.\n"
"Switch to a Firefox for Android build context or use 'mach bootstrap'\n"
"to setup an Android build environment.")
if wait:
self.log(logging.INFO, "emulator", {},
"Waiting for Android emulator to close...")
rc = emulator.wait()
if rc is not None:
self.log(logging.INFO, "emulator", {},
"Android emulator completed with return code %d." % rc)
else:
self.log(logging.WARN, "emulator", {},
"Unable to retrieve Android emulator return code.")
return 0