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.

Mercurial (563f437f24b9)

VCS Links

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 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822
# -*- coding: utf-8 -*-

# 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 __future__ import absolute_import, print_function, unicode_literals

from taskgraph import try_option_syntax
from taskgraph.util.attributes import match_run_on_projects, match_run_on_hg_branches

_target_task_methods = {}


def _target_task(name):
    def wrap(func):
        _target_task_methods[name] = func
        return func
    return wrap


def get_method(method):
    """Get a target_task_method to pass to a TaskGraphGenerator."""
    return _target_task_methods[method]


def filter_out_nightly(task, parameters):
    return (
        not task.attributes.get('nightly') and
        task.attributes.get('shipping_phase') in (None, 'build')
        )


def filter_out_cron(task, parameters):
    """
    Filter out tasks that run via cron.
    """
    return not task.attributes.get('cron')


def filter_for_project(task, parameters):
    """Filter tasks by project.  Optionally enable nightlies."""
    run_on_projects = set(task.attributes.get('run_on_projects', []))
    return match_run_on_projects(parameters['project'], run_on_projects)


def filter_for_hg_branch(task, parameters):
    """Filter tasks by hg branch.
    If `run_on_hg_branch` is not defined, then task runs on all branches"""
    run_on_hg_branches = set(task.attributes.get('run_on_hg_branches', ['all']))
    return match_run_on_hg_branches(parameters['hg_branch'], run_on_hg_branches)


def filter_on_platforms(task, platforms):
    """Filter tasks on the given platform"""
    platform = task.attributes.get('build_platform')
    return (platform in platforms)


def filter_release_tasks(task, parameters):
    platform = task.attributes.get('build_platform')
    if platform in (
            # On beta, Nightly builds are already PGOs
            'linux-pgo', 'linux64-pgo',
            'win32-pgo', 'win64-pgo',
            ):
        return False

    if platform in (
            'linux', 'linux64',
            'macosx64',
            'win32', 'win64', 'win64-aarch64',
            ):
        if task.attributes['kind'] == 'l10n':
            # This is on-change l10n
            return True
        if task.attributes['build_type'] == 'opt' and \
           task.attributes.get('unittest_suite') != 'talos' and \
           task.attributes.get('unittest_suite') != 'raptor':
            return False

    if task.attributes.get('shipping_phase') not in (None, 'build'):
        return False

    return True


def filter_out_missing_signoffs(task, parameters):
    for signoff in parameters['required_signoffs']:
        if signoff not in parameters['signoff_urls'] and \
           signoff in task.attributes.get('required_signoffs', []):
            return False
    return True


def standard_filter(task, parameters):
    return all(
        filter_func(task, parameters) for filter_func in
        (filter_out_cron, filter_for_project, filter_for_hg_branch)
    )


def _try_task_config(full_task_graph, parameters, graph_config):
    requested_tasks = parameters['try_task_config']['tasks']
    return list(set(requested_tasks) & full_task_graph.graph.nodes)


def _try_option_syntax(full_task_graph, parameters, graph_config):
    """Generate a list of target tasks based on try syntax in
    parameters['message'] and, for context, the full task graph."""
    options = try_option_syntax.TryOptionSyntax(parameters, full_task_graph, graph_config)
    target_tasks_labels = [t.label for t in full_task_graph.tasks.itervalues()
                           if options.task_matches(t)]

    attributes = {
        k: getattr(options, k) for k in [
            'env',
            'no_retry',
            'tag',
        ]
    }

    for l in target_tasks_labels:
        task = full_task_graph[l]
        if 'unittest_suite' in task.attributes:
            task.attributes['task_duplicates'] = options.trigger_tests

    for l in target_tasks_labels:
        task = full_task_graph[l]
        # If the developer wants test jobs to be rebuilt N times we add that value here
        if options.trigger_tests > 1 and 'unittest_suite' in task.attributes:
            task.attributes['task_duplicates'] = options.trigger_tests
            task.attributes['profile'] = False

        # If the developer wants test talos jobs to be rebuilt N times we add that value here
        if options.talos_trigger_tests > 1 and task.attributes.get('unittest_suite') == 'talos':
            task.attributes['task_duplicates'] = options.talos_trigger_tests
            task.attributes['profile'] = options.profile

        # If the developer wants test raptor jobs to be rebuilt N times we add that value here
        if options.raptor_trigger_tests > 1 and task.attributes.get('unittest_suite') == 'raptor':
            task.attributes['task_duplicates'] = options.raptor_trigger_tests
            task.attributes['profile'] = options.profile

        task.attributes.update(attributes)

    # Add notifications here as well
    if options.notifications:
        for task in full_task_graph:
            owner = parameters.get('owner')
            routes = task.task.setdefault('routes', [])
            if options.notifications == 'all':
                routes.append("notify.email.{}.on-any".format(owner))
            elif options.notifications == 'failure':
                routes.append("notify.email.{}.on-failed".format(owner))
                routes.append("notify.email.{}.on-exception".format(owner))

    return target_tasks_labels


