DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
import re
import requests
import logging

from buglist_creator import create_bugs_url
from kickoff.api import Releases, Release, ReleaseL10n
from release.l10n import parsePlainL10nChangesets
from release.versions import getAppVersion
from util.sendmail import sendmail
from util.retry import retry

log = logging.getLogger(__name__)


def matches(name, patterns):
    return any([re.search(p, name) for p in patterns])


def long_revision(repo, revision):
    """Convert short revision to long using JSON API

    >>> long_revision("releases/mozilla-beta", "59f372c35b24")
    u'59f372c35b2416ac84d6572d64c49227481a8a6c'

    >>> long_revision("releases/mozilla-beta", "59f372c35b2416ac84d6572d64c49227481a8a6c")
    u'59f372c35b2416ac84d6572d64c49227481a8a6c'
    """
    url = "https://hg.mozilla.org/{}/json-rev/{}".format(repo, revision)

    def _get():
        req = requests.get(url, timeout=60)
        req.raise_for_status()
        return req.json()["node"]

    return retry(_get)


class ReleaseRunner(object):
    def __init__(self, api_root=None, username=None, password=None,
                 timeout=60):
        self.new_releases = []
        self.releases_api = Releases((username, password), api_root=api_root,
                                     timeout=timeout)
        self.release_api = Release((username, password), api_root=api_root,
                                   timeout=timeout)
        self.release_l10n_api = ReleaseL10n((username, password),
                                            api_root=api_root, timeout=timeout)

    def get_release_requests(self, release_patterns):
        new_releases = self.releases_api.getReleases()
        if new_releases['releases']:
            new_releases = [self.release_api.getRelease(name) for name in
                            new_releases['releases']]
            our_releases = [r for r in new_releases if
                            matches(r['name'], release_patterns)]
            if our_releases:
                self.new_releases = our_releases
                log.info("Releases to handle are %s", self.new_releases)
                return True
            else:
                log.info("No releases to handle in %s", new_releases)
                return False
        else:
            log.info("No new releases: %s" % new_releases)
            return False

    def get_release_l10n(self, release):
        return self.release_l10n_api.getL10n(release)

    def update_status(self, release, status):
        log.info('updating status for %s to %s' % (release['name'], status))
        try:
            self.release_api.update(release['name'], status=status)
        except requests.HTTPError as e:
            log.warning('Caught HTTPError: %s' % e.response.content)
            log.warning('status update failed, continuing...', exc_info=True)

    def mark_as_completed(self, release):
        log.info('mark as completed %s' % release['name'])
        self.release_api.update(release['name'], complete=True,
                                status='Started')

    def mark_as_failed(self, release, why):
        log.info('mark as failed %s' % release['name'])
        self.release_api.update(release['name'], ready=False, status=why)


def email_release_drivers(smtp_server, from_, to, release, task_group_id, l10n_url):
    # Send an email to the mailing after the build
    email_buglist_string = create_bugs_url(release)

    content = """\
A new build has been submitted through ship-it:

Commit: https://hg.mozilla.org/{path}/rev/{revision}
Task group: https://tools.taskcluster.net/push-inspector/#/{task_group_id}
Locales: {l10n_url} (requires VPN access)

Created by {submitter}
Started by {starter}

{email_buglist_string}
""".format(path=release["branch"], revision=release["mozillaRevision"],
           submitter=release["submitter"], starter=release["starter"],
           task_group_id=task_group_id, l10n_url=l10n_url,
           email_buglist_string=email_buglist_string)

    comment = release.get("comment")
    if comment:
        content += "Comment:\n" + comment + "\n\n"

    # On r-d, we prefix the subject of the email in order to simplify filtering
    subject_prefix = ""
    if "Fennec" in release["name"]:
        subject_prefix = "[mobile] "
    if "Firefox" in release["name"] or "Devedition" in release["name"]:
        subject_prefix = "[desktop] "

    subject = subject_prefix + 'Build of %s' % release["name"]

    sendmail(from_=from_, to=to, subject=subject, body=content,
             smtp_server=smtp_server)


def get_partials(rr, partial_versions, product):
    partials = {}
    if not partial_versions:
        return partials
    for p in [stripped.strip() for stripped in partial_versions.split(',')]:
        partialVersion, buildNumber = p.split('build')
        partial_release_name = '{}-{}-build{}'.format(
            product.capitalize(), partialVersion, buildNumber,
        )
        partials[partialVersion] = {
            'appVersion': getAppVersion(partialVersion),
            'buildNumber': buildNumber,
            'locales': parsePlainL10nChangesets(
                rr.get_release_l10n(partial_release_name)).keys(),
        }
    return partials


def get_platform_locales(l10n_changesets, platform):
    # hardcode ja/ja-JP-mac exceptions
    if platform == "macosx64":
        ignore = "ja"
    else:
        ignore = "ja-JP-mac"

    return [l for l in l10n_changesets.keys() if l != ignore]


