# 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 sys import tarfile import time
import mozpack.path as mozpath from mach.decorators import Command, CommandArgument, SubCommand from mozbuild.base import MachCommandConditions as conditions from mozbuild.shellutil 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,
)
return 0
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. # Even though the archive is not compressed, use the .xz file extension # so that the taskcluster worker also skips compression. with tarfile.open(os.path.join(gradle_folder, "target.maven.tar.xz"), "w") as tar: for abs_path in get_maven_archive_paths(maven_folder):
tar.add(
abs_path,
arcname=os.path.join( "geckoview", os.path.relpath(abs_path, maven_folder)
),
)
# 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_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.",
) return 1
ifnot emulator.check_avd():
command_context.log(
logging.WARN, "emulator",
{}, "AVD not found. Please run |mach bootstrap|.",
) return 2
ifnot emulator.is_available():
command_context.log(
logging.WARN, "emulator",
{}, "Emulator binary not found.\n" "Install the Android SDK and make sure 'emulator' is in your PATH.",
) return 2
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.",
) return 0
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet)
¤
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 ist noch experimentell.