# 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/.
import argparse import logging import os import platform import shutil import sys import time import zipfile
import mozpack.path as mozpath from mach.decorators import Command, CommandArgument, SubCommand from mozbuild.base import MachCommandConditions as conditions from mozshellutil import split as shell_split
# Mach's conditions facility doesn't support subcommands. Print a # deprecation message ourselves instead.
LINT_DEPRECATION_MESSAGE = """
Android lints are now integrated with mozlint. Instead of
`mach android {api-lint,checkstyle,lint,test}`, run
`mach lint --linter android-{api-lint,checkstyle,lint,test}`. Or run `mach lint`. """
# 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.
@SubCommand( "android", "gradle-dependencies", """Collect Android Gradle dependencies.
See http://firefox-source-docs.mozilla.org/build/buildsystem/toolchains.html#firefox-for-android-with-gradle""", # NOQA: E501
)
@CommandArgument("args", nargs=argparse.REMAINDER) def android_gradle_dependencies(command_context, args): # We don't want to gate producing dependency archives on clean # lint or checkstyle, particularly because toolchain versions # can change the outputs for those processes.
gradle(
command_context,
command_context.substs["GRADLE_ANDROID_DEPENDENCIES_TASKS"]
+ ["--continue"]
+ args,
verbose=True,
)
return0
def get_maven_archive_paths(maven_folder): for subdir, _, files in os.walk(maven_folder): if"-SNAPSHOT"in subdir: continue for file in files: yield os.path.join(subdir, file)
# Create the archive, with no compression: The archive contents are large # files which cannot be significantly compressed; attempting to compress # the archive is usually expensive in time and results in minimal # reduction in size. with zipfile.ZipFile(
os.path.join(gradle_folder, "target.maven.zip"), "w"
) as target_zip: for abs_path in get_maven_archive_paths(maven_folder):
target_zip.write(
abs_path,
arcname=os.path.join( "geckoview", os.path.relpath(abs_path, maven_folder)
),
)
# Serialize the indexing build: the semanticdb-javac plugin races when concurrent # compile tasks write its shared output. --no-parallel is insufficient (it only # disables cross-project parallelism), so cap the worker pool to one. See bug 2036411. if command_context.substs.get("ENABLE_MOZSEARCH_PLUGIN"):
tasks = tasks + ["--max-workers=1"]
ret = gradle(
command_context,
tasks + args,
verbose=True,
)
return ret
def install_app_bundle(command_context, bundle): from mozdevice import ADBDeviceFactory
# In order to push to GitHub from TaskCluster, we store a private key # in the TaskCluster secrets store in the format {"content": "<KEY>"}, # and the corresponding public key as a writable deploy key for the # destination repo on GitHub.
secret = os.environ.get("GECKOVIEW_DOCS_UPLOAD_SECRET", "").format(**fmt) if secret: # Set up a private key from the secrets store if applicable. import requests
keyfile = mozpath.abspath("gv-docs-upload-key") with open(keyfile, "w") as f:
os.chmod(keyfile, 0o600)
f.write(req.json()["secret"]["content"])
# Turn off strict host key checking so ssh does not complain about # unknown github.com host. We're not pushing anything sensitive, so # it's okay to not check GitHub's host keys.
env["GIT_SSH_COMMAND"] = 'ssh -i "%s" -o StrictHostKeyChecking=no' % keyfile
# In automation, JAVA_HOME is set via mozconfig, which needs # to be specially handled in each mach command. This turns # $JAVA_HOME/bin/java into $JAVA_HOME.
java_home = os.path.dirname(os.path.dirname(command_context.substs["JAVA"]))
if command_context.substs.get("MOZ_AUTOMATION"):
gradle_flags += ["--console=plain"]
env = os.environ.copy()
env.update({ "GRADLE_OPTS": "-Dfile.encoding=utf-8", "JAVA_HOME": java_home, "JAVA_TOOL_OPTIONS": "-Dfile.encoding=utf-8", # Let Gradle get the right Python path on Windows "GRADLE_MACH_PYTHON": sys.executable,
}) # Set ANDROID_SDK_ROOT if --with-android-sdk was set. # See https://bugzilla.mozilla.org/show_bug.cgi?id=1576471
android_sdk_root = command_context.substs.get("ANDROID_SDK_ROOT", "") if android_sdk_root:
env["ANDROID_HOME"] = android_sdk_root
env["ANDROID_SDK_ROOT"] = android_sdk_root
should_print_status = env.get("MACH") andnot env.get("NO_BUILDSTATUS_MESSAGES") if should_print_status:
print("BUILDSTATUS " + str(time.time()) + " START_Gradle " + args[0])
rv = command_context.run_process(
[gradle_path] + gradle_flags + args,
explicit_env=env,
pass_thru=True, # Allow user to run gradle interactively.
ensure_exit_code=False, # Don't throw on non-zero exit code.
cwd=topsrcdir,
) if should_print_status:
print("BUILDSTATUS " + str(time.time()) + " END_Gradle " + args[0]) return rv
@Command( "android-emulator",
category="devenv",
conditions=[],
description="Run the Android emulator with an AVD from test automation. " "Environment variable MOZ_EMULATOR_COMMAND_ARGS, if present, will " "over-ride the command line arguments used to launch the emulator.",
)
@CommandArgument( "--version",
metavar="VERSION",
choices=["arm", "arm64", "x86_64"],
help="Specify which AVD to run in emulator. " 'One of "arm" (Android supporting armv7 binaries), ' '"arm64" (for Apple Silicon), or ' '"x86_64" (Android supporting x86 or x86_64 binaries, ' "recommended for most applications). " "By default, the value will match the current build environment.",
)
@CommandArgument("--wait", action="store_true", help="Wait for emulator to be closed.")
@CommandArgument("--gpu", help="Over-ride the emulator -gpu argument.")
@CommandArgument( "--verbose", action="store_true", help="Log informative status messages."
) def emulator(
command_context,
version,
wait=False,
gpu=None,
verbose=False,
): """
Run the Android emulator with one of the AVDs used in the Mozilla
automated test environment. If necessary, the AVD is fetched from
the taskcluster server and installed. """ from mozrunner.devices.android_device import AndroidEmulator
emulator = AndroidEmulator(
version,
verbose,
substs=command_context.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.
command_context.log(
logging.ERROR, "emulator",
{}, "An Android emulator is already running.\n" "Close the existing emulator and re-run this command.",
) return1
ifnot emulator.check_avd():
command_context.log(
logging.WARN, "emulator",
{}, "AVD not found. Please run |mach bootstrap|.",
) return2
command_context.log(
logging.INFO, "emulator",
{}, "Starting Android emulator running %s..." % emulator.get_avd_description(),
)
emulator.start(gpu) if emulator.wait_for_start():
command_context.log(
logging.INFO, "emulator", {}, "Android emulator is running."
) else: # This is unusual but the emulator may still function.
command_context.log(
logging.WARN, "emulator",
{}, "Unable to verify that emulator is running.",
)
if conditions.is_android(command_context):
command_context.log(
logging.INFO, "emulator",
{}, "Use 'mach install' to install or update Firefox on your emulator.",
) else:
command_context.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:
command_context.log(
logging.INFO, "emulator", {}, "Waiting for Android emulator to close..."
)
rc = emulator.wait() if rc isnotNone:
command_context.log(
logging.INFO, "emulator",
{}, "Android emulator completed with return code %d." % rc,
) else:
command_context.log(
logging.WARN, "emulator",
{}, "Unable to retrieve Android emulator return code.",
) return0
@SubCommand(
command="android-emulator",
subcommand="reset",
description="Resets the emulator and Android Virtual Device (AVD) by removing the " "'ANDROID_AVD_HOME' directory and re-bootstrapping the emulator and AVD.",
) def emulator_reset(command_context): from mozboot import android
if avd_home_path.exists():
command_context.log(
logging.INFO, "emulator", {}, f"Removing AVD directory: '{avd_home_path}'"
) try:
shutil.rmtree(avd_home_path)
command_context.log(
logging.INFO, "emulator",
{},
f"Successfully removed AVD directory: '{avd_home_path}'",
) except FileNotFoundError: pass# Directory doesn't exist, do nothing except Exception as e:
command_context.log(
logging.ERROR, "emulator",
{},
f"Failed to remove the AVD directory: '{avd_home_path}': {e}",
)
sdk_manager_tool_path = android.get_sdkmanager_tool_path(
android.get_sdk_path(os_name)
) ifnot sdk_manager_tool_path.exists():
command_context.log(
logging.ERROR, "emulator",
{},
f"Unable to proceed - 'sdkmanager' not found at {sdk_manager_tool_path}. "
f"Please run './mach bootstrap' to reinstall your Android SDK.",
) return1
@Command( "adb",
category="devenv",
description="Run the version of Android Debug Bridge (adb) utility that the build system would use.",
)
@CommandArgument("args", nargs=argparse.REMAINDER) def adb(
command_context,
args,
): """Run the version of Android Debug Bridge (adb) utility that the build
system would use.""" from mozrunner.devices.android_device import get_adb_path
adb_path = get_adb_path(command_context) ifnot adb_path:
command_context.log(
logging.ERROR, "adb",
{}, "ADB not found. Did you run `mach bootstrap` with Android selected yet?",
) return1
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.