@_target_task('try_tasks')
def target_tasks_try(full_task_graph, parameters, graph_config):
    try_mode = parameters['try_mode']
    if try_mode == 'try_task_config':
        return _try_task_config(full_task_graph, parameters, graph_config)
    elif try_mode == 'try_option_syntax':
        return _try_option_syntax(full_task_graph, parameters, graph_config)
    else:
        # With no try mode, we schedule nothing, allowing the user to add tasks
        # later via treeherder.
        return []


@_target_task('default')
def target_tasks_default(full_task_graph, parameters, graph_config):
    """Target the tasks which have indicated they should be run on this project
    via the `run_on_projects` attributes."""
    return [l for l, t in full_task_graph.tasks.iteritems()
            if standard_filter(t, parameters)
            and filter_out_nightly(t, parameters)]


@_target_task('ash_tasks')
def target_tasks_ash(full_task_graph, parameters, graph_config):
    """Target tasks that only run on the ash branch."""
    def filter(task):
        attr = task.attributes
        platform = attr.get('build_platform')
        # Early return if platform is None
        if not platform:
            return False
        # Only on Linux platforms
        if 'linux' not in platform:
            return False
        # No random non-build jobs either. This is being purposely done as a
        # blacklist so newly-added jobs aren't missed by default.
        for p in ('shippable', 'haz', 'artifact', 'cov', 'add-on'):
            if p in platform:
                return False
        for k in ('toolchain', 'l10n'):
            if k in attr['kind']:
                return False
        # and none of this linux64-asan/debug stuff
        if platform == 'linux64-asan' and attr['build_type'] == 'debug':
            return False

        if attr.get('unittest_suite'):
            # no non-e10s tests
            if not attr.get('e10s'):
                return False

            # filter out by test platform
            for p in ('-qr',):
                if p in attr['test_platform']:
                    return False

            # filter out raptor-fis (they are broken)
            if attr['unittest_suite'] == 'raptor' and attr.get('unittest_variant') == 'fission':
                return False

        # don't upload symbols
        if attr['kind'] == 'upload-symbols':
            return False
        return True

    return [l for l, t in full_task_graph.tasks.iteritems()
            if filter(t)
            and standard_filter(t, parameters)
            and filter_out_nightly(t, parameters)]


@_target_task('graphics_tasks')
def target_tasks_graphics(full_task_graph, parameters, graph_config):
    """In addition to doing the filtering by project that the 'default'
       filter does, also remove artifact builds because we have csets on
       the graphics branch that aren't on the candidate branches of artifact
       builds"""
    filtered_for_project = target_tasks_default(full_task_graph, parameters, graph_config)

    def filter(task):
        if task.attributes['kind'] == 'artifact-build':
            return False
        return True
    return [l for l in filtered_for_project if filter(full_task_graph[l])]


@_target_task('mochitest_valgrind')
def target_tasks_valgrind(full_task_graph, parameters, graph_config):
    """Target tasks for mochitest valgrind jobs."""
    def filter(task):
        platform = task.attributes.get('test_platform', '').split('/')[0]
        if platform not in ['linux64']:
            return False

        if task.attributes.get('unittest_suite', '').startswith('mochitest-valgrind-plain'):
            return True
        return False

    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]


@_target_task('mozilla_beta_tasks')
def target_tasks_mozilla_beta(full_task_graph, parameters, graph_config):
    """Select the set of tasks required for a promotable beta or release build
    of desktop, plus android CI. The candidates build process involves a pipeline
    of builds and signing, but does not include beetmover or balrog jobs."""

    return [l for l, t in full_task_graph.tasks.iteritems()
            if filter_release_tasks(t, parameters)
            and standard_filter(t, parameters)]