def get_l10n_config(index, product, branch, revision, platforms,
                    l10n_platforms, l10n_changesets, tc_task_indexes):
    l10n_platform_configs = {}
    for platform in l10n_platforms:
        # mar_tools lives in the unsigned task
        unsigned_route = tc_task_indexes[platform]['unsigned'].format(rev=revision)
        unsigned_task = index.findTask(unsigned_route)
        if tc_task_indexes[platform]['ci_system'] == 'bb':
            mar_tools_url = "https://queue.taskcluster.net/v1/task/{taskid}/artifacts/public/build".format(
                taskid=unsigned_task["taskId"]
            )
        else:
            mar_tools_url = "https://queue.taskcluster.net/v1/task/{taskid}/artifacts/public/build/host/bin".format(
                taskid=unsigned_task["taskId"]
            )
            if platform.startswith("mac"):
                # FIXME: dirty dirty hack
                mar_tools_url = "https://archive.mozilla.org/pub/firefox/nightly/2017/06/2017-06-21-03-02-08-mozilla-central"

        # en-US binary lives all over the places!
        if platform.startswith("linux"):
            route = tc_task_indexes[platform]['signed'].format(rev=revision)
        elif platform.startswith("mac"):
            if tc_task_indexes[platform]['ci_system'] == 'bb':
                route = tc_task_indexes[platform]['signed'].format(rev=revision)
            else:
                route = tc_task_indexes[platform]['repackage'].format(rev=revision)
        elif platform.startswith("win"):
            # BB has all binaries in one task
            # TC generates target.zip in this task, the installer is set below
            route = tc_task_indexes[platform]['signed'].format(rev=revision)
        signed_task = index.findTask(route)
        en_us_binary_url = "https://queue.taskcluster.net/v1/task/{taskid}/artifacts/public/build".format(
            taskid=signed_task["taskId"]
        )

        l10n_platform_configs[platform] = {
            "locales": get_platform_locales(l10n_changesets, platform),
            "en_us_binary_url": en_us_binary_url,
            "mar_tools_url": mar_tools_url,
            "chunks": platforms[platform].get("l10n_chunks", 10),
        }
        # Windows installer is a different beast
        if platform.startswith("win") and tc_task_indexes[platform]['ci_system'] == 'tc':
            route = tc_task_indexes[platform]['repackage-signing'].format(rev=revision)
            installer_task = index.findTask(route)
            en_us_installer_binary_url = "https://queue.taskcluster.net/v1/task/{taskid}/artifacts/public/build".format(
                taskid=installer_task["taskId"]
            )
            l10n_platform_configs[platform]['en_us_installer_binary_url'] = en_us_installer_binary_url

    return {
        "platforms": l10n_platform_configs,
        "changesets": l10n_changesets,
    }


def get_en_US_config(index, product, branch, revision, platforms,
                     tc_task_indexes):
    platform_configs = {}
    for platform in platforms:
        signed_route = tc_task_indexes[platform]['signed'].format(rev=revision)
        signed_task = index.findTask(signed_route)
        unsigned_route = tc_task_indexes[platform]['unsigned'].format(rev=revision)
        unsigned_task = index.findTask(unsigned_route)
        platform_configs[platform] = {
            "signed_task_id": signed_task["taskId"],
            "unsigned_task_id": unsigned_task["taskId"],
            "ci_system": tc_task_indexes[platform]["ci_system"],
        }
        for t in ("repackage", "repackage-signing"):
            if t in tc_task_indexes[platform]:
                route = tc_task_indexes[platform][t].format(rev=revision)
                task = index.findTask(route)
                platform_configs[platform]['{}_task_id'.format(t)] = task['taskId']

    return {
        "platforms": platform_configs,
    }


# FIXME: the following function should be removed and we should use
# next_version provided by ship-it
def bump_version(version):
    """Bump last digit

    >>> bump_version("45.0")
    '45.0.1'
    >>> bump_version("45.0.1")
    '45.0.2'
    >>> bump_version("45.0b3")
    '45.0b4'
    >>> bump_version("45.0esr")
    '45.0.1esr'
    >>> bump_version("45.0.1esr")
    '45.0.2esr'
    >>> bump_version("45.2.1esr")
    '45.2.2esr'
    """
    split_by = "."
    digit_index = 2
    suffix = ""
    if "b" in version:
        split_by = "b"
        digit_index = 1
    if "esr" in version:
        version = version.replace("esr", "")
        suffix = "esr"
    v = version.split(split_by)
    if len(v) < digit_index + 1:
        # 45.0 is 45.0.0 actually
        v.append("0")
    v[-1] = str(int(v[-1]) + 1)
    return split_by.join(v) + suffix


