# 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 json import os import sys import traceback
from mach.util import get_state_dir from mozbuild.base import MozbuildObject from mozversioncontrol import MissingVCSExtension, get_repository_object
from .lando import push_to_lando_try from .util.estimates import duration_summary from .util.manage_estimates import (
download_task_history_data,
make_trimmed_taskgraph_cache,
)
GIT_CINNABAR_NOT_FOUND = """
Could not detect `git-cinnabar`.
The `mach try` command requires git-cinnabar to be installed when
pushing from git. Please install it by running:
$ ./mach vcs-setup """.lstrip()
HG_PUSH_TO_TRY_NOT_FOUND = """
Could not detect `push-to-try`.
The `mach try` command requires the push-to-try extension enabled
when pushing from hg. Please install it by running:
$ ./mach vcs-setup """.lstrip()
VCS_NOT_FOUND = """
Could not detect version control. Only `hg` or `git` are supported. """.strip()
UNCOMMITTED_CHANGES = """
ERROR please commit changes before continuing """.strip()
def write_task_config_history(msg, try_task_config): ifnot os.path.isfile(history_path): ifnot os.path.isdir(os.path.dirname(history_path)):
os.makedirs(os.path.dirname(history_path))
history = [] else: with open(history_path) as fh:
history = fh.read().strip().splitlines()
history.insert(0, json.dumps([msg, try_task_config]))
history = history[:MAX_HISTORY] with open(history_path, "w") as fh:
fh.write("\n".join(history))
def generate_try_task_config(method, labels, params=None, routes=None):
params = params or {}
# The user has explicitly requested a set of jobs, so run them all # regardless of optimization (unless the selector explicitly sets this to # True). Their dependencies can be optimized though.
params.setdefault("optimize_target_tasks", False)
# Remove selected labels from 'existing_tasks' parameter if present if"existing_tasks"in params:
params["existing_tasks"] = {
label: tid for label, tid in params["existing_tasks"].items() if label notin labels
}
print( "estimates: Runs {} tasks ({} selected, {} dependencies)".format(
durations["dependency_count"] + durations["selected_count"],
durations["selected_count"],
durations["dependency_count"],
)
)
print( "estimates: Total task duration {}".format(
durations["dependency_duration"] + durations["selected_duration"]
)
) if"percentile"in durations:
percentile = durations["percentile"] if percentile > 50:
print("estimates: In the longest {}% of durations".format(100 - percentile)) else:
print("estimates: In the shortest {}% of durations".format(percentile))
print( "estimates: Should take about {} (Finished around {})".format(
durations["wall_duration_seconds"],
durations["eta_datetime"].strftime("%Y-%m-%d %H:%M"),
)
)
# improves on `" ".join(sys.argv[:])` by requoting argv items containing spaces or single quotes def get_sys_argv(injected_argv=None):
argv_to_use = injected_argv or sys.argv[:]
formatted_argv = [] for item in argv_to_use: if" "in item or"'"in item:
formatted_item = f'"{item}"' else:
formatted_item = item
formatted_argv.append(formatted_item)
if try_task_config and method notin ("auto", "empty"): try:
display_push_estimates(try_task_config) except Exception:
traceback.print_exc()
print("warning: unable to display push estimates")
# Format the commit message
closed_tree_string = " ON A CLOSED TREE"if closed_tree else""
the_cmdline = get_sys_argv()
full_commandline_entry = f"mach try command: `{the_cmdline}`"
commit_message = "{}{}\n\n{}\n\nPushed via `mach try {}`".format(
msg,
closed_tree_string,
full_commandline_entry,
method,
)
changed_files = {}
if try_task_config:
changed_files["try_task_config.json"] = (
json.dumps(
try_task_config, indent=4, separators=(",", ": "), sort_keys=True
)
+ "\n"
) if push and method notin ("again", "auto", "empty"):
write_task_config_history(msg, try_task_config)
if (push or stage_changes) and files_to_change:
changed_files.update(files_to_change.items())
ifnot push:
print("Commit message:")
print(commit_message)
config = changed_files.pop("try_task_config.json", None) if config:
print("Calculated try_task_config.json:")
print(config) if stage_changes:
vcs.stage_changes(changed_files)
return
if push_to_lando ornot push_to_vcs:
print("Note: `--push-to-lando` is now the default behaviour of `mach try`.")
print("Note: Use `--push-to-vcs` to push changes to try directly.")
try: if push_to_vcs:
vcs.push_to_try(
commit_message,
changed_files=changed_files,
allow_log_capture=allow_log_capture,
) else:
push_to_lando_try(vcs, commit_message, changed_files) except MissingVCSExtension as e: if e.ext == "push-to-try":
print(HG_PUSH_TO_TRY_NOT_FOUND) elif e.ext == "cinnabar":
print(GIT_CINNABAR_NOT_FOUND) else: raise
sys.exit(1) finally: if"try_task_config.json"in changed_files and os.path.isfile( "try_task_config.json"
):
os.remove("try_task_config.json")
¤ Dauer der Verarbeitung: 0.14 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.