@_target_task('mozilla_release_tasks')
def target_tasks_mozilla_release(full_task_graph, parameters, graph_config):
    """Select the set of tasks required for a promotable beta or release build
    of desktop, plus android CI. The candidates build process involves a pipeline
    of builds and signing, but does not include beetmover or balrog jobs."""

    return [l for l, t in full_task_graph.tasks.iteritems()
            if filter_release_tasks(t, parameters)
            and standard_filter(t, parameters)]


@_target_task('mozilla_esr60_tasks')
def target_tasks_mozilla_esr60(full_task_graph, parameters, graph_config):
    """Select the set of tasks required for a promotable beta or release build
    of desktop. The candidates build process involves a pipeline of builds and
    signing, but does not include beetmover or balrog jobs."""

    def filter(task):
        if not filter_release_tasks(task, parameters):
            return False

        if not standard_filter(task, parameters):
            return False

        platform = task.attributes.get('build_platform')

        # Android is not built on esr60.
        if platform and 'android' in platform:
            return False

        # All else was already filtered
        return True

    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]


@_target_task('mozilla_esr68_tasks')
def target_tasks_mozilla_esr68(full_task_graph, parameters, graph_config):
    """Select the set of tasks required for a promotable beta or release build
    of desktop, plus android CI. The candidates build process involves a pipeline
    of builds and signing, but does not include beetmover or balrog jobs."""

    def filter(task):
        if not filter_release_tasks(task, parameters):
            return False

        if not standard_filter(task, parameters):
            return False

        platform = task.attributes.get('test_platform')

        # Don't run QuantumRender tests on esr68.
        if platform and '-qr/' in platform:
            return False

        # Unlike esr60, we do want all kinds of fennec builds on esr68.

        return True

    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]


@_target_task('promote_desktop')
def target_tasks_promote_desktop(full_task_graph, parameters, graph_config):
    """Select the superset of tasks required to promote a beta or release build
    of a desktop product. This should include all non-android
    mozilla_{beta,release} tasks, plus l10n, beetmover, balrog, etc."""

    def filter(task):
        if task.attributes.get('shipping_product') != parameters['release_product']:
            return False

        # 'secondary' balrog/update verify/final verify tasks only run for RCs
        if parameters.get('release_type') != 'release-rc':
            if 'secondary' in task.kind:
                return False

        if not filter_out_missing_signoffs(task, parameters):
            return False

        if task.attributes.get('shipping_phase') == 'promote':
            return True

    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]


@_target_task('push_desktop')
def target_tasks_push_desktop(full_task_graph, parameters, graph_config):
    """Select the set of tasks required to push a build of desktop to cdns.
    Previous build deps will be optimized out via action task."""
    filtered_for_candidates = target_tasks_promote_desktop(
        full_task_graph, parameters, graph_config,
    )

    def filter(task):
        if not filter_out_missing_signoffs(task, parameters):
            return False
        # Include promotion tasks; these will be optimized out
        if task.label in filtered_for_candidates:
            return True
        if task.attributes.get('shipping_product') == parameters['release_product'] and \
                task.attributes.get('shipping_phase') == 'push':
            return True

    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]


@_target_task('ship_desktop')
def target_tasks_ship_desktop(full_task_graph, parameters, graph_config):
    """Select the set of tasks required to ship desktop.
    Previous build deps will be optimized out via action task."""
    is_rc = (parameters.get('release_type') == 'release-rc')
    if is_rc:
        # ship_firefox_rc runs after `promote` rather than `push`; include
        # all promote tasks.
        filtered_for_candidates = target_tasks_promote_desktop(
            full_task_graph, parameters, graph_config,
        )
    else:
        # ship_firefox runs after `push`; include all push tasks.
        filtered_for_candidates = target_tasks_push_desktop(
            full_task_graph, parameters, graph_config,
        )

    def filter(task):
        if not filter_out_missing_signoffs(task, parameters):
            return False
        # Include promotion tasks; these will be optimized out
        if task.label in filtered_for_candidates:
            return True
        if task.attributes.get('shipping_product') != parameters['release_product'] or \
                task.attributes.get('shipping_phase') != 'ship':
            return False

        if 'secondary' in task.kind:
            return is_rc
        else:
            return not is_rc

    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]


@_target_task('promote_fennec')
def target_tasks_promote_fennec(full_task_graph, parameters, graph_config):
    """Select the set of tasks required for a candidates build of fennec. The
    nightly build process involves a pipeline of builds, signing,
    and, eventually, uploading the tasks to balrog."""

    def filter(task):
        attr = task.attributes.get
        # Don't ship single locale fennec anymore - Bug 1408083
        if attr("locale") or attr("chunk_locales"):
            return False
        if task.attributes.get('shipping_product') == 'fennec' and \
                task.attributes.get('shipping_phase') == 'promote':
            return True

    return [l for l, t in full_task_graph.tasks.iteritems() if filter(full_task_graph[l])]


