Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ jobs:
- name: Start MySQL service (Linux)
if: runner.os == 'Linux'
run: sudo systemctl start mysql.service
- name: Install Mercurial (Linux)
if: runner.os == 'Linux'
run: sudo apt-get install -y mercurial
- name: Start MySQL service (Windows)
if: runner.os == 'Windows'
run: |
Expand Down
37 changes: 37 additions & 0 deletions components/hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@
from components.logging import logEntryExit
from components.providerbase import BaseProvider, INeedsCommandProvider, INeedsLoggingProvider

# Shelve is part of Mercurial but not enabled by default.
HG_SHELVE = ["hg", "--config", "extensions.shelve="]
# The shelf the spurious-update check saves the working directory in.
SPURIOUS_CHECK_SHELF = "updatebot-spurious-check"


def reset_repository(cmdrunner):
cmdrunner.run(["hg", "checkout", "-C", "."])
cmdrunner.run(["hg", "purge", "."])
# Drop the shelf if a run was interrupted partway through the spurious-update
# check. Only ours: the checkout may have other shelves. It's usually not there.
cmdrunner.run(HG_SHELVE + ["shelve", "--delete", SPURIOUS_CHECK_SHELF], clean_return=False)

original_revision = os.environ.get("GECKO_HEAD_REV", "")
if original_revision:
Expand Down Expand Up @@ -39,9 +47,38 @@ def commit_patches(self, library, bug_id, new_release_version):
# Note that this commit message format changes, one must also edit the
# Updatebot Verify job in mozilla-central ( verify-updatebot.py )
bug_id = "Bug {0}".format(bug_id)
# `./mach vendor --patch-mode only` doesn't register files the patches add or
# delete (only a full vendor does), so do that here or they'd be left out.
self.run(["hg", "addremove", "-q", library.vendor_directory, os.path.dirname(library.yaml_path)])
self.run(["hg", "commit", "-m", "%s - Apply mozilla patches for %s" %
(bug_id, library.name)])

@logEntryExit
def save_working_directory(self, name):
# Saves the uncommitted changes (including added, removed and untracked
# files) without changing the working directory.
self.run(HG_SHELVE + ["shelve", "--keep", "--unknown", "--name", name])

@logEntryExit
def restore_working_directory(self, name):
# Discards the uncommitted changes and puts back the ones saved as name.
self.run(["hg", "revert", "--all", "--no-backup"])
self.run(["hg", "purge", "."])
self.run(HG_SHELVE + ["unshelve", "--name", name])

@logEntryExit
def forget_saved_working_directory(self, name):
self.run(HG_SHELVE + ["shelve", "--delete", name])

@logEntryExit
def changed_files(self, exclude=()):
# Files that differ from the working directory's parent, counting new and
# deleted files, with paths relative to the root of the checkout.
self.run(["hg", "addremove", "-q"])
excluded = set(os.path.normpath(p) for p in exclude)
files = self.run(["hg", "--config", "ui.relative-paths=no", "status", "--no-status"]).stdout.decode().splitlines()
return [f for f in files if f and os.path.normpath(f) not in excluded]

@logEntryExit
def diff_stats(self):
ret = self.run(["hg", "diff", "--stat"])
Expand Down
11 changes: 10 additions & 1 deletion components/libraryprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def __init__(self, dict):
self.fuzzy_query = dict.get('fuzzy_query', None)
self.fuzzy_paths = dict.get('fuzzy_paths', None)
self.yaml_path = dict['yaml_path']
# Paths are relative to the root of the gecko checkout, like yaml_path
self.vendor_directory = dict.get('vendor_directory') or os.path.dirname(self.yaml_path)
self.generated = [os.path.join(self.vendor_directory, g) for g in dict.get('generated', [])]
self.tasks = []
self.should_show_commit_details = self.name != 'irregexp' and self.flavor != 'individual-files'

Expand Down Expand Up @@ -227,7 +230,9 @@ def validate_library(yaml_contents, yaml_path):
'fuzzy_query': '',
'fuzzy_paths': [],
'tasks': [],
'yaml_path': ''
'yaml_path': '',
'vendor_directory': '',
'generated': []
}

get_or_none = functools.partial(get_sub_key_or_none, dict=library, yaml_path=yaml_path)
Expand Down Expand Up @@ -257,6 +262,10 @@ def validate_library(yaml_contents, yaml_path):
else:
validated_library['has_patches'] = False

if 'vendoring' in library:
validated_library['vendor_directory'] = library['vendoring'].get('vendor-directory', '')
validated_library['generated'] = library['vendoring'].get('generated', [])
Comment thread
tomrittervg marked this conversation as resolved.
Resolved

if 'vendoring' in library and 'flavor' in library['vendoring']:
validated_library['flavor'] = library['vendoring']['flavor']
else:
Expand Down
5 changes: 4 additions & 1 deletion components/mach_vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def vendor(self, library, revision):
return (VendorResult.GENERAL_ERROR, msg)

