# 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 mach.decorators import Command from mach.util import get_state_dir from mozbuild.base import BinaryNotFoundException, MozbuildObject from mozbuild.base import MachCommandConditions as Conditions
HERE = os.path.dirname(os.path.realpath(__file__))
class RaptorRunner(MozbuildObject): def run_test(self, raptor_args, kwargs): """Setup and run mozharness.
We want to do a few things before running Raptor:
1. Clone mozharness
2. Make the config for Raptor mozharness
3. Run mozharness """ # Validate that the user is using a supported python version before doing anything else
max_py_major, max_py_minor = 3, 11
sys_maj, sys_min = sys.version_info.major, sys.version_info.minor if sys_min > max_py_minor: raise PythonVersionException(
print(
f"\tPlease downgrade your Python version as Raptor does not yet support Python "
f"versions greater than {max_py_major}.{max_py_minor}."
f"\n\tYou seem to currently be using Python {sys_maj}.{sys_min}."
f"\n\tSee here for a possible solution in debugging your python environment: "
f"https://firefox-source-docs.mozilla.org/testing/perfdocs/"
f"debugging.html#debugging-local-python-environment"
)
)
self.init_variables(raptor_args, kwargs)
self.make_config()
self.write_config()
self.make_args() return self.run_mozharness()
if Conditions.is_android(self) or kwargs["app"] in ANDROID_BROWSERS:
self.binary_path = None else:
self.binary_path = kwargs.get("binary") or self.get_binary_path()
# We don't set `browsertime_{chromedriver,geckodriver} -- those will be found by # browsertime in its `node_modules` directory, which is appropriate for local builds. # We don't set `browsertime_ffmpeg` yet: it will need to be on the path. There is code # to configure the environment including the path in # `tools/browsertime/mach_commands.py` but integrating it here will take more effort.
self.config.update(
{ "browsertime_browsertimejs": browsertime.browsertime_path(), "browsertime_vismet_script": browsertime.visualmetrics_path(),
}
)
def _get_browsertime_package(): with open(
os.path.join(
self.topsrcdir, "tools", "browsertime", "node_modules", "browsertime", "package.json",
)
) as package: return json.load(package)
def _get_browsertime_resolved(): try: with open(
os.path.join(
self.topsrcdir, "tools", "browsertime", "node_modules", ".package-lock.json",
)
) as package_lock: return json.load(package_lock)["packages"][ "node_modules/browsertime"
]["resolved"] except FileNotFoundError: # Older versions of node/npm add this metadata to package.json return _get_browsertime_package()["_from"]
def _should_install(): # If ffmpeg doesn't exist in the .mozbuild directory, # then we should install
btime_cache = os.path.join(self.config["mozbuild_path"], "browsertime") ifnot os.path.exists(btime_cache) ornot any(
["ffmpeg"in cache_dir for cache_dir in os.listdir(btime_cache)]
): returnTrue
# If browsertime doesn't exist, install it ifnot os.path.exists(
self.config["browsertime_browsertimejs"]
) ornot os.path.exists(self.config["browsertime_vismet_script"]): returnTrue
# Browsertime exists, check if it's outdated with open(
os.path.join(self.topsrcdir, "tools", "browsertime", "package.json")
) as new:
new_pkg = json.load(new)
def _get_browsertime_version(): # Returns the (version number, current commit) used return (
_get_browsertime_package()["version"],
_get_browsertime_resolved(),
)
# Check if browsertime scripts exist and try to install them if # they aren't if _should_install(): # TODO: Make this "integration" nicer in the near future
print("Missing browsertime files...attempting to install")
subprocess.check_output(
[
os.path.join(self.topsrcdir, "mach"), "browsertime", "--setup", "--clobber",
],
shell="windows"in platform.system().lower(),
) if _should_install(): raise Exception( "Failed installation attempt. Cannot find browsertime scripts. " "Run `./mach browsertime --setup --clobber` to set it up."
)
# Bug 1766112 - For the time being, we need to trigger a # clean build to upgrade browsertime. This should be disabled # after some time.
print( "Setting --clean to True to rebuild Python " "environment for Browsertime upgrade..."
)
self.config["clean"] = True
print("Using browsertime version %s from %s" % _get_browsertime_version())
def setup_node(command_context): """Fetch the latest node-18 binary and install it into the .mozbuild directory.""" import platform
from mozbuild.artifact_commands import artifact_toolchain from mozbuild.nodeutil import find_node_executable from packaging.version import Version
print("Setting up node for browsertime...")
state_dir = get_state_dir()
cache_path = os.path.join(state_dir, "browsertime", "node-18")
def __check_for_node(): # Check standard locations first
node_exe = find_node_executable(min_version=Version("18.0.0")) if node_exe and (node_exe[0] isnotNone): return node_exe[0] ifnot os.path.exists(cache_path): returnNone
# Change directories to where node should be installed # before installing. Otherwise, it gets installed in the # top level of the repo (or the current working directory).
cur_dir = os.getcwd()
os.chdir(cache_path)
artifact_toolchain(
command_context,
verbose=False,
from_build=[toolchain_job],
no_unpack=False,
retry=0,
cache_dir=cache_path,
)
os.chdir(cur_dir)
node_exe = __check_for_node() if node_exe isNone: raise Exception("Could not find Node v18 binary for Raptor-Browsertime")
print("Finished downloading Node v18 from Taskcluster")
print("Node v18+ found at: %s" % node_exe) return node_exe
def create_parser():
sys.path.insert(0, HERE) # allow to import the raptor package from raptor.cmdline import create_parser
# Setup node for browsertime
kwargs["browsertime_node"] = setup_node(command_context)
is_android = Conditions.is_android(build_obj) or kwargs["app"] in ANDROID_BROWSERS
if is_android: from mozrunner.devices.android_device import (
InstallIntent,
verify_android_device,
)
install = (
InstallIntent.NO if kwargs.pop("no_install", False) else InstallIntent.YES
)
verbose = False if (
kwargs.get("log_mach_verbose") or kwargs.get("log_tbpl_level") == "debug" or kwargs.get("log_mach_level") == "debug" or kwargs.get("log_raw_level") == "debug"
):
verbose = True ifnot verify_android_device(
build_obj,
install=install,
app=kwargs["binary"],
verbose=verbose,
xre=True,
): # Equivalent to 'run_local' = True.
print( "****************************************************************************"
)
print( "Unable to verify device, please check your attached/connected android device"
)
print( "****************************************************************************"
) return 1 # Disable fission until geckoview supports fission by default. # Need fission on Android? Use '--setpref fission.autostart=true'
kwargs["fission"] = False
# Remove mach global arguments from sys.argv to prevent them # from being consumed by raptor. Treat any item in sys.argv # occuring before "raptor" as a mach global argument.
argv = []
in_mach = True for arg in sys.argv: ifnot in_mach:
argv.append(arg) if arg.startswith("raptor"):
in_mach = False
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.