Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | """ |
| 3 | BitBake 'TaskData' implementation |
| 4 | |
| 5 | Task data collection and handling |
| 6 | |
| 7 | """ |
| 8 | |
| 9 | # Copyright (C) 2006 Richard Purdie |
| 10 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 11 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | |
| 14 | import logging |
| 15 | import re |
| 16 | import bb |
| 17 | |
| 18 | logger = logging.getLogger("BitBake.TaskData") |
| 19 | |
| 20 | def re_match_strings(target, strings): |
| 21 | """ |
| 22 | Whether or not the string 'target' matches |
| 23 | any one string of the strings which can be regular expression string |
| 24 | """ |
| 25 | return any(name == target or re.match(name, target) |
| 26 | for name in strings) |
| 27 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 28 | class TaskEntry: |
| 29 | def __init__(self): |
| 30 | self.tdepends = [] |
| 31 | self.idepends = [] |
| 32 | self.irdepends = [] |
| 33 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 34 | class TaskData: |
| 35 | """ |
| 36 | BitBake Task Data implementation |
| 37 | """ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 38 | def __init__(self, abort = True, skiplist = None, allowincomplete = False): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 39 | self.build_targets = {} |
| 40 | self.run_targets = {} |
| 41 | |
| 42 | self.external_targets = [] |
| 43 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 44 | self.seenfns = [] |
| 45 | self.taskentries = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | |
| 47 | self.depids = {} |
| 48 | self.rdepids = {} |
| 49 | |
| 50 | self.consider_msgs_cache = [] |
| 51 | |
| 52 | self.failed_deps = [] |
| 53 | self.failed_rdeps = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 54 | self.failed_fns = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 55 | |
| 56 | self.abort = abort |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 57 | self.allowincomplete = allowincomplete |
| 58 | |
| 59 | self.skiplist = skiplist |
| 60 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 61 | self.mcdepends = [] |
| 62 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 63 | def add_tasks(self, fn, dataCache): |
| 64 | """ |
| 65 | Add tasks for a given fn to the database |
| 66 | """ |
| 67 | |
| 68 | task_deps = dataCache.task_deps[fn] |
| 69 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 70 | if fn in self.failed_fns: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 71 | bb.msg.fatal("TaskData", "Trying to re-add a failed file? Something is broken...") |
| 72 | |
| 73 | # Check if we've already seen this fn |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 74 | if fn in self.seenfns: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 75 | return |
| 76 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 77 | self.seenfns.append(fn) |
| 78 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 79 | self.add_extra_deps(fn, dataCache) |
| 80 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 81 | def add_mcdepends(task): |
| 82 | for dep in task_deps['mcdepends'][task].split(): |
| 83 | if len(dep.split(':')) != 5: |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 84 | bb.msg.fatal("TaskData", "Error for %s:%s[%s], multiconfig dependency %s does not contain exactly four ':' characters.\n Task '%s' should be specified in the form 'mc:fromMC:toMC:packagename:task'" % (fn, task, 'mcdepends', dep, 'mcdepends')) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 85 | if dep not in self.mcdepends: |
| 86 | self.mcdepends.append(dep) |
| 87 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 88 | # Common code for dep_name/depends = 'depends'/idepends and 'rdepends'/irdepends |
| 89 | def handle_deps(task, dep_name, depends, seen): |
| 90 | if dep_name in task_deps and task in task_deps[dep_name]: |
| 91 | ids = [] |
| 92 | for dep in task_deps[dep_name][task].split(): |
| 93 | if dep: |
| 94 | parts = dep.split(":") |
| 95 | if len(parts) != 2: |
| 96 | bb.msg.fatal("TaskData", "Error for %s:%s[%s], dependency %s in '%s' does not contain exactly one ':' character.\n Task '%s' should be specified in the form 'packagename:task'" % (fn, task, dep_name, dep, task_deps[dep_name][task], dep_name)) |
| 97 | ids.append((parts[0], parts[1])) |
| 98 | seen(parts[0]) |
| 99 | depends.extend(ids) |
| 100 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 101 | for task in task_deps['tasks']: |
| 102 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 103 | tid = "%s:%s" % (fn, task) |
| 104 | self.taskentries[tid] = TaskEntry() |
| 105 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 106 | # Work out task dependencies |
| 107 | parentids = [] |
| 108 | for dep in task_deps['parents'][task]: |
| 109 | if dep not in task_deps['tasks']: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 110 | bb.debug(2, "Not adding dependency of %s on %s since %s does not exist" % (task, dep, dep)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 111 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 112 | parentid = "%s:%s" % (fn, dep) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 113 | parentids.append(parentid) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 114 | self.taskentries[tid].tdepends.extend(parentids) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 115 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 116 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 117 | # Touch all intertask dependencies |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 118 | handle_deps(task, 'depends', self.taskentries[tid].idepends, self.seen_build_target) |
| 119 | handle_deps(task, 'rdepends', self.taskentries[tid].irdepends, self.seen_run_target) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 120 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 121 | if 'mcdepends' in task_deps and task in task_deps['mcdepends']: |
| 122 | add_mcdepends(task) |
| 123 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 124 | # Work out build dependencies |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 125 | if not fn in self.depids: |
| 126 | dependids = set() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 127 | for depend in dataCache.deps[fn]: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 128 | dependids.add(depend) |
| 129 | self.depids[fn] = list(dependids) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 130 | logger.debug(2, "Added dependencies %s for %s", str(dataCache.deps[fn]), fn) |
| 131 | |
| 132 | # Work out runtime dependencies |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 133 | if not fn in self.rdepids: |
| 134 | rdependids = set() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 135 | rdepends = dataCache.rundeps[fn] |
| 136 | rrecs = dataCache.runrecs[fn] |
| 137 | rdependlist = [] |
| 138 | rreclist = [] |
| 139 | for package in rdepends: |
| 140 | for rdepend in rdepends[package]: |
| 141 | rdependlist.append(rdepend) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 142 | rdependids.add(rdepend) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 143 | for package in rrecs: |
| 144 | for rdepend in rrecs[package]: |
| 145 | rreclist.append(rdepend) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 146 | rdependids.add(rdepend) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 147 | if rdependlist: |
| 148 | logger.debug(2, "Added runtime dependencies %s for %s", str(rdependlist), fn) |
| 149 | if rreclist: |
| 150 | logger.debug(2, "Added runtime recommendations %s for %s", str(rreclist), fn) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 151 | self.rdepids[fn] = list(rdependids) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 152 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 153 | for dep in self.depids[fn]: |
| 154 | self.seen_build_target(dep) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 155 | if dep in self.failed_deps: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 156 | self.fail_fn(fn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 157 | return |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 158 | for dep in self.rdepids[fn]: |
| 159 | self.seen_run_target(dep) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 160 | if dep in self.failed_rdeps: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 161 | self.fail_fn(fn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 162 | return |
| 163 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 164 | def add_extra_deps(self, fn, dataCache): |
| 165 | func = dataCache.extradepsfunc.get(fn, None) |
| 166 | if func: |
| 167 | bb.providers.buildWorldTargetList(dataCache) |
| 168 | pn = dataCache.pkg_fn[fn] |
| 169 | params = {'deps': dataCache.deps[fn], |
| 170 | 'world_target': dataCache.world_target, |
| 171 | 'pkg_pn': dataCache.pkg_pn, |
| 172 | 'self_pn': pn} |
| 173 | funcname = '_%s_calculate_extra_depends' % pn.replace('-', '_') |
| 174 | paramlist = ','.join(params.keys()) |
| 175 | func = 'def %s(%s):\n%s\n\n%s(%s)' % (funcname, paramlist, func, funcname, paramlist) |
| 176 | bb.utils.better_exec(func, params) |
| 177 | |
| 178 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 179 | def have_build_target(self, target): |
| 180 | """ |
| 181 | Have we a build target matching this name? |
| 182 | """ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 183 | if target in self.build_targets and self.build_targets[target]: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 184 | return True |
| 185 | return False |
| 186 | |
| 187 | def have_runtime_target(self, target): |
| 188 | """ |
| 189 | Have we a runtime target matching this name? |
| 190 | """ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 191 | if target in self.run_targets and self.run_targets[target]: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 192 | return True |
| 193 | return False |
| 194 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 195 | def seen_build_target(self, name): |
| 196 | """ |
| 197 | Maintain a list of build targets |
| 198 | """ |
| 199 | if name not in self.build_targets: |
| 200 | self.build_targets[name] = [] |
| 201 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 202 | def add_build_target(self, fn, item): |
| 203 | """ |
| 204 | Add a build target. |
| 205 | If already present, append the provider fn to the list |
| 206 | """ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 207 | if item in self.build_targets: |
| 208 | if fn in self.build_targets[item]: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 209 | return |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 210 | self.build_targets[item].append(fn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 211 | return |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 212 | self.build_targets[item] = [fn] |
| 213 | |
| 214 | def seen_run_target(self, name): |
| 215 | """ |
| 216 | Maintain a list of runtime build targets |
| 217 | """ |
| 218 | if name not in self.run_targets: |
| 219 | self.run_targets[name] = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 220 | |
| 221 | def add_runtime_target(self, fn, item): |
| 222 | """ |
| 223 | Add a runtime target. |
| 224 | If already present, append the provider fn to the list |
| 225 | """ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 226 | if item in self.run_targets: |
| 227 | if fn in self.run_targets[item]: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 228 | return |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 229 | self.run_targets[item].append(fn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 230 | return |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 231 | self.run_targets[item] = [fn] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 232 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 233 | def mark_external_target(self, target): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 234 | """ |
| 235 | Mark a build target as being externally requested |
| 236 | """ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 237 | if target not in self.external_targets: |
| 238 | self.external_targets.append(target) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 239 | |
| 240 | def get_unresolved_build_targets(self, dataCache): |
| 241 | """ |
| 242 | Return a list of build targets who's providers |
| 243 | are unknown. |
| 244 | """ |
| 245 | unresolved = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 246 | for target in self.build_targets: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 247 | if re_match_strings(target, dataCache.ignored_dependencies): |
| 248 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 249 | if target in self.failed_deps: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 250 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 251 | if not self.build_targets[target]: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 252 | unresolved.append(target) |
| 253 | return unresolved |
| 254 | |
| 255 | def get_unresolved_run_targets(self, dataCache): |
| 256 | """ |
| 257 | Return a list of runtime targets who's providers |
| 258 | are unknown. |
| 259 | """ |
| 260 | unresolved = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 261 | for target in self.run_targets: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 262 | if re_match_strings(target, dataCache.ignored_dependencies): |
| 263 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 264 | if target in self.failed_rdeps: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 265 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 266 | if not self.run_targets[target]: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 267 | unresolved.append(target) |
| 268 | return unresolved |
| 269 | |
| 270 | def get_provider(self, item): |
| 271 | """ |
| 272 | Return a list of providers of item |
| 273 | """ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 274 | return self.build_targets[item] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 275 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 276 | def get_dependees(self, item): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 277 | """ |
| 278 | Return a list of targets which depend on item |
| 279 | """ |
| 280 | dependees = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 281 | for fn in self.depids: |
| 282 | if item in self.depids[fn]: |
| 283 | dependees.append(fn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 284 | return dependees |
| 285 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 286 | def get_rdependees(self, item): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 287 | """ |
| 288 | Return a list of targets which depend on runtime item |
| 289 | """ |
| 290 | dependees = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 291 | for fn in self.rdepids: |
| 292 | if item in self.rdepids[fn]: |
| 293 | dependees.append(fn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 294 | return dependees |
| 295 | |
| 296 | def get_reasons(self, item, runtime=False): |
| 297 | """ |
| 298 | Get the reason(s) for an item not being provided, if any |
| 299 | """ |
| 300 | reasons = [] |
| 301 | if self.skiplist: |
| 302 | for fn in self.skiplist: |
| 303 | skipitem = self.skiplist[fn] |
| 304 | if skipitem.pn == item: |
| 305 | reasons.append("%s was skipped: %s" % (skipitem.pn, skipitem.skipreason)) |
| 306 | elif runtime and item in skipitem.rprovides: |
| 307 | reasons.append("%s RPROVIDES %s but was skipped: %s" % (skipitem.pn, item, skipitem.skipreason)) |
| 308 | elif not runtime and item in skipitem.provides: |
| 309 | reasons.append("%s PROVIDES %s but was skipped: %s" % (skipitem.pn, item, skipitem.skipreason)) |
| 310 | return reasons |
| 311 | |
| 312 | def get_close_matches(self, item, provider_list): |
| 313 | import difflib |
| 314 | if self.skiplist: |
| 315 | skipped = [] |
| 316 | for fn in self.skiplist: |
| 317 | skipped.append(self.skiplist[fn].pn) |
| 318 | full_list = provider_list + skipped |
| 319 | else: |
| 320 | full_list = provider_list |
| 321 | return difflib.get_close_matches(item, full_list, cutoff=0.7) |
| 322 | |
| 323 | def add_provider(self, cfgData, dataCache, item): |
| 324 | try: |
| 325 | self.add_provider_internal(cfgData, dataCache, item) |
| 326 | except bb.providers.NoProvider: |
| 327 | if self.abort: |
| 328 | raise |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 329 | self.remove_buildtarget(item) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 330 | |
| 331 | self.mark_external_target(item) |
| 332 | |
| 333 | def add_provider_internal(self, cfgData, dataCache, item): |
| 334 | """ |
| 335 | Add the providers of item to the task data |
| 336 | Mark entries were specifically added externally as against dependencies |
| 337 | added internally during dependency resolution |
| 338 | """ |
| 339 | |
| 340 | if re_match_strings(item, dataCache.ignored_dependencies): |
| 341 | return |
| 342 | |
| 343 | if not item in dataCache.providers: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 344 | close_matches = self.get_close_matches(item, list(dataCache.providers.keys())) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 345 | # Is it in RuntimeProviders ? |
| 346 | all_p = bb.providers.getRuntimeProviders(dataCache, item) |
| 347 | for fn in all_p: |
| 348 | new = dataCache.pkg_fn[fn] + " RPROVIDES " + item |
| 349 | if new not in close_matches: |
| 350 | close_matches.append(new) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 351 | bb.event.fire(bb.event.NoProvider(item, dependees=self.get_dependees(item), reasons=self.get_reasons(item), close_matches=close_matches), cfgData) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 352 | raise bb.providers.NoProvider(item) |
| 353 | |
| 354 | if self.have_build_target(item): |
| 355 | return |
| 356 | |
| 357 | all_p = dataCache.providers[item] |
| 358 | |
| 359 | eligible, foundUnique = bb.providers.filterProviders(all_p, item, cfgData, dataCache) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 360 | eligible = [p for p in eligible if not p in self.failed_fns] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 361 | |
| 362 | if not eligible: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 363 | bb.event.fire(bb.event.NoProvider(item, dependees=self.get_dependees(item), reasons=["No eligible PROVIDERs exist for '%s'" % item]), cfgData) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 364 | raise bb.providers.NoProvider(item) |
| 365 | |
| 366 | if len(eligible) > 1 and foundUnique == False: |
| 367 | if item not in self.consider_msgs_cache: |
| 368 | providers_list = [] |
| 369 | for fn in eligible: |
| 370 | providers_list.append(dataCache.pkg_fn[fn]) |
| 371 | bb.event.fire(bb.event.MultipleProviders(item, providers_list), cfgData) |
| 372 | self.consider_msgs_cache.append(item) |
| 373 | |
| 374 | for fn in eligible: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 375 | if fn in self.failed_fns: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 376 | continue |
| 377 | logger.debug(2, "adding %s to satisfy %s", fn, item) |
| 378 | self.add_build_target(fn, item) |
| 379 | self.add_tasks(fn, dataCache) |
| 380 | |
| 381 | |
| 382 | #item = dataCache.pkg_fn[fn] |
| 383 | |
| 384 | def add_rprovider(self, cfgData, dataCache, item): |
| 385 | """ |
| 386 | Add the runtime providers of item to the task data |
| 387 | (takes item names from RDEPENDS/PACKAGES namespace) |
| 388 | """ |
| 389 | |
| 390 | if re_match_strings(item, dataCache.ignored_dependencies): |
| 391 | return |
| 392 | |
| 393 | if self.have_runtime_target(item): |
| 394 | return |
| 395 | |
| 396 | all_p = bb.providers.getRuntimeProviders(dataCache, item) |
| 397 | |
| 398 | if not all_p: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 399 | bb.event.fire(bb.event.NoProvider(item, runtime=True, dependees=self.get_rdependees(item), reasons=self.get_reasons(item, True)), cfgData) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 400 | raise bb.providers.NoRProvider(item) |
| 401 | |
| 402 | eligible, numberPreferred = bb.providers.filterProvidersRunTime(all_p, item, cfgData, dataCache) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 403 | eligible = [p for p in eligible if not p in self.failed_fns] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 404 | |
| 405 | if not eligible: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 406 | bb.event.fire(bb.event.NoProvider(item, runtime=True, dependees=self.get_rdependees(item), reasons=["No eligible RPROVIDERs exist for '%s'" % item]), cfgData) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 407 | raise bb.providers.NoRProvider(item) |
| 408 | |
| 409 | if len(eligible) > 1 and numberPreferred == 0: |
| 410 | if item not in self.consider_msgs_cache: |
| 411 | providers_list = [] |
| 412 | for fn in eligible: |
| 413 | providers_list.append(dataCache.pkg_fn[fn]) |
| 414 | bb.event.fire(bb.event.MultipleProviders(item, providers_list, runtime=True), cfgData) |
| 415 | self.consider_msgs_cache.append(item) |
| 416 | |
| 417 | if numberPreferred > 1: |
| 418 | if item not in self.consider_msgs_cache: |
| 419 | providers_list = [] |
| 420 | for fn in eligible: |
| 421 | providers_list.append(dataCache.pkg_fn[fn]) |
| 422 | bb.event.fire(bb.event.MultipleProviders(item, providers_list, runtime=True), cfgData) |
| 423 | self.consider_msgs_cache.append(item) |
| 424 | raise bb.providers.MultipleRProvider(item) |
| 425 | |
| 426 | # run through the list until we find one that we can build |
| 427 | for fn in eligible: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 428 | if fn in self.failed_fns: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 429 | continue |
| 430 | logger.debug(2, "adding '%s' to satisfy runtime '%s'", fn, item) |
| 431 | self.add_runtime_target(fn, item) |
| 432 | self.add_tasks(fn, dataCache) |
| 433 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 434 | def fail_fn(self, fn, missing_list=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 435 | """ |
| 436 | Mark a file as failed (unbuildable) |
| 437 | Remove any references from build and runtime provider lists |
| 438 | |
| 439 | missing_list, A list of missing requirements for this target |
| 440 | """ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 441 | if fn in self.failed_fns: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 442 | return |
| 443 | if not missing_list: |
| 444 | missing_list = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 445 | logger.debug(1, "File '%s' is unbuildable, removing...", fn) |
| 446 | self.failed_fns.append(fn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 447 | for target in self.build_targets: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 448 | if fn in self.build_targets[target]: |
| 449 | self.build_targets[target].remove(fn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 450 | if len(self.build_targets[target]) == 0: |
| 451 | self.remove_buildtarget(target, missing_list) |
| 452 | for target in self.run_targets: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 453 | if fn in self.run_targets[target]: |
| 454 | self.run_targets[target].remove(fn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 455 | if len(self.run_targets[target]) == 0: |
| 456 | self.remove_runtarget(target, missing_list) |
| 457 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 458 | def remove_buildtarget(self, target, missing_list=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 459 | """ |
| 460 | Mark a build target as failed (unbuildable) |
| 461 | Trigger removal of any files that have this as a dependency |
| 462 | """ |
| 463 | if not missing_list: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 464 | missing_list = [target] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 465 | else: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 466 | missing_list = [target] + missing_list |
| 467 | logger.verbose("Target '%s' is unbuildable, removing...\nMissing or unbuildable dependency chain was: %s", target, missing_list) |
| 468 | self.failed_deps.append(target) |
| 469 | dependees = self.get_dependees(target) |
| 470 | for fn in dependees: |
| 471 | self.fail_fn(fn, missing_list) |
| 472 | for tid in self.taskentries: |
| 473 | for (idepend, idependtask) in self.taskentries[tid].idepends: |
| 474 | if idepend == target: |
| 475 | fn = tid.rsplit(":",1)[0] |
| 476 | self.fail_fn(fn, missing_list) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 477 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 478 | if self.abort and target in self.external_targets: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 479 | logger.error("Required build target '%s' has no buildable providers.\nMissing or unbuildable dependency chain was: %s", target, missing_list) |
| 480 | raise bb.providers.NoProvider(target) |
| 481 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 482 | def remove_runtarget(self, target, missing_list=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 483 | """ |
| 484 | Mark a run target as failed (unbuildable) |
| 485 | Trigger removal of any files that have this as a dependency |
| 486 | """ |
| 487 | if not missing_list: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 488 | missing_list = [target] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 489 | else: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 490 | missing_list = [target] + missing_list |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 491 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 492 | logger.info("Runtime target '%s' is unbuildable, removing...\nMissing or unbuildable dependency chain was: %s", target, missing_list) |
| 493 | self.failed_rdeps.append(target) |
| 494 | dependees = self.get_rdependees(target) |
| 495 | for fn in dependees: |
| 496 | self.fail_fn(fn, missing_list) |
| 497 | for tid in self.taskentries: |
| 498 | for (idepend, idependtask) in self.taskentries[tid].irdepends: |
| 499 | if idepend == target: |
| 500 | fn = tid.rsplit(":",1)[0] |
| 501 | self.fail_fn(fn, missing_list) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 502 | |
| 503 | def add_unresolved(self, cfgData, dataCache): |
| 504 | """ |
| 505 | Resolve all unresolved build and runtime targets |
| 506 | """ |
| 507 | logger.info("Resolving any missing task queue dependencies") |
| 508 | while True: |
| 509 | added = 0 |
| 510 | for target in self.get_unresolved_build_targets(dataCache): |
| 511 | try: |
| 512 | self.add_provider_internal(cfgData, dataCache, target) |
| 513 | added = added + 1 |
| 514 | except bb.providers.NoProvider: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 515 | if self.abort and target in self.external_targets and not self.allowincomplete: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 516 | raise |
| 517 | if not self.allowincomplete: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 518 | self.remove_buildtarget(target) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 519 | for target in self.get_unresolved_run_targets(dataCache): |
| 520 | try: |
| 521 | self.add_rprovider(cfgData, dataCache, target) |
| 522 | added = added + 1 |
| 523 | except (bb.providers.NoRProvider, bb.providers.MultipleRProvider): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 524 | self.remove_runtarget(target) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 525 | logger.debug(1, "Resolved " + str(added) + " extra dependencies") |
| 526 | if added == 0: |
| 527 | break |
| 528 | # self.dump_data() |
| 529 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 530 | def get_providermap(self, prefix=None): |
| 531 | provmap = {} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 532 | for name in self.build_targets: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 533 | if prefix and not name.startswith(prefix): |
| 534 | continue |
| 535 | if self.have_build_target(name): |
| 536 | provider = self.get_provider(name) |
| 537 | if provider: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 538 | provmap[name] = provider[0] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 539 | return provmap |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 540 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 541 | def get_mcdepends(self): |
| 542 | return self.mcdepends |
| 543 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 544 | def dump_data(self): |
| 545 | """ |
| 546 | Dump some debug information on the internal data structures |
| 547 | """ |
| 548 | logger.debug(3, "build_names:") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 549 | logger.debug(3, ", ".join(self.build_targets)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 550 | |
| 551 | logger.debug(3, "run_names:") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 552 | logger.debug(3, ", ".join(self.run_targets)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 553 | |
| 554 | logger.debug(3, "build_targets:") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 555 | for target in self.build_targets: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 556 | targets = "None" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 557 | if target in self.build_targets: |
| 558 | targets = self.build_targets[target] |
| 559 | logger.debug(3, " %s: %s", target, targets) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 560 | |
| 561 | logger.debug(3, "run_targets:") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 562 | for target in self.run_targets: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 563 | targets = "None" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 564 | if target in self.run_targets: |
| 565 | targets = self.run_targets[target] |
| 566 | logger.debug(3, " %s: %s", target, targets) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 567 | |
| 568 | logger.debug(3, "tasks:") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 569 | for tid in self.taskentries: |
| 570 | logger.debug(3, " %s: %s %s %s", |
| 571 | tid, |
| 572 | self.taskentries[tid].idepends, |
| 573 | self.taskentries[tid].irdepends, |
| 574 | self.taskentries[tid].tdepends) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 575 | |
| 576 | logger.debug(3, "dependency ids (per fn):") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 577 | for fn in self.depids: |
| 578 | logger.debug(3, " %s: %s", fn, self.depids[fn]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 579 | |
| 580 | logger.debug(3, "runtime dependency ids (per fn):") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 581 | for fn in self.rdepids: |
| 582 | logger.debug(3, " %s: %s", fn, self.rdepids[fn]) |