@_target_task('ship_fennec')
def target_tasks_ship_fennec(full_task_graph, parameters, graph_config):
    """Select the set of tasks required to ship fennec.
    Previous build deps will be optimized out via action task."""
    is_rc = (parameters.get('release_type') == 'release-rc')
    filtered_for_candidates = target_tasks_promote_fennec(
        full_task_graph, parameters, graph_config,
    )

    def filter(task):
        # Include candidates build tasks; these will be optimized out
        if task.label in filtered_for_candidates:
            return True
        if task.attributes.get('shipping_product') != 'fennec' or \
                task.attributes.get('shipping_phase') not in ('ship', 'push'):
            return False
        # We always run push-apk during ship
        if task.kind == 'push-apk':
            return True
        # secondary-notify-ship is only for RC
        if task.kind in (
            'release-secondary-notify-ship',
        ):
            return is_rc

        # Everything else is only for non-RC
        return not is_rc

    return [l for l, t in full_task_graph.tasks.iteritems() if filter(full_task_graph[l])]


@_target_task('pine_tasks')
def target_tasks_pine(full_task_graph, parameters, graph_config):
    """Bug 1339179 - no mobile automation needed on pine"""
    def filter(task):
        platform = task.attributes.get('build_platform')
        # disable mobile jobs
        if str(platform).startswith('android'):
            return False
        # disable asan
        if platform == 'linux64-asan':
            return False
        # disable non-pine and nightly tasks
        if standard_filter(task, parameters) or filter_out_nightly(task, parameters):
            return True
    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]


@_target_task('ship_geckoview')
def target_tasks_ship_geckoview(full_task_graph, parameters, graph_config):
    """Select the set of tasks required to ship geckoview nightly. The
    nightly build process involves a pipeline of builds and an upload to
    maven.mozilla.org."""
    def filter(task):
        # XXX Starting 69, we don't ship Fennec Nightly anymore. We just want geckoview to be
        # uploaded
        return (
            task.attributes.get('shipping_product') == 'fennec' and
            task.kind in ('beetmover-geckoview', 'upload-symbols')
        )

    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]


@_target_task('fennec_v68')
def target_tasks_fennec_v68(full_task_graph, parameters, graph_config):
    """
    Select tasks required for running tp6m fennec v68 tests
    """
    def filter(task):
        platform = task.attributes.get('build_platform')
        attributes = task.attributes

        if platform and 'android' not in platform:
            return False
        if attributes.get('unittest_suite') != 'raptor':
            return False
        if '-fennec68-' in attributes.get('raptor_try_name'):
            return True

    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]


@_target_task('general_perf_testing')
def target_tasks_general_perf_testing(full_task_graph, parameters, graph_config):
    """
    Select tasks required for running performance tests 3 times a week.
    """
    def filter(task):
        platform = task.attributes.get('build_platform')
        attributes = task.attributes
        if attributes.get('unittest_suite') != 'raptor':
            return False
        try_name = attributes.get('raptor_try_name')
        # Run chrome and chromium on all platforms available
        if '-chrome' in try_name:
            return True
        if '-chromium' in try_name:
            return True

        # Run the following tests on android geckoview
        if platform and 'android' not in platform:
            return False
        if 'geckoview' not in try_name:
            return False

        # Run cpu+memory, and power tests
        cpu_n_memory_task = '-cpu' in try_name and '-memory' in try_name
        power_task = '-power' in try_name
        # Ignore cpu+memory+power tests
        if power_task and cpu_n_memory_task:
            return False
        if power_task or cpu_n_memory_task:
            if 'pgo' not in platform:
                return False
            if '-speedometer-' in try_name:
                return True
            if '-scn' in try_name and '-idle' in try_name:
                return True
        return False

    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]


def make_desktop_nightly_filter(platforms):
    """Returns a filter that gets all nightly tasks on the given platform."""
    def filter(task, parameters):
        return all([
            filter_on_platforms(task, platforms),
            filter_for_project(task, parameters),
            any([
                task.attributes.get('nightly', False),
                task.attributes.get('shippable', False),
            ]),
            # Tests and nightly only builds don't have `shipping_product` set
            task.attributes.get('shipping_product') in {None, "firefox", "thunderbird"},
            task.kind not in {'l10n'},  # no on-change l10n
        ])
    return filter


