dependencies.py (5579B)
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.util.dependencies import group_by 6 7 8 def skip_only_or_not(config, task): 9 """Return True if we should skip this task based on `only_` or `not_` config.""" 10 only_platforms = config.get("only-for-build-platforms") 11 not_platforms = config.get("not-for-build-platforms") 12 only_attributes = config.get("only-for-attributes") 13 not_attributes = config.get("not-for-attributes") 14 task_attrs = task.attributes 15 if only_platforms or not_platforms: 16 platform = task_attrs.get("build_platform") 17 build_type = task_attrs.get("build_type") 18 if not platform or not build_type: 19 return True 20 combined_platform = f"{platform}/{build_type}" 21 if only_platforms and combined_platform not in only_platforms: 22 return True 23 if not_platforms and combined_platform in not_platforms: 24 return True 25 if only_attributes: 26 if not set(only_attributes) & set(task_attrs): 27 # make sure any attribute exists 28 return True 29 if not_attributes: 30 if set(not_attributes) & set(task_attrs): 31 return True 32 return False 33 34 35 @group_by("single-with-filters") 36 def single_grouping(config, tasks): 37 for task in tasks: 38 if skip_only_or_not(config.config, task): 39 continue 40 yield [task] 41 42 43 @group_by("platform") 44 def platform_grouping(config, tasks): 45 groups = {} 46 for task in tasks: 47 if task.kind not in config.config.get("kind-dependencies", []): 48 continue 49 if skip_only_or_not(config.config, task): 50 continue 51 platform = task.attributes.get("build_platform") 52 build_type = task.attributes.get("build_type") 53 product = task.attributes.get( 54 "shipping_product", task.task.get("shipping-product") 55 ) 56 57 groups.setdefault((platform, build_type, product), []).append(task) 58 return groups.values() 59 60 61 @group_by("single-locale") 62 def single_locale_grouping(config, tasks): 63 """Split by a single locale (but also by platform, build-type, product) 64 65 The locale can be `None` (en-US build/signing/repackage), a single locale, 66 or multiple locales per task, e.g. for l10n chunking. In the case of a task 67 with, say, five locales, the task will show up in all five locale groupings. 68 69 This grouping is written for non-partner-repack beetmover, but might also 70 be useful elsewhere. 71 72 """ 73 groups = {} 74 75 for task in tasks: 76 if task.kind not in config.config.get("kind-dependencies", []): 77 continue 78 if skip_only_or_not(config.config, task): 79 continue 80 platform = task.attributes.get("build_platform") 81 build_type = task.attributes.get("build_type") 82 product = task.attributes.get( 83 "shipping_product", task.task.get("shipping-product") 84 ) 85 task_locale = task.attributes.get("locale") 86 chunk_locales = task.attributes.get("chunk_locales") 87 locales = chunk_locales or [task_locale] 88 89 for locale in locales: 90 locale_key = (platform, build_type, product, locale) 91 groups.setdefault(locale_key, []) 92 if task not in groups[locale_key]: 93 groups[locale_key].append(task) 94 95 return groups.values() 96 97 98 @group_by("chunk-locales") 99 def chunk_locale_grouping(config, tasks): 100 """Split by a chunk_locale (but also by platform, build-type, product) 101 102 This grouping is written for mac signing with notarization, but might also 103 be useful elsewhere. 104 105 """ 106 groups = {} 107 108 for task in tasks: 109 if task.kind not in config.config.get("kind-dependencies", []): 110 continue 111 if skip_only_or_not(config.config, task): 112 continue 113 platform = task.attributes.get("build_platform") 114 build_type = task.attributes.get("build_type") 115 product = task.attributes.get( 116 "shipping_product", task.task.get("shipping-product") 117 ) 118 chunk_locales = tuple(sorted(task.attributes.get("chunk_locales", []))) 119 120 chunk_locale_key = (platform, build_type, product, chunk_locales) 121 groups.setdefault(chunk_locale_key, []) 122 if task not in groups[chunk_locale_key]: 123 groups[chunk_locale_key].append(task) 124 125 return groups.values() 126 127 128 @group_by("partner-repack-ids") 129 def partner_repack_ids_grouping(config, tasks): 130 """Split by partner_repack_ids (but also by platform, build-type, product) 131 132 This grouping is written for release-{eme-free,partner}-repack-signing. 133 134 """ 135 groups = {} 136 137 for task in tasks: 138 if task.kind not in config.config.get("kind-dependencies", []): 139 continue 140 if skip_only_or_not(config.config, task): 141 continue 142 platform = task.attributes.get("build_platform") 143 build_type = task.attributes.get("build_type") 144 product = task.attributes.get( 145 "shipping_product", task.task.get("shipping-product") 146 ) 147 partner_repack_ids = tuple( 148 sorted(task.task.get("extra", {}).get("repack_ids", [])) 149 ) 150 151 partner_repack_ids_key = (platform, build_type, product, partner_repack_ids) 152 groups.setdefault(partner_repack_ids_key, []) 153 if task not in groups[partner_repack_ids_key]: 154 groups[partner_repack_ids_key].append(task) 155 156 return groups.values()