@logEntryExit
def patch(self, library, revision):
def patch(self, library, revision, ignore_modified=False):
cmd = ["./mach", "vendor", "--patch-mode", "only", library.yaml_path]
if ignore_modified:
# mach otherwise refuses to run while any tracked file is modified
cmd.append("--ignore-modified")
self.run(cmd, clean_return=True)
31 changes: 30 additions & 1 deletion tasktypes/vendoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from components.mach_vendor import VendorResult
from components.dbmodels import JOBSTATUS, JOBOUTCOME, JOBTYPE
from components.logging import LogLevel, logEntryExit, logEntryExitNoArgs
from components.hg import reset_repository
from components.hg import reset_repository, SPURIOUS_CHECK_SHELF


def _patch_exception_message(e):
Expand Down Expand Up @@ -95,6 +95,31 @@ def process_task(self, library, task):
self._process_new_job(library, task, new_version, timestamp, most_recent_job)
self._reset_for_new_job()

# ====================================================================
@logEntryExit
def _only_patches_changed(self, library):
# We vendor with --patch-mode none, so mach's spurious-update check sees our
# patches being removed as a change. Reapply them and see whether anything
# still differs from the tree, then put the working directory back as it was.
self.mercurialProvider.save_working_directory(SPURIOUS_CHECK_SHELF)
spurious = False
try:
try:
# The vendored changes are uncommitted here, so mach has to be told that's expected
self.vendorProvider.patch(library, None, ignore_modified=True)
except Exception as e:
# The normal flow will report the failure; we just can't tell if it's spurious.
self.logger.log("Couldn't apply the patches to check for a spurious update: %s" % e, level=LogLevel.Info)
return False
changed = self.mercurialProvider.changed_files(exclude=[library.yaml_path] + library.generated)
spurious = not changed
return spurious
finally:
if spurious:
self.mercurialProvider.forget_saved_working_directory(SPURIOUS_CHECK_SHELF)
else:
self.mercurialProvider.restore_working_directory(SPURIOUS_CHECK_SHELF)

# ====================================================================
@logEntryExit
def _reset_for_new_job(self):
Expand Down Expand Up @@ -146,6 +171,10 @@ def _process_new_job(self, library, task, new_version, timestamp, most_recent_jo
if result == VendorResult.SPURIOUS_UPDATE:
self.logger.log("Version %s was a spruious update." % new_version)
return
if result == VendorResult.SUCCESS and library.has_patches and self._only_patches_changed(library):
self.logger.log("Version %s only removes and reapplies our patches, so it was a spurious update." % new_version, level=LogLevel.Info)
reset_repository(self.cmdProvider)
return

# Create the job ----------------------
created_job = self.dbProvider.create_job(JOBTYPE.VENDORING, library, new_version, JOBSTATUS.CREATED, JOBOUTCOME.PENDING)
Expand Down
1 change: 1 addition & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"run_command",
"functionality_commitalert",
"functionality_all_platforms",
"functionality_vendoring_hg",
"python_language",
"treeherder_api",
"library",
Expand Down
35 changes: 34 additions & 1 deletion tests/functionality_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import platform
import inspect
from functools import wraps
from collections import OrderedDict

Expand Down Expand Up @@ -78,8 +79,40 @@ def default_phab_submit():

return ARC_OUTPUT % (value, value)

# For libraries with patches, Updatebot runs `./mach vendor --patch-mode only`
# twice: first while checking for a spurious update (between shelving and
# unshelving the working directory), then again in the normal flow. Tests'
# 'patch' callbacks are written for the normal flow only, so the check's call
# goes to 'spurious_check_patch' instead; with the default 'changed_files'
# it finds a real change and the normal flow carries on.
#
# True while Updatebot is inside that check: set by the `hg shelve --keep`
# that starts it, cleared by the `hg unshelve` or `hg shelve --delete` that
# ends it. (A one-element list so the callbacks below can change it.)
in_spurious_check = [False]

def set_in_spurious_check(value):
def callback():
in_spurious_check[0] = value
return ""
return callback

def call(callback, cmd):
return callback(cmd) if len(inspect.signature(callback).parameters) > 0 else callback()

def patch(cmd):
if in_spurious_check[0]:
return call(command_callbacks.get('spurious_check_patch', lambda: ""), cmd)
return call(command_callbacks.get('patch', AssertFalse), cmd)

return OrderedDict([
("./mach vendor --patch-mode only", command_callbacks.get('patch', AssertFalse)),
("hg --config extensions.shelve= shelve --keep", set_in_spurious_check(True)),
("hg --config extensions.shelve= unshelve", set_in_spurious_check(False)),
("hg --config extensions.shelve= shelve --delete", set_in_spurious_check(False)),
("hg revert --all --no-backup", lambda: ""),
("hg addremove", lambda: ""),
("hg --config ui.relative-paths=no status", command_callbacks.get('changed_files', lambda: "media/libdav1d/src/changed.c")),
("./mach vendor --patch-mode only", patch),
("./mach vendor --check-for-update", command_callbacks.get('check_for_update', lambda: expected_values.library_new_version_id() + " 2020-08-21T15:13:49.000+02:00")),
("./mach vendor ", command_callbacks.get('vendor', lambda: "")),
("hg commit", command_callbacks.get('commit', lambda: "")),
Expand Down
Loading
Loading