@_target_task('nightly_linux')
def target_tasks_nightly_linux(full_task_graph, parameters, graph_config):
    """Select the set of tasks required for a nightly build of linux. The
    nightly build process involves a pipeline of builds, signing,
    and, eventually, uploading the tasks to balrog."""
    filter = make_desktop_nightly_filter({
        'linux64-nightly', 'linux-nightly', 'linux64-shippable', 'linux-shippable'
        })
    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t, parameters)]


@_target_task('nightly_macosx')
def target_tasks_nightly_macosx(full_task_graph, parameters, graph_config):
    """Select the set of tasks required for a nightly build of macosx. The
    nightly build process involves a pipeline of builds, signing,
    and, eventually, uploading the tasks to balrog."""
    filter = make_desktop_nightly_filter({'macosx64-nightly', 'macosx64-shippable'})
    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t, parameters)]


@_target_task('nightly_win32')
def target_tasks_nightly_win32(full_task_graph, parameters, graph_config):
    """Select the set of tasks required for a nightly build of win32 and win64.
    The nightly build process involves a pipeline of builds, signing,
    and, eventually, uploading the tasks to balrog."""
    filter = make_desktop_nightly_filter({'win32-nightly', 'win32-shippable'})
    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t, parameters)]


@_target_task('nightly_win64')
def target_tasks_nightly_win64(full_task_graph, parameters, graph_config):
    """Select the set of tasks required for a nightly build of win32 and win64.
    The nightly build process involves a pipeline of builds, signing,
    and, eventually, uploading the tasks to balrog."""
    filter = make_desktop_nightly_filter({'win64-nightly', 'win64-shippable'})
    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t, parameters)]


@_target_task('nightly_win64_aarch64')
def target_tasks_nightly_win64_aarch64(full_task_graph, parameters, graph_config):
    """Select the set of tasks required for a nightly build of win32 and win64.
    The nightly build process involves a pipeline of builds, signing,
    and, eventually, uploading the tasks to balrog."""
    filter = make_desktop_nightly_filter({'win64-aarch64-nightly', 'win64-aarch64-shippable'})
    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t, parameters)]


@_target_task('nightly_asan')
def target_tasks_nightly_asan(full_task_graph, parameters, graph_config):
    """Select the set of tasks required for a nightly build of asan. The
    nightly build process involves a pipeline of builds, signing,
    and, eventually, uploading the tasks to balrog."""
    filter = make_desktop_nightly_filter({
        'linux64-asan-reporter-nightly',
        'win64-asan-reporter-nightly'
    })
    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t, parameters)]


@_target_task('nightly_desktop')
def target_tasks_nightly_desktop(full_task_graph, parameters, graph_config):
    """Select the set of tasks required for a nightly build of linux, mac,
    windows."""
    # Tasks that aren't platform specific
    release_filter = make_desktop_nightly_filter({None})
    release_tasks = [
        l for l, t in full_task_graph.tasks.iteritems()
        if release_filter(t, parameters)
    ]
    # Avoid duplicate tasks.
    return list(
        set(target_tasks_nightly_win32(full_task_graph, parameters, graph_config))
        | set(target_tasks_nightly_win64(full_task_graph, parameters, graph_config))
        | set(target_tasks_nightly_win64_aarch64(full_task_graph, parameters, graph_config))
        | set(target_tasks_nightly_macosx(full_task_graph, parameters, graph_config))
        | set(target_tasks_nightly_linux(full_task_graph, parameters, graph_config))
        | set(target_tasks_nightly_asan(full_task_graph, parameters, graph_config))
        | set(release_tasks)
    )


# Run Searchfox analysis once daily.
@_target_task('searchfox_index')
def target_tasks_searchfox(full_task_graph, parameters, graph_config):
    """Select tasks required for indexing Firefox for Searchfox web site each day"""
    return ['searchfox-linux64-searchfox/debug',
            'searchfox-macosx64-searchfox/debug',
            'searchfox-win64-searchfox/debug',
            'searchfox-android-armv7-searchfox/debug',
            'source-test-file-metadata-bugzilla-components']


@_target_task('customv8_update')
def target_tasks_customv8_update(full_task_graph, parameters, graph_config):
    """Select tasks required for building latest d8/v8 version."""
    return ['toolchain-linux64-custom-v8']