def make_task_graph_strict_kwargs(appVersion, balrog_api_root, balrog_password, balrog_username,
                                  beetmover_aws_access_key_id, beetmover_aws_secret_access_key,
                                  beetmover_candidates_bucket, bouncer_enabled, branch, buildNumber,
                                  build_tools_repo_path, candidates_fennec_enabled,
                                  checksums_enabled, binary_transparency_enabled, en_US_config,
                                  root_home_dir, extra_balrog_submitter_params, final_verify_channels,
                                  final_verify_platforms, uptake_monitoring_platforms,
                                  funsize_balrog_api_root, l10n_config, signing_cert,
                                  l10n_changesets, mozharness_changeset, next_version,
                                  partial_updates, partner_repacks_platforms,
                                  eme_free_repacks_platforms, sha1_repacks_platforms,
                                  postrelease_bouncer_aliases_enabled, uptake_monitoring_enabled,
                                  postrelease_version_bump_enabled, moz_disable_mar_cert_verification,
                                  postrelease_mark_as_shipped_enabled, accepted_mar_channel_id, public_key,
                                  product, stage_product, funsize_product, push_to_candidates_enabled,
                                  push_to_releases_automatic, push_to_releases_enabled, release_channels,
                                  repo_path, revision, signing_class, signing_pvt_key, source_enabled,
                                  tuxedo_server_url, update_verify_enabled, updates_builder_enabled,
                                  updates_enabled, verifyConfigs, version, publish_to_balrog_channels,
                                  snap_enabled, update_verify_channel, update_verify_requires_cdn_push,
                                  release_eta):
    """simple wrapper that sanitizes whatever calls make_task_graph uses universally known kwargs"""

    kwargs = dict(
        appVersion=appVersion,
        balrog_api_root=balrog_api_root,
        balrog_password=balrog_password,
        balrog_username=balrog_username,
        beetmover_aws_access_key_id=beetmover_aws_access_key_id,
        beetmover_aws_secret_access_key=beetmover_aws_secret_access_key,
        beetmover_candidates_bucket=beetmover_candidates_bucket,
        bouncer_enabled=bouncer_enabled,
        branch=branch,
        buildNumber=buildNumber,
        build_tools_repo_path=build_tools_repo_path,
        candidates_fennec_enabled=candidates_fennec_enabled,
        checksums_enabled=checksums_enabled,
        binary_transparency_enabled=binary_transparency_enabled,
        en_US_config=en_US_config,
        final_verify_channels=final_verify_channels,
        final_verify_platforms=final_verify_platforms,
        uptake_monitoring_platforms=uptake_monitoring_platforms,
        funsize_balrog_api_root=funsize_balrog_api_root,
        l10n_changesets=l10n_changesets,
        l10n_config=l10n_config,
        mozharness_changeset=mozharness_changeset,
        next_version=next_version,
        partial_updates=partial_updates,
        partner_repacks_platforms=partner_repacks_platforms,
        eme_free_repacks_platforms=eme_free_repacks_platforms,
        sha1_repacks_platforms=sha1_repacks_platforms,
        postrelease_bouncer_aliases_enabled=postrelease_bouncer_aliases_enabled,
        uptake_monitoring_enabled=uptake_monitoring_enabled,
        postrelease_version_bump_enabled=postrelease_version_bump_enabled,
        postrelease_mark_as_shipped_enabled=postrelease_mark_as_shipped_enabled,
        product=product,
        public_key=public_key,
        push_to_candidates_enabled=push_to_candidates_enabled,
        push_to_releases_automatic=push_to_releases_automatic,
        push_to_releases_enabled=push_to_releases_enabled,
        release_channels=release_channels,
        repo_path=repo_path,
        revision=revision,
        signing_class=signing_class,
        accepted_mar_channel_id=accepted_mar_channel_id,
        signing_cert=signing_cert,
        moz_disable_mar_cert_verification=moz_disable_mar_cert_verification,
        root_home_dir=root_home_dir,
        signing_pvt_key=signing_pvt_key,
        source_enabled=source_enabled,
        stage_product=stage_product,
        tuxedo_server_url=tuxedo_server_url,
        update_verify_enabled=update_verify_enabled,
        updates_builder_enabled=updates_builder_enabled,
        updates_enabled=updates_enabled,
        verifyConfigs=verifyConfigs,
        version=version,
        publish_to_balrog_channels=publish_to_balrog_channels,
        snap_enabled=snap_enabled,
        update_verify_channel=update_verify_channel,
        update_verify_requires_cdn_push=update_verify_requires_cdn_push,
        funsize_product=funsize_product,
        release_eta=release_eta,
    )
    if extra_balrog_submitter_params:
        kwargs["extra_balrog_submitter_params"] = extra_balrog_submitter_params

    # don't import releasetasks until required within function impl to avoid global failures
    # during nosetests
    from releasetasks import make_task_graph
    return make_task_graph(**kwargs)


def get_funsize_product(product_name):
    if product_name == 'devedition':    # See bug 1366075
        return 'firefox'
    return product_name