attribution.py (4051B)
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 from taskgraph.transforms.base import TransformSequence 6 from taskgraph.util.dependencies import get_primary_dependency 7 from taskgraph.util.schema import resolve_keyed_by 8 9 from gecko_taskgraph.util.partners import build_macos_attribution_dmg_command 10 11 transforms = TransformSequence() 12 resolve_keyed_by_transforms = TransformSequence() 13 14 15 @resolve_keyed_by_transforms.add 16 def attribution_keyed_by(config, jobs): 17 keyed_by_fields = ( 18 "attributes.release_artifacts", 19 "run.command", 20 "properties-with-locale", # properties-with-locale only exists in the l10n task 21 ) 22 for job in jobs: 23 build_platform = {"build-platform": job["attributes"]["build_platform"]} 24 for field in keyed_by_fields: 25 resolve_keyed_by(item=job, field=field, item_name=field, **build_platform) 26 yield job 27 28 29 @transforms.add 30 def remove_attributes(config, jobs): 31 """Remove attributes from parent task that aren't necessary.""" 32 for job in jobs: 33 for attr in ( 34 "accepted-mar-channel-ids", 35 "l10n_chunk", 36 "mar-channel-id", 37 "repackage_type", 38 "required_signoffs", 39 "shippable", 40 "signed", 41 "stub-installer", 42 "update-channel", 43 ): 44 if attr in job["attributes"]: 45 del job["attributes"][attr] 46 yield job 47 48 49 @transforms.add 50 def stub_installer(config, jobs): 51 """Not all windows builds come with a stub installer (only win32, and not 52 on esr), so conditionally add it here based on our dependency's 53 stub-installer attribute.""" 54 for job in jobs: 55 dep_task = get_primary_dependency(config, job) 56 assert dep_task 57 58 if dep_task.attributes.get("stub-installer"): 59 locale = job["attributes"].get("locale") 60 if locale: 61 artifact = f"{locale}/target.stub-installer.exe" 62 else: 63 artifact = "target.stub-installer.exe" 64 65 job["fetches"][dep_task.kind].append(artifact) 66 job["run"]["command"] += [ 67 "--input", 68 "/builds/worker/fetches/target.stub-installer.exe", 69 ] 70 job["attributes"]["release_artifacts"].append( 71 "public/build/target.stub-installer.exe" 72 ) 73 yield job 74 75 76 @transforms.add 77 def set_treeherder(config, jobs): 78 for job in jobs: 79 th = job.setdefault("treeherder", {}) 80 attrs = job["attributes"] 81 82 th["platform"] = f"{attrs['build_platform']}/{attrs['build_type']}" 83 th["symbol"] = th["symbol"].format(**attrs) 84 yield job 85 86 87 @transforms.add 88 def set_locale_label(config, jobs): 89 for job in jobs: 90 attrs = job["attributes"] 91 if locale := attrs.get("locale"): 92 platform, ship_type = attrs["build_platform"].rsplit("-", 1) 93 job["label"] = ( 94 f"attribution-{platform}-{locale}-{ship_type}/{attrs['build_type']}" 95 ) 96 97 yield job 98 99 100 @transforms.add 101 def mac_attribution(config, jobs): 102 """Adds \t padding to the mac attribution data. Implicitly assumes that the 103 attribution data is the last thing in job.run.command 104 """ 105 for job in jobs: 106 dlsource = job.pop("dlsource") 107 if "macosx" in job["attributes"]["build_platform"]: 108 job["run"]["command"] = build_macos_attribution_dmg_command( 109 "/builds/worker/fetches/dmg/dmg", 110 [ 111 { 112 "input": "/builds/worker/fetches/target.dmg", 113 "output": "/builds/worker/artifacts/target.dmg", 114 "attribution": f"dlsource={dlsource}", 115 } 116 ], 117 ) 118 job["fetches"].setdefault("toolchain", []).append("linux64-libdmg") 119 120 yield job