tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

build_lints.py (2195B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 """
      5 Apply some defaults and minor modifications to the jobs defined in the build
      6 kind.
      7 """
      8 
      9 from taskgraph.transforms.base import TransformSequence
     10 
     11 transforms = TransformSequence()
     12 
     13 
     14 @transforms.add
     15 def check_mozharness_perfherder_options(config, jobs):
     16    """Verify that multiple jobs don't use the same perfherder bucket.
     17 
     18    Build jobs record perfherder metrics by default. Perfherder metrics go
     19    to a bucket derived by the platform by default. The name can further be
     20    customized by the presence of "extra options" either defined in
     21    mozharness sub-configs or in an environment variable.
     22 
     23    This linter tries to verify that no 2 jobs will send Perfherder metrics
     24    to the same bucket by looking for jobs not defining extra options when
     25    their platform or mozharness config are otherwise similar.
     26    """
     27 
     28    SEEN_CONFIGS = {}
     29 
     30    for job in jobs:
     31        if job["run"]["using"] != "mozharness":
     32            yield job
     33            continue
     34 
     35        worker = job.get("worker", {})
     36 
     37        platform = job["treeherder"]["platform"]
     38        primary_config = job["run"]["config"][0]
     39        options = worker.get("env", {}).get("PERFHERDER_EXTRA_OPTIONS")
     40        shippable = job.get("attributes", {}).get("shippable", False)
     41 
     42        # This isn't strictly necessary. But the Perfherder code looking at the
     43        # values we care about is only active on builds. So it doesn't make
     44        # sense to run this linter elsewhere.
     45        assert primary_config.startswith("builds/")
     46 
     47        key = (platform, primary_config, shippable, options)
     48 
     49        if key in SEEN_CONFIGS:
     50            raise Exception(
     51                "Non-unique Perfherder data collection for jobs %s-%s and %s: "
     52                "set PERFHERDER_EXTRA_OPTIONS in worker environment variables "
     53                "or use different mozconfigs"
     54                % (config.kind, job["name"], SEEN_CONFIGS[key])
     55            )
     56 
     57        SEEN_CONFIGS[key] = "{}-{}".format(config.kind, job["name"])
     58 
     59        yield job