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