@_target_task('chromium_update')
def target_tasks_chromium_update(full_task_graph, parameters, graph_config):
    """Select tasks required for building latest chromium versions."""
    return ['fetch-linux64-chromium',
            'fetch-win32-chromium',
            'fetch-win64-chromium',
            'fetch-mac-chromium']


@_target_task('pipfile_update')
def target_tasks_pipfile_update(full_task_graph, parameters, graph_config):
    """Select the set of tasks required to perform nightly in-tree pipfile updates
    """
    def filter(task):
        # For now any task in the repo-update kind is ok
        return task.kind in ['pipfile-update']
    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]


@_target_task('file_update')
def target_tasks_file_update(full_task_graph, parameters, graph_config):
    """Select the set of tasks required to perform nightly in-tree file updates
    """
    def filter(task):
        # For now any task in the repo-update kind is ok
        return task.kind in ['repo-update']
    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]


@_target_task('cron_bouncer_check')
def target_tasks_bouncer_check(full_task_graph, parameters, graph_config):
    """Select the set of tasks required to perform bouncer version verification.
    """
    def filter(task):
        if not filter_for_project(task, parameters):
            return False
        # For now any task in the repo-update kind is ok
        return task.kind in ['cron-bouncer-check']
    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]


@_target_task('staging_release_builds')
def target_tasks_staging_release(full_task_graph, parameters, graph_config):
    """
    Select all builds that are part of releases.
    """

    def filter(task):
        if not task.attributes.get('shipping_product'):
            return False
        if (parameters['release_type'].startswith('esr')
                and 'android' in task.attributes.get('build_platform', '')):
            return False
        if (parameters['release_type'] != 'beta'
                and 'devedition' in task.attributes.get('build_platform', '')):
            return False
        if task.attributes.get('shipping_phase') == 'build':
            return True
        return False

    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]


@_target_task('release_simulation')
def target_tasks_release_simulation(full_task_graph, parameters, graph_config):
    """
    Select builds that would run on push on a release branch.
    """
    project_by_release = {
        'nightly': 'mozilla-central',
        'beta': 'mozilla-beta',
        'release': 'mozilla-release',
        'esr60': 'mozilla-esr60',
    }
    target_project = project_by_release.get(parameters['release_type'])
    if target_project is None:
        raise Exception('Unknown or unspecified release type in simulation run.')

    def filter_for_target_project(task):
        """Filter tasks by project.  Optionally enable nightlies."""
        run_on_projects = set(task.attributes.get('run_on_projects', []))
        return match_run_on_projects(target_project, run_on_projects)

    def filter_out_android_on_esr(task):
        if (parameters['release_type'].startswith('esr')
                and 'android' in task.attributes.get('build_platform', '')):
            return False
        return True

    return [l for l, t in full_task_graph.tasks.iteritems()
            if filter_release_tasks(t, parameters)
            and filter_out_cron(t, parameters)
            and filter_for_target_project(t)
            and filter_out_android_on_esr(t)]


@_target_task('codereview')
def target_tasks_codereview(full_task_graph, parameters, graph_config):
    """Select all code review tasks needed to produce a report"""

    def filter(task):
        # Ending tasks
        if task.kind in ['code-review']:
            return True

        # Analyzer tasks
        if task.attributes.get('code-review') is True:
            return True

        return False

    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]


@_target_task('nothing')
def target_tasks_nothing(full_task_graph, parameters, graph_config):
    """Select nothing, for DONTBUILD pushes"""
    return []


@_target_task('raptor_tp6m')
def target_tasks_raptor_tp6m(full_task_graph, parameters, graph_config):
    """
    Select tasks required for running raptor cold page-load tests on fenix and refbrow
    """
    def filter(task):
        platform = task.attributes.get('build_platform')
        attributes = task.attributes

        if platform and 'android' not in platform:
            return False
        if attributes.get('unittest_suite') != 'raptor':
            return False
        try_name = attributes.get('raptor_try_name')
        if '-cold' in try_name and 'pgo' in platform:
            if '-1-refbrow-' in try_name:
                return True
            if '-1-fenix-' in try_name:
                return True

    return [l for l, t in full_task_graph.tasks.iteritems() if filter(t)]


@_target_task('condprof')
def target_tasks_condprof(full_task_graph, parameters, graph_config):
    """
    Select tasks required for building conditioned profiles.
    """
    for name, task in full_task_graph.tasks.iteritems():
        if task.kind == "condprof":
            yield name