| 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 'RunQueue' implementation | 
|  | 6 |  | 
|  | 7 | Handles preparation and execution of a queue of tasks | 
|  | 8 | """ | 
|  | 9 |  | 
|  | 10 | # Copyright (C) 2006-2007  Richard Purdie | 
|  | 11 | # | 
|  | 12 | # This program is free software; you can redistribute it and/or modify | 
|  | 13 | # it under the terms of the GNU General Public License version 2 as | 
|  | 14 | # published by the Free Software Foundation. | 
|  | 15 | # | 
|  | 16 | # This program is distributed in the hope that it will be useful, | 
|  | 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 19 | # GNU General Public License for more details. | 
|  | 20 | # | 
|  | 21 | # You should have received a copy of the GNU General Public License along | 
|  | 22 | # with this program; if not, write to the Free Software Foundation, Inc., | 
|  | 23 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 
|  | 24 |  | 
|  | 25 | import copy | 
|  | 26 | import os | 
|  | 27 | import sys | 
|  | 28 | import signal | 
|  | 29 | import stat | 
|  | 30 | import fcntl | 
|  | 31 | import errno | 
|  | 32 | import logging | 
|  | 33 | import re | 
|  | 34 | import bb | 
|  | 35 | from bb import msg, data, event | 
|  | 36 | from bb import monitordisk | 
|  | 37 | import subprocess | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 38 | import pickle | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 39 | from multiprocessing import Process | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 |  | 
|  | 41 | bblogger = logging.getLogger("BitBake") | 
|  | 42 | logger = logging.getLogger("BitBake.RunQueue") | 
|  | 43 |  | 
|  | 44 | __find_md5__ = re.compile( r'(?i)(?<![a-z0-9])[a-f0-9]{32}(?![a-z0-9])' ) | 
|  | 45 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 46 | def fn_from_tid(tid): | 
|  | 47 | return tid.rsplit(":", 1)[0] | 
|  | 48 |  | 
|  | 49 | def taskname_from_tid(tid): | 
|  | 50 | return tid.rsplit(":", 1)[1] | 
|  | 51 |  | 
|  | 52 | def split_tid(tid): | 
|  | 53 | (mc, fn, taskname, _) = split_tid_mcfn(tid) | 
|  | 54 | return (mc, fn, taskname) | 
|  | 55 |  | 
|  | 56 | def split_tid_mcfn(tid): | 
|  | 57 | if tid.startswith('multiconfig:'): | 
|  | 58 | elems = tid.split(':') | 
|  | 59 | mc = elems[1] | 
|  | 60 | fn = ":".join(elems[2:-1]) | 
|  | 61 | taskname = elems[-1] | 
|  | 62 | mcfn = "multiconfig:" + mc + ":" + fn | 
|  | 63 | else: | 
|  | 64 | tid = tid.rsplit(":", 1) | 
|  | 65 | mc = "" | 
|  | 66 | fn = tid[0] | 
|  | 67 | taskname = tid[1] | 
|  | 68 | mcfn = fn | 
|  | 69 |  | 
|  | 70 | return (mc, fn, taskname, mcfn) | 
|  | 71 |  | 
|  | 72 | def build_tid(mc, fn, taskname): | 
|  | 73 | if mc: | 
|  | 74 | return "multiconfig:" + mc + ":" + fn + ":" + taskname | 
|  | 75 | return fn + ":" + taskname | 
|  | 76 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 77 | class RunQueueStats: | 
|  | 78 | """ | 
|  | 79 | Holds statistics on the tasks handled by the associated runQueue | 
|  | 80 | """ | 
|  | 81 | def __init__(self, total): | 
|  | 82 | self.completed = 0 | 
|  | 83 | self.skipped = 0 | 
|  | 84 | self.failed = 0 | 
|  | 85 | self.active = 0 | 
|  | 86 | self.total = total | 
|  | 87 |  | 
|  | 88 | def copy(self): | 
|  | 89 | obj = self.__class__(self.total) | 
|  | 90 | obj.__dict__.update(self.__dict__) | 
|  | 91 | return obj | 
|  | 92 |  | 
|  | 93 | def taskFailed(self): | 
|  | 94 | self.active = self.active - 1 | 
|  | 95 | self.failed = self.failed + 1 | 
|  | 96 |  | 
|  | 97 | def taskCompleted(self, number = 1): | 
|  | 98 | self.active = self.active - number | 
|  | 99 | self.completed = self.completed + number | 
|  | 100 |  | 
|  | 101 | def taskSkipped(self, number = 1): | 
|  | 102 | self.active = self.active + number | 
|  | 103 | self.skipped = self.skipped + number | 
|  | 104 |  | 
|  | 105 | def taskActive(self): | 
|  | 106 | self.active = self.active + 1 | 
|  | 107 |  | 
|  | 108 | # These values indicate the next step due to be run in the | 
|  | 109 | # runQueue state machine | 
|  | 110 | runQueuePrepare = 2 | 
|  | 111 | runQueueSceneInit = 3 | 
|  | 112 | runQueueSceneRun = 4 | 
|  | 113 | runQueueRunInit = 5 | 
|  | 114 | runQueueRunning = 6 | 
|  | 115 | runQueueFailed = 7 | 
|  | 116 | runQueueCleanUp = 8 | 
|  | 117 | runQueueComplete = 9 | 
|  | 118 |  | 
|  | 119 | class RunQueueScheduler(object): | 
|  | 120 | """ | 
|  | 121 | Control the order tasks are scheduled in. | 
|  | 122 | """ | 
|  | 123 | name = "basic" | 
|  | 124 |  | 
|  | 125 | def __init__(self, runqueue, rqdata): | 
|  | 126 | """ | 
|  | 127 | The default scheduler just returns the first buildable task (the | 
|  | 128 | priority map is sorted by task number) | 
|  | 129 | """ | 
|  | 130 | self.rq = runqueue | 
|  | 131 | self.rqdata = rqdata | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 132 | self.numTasks = len(self.rqdata.runtaskentries) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 133 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 134 | self.prio_map = [self.rqdata.runtaskentries.keys()] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 135 |  | 
|  | 136 | self.buildable = [] | 
|  | 137 | self.stamps = {} | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 138 | for tid in self.rqdata.runtaskentries: | 
|  | 139 | (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) | 
|  | 140 | self.stamps[tid] = bb.build.stampfile(taskname, self.rqdata.dataCaches[mc], taskfn, noextra=True) | 
|  | 141 | if tid in self.rq.runq_buildable: | 
|  | 142 | self.buildable.append(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 143 |  | 
|  | 144 | self.rev_prio_map = None | 
|  | 145 |  | 
|  | 146 | def next_buildable_task(self): | 
|  | 147 | """ | 
|  | 148 | Return the id of the first task we find that is buildable | 
|  | 149 | """ | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 150 | self.buildable = [x for x in self.buildable if x not in self.rq.runq_running] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 151 | if not self.buildable: | 
|  | 152 | return None | 
|  | 153 | if len(self.buildable) == 1: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 154 | tid = self.buildable[0] | 
|  | 155 | stamp = self.stamps[tid] | 
|  | 156 | if stamp not in self.rq.build_stamps.values(): | 
|  | 157 | return tid | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 158 |  | 
|  | 159 | if not self.rev_prio_map: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 160 | self.rev_prio_map = {} | 
|  | 161 | for tid in self.rqdata.runtaskentries: | 
|  | 162 | self.rev_prio_map[tid] = self.prio_map.index(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 163 |  | 
|  | 164 | best = None | 
|  | 165 | bestprio = None | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 166 | for tid in self.buildable: | 
|  | 167 | prio = self.rev_prio_map[tid] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 168 | if bestprio is None or bestprio > prio: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 169 | stamp = self.stamps[tid] | 
|  | 170 | if stamp in self.rq.build_stamps.values(): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 171 | continue | 
|  | 172 | bestprio = prio | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 173 | best = tid | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 174 |  | 
|  | 175 | return best | 
|  | 176 |  | 
|  | 177 | def next(self): | 
|  | 178 | """ | 
|  | 179 | Return the id of the task we should build next | 
|  | 180 | """ | 
|  | 181 | if self.rq.stats.active < self.rq.number_tasks: | 
|  | 182 | return self.next_buildable_task() | 
|  | 183 |  | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 184 | def newbuildable(self, task): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 185 | self.buildable.append(task) | 
|  | 186 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 187 | def describe_task(self, taskid): | 
|  | 188 | result = 'ID %s' % taskid | 
|  | 189 | if self.rev_prio_map: | 
|  | 190 | result = result + (' pri %d' % self.rev_prio_map[taskid]) | 
|  | 191 | return result | 
|  | 192 |  | 
|  | 193 | def dump_prio(self, comment): | 
|  | 194 | bb.debug(3, '%s (most important first):\n%s' % | 
|  | 195 | (comment, | 
|  | 196 | '\n'.join(['%d. %s' % (index + 1, self.describe_task(taskid)) for | 
|  | 197 | index, taskid in enumerate(self.prio_map)]))) | 
|  | 198 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 199 | class RunQueueSchedulerSpeed(RunQueueScheduler): | 
|  | 200 | """ | 
|  | 201 | A scheduler optimised for speed. The priority map is sorted by task weight, | 
|  | 202 | heavier weighted tasks (tasks needed by the most other tasks) are run first. | 
|  | 203 | """ | 
|  | 204 | name = "speed" | 
|  | 205 |  | 
|  | 206 | def __init__(self, runqueue, rqdata): | 
|  | 207 | """ | 
|  | 208 | The priority map is sorted by task weight. | 
|  | 209 | """ | 
|  | 210 | RunQueueScheduler.__init__(self, runqueue, rqdata) | 
|  | 211 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 212 | weights = {} | 
|  | 213 | for tid in self.rqdata.runtaskentries: | 
|  | 214 | weight = self.rqdata.runtaskentries[tid].weight | 
|  | 215 | if not weight in weights: | 
|  | 216 | weights[weight] = [] | 
|  | 217 | weights[weight].append(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 218 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 219 | self.prio_map = [] | 
|  | 220 | for weight in sorted(weights): | 
|  | 221 | for w in weights[weight]: | 
|  | 222 | self.prio_map.append(w) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 223 |  | 
|  | 224 | self.prio_map.reverse() | 
|  | 225 |  | 
|  | 226 | class RunQueueSchedulerCompletion(RunQueueSchedulerSpeed): | 
|  | 227 | """ | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 228 | A scheduler optimised to complete .bb files as quickly as possible. The | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 229 | priority map is sorted by task weight, but then reordered so once a given | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 230 | .bb file starts to build, it's completed as quickly as possible by | 
|  | 231 | running all tasks related to the same .bb file one after the after. | 
|  | 232 | This works well where disk space is at a premium and classes like OE's | 
|  | 233 | rm_work are in force. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 234 | """ | 
|  | 235 | name = "completion" | 
|  | 236 |  | 
|  | 237 | def __init__(self, runqueue, rqdata): | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 238 | super(RunQueueSchedulerCompletion, self).__init__(runqueue, rqdata) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 239 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 240 | # Extract list of tasks for each recipe, with tasks sorted | 
|  | 241 | # ascending from "must run first" (typically do_fetch) to | 
|  | 242 | # "runs last" (do_build). The speed scheduler prioritizes | 
|  | 243 | # tasks that must run first before the ones that run later; | 
|  | 244 | # this is what we depend on here. | 
|  | 245 | task_lists = {} | 
|  | 246 | for taskid in self.prio_map: | 
|  | 247 | fn, taskname = taskid.rsplit(':', 1) | 
|  | 248 | task_lists.setdefault(fn, []).append(taskname) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 249 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 250 | # Now unify the different task lists. The strategy is that | 
|  | 251 | # common tasks get skipped and new ones get inserted after the | 
|  | 252 | # preceeding common one(s) as they are found. Because task | 
|  | 253 | # lists should differ only by their number of tasks, but not | 
|  | 254 | # the ordering of the common tasks, this should result in a | 
|  | 255 | # deterministic result that is a superset of the individual | 
|  | 256 | # task ordering. | 
|  | 257 | all_tasks = [] | 
|  | 258 | for recipe, new_tasks in task_lists.items(): | 
|  | 259 | index = 0 | 
|  | 260 | old_task = all_tasks[index] if index < len(all_tasks) else None | 
|  | 261 | for new_task in new_tasks: | 
|  | 262 | if old_task == new_task: | 
|  | 263 | # Common task, skip it. This is the fast-path which | 
|  | 264 | # avoids a full search. | 
|  | 265 | index += 1 | 
|  | 266 | old_task = all_tasks[index] if index < len(all_tasks) else None | 
|  | 267 | else: | 
|  | 268 | try: | 
|  | 269 | index = all_tasks.index(new_task) | 
|  | 270 | # Already present, just not at the current | 
|  | 271 | # place. We re-synchronized by changing the | 
|  | 272 | # index so that it matches again. Now | 
|  | 273 | # move on to the next existing task. | 
|  | 274 | index += 1 | 
|  | 275 | old_task = all_tasks[index] if index < len(all_tasks) else None | 
|  | 276 | except ValueError: | 
|  | 277 | # Not present. Insert before old_task, which | 
|  | 278 | # remains the same (but gets shifted back). | 
|  | 279 | all_tasks.insert(index, new_task) | 
|  | 280 | index += 1 | 
|  | 281 | bb.debug(3, 'merged task list: %s'  % all_tasks) | 
|  | 282 |  | 
|  | 283 | # Now reverse the order so that tasks that finish the work on one | 
|  | 284 | # recipe are considered more imporant (= come first). The ordering | 
|  | 285 | # is now so that do_build is most important. | 
|  | 286 | all_tasks.reverse() | 
|  | 287 |  | 
|  | 288 | # Group tasks of the same kind before tasks of less important | 
|  | 289 | # kinds at the head of the queue (because earlier = lower | 
|  | 290 | # priority number = runs earlier), while preserving the | 
|  | 291 | # ordering by recipe. If recipe foo is more important than | 
|  | 292 | # bar, then the goal is to work on foo's do_populate_sysroot | 
|  | 293 | # before bar's do_populate_sysroot and on the more important | 
|  | 294 | # tasks of foo before any of the less important tasks in any | 
|  | 295 | # other recipe (if those other recipes are more important than | 
|  | 296 | # foo). | 
|  | 297 | # | 
|  | 298 | # All of this only applies when tasks are runable. Explicit | 
|  | 299 | # dependencies still override this ordering by priority. | 
|  | 300 | # | 
|  | 301 | # Here's an example why this priority re-ordering helps with | 
|  | 302 | # minimizing disk usage. Consider a recipe foo with a higher | 
|  | 303 | # priority than bar where foo DEPENDS on bar. Then the | 
|  | 304 | # implicit rule (from base.bbclass) is that foo's do_configure | 
|  | 305 | # depends on bar's do_populate_sysroot. This ensures that | 
|  | 306 | # bar's do_populate_sysroot gets done first. Normally the | 
|  | 307 | # tasks from foo would continue to run once that is done, and | 
|  | 308 | # bar only gets completed and cleaned up later. By ordering | 
|  | 309 | # bar's task that depend on bar's do_populate_sysroot before foo's | 
|  | 310 | # do_configure, that problem gets avoided. | 
|  | 311 | task_index = 0 | 
|  | 312 | self.dump_prio('original priorities') | 
|  | 313 | for task in all_tasks: | 
|  | 314 | for index in range(task_index, self.numTasks): | 
|  | 315 | taskid = self.prio_map[index] | 
|  | 316 | taskname = taskid.rsplit(':', 1)[1] | 
|  | 317 | if taskname == task: | 
|  | 318 | del self.prio_map[index] | 
|  | 319 | self.prio_map.insert(task_index, taskid) | 
|  | 320 | task_index += 1 | 
|  | 321 | self.dump_prio('completion priorities') | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 322 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 323 | class RunTaskEntry(object): | 
|  | 324 | def __init__(self): | 
|  | 325 | self.depends = set() | 
|  | 326 | self.revdeps = set() | 
|  | 327 | self.hash = None | 
|  | 328 | self.task = None | 
|  | 329 | self.weight = 1 | 
|  | 330 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 331 | class RunQueueData: | 
|  | 332 | """ | 
|  | 333 | BitBake Run Queue implementation | 
|  | 334 | """ | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 335 | def __init__(self, rq, cooker, cfgData, dataCaches, taskData, targets): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 336 | self.cooker = cooker | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 337 | self.dataCaches = dataCaches | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 338 | self.taskData = taskData | 
|  | 339 | self.targets = targets | 
|  | 340 | self.rq = rq | 
|  | 341 | self.warn_multi_bb = False | 
|  | 342 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 343 | self.stampwhitelist = cfgData.getVar("BB_STAMP_WHITELIST") or "" | 
|  | 344 | self.multi_provider_whitelist = (cfgData.getVar("MULTI_PROVIDER_WHITELIST") or "").split() | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 345 | self.setscenewhitelist = get_setscene_enforce_whitelist(cfgData) | 
|  | 346 | self.setscenewhitelist_checked = False | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 347 | self.setscene_enforce = (cfgData.getVar('BB_SETSCENE_ENFORCE') == "1") | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 348 | self.init_progress_reporter = bb.progress.DummyMultiStageProcessProgressReporter() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 349 |  | 
|  | 350 | self.reset() | 
|  | 351 |  | 
|  | 352 | def reset(self): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 353 | self.runtaskentries = {} | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 354 |  | 
|  | 355 | def runq_depends_names(self, ids): | 
|  | 356 | import re | 
|  | 357 | ret = [] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 358 | for id in ids: | 
|  | 359 | nam = os.path.basename(id) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 360 | nam = re.sub("_[^,]*,", ",", nam) | 
|  | 361 | ret.extend([nam]) | 
|  | 362 | return ret | 
|  | 363 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 364 | def get_task_hash(self, tid): | 
|  | 365 | return self.runtaskentries[tid].hash | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 366 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 367 | def get_user_idstring(self, tid, task_name_suffix = ""): | 
|  | 368 | return tid + task_name_suffix | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 369 |  | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 370 | def get_short_user_idstring(self, task, task_name_suffix = ""): | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 371 | (mc, fn, taskname, taskfn) = split_tid_mcfn(task) | 
|  | 372 | pn = self.dataCaches[mc].pkg_fn[taskfn] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 373 | taskname = taskname_from_tid(task) + task_name_suffix | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 374 | return "%s:%s" % (pn, taskname) | 
|  | 375 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 376 | def circular_depchains_handler(self, tasks): | 
|  | 377 | """ | 
|  | 378 | Some tasks aren't buildable, likely due to circular dependency issues. | 
|  | 379 | Identify the circular dependencies and print them in a user readable format. | 
|  | 380 | """ | 
|  | 381 | from copy import deepcopy | 
|  | 382 |  | 
|  | 383 | valid_chains = [] | 
|  | 384 | explored_deps = {} | 
|  | 385 | msgs = [] | 
|  | 386 |  | 
|  | 387 | def chain_reorder(chain): | 
|  | 388 | """ | 
|  | 389 | Reorder a dependency chain so the lowest task id is first | 
|  | 390 | """ | 
|  | 391 | lowest = 0 | 
|  | 392 | new_chain = [] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 393 | for entry in range(len(chain)): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 394 | if chain[entry] < chain[lowest]: | 
|  | 395 | lowest = entry | 
|  | 396 | new_chain.extend(chain[lowest:]) | 
|  | 397 | new_chain.extend(chain[:lowest]) | 
|  | 398 | return new_chain | 
|  | 399 |  | 
|  | 400 | def chain_compare_equal(chain1, chain2): | 
|  | 401 | """ | 
|  | 402 | Compare two dependency chains and see if they're the same | 
|  | 403 | """ | 
|  | 404 | if len(chain1) != len(chain2): | 
|  | 405 | return False | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 406 | for index in range(len(chain1)): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 407 | if chain1[index] != chain2[index]: | 
|  | 408 | return False | 
|  | 409 | return True | 
|  | 410 |  | 
|  | 411 | def chain_array_contains(chain, chain_array): | 
|  | 412 | """ | 
|  | 413 | Return True if chain_array contains chain | 
|  | 414 | """ | 
|  | 415 | for ch in chain_array: | 
|  | 416 | if chain_compare_equal(ch, chain): | 
|  | 417 | return True | 
|  | 418 | return False | 
|  | 419 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 420 | def find_chains(tid, prev_chain): | 
|  | 421 | prev_chain.append(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 422 | total_deps = [] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 423 | total_deps.extend(self.runtaskentries[tid].revdeps) | 
|  | 424 | for revdep in self.runtaskentries[tid].revdeps: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 425 | if revdep in prev_chain: | 
|  | 426 | idx = prev_chain.index(revdep) | 
|  | 427 | # To prevent duplicates, reorder the chain to start with the lowest taskid | 
|  | 428 | # and search through an array of those we've already printed | 
|  | 429 | chain = prev_chain[idx:] | 
|  | 430 | new_chain = chain_reorder(chain) | 
|  | 431 | if not chain_array_contains(new_chain, valid_chains): | 
|  | 432 | valid_chains.append(new_chain) | 
|  | 433 | msgs.append("Dependency loop #%d found:\n" % len(valid_chains)) | 
|  | 434 | for dep in new_chain: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 435 | msgs.append("  Task %s (dependent Tasks %s)\n" % (dep, self.runq_depends_names(self.runtaskentries[dep].depends))) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 436 | msgs.append("\n") | 
|  | 437 | if len(valid_chains) > 10: | 
|  | 438 | msgs.append("Aborted dependency loops search after 10 matches.\n") | 
|  | 439 | return msgs | 
|  | 440 | continue | 
|  | 441 | scan = False | 
|  | 442 | if revdep not in explored_deps: | 
|  | 443 | scan = True | 
|  | 444 | elif revdep in explored_deps[revdep]: | 
|  | 445 | scan = True | 
|  | 446 | else: | 
|  | 447 | for dep in prev_chain: | 
|  | 448 | if dep in explored_deps[revdep]: | 
|  | 449 | scan = True | 
|  | 450 | if scan: | 
|  | 451 | find_chains(revdep, copy.deepcopy(prev_chain)) | 
|  | 452 | for dep in explored_deps[revdep]: | 
|  | 453 | if dep not in total_deps: | 
|  | 454 | total_deps.append(dep) | 
|  | 455 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 456 | explored_deps[tid] = total_deps | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 457 |  | 
|  | 458 | for task in tasks: | 
|  | 459 | find_chains(task, []) | 
|  | 460 |  | 
|  | 461 | return msgs | 
|  | 462 |  | 
|  | 463 | def calculate_task_weights(self, endpoints): | 
|  | 464 | """ | 
|  | 465 | Calculate a number representing the "weight" of each task. Heavier weighted tasks | 
|  | 466 | have more dependencies and hence should be executed sooner for maximum speed. | 
|  | 467 |  | 
|  | 468 | This function also sanity checks the task list finding tasks that are not | 
|  | 469 | possible to execute due to circular dependencies. | 
|  | 470 | """ | 
|  | 471 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 472 | numTasks = len(self.runtaskentries) | 
|  | 473 | weight = {} | 
|  | 474 | deps_left = {} | 
|  | 475 | task_done = {} | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 476 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 477 | for tid in self.runtaskentries: | 
|  | 478 | task_done[tid] = False | 
|  | 479 | weight[tid] = 1 | 
|  | 480 | deps_left[tid] = len(self.runtaskentries[tid].revdeps) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 481 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 482 | for tid in endpoints: | 
|  | 483 | weight[tid] = 10 | 
|  | 484 | task_done[tid] = True | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 485 |  | 
|  | 486 | while True: | 
|  | 487 | next_points = [] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 488 | for tid in endpoints: | 
|  | 489 | for revdep in self.runtaskentries[tid].depends: | 
|  | 490 | weight[revdep] = weight[revdep] + weight[tid] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 491 | deps_left[revdep] = deps_left[revdep] - 1 | 
|  | 492 | if deps_left[revdep] == 0: | 
|  | 493 | next_points.append(revdep) | 
|  | 494 | task_done[revdep] = True | 
|  | 495 | endpoints = next_points | 
|  | 496 | if len(next_points) == 0: | 
|  | 497 | break | 
|  | 498 |  | 
|  | 499 | # Circular dependency sanity check | 
|  | 500 | problem_tasks = [] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 501 | for tid in self.runtaskentries: | 
|  | 502 | if task_done[tid] is False or deps_left[tid] != 0: | 
|  | 503 | problem_tasks.append(tid) | 
|  | 504 | logger.debug(2, "Task %s is not buildable", tid) | 
|  | 505 | logger.debug(2, "(Complete marker was %s and the remaining dependency count was %s)\n", task_done[tid], deps_left[tid]) | 
|  | 506 | self.runtaskentries[tid].weight = weight[tid] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 507 |  | 
|  | 508 | if problem_tasks: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 509 | message = "%s unbuildable tasks were found.\n" % len(problem_tasks) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 510 | message = message + "These are usually caused by circular dependencies and any circular dependency chains found will be printed below. Increase the debug level to see a list of unbuildable tasks.\n\n" | 
|  | 511 | message = message + "Identifying dependency loops (this may take a short while)...\n" | 
|  | 512 | logger.error(message) | 
|  | 513 |  | 
|  | 514 | msgs = self.circular_depchains_handler(problem_tasks) | 
|  | 515 |  | 
|  | 516 | message = "\n" | 
|  | 517 | for msg in msgs: | 
|  | 518 | message = message + msg | 
|  | 519 | bb.msg.fatal("RunQueue", message) | 
|  | 520 |  | 
|  | 521 | return weight | 
|  | 522 |  | 
|  | 523 | def prepare(self): | 
|  | 524 | """ | 
|  | 525 | Turn a set of taskData into a RunQueue and compute data needed | 
|  | 526 | to optimise the execution order. | 
|  | 527 | """ | 
|  | 528 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 529 | runq_build = {} | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 530 | recursivetasks = {} | 
|  | 531 | recursiveitasks = {} | 
|  | 532 | recursivetasksselfref = set() | 
|  | 533 |  | 
|  | 534 | taskData = self.taskData | 
|  | 535 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 536 | found = False | 
|  | 537 | for mc in self.taskData: | 
|  | 538 | if len(taskData[mc].taskentries) > 0: | 
|  | 539 | found = True | 
|  | 540 | break | 
|  | 541 | if not found: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 542 | # Nothing to do | 
|  | 543 | return 0 | 
|  | 544 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 545 | self.init_progress_reporter.start() | 
|  | 546 | self.init_progress_reporter.next_stage() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 547 |  | 
|  | 548 | # Step A - Work out a list of tasks to run | 
|  | 549 | # | 
|  | 550 | # Taskdata gives us a list of possible providers for every build and run | 
|  | 551 | # target ordered by priority. It also gives information on each of those | 
|  | 552 | # providers. | 
|  | 553 | # | 
|  | 554 | # To create the actual list of tasks to execute we fix the list of | 
|  | 555 | # providers and then resolve the dependencies into task IDs. This | 
|  | 556 | # process is repeated for each type of dependency (tdepends, deptask, | 
|  | 557 | # rdeptast, recrdeptask, idepends). | 
|  | 558 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 559 | def add_build_dependencies(depids, tasknames, depends, mc): | 
|  | 560 | for depname in depids: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 561 | # Won't be in build_targets if ASSUME_PROVIDED | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 562 | if depname not in taskData[mc].build_targets or not taskData[mc].build_targets[depname]: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 563 | continue | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 564 | depdata = taskData[mc].build_targets[depname][0] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 565 | if depdata is None: | 
|  | 566 | continue | 
|  | 567 | for taskname in tasknames: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 568 | t = depdata + ":" + taskname | 
|  | 569 | if t in taskData[mc].taskentries: | 
|  | 570 | depends.add(t) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 571 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 572 | def add_runtime_dependencies(depids, tasknames, depends, mc): | 
|  | 573 | for depname in depids: | 
|  | 574 | if depname not in taskData[mc].run_targets or not taskData[mc].run_targets[depname]: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 575 | continue | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 576 | depdata = taskData[mc].run_targets[depname][0] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 577 | if depdata is None: | 
|  | 578 | continue | 
|  | 579 | for taskname in tasknames: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 580 | t = depdata + ":" + taskname | 
|  | 581 | if t in taskData[mc].taskentries: | 
|  | 582 | depends.add(t) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 583 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 584 | for mc in taskData: | 
|  | 585 | for tid in taskData[mc].taskentries: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 586 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 587 | (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) | 
|  | 588 | #runtid = build_tid(mc, fn, taskname) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 589 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 590 | #logger.debug(2, "Processing %s,%s:%s", mc, fn, taskname) | 
|  | 591 |  | 
|  | 592 | depends = set() | 
|  | 593 | task_deps = self.dataCaches[mc].task_deps[taskfn] | 
|  | 594 |  | 
|  | 595 | self.runtaskentries[tid] = RunTaskEntry() | 
|  | 596 |  | 
|  | 597 | if fn in taskData[mc].failed_fns: | 
|  | 598 | continue | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 599 |  | 
|  | 600 | # Resolve task internal dependencies | 
|  | 601 | # | 
|  | 602 | # e.g. addtask before X after Y | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 603 | for t in taskData[mc].taskentries[tid].tdepends: | 
|  | 604 | (_, depfn, deptaskname, _) = split_tid_mcfn(t) | 
|  | 605 | depends.add(build_tid(mc, depfn, deptaskname)) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 606 |  | 
|  | 607 | # Resolve 'deptask' dependencies | 
|  | 608 | # | 
|  | 609 | # e.g. do_sometask[deptask] = "do_someothertask" | 
|  | 610 | # (makes sure sometask runs after someothertask of all DEPENDS) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 611 | if 'deptask' in task_deps and taskname in task_deps['deptask']: | 
|  | 612 | tasknames = task_deps['deptask'][taskname].split() | 
|  | 613 | add_build_dependencies(taskData[mc].depids[taskfn], tasknames, depends, mc) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 614 |  | 
|  | 615 | # Resolve 'rdeptask' dependencies | 
|  | 616 | # | 
|  | 617 | # e.g. do_sometask[rdeptask] = "do_someothertask" | 
|  | 618 | # (makes sure sometask runs after someothertask of all RDEPENDS) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 619 | if 'rdeptask' in task_deps and taskname in task_deps['rdeptask']: | 
|  | 620 | tasknames = task_deps['rdeptask'][taskname].split() | 
|  | 621 | add_runtime_dependencies(taskData[mc].rdepids[taskfn], tasknames, depends, mc) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 622 |  | 
|  | 623 | # Resolve inter-task dependencies | 
|  | 624 | # | 
|  | 625 | # e.g. do_sometask[depends] = "targetname:do_someothertask" | 
|  | 626 | # (makes sure sometask runs after targetname's someothertask) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 627 | idepends = taskData[mc].taskentries[tid].idepends | 
|  | 628 | for (depname, idependtask) in idepends: | 
|  | 629 | if depname in taskData[mc].build_targets and taskData[mc].build_targets[depname] and not depname in taskData[mc].failed_deps: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 630 | # Won't be in build_targets if ASSUME_PROVIDED | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 631 | depdata = taskData[mc].build_targets[depname][0] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 632 | if depdata is not None: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 633 | t = depdata + ":" + idependtask | 
|  | 634 | depends.add(t) | 
|  | 635 | if t not in taskData[mc].taskentries: | 
|  | 636 | bb.msg.fatal("RunQueue", "Task %s in %s depends upon non-existent task %s in %s" % (taskname, fn, idependtask, depdata)) | 
|  | 637 | irdepends = taskData[mc].taskentries[tid].irdepends | 
|  | 638 | for (depname, idependtask) in irdepends: | 
|  | 639 | if depname in taskData[mc].run_targets: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 640 | # Won't be in run_targets if ASSUME_PROVIDED | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 641 | if not taskData[mc].run_targets[depname]: | 
|  | 642 | continue | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 643 | depdata = taskData[mc].run_targets[depname][0] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 644 | if depdata is not None: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 645 | t = depdata + ":" + idependtask | 
|  | 646 | depends.add(t) | 
|  | 647 | if t not in taskData[mc].taskentries: | 
|  | 648 | bb.msg.fatal("RunQueue", "Task %s in %s rdepends upon non-existent task %s in %s" % (taskname, fn, idependtask, depdata)) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 649 |  | 
|  | 650 | # Resolve recursive 'recrdeptask' dependencies (Part A) | 
|  | 651 | # | 
|  | 652 | # e.g. do_sometask[recrdeptask] = "do_someothertask" | 
|  | 653 | # (makes sure sometask runs after someothertask of all DEPENDS, RDEPENDS and intertask dependencies, recursively) | 
|  | 654 | # We cover the recursive part of the dependencies below | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 655 | if 'recrdeptask' in task_deps and taskname in task_deps['recrdeptask']: | 
|  | 656 | tasknames = task_deps['recrdeptask'][taskname].split() | 
|  | 657 | recursivetasks[tid] = tasknames | 
|  | 658 | add_build_dependencies(taskData[mc].depids[taskfn], tasknames, depends, mc) | 
|  | 659 | add_runtime_dependencies(taskData[mc].rdepids[taskfn], tasknames, depends, mc) | 
|  | 660 | if taskname in tasknames: | 
|  | 661 | recursivetasksselfref.add(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 662 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 663 | if 'recideptask' in task_deps and taskname in task_deps['recideptask']: | 
|  | 664 | recursiveitasks[tid] = [] | 
|  | 665 | for t in task_deps['recideptask'][taskname].split(): | 
|  | 666 | newdep = build_tid(mc, fn, t) | 
|  | 667 | recursiveitasks[tid].append(newdep) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 668 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 669 | self.runtaskentries[tid].depends = depends | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 670 | # Remove all self references | 
|  | 671 | self.runtaskentries[tid].depends.discard(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 672 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 673 | #self.dump_data() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 674 |  | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 675 | self.init_progress_reporter.next_stage() | 
|  | 676 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 677 | # Resolve recursive 'recrdeptask' dependencies (Part B) | 
|  | 678 | # | 
|  | 679 | # e.g. do_sometask[recrdeptask] = "do_someothertask" | 
|  | 680 | # (makes sure sometask runs after someothertask of all DEPENDS, RDEPENDS and intertask dependencies, recursively) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 681 | # We need to do this separately since we need all of runtaskentries[*].depends to be complete before this is processed | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 682 |  | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 683 | # Generating/interating recursive lists of dependencies is painful and potentially slow | 
|  | 684 | # Precompute recursive task dependencies here by: | 
|  | 685 | #     a) create a temp list of reverse dependencies (revdeps) | 
|  | 686 | #     b) walk up the ends of the chains (when a given task no longer has dependencies i.e. len(deps) == 0) | 
|  | 687 | #     c) combine the total list of dependencies in cumulativedeps | 
|  | 688 | #     d) optimise by pre-truncating 'task' off the items in cumulativedeps (keeps items in sets lower) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 689 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 690 |  | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 691 | revdeps = {} | 
|  | 692 | deps = {} | 
|  | 693 | cumulativedeps = {} | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 694 | for tid in self.runtaskentries: | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 695 | deps[tid] = set(self.runtaskentries[tid].depends) | 
|  | 696 | revdeps[tid] = set() | 
|  | 697 | cumulativedeps[tid] = set() | 
|  | 698 | # Generate a temp list of reverse dependencies | 
|  | 699 | for tid in self.runtaskentries: | 
|  | 700 | for dep in self.runtaskentries[tid].depends: | 
|  | 701 | revdeps[dep].add(tid) | 
|  | 702 | # Find the dependency chain endpoints | 
|  | 703 | endpoints = set() | 
|  | 704 | for tid in self.runtaskentries: | 
|  | 705 | if len(deps[tid]) == 0: | 
|  | 706 | endpoints.add(tid) | 
|  | 707 | # Iterate the chains collating dependencies | 
|  | 708 | while endpoints: | 
|  | 709 | next = set() | 
|  | 710 | for tid in endpoints: | 
|  | 711 | for dep in revdeps[tid]: | 
|  | 712 | cumulativedeps[dep].add(fn_from_tid(tid)) | 
|  | 713 | cumulativedeps[dep].update(cumulativedeps[tid]) | 
|  | 714 | if tid in deps[dep]: | 
|  | 715 | deps[dep].remove(tid) | 
|  | 716 | if len(deps[dep]) == 0: | 
|  | 717 | next.add(dep) | 
|  | 718 | endpoints = next | 
|  | 719 | #for tid in deps: | 
|  | 720 | #    if len(deps[tid]) != 0: | 
|  | 721 | #        bb.warn("Sanity test failure, dependencies left for %s (%s)" % (tid, deps[tid])) | 
|  | 722 |  | 
|  | 723 | # Loop here since recrdeptasks can depend upon other recrdeptasks and we have to | 
|  | 724 | # resolve these recursively until we aren't adding any further extra dependencies | 
|  | 725 | extradeps = True | 
|  | 726 | while extradeps: | 
|  | 727 | extradeps = 0 | 
|  | 728 | for tid in recursivetasks: | 
|  | 729 | tasknames = recursivetasks[tid] | 
|  | 730 |  | 
|  | 731 | totaldeps = set(self.runtaskentries[tid].depends) | 
|  | 732 | if tid in recursiveitasks: | 
|  | 733 | totaldeps.update(recursiveitasks[tid]) | 
|  | 734 | for dep in recursiveitasks[tid]: | 
|  | 735 | if dep not in self.runtaskentries: | 
|  | 736 | continue | 
|  | 737 | totaldeps.update(self.runtaskentries[dep].depends) | 
|  | 738 |  | 
|  | 739 | deps = set() | 
|  | 740 | for dep in totaldeps: | 
|  | 741 | if dep in cumulativedeps: | 
|  | 742 | deps.update(cumulativedeps[dep]) | 
|  | 743 |  | 
|  | 744 | for t in deps: | 
|  | 745 | for taskname in tasknames: | 
|  | 746 | newtid = t + ":" + taskname | 
|  | 747 | if newtid == tid: | 
|  | 748 | continue | 
|  | 749 | if newtid in self.runtaskentries and newtid not in self.runtaskentries[tid].depends: | 
|  | 750 | extradeps += 1 | 
|  | 751 | self.runtaskentries[tid].depends.add(newtid) | 
|  | 752 |  | 
|  | 753 | # Handle recursive tasks which depend upon other recursive tasks | 
|  | 754 | deps = set() | 
|  | 755 | for dep in self.runtaskentries[tid].depends.intersection(recursivetasks): | 
|  | 756 | deps.update(self.runtaskentries[dep].depends.difference(self.runtaskentries[tid].depends)) | 
|  | 757 | for newtid in deps: | 
|  | 758 | for taskname in tasknames: | 
|  | 759 | if not newtid.endswith(":" + taskname): | 
|  | 760 | continue | 
|  | 761 | if newtid in self.runtaskentries: | 
|  | 762 | extradeps += 1 | 
|  | 763 | self.runtaskentries[tid].depends.add(newtid) | 
|  | 764 |  | 
|  | 765 | bb.debug(1, "Added %s recursive dependencies in this loop" % extradeps) | 
|  | 766 |  | 
|  | 767 | # Remove recrdeptask circular references so that do_a[recrdeptask] = "do_a do_b" can work | 
|  | 768 | for tid in recursivetasksselfref: | 
|  | 769 | self.runtaskentries[tid].depends.difference_update(recursivetasksselfref) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 770 |  | 
|  | 771 | self.init_progress_reporter.next_stage() | 
|  | 772 |  | 
|  | 773 | #self.dump_data() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 774 |  | 
|  | 775 | # Step B - Mark all active tasks | 
|  | 776 | # | 
|  | 777 | # Start with the tasks we were asked to run and mark all dependencies | 
|  | 778 | # as active too. If the task is to be 'forced', clear its stamp. Once | 
|  | 779 | # all active tasks are marked, prune the ones we don't need. | 
|  | 780 |  | 
|  | 781 | logger.verbose("Marking Active Tasks") | 
|  | 782 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 783 | def mark_active(tid, depth): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 784 | """ | 
|  | 785 | Mark an item as active along with its depends | 
|  | 786 | (calls itself recursively) | 
|  | 787 | """ | 
|  | 788 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 789 | if tid in runq_build: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 790 | return | 
|  | 791 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 792 | runq_build[tid] = 1 | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 793 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 794 | depends = self.runtaskentries[tid].depends | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 795 | for depend in depends: | 
|  | 796 | mark_active(depend, depth+1) | 
|  | 797 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 798 | self.target_tids = [] | 
|  | 799 | for (mc, target, task, fn) in self.targets: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 800 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 801 | if target not in taskData[mc].build_targets or not taskData[mc].build_targets[target]: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 802 | continue | 
|  | 803 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 804 | if target in taskData[mc].failed_deps: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 805 | continue | 
|  | 806 |  | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 807 | parents = False | 
|  | 808 | if task.endswith('-'): | 
|  | 809 | parents = True | 
|  | 810 | task = task[:-1] | 
|  | 811 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 812 | if fn in taskData[mc].failed_fns: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 813 | continue | 
|  | 814 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 815 | # fn already has mc prefix | 
|  | 816 | tid = fn + ":" + task | 
|  | 817 | self.target_tids.append(tid) | 
|  | 818 | if tid not in taskData[mc].taskentries: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 819 | import difflib | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 820 | tasks = [] | 
|  | 821 | for x in taskData[mc].taskentries: | 
|  | 822 | if x.startswith(fn + ":"): | 
|  | 823 | tasks.append(taskname_from_tid(x)) | 
|  | 824 | close_matches = difflib.get_close_matches(task, tasks, cutoff=0.7) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 825 | if close_matches: | 
|  | 826 | extra = ". Close matches:\n  %s" % "\n  ".join(close_matches) | 
|  | 827 | else: | 
|  | 828 | extra = "" | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 829 | bb.msg.fatal("RunQueue", "Task %s does not exist for target %s (%s)%s" % (task, target, tid, extra)) | 
|  | 830 |  | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 831 | # For tasks called "XXXX-", ony run their dependencies | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 832 | if parents: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 833 | for i in self.runtaskentries[tid].depends: | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 834 | mark_active(i, 1) | 
|  | 835 | else: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 836 | mark_active(tid, 1) | 
|  | 837 |  | 
|  | 838 | self.init_progress_reporter.next_stage() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 839 |  | 
|  | 840 | # Step C - Prune all inactive tasks | 
|  | 841 | # | 
|  | 842 | # Once all active tasks are marked, prune the ones we don't need. | 
|  | 843 |  | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 844 | delcount = {} | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 845 | for tid in list(self.runtaskentries.keys()): | 
|  | 846 | if tid not in runq_build: | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 847 | delcount[tid] = self.runtaskentries[tid] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 848 | del self.runtaskentries[tid] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 849 |  | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 850 | # Handle --runall | 
|  | 851 | if self.cooker.configuration.runall: | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 852 | # re-run the mark_active and then drop unused tasks from new list | 
|  | 853 | runq_build = {} | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 854 |  | 
|  | 855 | for task in self.cooker.configuration.runall: | 
|  | 856 | runall_tids = set() | 
|  | 857 | for tid in list(self.runtaskentries): | 
|  | 858 | wanttid = fn_from_tid(tid) + ":do_%s" % task | 
|  | 859 | if wanttid in delcount: | 
|  | 860 | self.runtaskentries[wanttid] = delcount[wanttid] | 
|  | 861 | if wanttid in self.runtaskentries: | 
|  | 862 | runall_tids.add(wanttid) | 
|  | 863 |  | 
|  | 864 | for tid in list(runall_tids): | 
|  | 865 | mark_active(tid,1) | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 866 |  | 
|  | 867 | for tid in list(self.runtaskentries.keys()): | 
|  | 868 | if tid not in runq_build: | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 869 | delcount[tid] = self.runtaskentries[tid] | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 870 | del self.runtaskentries[tid] | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 871 |  | 
|  | 872 | if len(self.runtaskentries) == 0: | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 873 | bb.msg.fatal("RunQueue", "Could not find any tasks with the tasknames %s to run within the recipes of the taskgraphs of the targets %s" % (str(self.cooker.configuration.runall), str(self.targets))) | 
|  | 874 |  | 
|  | 875 | self.init_progress_reporter.next_stage() | 
|  | 876 |  | 
|  | 877 | # Handle runonly | 
|  | 878 | if self.cooker.configuration.runonly: | 
|  | 879 | # re-run the mark_active and then drop unused tasks from new list | 
|  | 880 | runq_build = {} | 
|  | 881 |  | 
|  | 882 | for task in self.cooker.configuration.runonly: | 
|  | 883 | runonly_tids = { k: v for k, v in self.runtaskentries.items() if taskname_from_tid(k) == "do_%s" % task } | 
|  | 884 |  | 
|  | 885 | for tid in list(runonly_tids): | 
|  | 886 | mark_active(tid,1) | 
|  | 887 |  | 
|  | 888 | for tid in list(self.runtaskentries.keys()): | 
|  | 889 | if tid not in runq_build: | 
|  | 890 | delcount[tid] = self.runtaskentries[tid] | 
|  | 891 | del self.runtaskentries[tid] | 
|  | 892 |  | 
|  | 893 | if len(self.runtaskentries) == 0: | 
|  | 894 | bb.msg.fatal("RunQueue", "Could not find any tasks with the tasknames %s to run within the taskgraphs of the targets %s" % (str(self.cooker.configuration.runonly), str(self.targets))) | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 895 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 896 | # | 
|  | 897 | # Step D - Sanity checks and computation | 
|  | 898 | # | 
|  | 899 |  | 
|  | 900 | # Check to make sure we still have tasks to run | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 901 | if len(self.runtaskentries) == 0: | 
|  | 902 | if not taskData[''].abort: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 903 | bb.msg.fatal("RunQueue", "All buildable tasks have been run but the build is incomplete (--continue mode). Errors for the tasks that failed will have been printed above.") | 
|  | 904 | else: | 
|  | 905 | bb.msg.fatal("RunQueue", "No active tasks and not in --continue mode?! Please report this bug.") | 
|  | 906 |  | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 907 | logger.verbose("Pruned %s inactive tasks, %s left", len(delcount), len(self.runtaskentries)) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 908 |  | 
|  | 909 | logger.verbose("Assign Weightings") | 
|  | 910 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 911 | self.init_progress_reporter.next_stage() | 
|  | 912 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 913 | # Generate a list of reverse dependencies to ease future calculations | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 914 | for tid in self.runtaskentries: | 
|  | 915 | for dep in self.runtaskentries[tid].depends: | 
|  | 916 | self.runtaskentries[dep].revdeps.add(tid) | 
|  | 917 |  | 
|  | 918 | self.init_progress_reporter.next_stage() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 919 |  | 
|  | 920 | # Identify tasks at the end of dependency chains | 
|  | 921 | # Error on circular dependency loops (length two) | 
|  | 922 | endpoints = [] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 923 | for tid in self.runtaskentries: | 
|  | 924 | revdeps = self.runtaskentries[tid].revdeps | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 925 | if len(revdeps) == 0: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 926 | endpoints.append(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 927 | for dep in revdeps: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 928 | if dep in self.runtaskentries[tid].depends: | 
|  | 929 | bb.msg.fatal("RunQueue", "Task %s has circular dependency on %s" % (tid, dep)) | 
|  | 930 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 931 |  | 
|  | 932 | logger.verbose("Compute totals (have %s endpoint(s))", len(endpoints)) | 
|  | 933 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 934 | self.init_progress_reporter.next_stage() | 
|  | 935 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 936 | # Calculate task weights | 
|  | 937 | # Check of higher length circular dependencies | 
|  | 938 | self.runq_weight = self.calculate_task_weights(endpoints) | 
|  | 939 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 940 | self.init_progress_reporter.next_stage() | 
|  | 941 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 942 | # Sanity Check - Check for multiple tasks building the same provider | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 943 | for mc in self.dataCaches: | 
|  | 944 | prov_list = {} | 
|  | 945 | seen_fn = [] | 
|  | 946 | for tid in self.runtaskentries: | 
|  | 947 | (tidmc, fn, taskname, taskfn) = split_tid_mcfn(tid) | 
|  | 948 | if taskfn in seen_fn: | 
|  | 949 | continue | 
|  | 950 | if mc != tidmc: | 
|  | 951 | continue | 
|  | 952 | seen_fn.append(taskfn) | 
|  | 953 | for prov in self.dataCaches[mc].fn_provides[taskfn]: | 
|  | 954 | if prov not in prov_list: | 
|  | 955 | prov_list[prov] = [taskfn] | 
|  | 956 | elif taskfn not in prov_list[prov]: | 
|  | 957 | prov_list[prov].append(taskfn) | 
|  | 958 | for prov in prov_list: | 
|  | 959 | if len(prov_list[prov]) < 2: | 
|  | 960 | continue | 
|  | 961 | if prov in self.multi_provider_whitelist: | 
|  | 962 | continue | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 963 | seen_pn = [] | 
|  | 964 | # If two versions of the same PN are being built its fatal, we don't support it. | 
|  | 965 | for fn in prov_list[prov]: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 966 | pn = self.dataCaches[mc].pkg_fn[fn] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 967 | if pn not in seen_pn: | 
|  | 968 | seen_pn.append(pn) | 
|  | 969 | else: | 
|  | 970 | bb.fatal("Multiple versions of %s are due to be built (%s). Only one version of a given PN should be built in any given build. You likely need to set PREFERRED_VERSION_%s to select the correct version or don't depend on multiple versions." % (pn, " ".join(prov_list[prov]), pn)) | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 971 | msg = "Multiple .bb files are due to be built which each provide %s:\n  %s" % (prov, "\n  ".join(prov_list[prov])) | 
|  | 972 | # | 
|  | 973 | # Construct a list of things which uniquely depend on each provider | 
|  | 974 | # since this may help the user figure out which dependency is triggering this warning | 
|  | 975 | # | 
|  | 976 | msg += "\nA list of tasks depending on these providers is shown and may help explain where the dependency comes from." | 
|  | 977 | deplist = {} | 
|  | 978 | commondeps = None | 
|  | 979 | for provfn in prov_list[prov]: | 
|  | 980 | deps = set() | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 981 | for tid in self.runtaskentries: | 
|  | 982 | fn = fn_from_tid(tid) | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 983 | if fn != provfn: | 
|  | 984 | continue | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 985 | for dep in self.runtaskentries[tid].revdeps: | 
|  | 986 | fn = fn_from_tid(dep) | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 987 | if fn == provfn: | 
|  | 988 | continue | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 989 | deps.add(dep) | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 990 | if not commondeps: | 
|  | 991 | commondeps = set(deps) | 
|  | 992 | else: | 
|  | 993 | commondeps &= deps | 
|  | 994 | deplist[provfn] = deps | 
|  | 995 | for provfn in deplist: | 
|  | 996 | msg += "\n%s has unique dependees:\n  %s" % (provfn, "\n  ".join(deplist[provfn] - commondeps)) | 
|  | 997 | # | 
|  | 998 | # Construct a list of provides and runtime providers for each recipe | 
|  | 999 | # (rprovides has to cover RPROVIDES, PACKAGES, PACKAGES_DYNAMIC) | 
|  | 1000 | # | 
|  | 1001 | msg += "\nIt could be that one recipe provides something the other doesn't and should. The following provider and runtime provider differences may be helpful." | 
|  | 1002 | provide_results = {} | 
|  | 1003 | rprovide_results = {} | 
|  | 1004 | commonprovs = None | 
|  | 1005 | commonrprovs = None | 
|  | 1006 | for provfn in prov_list[prov]: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1007 | provides = set(self.dataCaches[mc].fn_provides[provfn]) | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1008 | rprovides = set() | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1009 | for rprovide in self.dataCaches[mc].rproviders: | 
|  | 1010 | if provfn in self.dataCaches[mc].rproviders[rprovide]: | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1011 | rprovides.add(rprovide) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1012 | for package in self.dataCaches[mc].packages: | 
|  | 1013 | if provfn in self.dataCaches[mc].packages[package]: | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1014 | rprovides.add(package) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1015 | for package in self.dataCaches[mc].packages_dynamic: | 
|  | 1016 | if provfn in self.dataCaches[mc].packages_dynamic[package]: | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1017 | rprovides.add(package) | 
|  | 1018 | if not commonprovs: | 
|  | 1019 | commonprovs = set(provides) | 
|  | 1020 | else: | 
|  | 1021 | commonprovs &= provides | 
|  | 1022 | provide_results[provfn] = provides | 
|  | 1023 | if not commonrprovs: | 
|  | 1024 | commonrprovs = set(rprovides) | 
|  | 1025 | else: | 
|  | 1026 | commonrprovs &= rprovides | 
|  | 1027 | rprovide_results[provfn] = rprovides | 
|  | 1028 | #msg += "\nCommon provides:\n  %s" % ("\n  ".join(commonprovs)) | 
|  | 1029 | #msg += "\nCommon rprovides:\n  %s" % ("\n  ".join(commonrprovs)) | 
|  | 1030 | for provfn in prov_list[prov]: | 
|  | 1031 | msg += "\n%s has unique provides:\n  %s" % (provfn, "\n  ".join(provide_results[provfn] - commonprovs)) | 
|  | 1032 | msg += "\n%s has unique rprovides:\n  %s" % (provfn, "\n  ".join(rprovide_results[provfn] - commonrprovs)) | 
|  | 1033 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1034 | if self.warn_multi_bb: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1035 | logger.warning(msg) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1036 | else: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1037 | logger.error(msg) | 
|  | 1038 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1039 | self.init_progress_reporter.next_stage() | 
|  | 1040 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1041 | # Create a whitelist usable by the stamp checks | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1042 | self.stampfnwhitelist = {} | 
|  | 1043 | for mc in self.taskData: | 
|  | 1044 | self.stampfnwhitelist[mc] = [] | 
|  | 1045 | for entry in self.stampwhitelist.split(): | 
|  | 1046 | if entry not in self.taskData[mc].build_targets: | 
|  | 1047 | continue | 
|  | 1048 | fn = self.taskData.build_targets[entry][0] | 
|  | 1049 | self.stampfnwhitelist[mc].append(fn) | 
|  | 1050 |  | 
|  | 1051 | self.init_progress_reporter.next_stage() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1052 |  | 
|  | 1053 | # Iterate over the task list looking for tasks with a 'setscene' function | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1054 | self.runq_setscene_tids = [] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1055 | if not self.cooker.configuration.nosetscene: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1056 | for tid in self.runtaskentries: | 
|  | 1057 | (mc, fn, taskname, _) = split_tid_mcfn(tid) | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1058 | setscenetid = tid + "_setscene" | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1059 | if setscenetid not in taskData[mc].taskentries: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1060 | continue | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1061 | self.runq_setscene_tids.append(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1062 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1063 | def invalidate_task(tid, error_nostamp): | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1064 | (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) | 
|  | 1065 | taskdep = self.dataCaches[mc].task_deps[taskfn] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1066 | if fn + ":" + taskname not in taskData[mc].taskentries: | 
|  | 1067 | logger.warning("Task %s does not exist, invalidating this task will have no effect" % taskname) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1068 | if 'nostamp' in taskdep and taskname in taskdep['nostamp']: | 
|  | 1069 | if error_nostamp: | 
|  | 1070 | bb.fatal("Task %s is marked nostamp, cannot invalidate this task" % taskname) | 
|  | 1071 | else: | 
|  | 1072 | bb.debug(1, "Task %s is marked nostamp, cannot invalidate this task" % taskname) | 
|  | 1073 | else: | 
|  | 1074 | logger.verbose("Invalidate task %s, %s", taskname, fn) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1075 | bb.parse.siggen.invalidate_task(taskname, self.dataCaches[mc], fn) | 
|  | 1076 |  | 
|  | 1077 | self.init_progress_reporter.next_stage() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1078 |  | 
|  | 1079 | # Invalidate task if force mode active | 
|  | 1080 | if self.cooker.configuration.force: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1081 | for tid in self.target_tids: | 
|  | 1082 | invalidate_task(tid, False) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1083 |  | 
|  | 1084 | # Invalidate task if invalidate mode active | 
|  | 1085 | if self.cooker.configuration.invalidate_stamp: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1086 | for tid in self.target_tids: | 
|  | 1087 | fn = fn_from_tid(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1088 | for st in self.cooker.configuration.invalidate_stamp.split(','): | 
|  | 1089 | if not st.startswith("do_"): | 
|  | 1090 | st = "do_%s" % st | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1091 | invalidate_task(fn + ":" + st, True) | 
|  | 1092 |  | 
|  | 1093 | self.init_progress_reporter.next_stage() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1094 |  | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1095 | # Create and print to the logs a virtual/xxxx -> PN (fn) table | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1096 | for mc in taskData: | 
|  | 1097 | virtmap = taskData[mc].get_providermap(prefix="virtual/") | 
|  | 1098 | virtpnmap = {} | 
|  | 1099 | for v in virtmap: | 
|  | 1100 | virtpnmap[v] = self.dataCaches[mc].pkg_fn[virtmap[v]] | 
|  | 1101 | bb.debug(2, "%s resolved to: %s (%s)" % (v, virtpnmap[v], virtmap[v])) | 
|  | 1102 | if hasattr(bb.parse.siggen, "tasks_resolved"): | 
|  | 1103 | bb.parse.siggen.tasks_resolved(virtmap, virtpnmap, self.dataCaches[mc]) | 
|  | 1104 |  | 
|  | 1105 | self.init_progress_reporter.next_stage() | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1106 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1107 | # Iterate over the task list and call into the siggen code | 
|  | 1108 | dealtwith = set() | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1109 | todeal = set(self.runtaskentries) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1110 | while len(todeal) > 0: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1111 | for tid in todeal.copy(): | 
|  | 1112 | if len(self.runtaskentries[tid].depends - dealtwith) == 0: | 
|  | 1113 | dealtwith.add(tid) | 
|  | 1114 | todeal.remove(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1115 | procdep = [] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1116 | for dep in self.runtaskentries[tid].depends: | 
|  | 1117 | procdep.append(fn_from_tid(dep) + "." + taskname_from_tid(dep)) | 
|  | 1118 | (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) | 
|  | 1119 | self.runtaskentries[tid].hash = bb.parse.siggen.get_taskhash(taskfn, taskname, procdep, self.dataCaches[mc]) | 
|  | 1120 | task = self.runtaskentries[tid].task | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1121 |  | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1122 | bb.parse.siggen.writeout_file_checksum_cache() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1123 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1124 | #self.dump_data() | 
|  | 1125 | return len(self.runtaskentries) | 
|  | 1126 |  | 
|  | 1127 | def dump_data(self): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1128 | """ | 
|  | 1129 | Dump some debug information on the internal data structures | 
|  | 1130 | """ | 
|  | 1131 | logger.debug(3, "run_tasks:") | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1132 | for tid in self.runtaskentries: | 
|  | 1133 | logger.debug(3, " %s: %s   Deps %s RevDeps %s", tid, | 
|  | 1134 | self.runtaskentries[tid].weight, | 
|  | 1135 | self.runtaskentries[tid].depends, | 
|  | 1136 | self.runtaskentries[tid].revdeps) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1137 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1138 | class RunQueueWorker(): | 
|  | 1139 | def __init__(self, process, pipe): | 
|  | 1140 | self.process = process | 
|  | 1141 | self.pipe = pipe | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1142 |  | 
|  | 1143 | class RunQueue: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1144 | def __init__(self, cooker, cfgData, dataCaches, taskData, targets): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1145 |  | 
|  | 1146 | self.cooker = cooker | 
|  | 1147 | self.cfgData = cfgData | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1148 | self.rqdata = RunQueueData(self, cooker, cfgData, dataCaches, taskData, targets) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1149 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1150 | self.stamppolicy = cfgData.getVar("BB_STAMP_POLICY") or "perfile" | 
|  | 1151 | self.hashvalidate = cfgData.getVar("BB_HASHCHECK_FUNCTION") or None | 
|  | 1152 | self.setsceneverify = cfgData.getVar("BB_SETSCENE_VERIFY_FUNCTION2") or None | 
|  | 1153 | self.depvalidate = cfgData.getVar("BB_SETSCENE_DEPVALID") or None | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1154 |  | 
|  | 1155 | self.state = runQueuePrepare | 
|  | 1156 |  | 
|  | 1157 | # For disk space monitor | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1158 | # Invoked at regular time intervals via the bitbake heartbeat event | 
|  | 1159 | # while the build is running. We generate a unique name for the handler | 
|  | 1160 | # here, just in case that there ever is more than one RunQueue instance, | 
|  | 1161 | # start the handler when reaching runQueueSceneRun, and stop it when | 
|  | 1162 | # done with the build. | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1163 | self.dm = monitordisk.diskMonitor(cfgData) | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1164 | self.dm_event_handler_name = '_bb_diskmonitor_' + str(id(self)) | 
|  | 1165 | self.dm_event_handler_registered = False | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1166 | self.rqexe = None | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1167 | self.worker = {} | 
|  | 1168 | self.fakeworker = {} | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1169 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1170 | def _start_worker(self, mc, fakeroot = False, rqexec = None): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1171 | logger.debug(1, "Starting bitbake-worker") | 
|  | 1172 | magic = "decafbad" | 
|  | 1173 | if self.cooker.configuration.profile: | 
|  | 1174 | magic = "decafbadbad" | 
|  | 1175 | if fakeroot: | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1176 | magic = magic + "beef" | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1177 | mcdata = self.cooker.databuilder.mcdata[mc] | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1178 | fakerootcmd = mcdata.getVar("FAKEROOTCMD") | 
|  | 1179 | fakerootenv = (mcdata.getVar("FAKEROOTBASEENV") or "").split() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1180 | env = os.environ.copy() | 
|  | 1181 | for key, value in (var.split('=') for var in fakerootenv): | 
|  | 1182 | env[key] = value | 
|  | 1183 | worker = subprocess.Popen([fakerootcmd, "bitbake-worker", magic], stdout=subprocess.PIPE, stdin=subprocess.PIPE, env=env) | 
|  | 1184 | else: | 
|  | 1185 | worker = subprocess.Popen(["bitbake-worker", magic], stdout=subprocess.PIPE, stdin=subprocess.PIPE) | 
|  | 1186 | bb.utils.nonblockingfd(worker.stdout) | 
|  | 1187 | workerpipe = runQueuePipe(worker.stdout, None, self.cfgData, self, rqexec) | 
|  | 1188 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1189 | runqhash = {} | 
|  | 1190 | for tid in self.rqdata.runtaskentries: | 
|  | 1191 | runqhash[tid] = self.rqdata.runtaskentries[tid].hash | 
|  | 1192 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1193 | workerdata = { | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1194 | "taskdeps" : self.rqdata.dataCaches[mc].task_deps, | 
|  | 1195 | "fakerootenv" : self.rqdata.dataCaches[mc].fakerootenv, | 
|  | 1196 | "fakerootdirs" : self.rqdata.dataCaches[mc].fakerootdirs, | 
|  | 1197 | "fakerootnoenv" : self.rqdata.dataCaches[mc].fakerootnoenv, | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1198 | "sigdata" : bb.parse.siggen.get_taskdata(), | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1199 | "runq_hash" : runqhash, | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1200 | "logdefaultdebug" : bb.msg.loggerDefaultDebugLevel, | 
|  | 1201 | "logdefaultverbose" : bb.msg.loggerDefaultVerbose, | 
|  | 1202 | "logdefaultverboselogs" : bb.msg.loggerVerboseLogs, | 
|  | 1203 | "logdefaultdomain" : bb.msg.loggerDefaultDomains, | 
|  | 1204 | "prhost" : self.cooker.prhost, | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1205 | "buildname" : self.cfgData.getVar("BUILDNAME"), | 
|  | 1206 | "date" : self.cfgData.getVar("DATE"), | 
|  | 1207 | "time" : self.cfgData.getVar("TIME"), | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1208 | } | 
|  | 1209 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1210 | worker.stdin.write(b"<cookerconfig>" + pickle.dumps(self.cooker.configuration) + b"</cookerconfig>") | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1211 | worker.stdin.write(b"<extraconfigdata>" + pickle.dumps(self.cooker.extraconfigdata) + b"</extraconfigdata>") | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1212 | worker.stdin.write(b"<workerdata>" + pickle.dumps(workerdata) + b"</workerdata>") | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1213 | worker.stdin.flush() | 
|  | 1214 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1215 | return RunQueueWorker(worker, workerpipe) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1216 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1217 | def _teardown_worker(self, worker): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1218 | if not worker: | 
|  | 1219 | return | 
|  | 1220 | logger.debug(1, "Teardown for bitbake-worker") | 
|  | 1221 | try: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1222 | worker.process.stdin.write(b"<quit></quit>") | 
|  | 1223 | worker.process.stdin.flush() | 
|  | 1224 | worker.process.stdin.close() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1225 | except IOError: | 
|  | 1226 | pass | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1227 | while worker.process.returncode is None: | 
|  | 1228 | worker.pipe.read() | 
|  | 1229 | worker.process.poll() | 
|  | 1230 | while worker.pipe.read(): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1231 | continue | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1232 | worker.pipe.close() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1233 |  | 
|  | 1234 | def start_worker(self): | 
|  | 1235 | if self.worker: | 
|  | 1236 | self.teardown_workers() | 
|  | 1237 | self.teardown = False | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1238 | for mc in self.rqdata.dataCaches: | 
|  | 1239 | self.worker[mc] = self._start_worker(mc) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1240 |  | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1241 | def start_fakeworker(self, rqexec, mc): | 
|  | 1242 | if not mc in self.fakeworker: | 
|  | 1243 | self.fakeworker[mc] = self._start_worker(mc, True, rqexec) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1244 |  | 
|  | 1245 | def teardown_workers(self): | 
|  | 1246 | self.teardown = True | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1247 | for mc in self.worker: | 
|  | 1248 | self._teardown_worker(self.worker[mc]) | 
|  | 1249 | self.worker = {} | 
|  | 1250 | for mc in self.fakeworker: | 
|  | 1251 | self._teardown_worker(self.fakeworker[mc]) | 
|  | 1252 | self.fakeworker = {} | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1253 |  | 
|  | 1254 | def read_workers(self): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1255 | for mc in self.worker: | 
|  | 1256 | self.worker[mc].pipe.read() | 
|  | 1257 | for mc in self.fakeworker: | 
|  | 1258 | self.fakeworker[mc].pipe.read() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1259 |  | 
|  | 1260 | def active_fds(self): | 
|  | 1261 | fds = [] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1262 | for mc in self.worker: | 
|  | 1263 | fds.append(self.worker[mc].pipe.input) | 
|  | 1264 | for mc in self.fakeworker: | 
|  | 1265 | fds.append(self.fakeworker[mc].pipe.input) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1266 | return fds | 
|  | 1267 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1268 | def check_stamp_task(self, tid, taskname = None, recurse = False, cache = None): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1269 | def get_timestamp(f): | 
|  | 1270 | try: | 
|  | 1271 | if not os.access(f, os.F_OK): | 
|  | 1272 | return None | 
|  | 1273 | return os.stat(f)[stat.ST_MTIME] | 
|  | 1274 | except: | 
|  | 1275 | return None | 
|  | 1276 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1277 | (mc, fn, tn, taskfn) = split_tid_mcfn(tid) | 
|  | 1278 | if taskname is None: | 
|  | 1279 | taskname = tn | 
|  | 1280 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1281 | if self.stamppolicy == "perfile": | 
|  | 1282 | fulldeptree = False | 
|  | 1283 | else: | 
|  | 1284 | fulldeptree = True | 
|  | 1285 | stampwhitelist = [] | 
|  | 1286 | if self.stamppolicy == "whitelist": | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1287 | stampwhitelist = self.rqdata.stampfnwhitelist[mc] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1288 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1289 | stampfile = bb.build.stampfile(taskname, self.rqdata.dataCaches[mc], taskfn) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1290 |  | 
|  | 1291 | # If the stamp is missing, it's not current | 
|  | 1292 | if not os.access(stampfile, os.F_OK): | 
|  | 1293 | logger.debug(2, "Stampfile %s not available", stampfile) | 
|  | 1294 | return False | 
|  | 1295 | # If it's a 'nostamp' task, it's not current | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1296 | taskdep = self.rqdata.dataCaches[mc].task_deps[taskfn] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1297 | if 'nostamp' in taskdep and taskname in taskdep['nostamp']: | 
|  | 1298 | logger.debug(2, "%s.%s is nostamp\n", fn, taskname) | 
|  | 1299 | return False | 
|  | 1300 |  | 
|  | 1301 | if taskname != "do_setscene" and taskname.endswith("_setscene"): | 
|  | 1302 | return True | 
|  | 1303 |  | 
|  | 1304 | if cache is None: | 
|  | 1305 | cache = {} | 
|  | 1306 |  | 
|  | 1307 | iscurrent = True | 
|  | 1308 | t1 = get_timestamp(stampfile) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1309 | for dep in self.rqdata.runtaskentries[tid].depends: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1310 | if iscurrent: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1311 | (mc2, fn2, taskname2, taskfn2) = split_tid_mcfn(dep) | 
|  | 1312 | stampfile2 = bb.build.stampfile(taskname2, self.rqdata.dataCaches[mc2], taskfn2) | 
|  | 1313 | stampfile3 = bb.build.stampfile(taskname2 + "_setscene", self.rqdata.dataCaches[mc2], taskfn2) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1314 | t2 = get_timestamp(stampfile2) | 
|  | 1315 | t3 = get_timestamp(stampfile3) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1316 | if t3 and not t2: | 
|  | 1317 | continue | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1318 | if t3 and t3 > t2: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1319 | continue | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1320 | if fn == fn2 or (fulldeptree and fn2 not in stampwhitelist): | 
|  | 1321 | if not t2: | 
|  | 1322 | logger.debug(2, 'Stampfile %s does not exist', stampfile2) | 
|  | 1323 | iscurrent = False | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1324 | break | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1325 | if t1 < t2: | 
|  | 1326 | logger.debug(2, 'Stampfile %s < %s', stampfile, stampfile2) | 
|  | 1327 | iscurrent = False | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1328 | break | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1329 | if recurse and iscurrent: | 
|  | 1330 | if dep in cache: | 
|  | 1331 | iscurrent = cache[dep] | 
|  | 1332 | if not iscurrent: | 
|  | 1333 | logger.debug(2, 'Stampfile for dependency %s:%s invalid (cached)' % (fn2, taskname2)) | 
|  | 1334 | else: | 
|  | 1335 | iscurrent = self.check_stamp_task(dep, recurse=True, cache=cache) | 
|  | 1336 | cache[dep] = iscurrent | 
|  | 1337 | if recurse: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1338 | cache[tid] = iscurrent | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1339 | return iscurrent | 
|  | 1340 |  | 
|  | 1341 | def _execute_runqueue(self): | 
|  | 1342 | """ | 
|  | 1343 | Run the tasks in a queue prepared by rqdata.prepare() | 
|  | 1344 | Upon failure, optionally try to recover the build using any alternate providers | 
|  | 1345 | (if the abort on failure configuration option isn't set) | 
|  | 1346 | """ | 
|  | 1347 |  | 
|  | 1348 | retval = True | 
|  | 1349 |  | 
|  | 1350 | if self.state is runQueuePrepare: | 
|  | 1351 | self.rqexe = RunQueueExecuteDummy(self) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1352 | # NOTE: if you add, remove or significantly refactor the stages of this | 
|  | 1353 | # process then you should recalculate the weightings here. This is quite | 
|  | 1354 | # easy to do - just change the next line temporarily to pass debug=True as | 
|  | 1355 | # the last parameter and you'll get a printout of the weightings as well | 
|  | 1356 | # as a map to the lines where next_stage() was called. Of course this isn't | 
|  | 1357 | # critical, but it helps to keep the progress reporting accurate. | 
|  | 1358 | self.rqdata.init_progress_reporter = bb.progress.MultiStageProcessProgressReporter(self.cooker.data, | 
|  | 1359 | "Initialising tasks", | 
|  | 1360 | [43, 967, 4, 3, 1, 5, 3, 7, 13, 1, 2, 1, 1, 246, 35, 1, 38, 1, 35, 2, 338, 204, 142, 3, 3, 37, 244]) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1361 | if self.rqdata.prepare() == 0: | 
|  | 1362 | self.state = runQueueComplete | 
|  | 1363 | else: | 
|  | 1364 | self.state = runQueueSceneInit | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1365 | self.rqdata.init_progress_reporter.next_stage() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1366 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1367 | # we are ready to run,  emit dependency info to any UI or class which | 
|  | 1368 | # needs it | 
|  | 1369 | depgraph = self.cooker.buildDependTree(self, self.rqdata.taskData) | 
|  | 1370 | self.rqdata.init_progress_reporter.next_stage() | 
|  | 1371 | bb.event.fire(bb.event.DepTreeGenerated(depgraph), self.cooker.data) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1372 |  | 
|  | 1373 | if self.state is runQueueSceneInit: | 
|  | 1374 | dump = self.cooker.configuration.dump_signatures | 
|  | 1375 | if dump: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1376 | self.rqdata.init_progress_reporter.finish() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1377 | if 'printdiff' in dump: | 
|  | 1378 | invalidtasks = self.print_diffscenetasks() | 
|  | 1379 | self.dump_signatures(dump) | 
|  | 1380 | if 'printdiff' in dump: | 
|  | 1381 | self.write_diffscenetasks(invalidtasks) | 
|  | 1382 | self.state = runQueueComplete | 
|  | 1383 | else: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1384 | self.rqdata.init_progress_reporter.next_stage() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1385 | self.start_worker() | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1386 | self.rqdata.init_progress_reporter.next_stage() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1387 | self.rqexe = RunQueueExecuteScenequeue(self) | 
|  | 1388 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1389 | if self.state is runQueueSceneRun: | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1390 | if not self.dm_event_handler_registered: | 
|  | 1391 | res = bb.event.register(self.dm_event_handler_name, | 
|  | 1392 | lambda x: self.dm.check(self) if self.state in [runQueueSceneRun, runQueueRunning, runQueueCleanUp] else False, | 
|  | 1393 | ('bb.event.HeartbeatEvent',)) | 
|  | 1394 | self.dm_event_handler_registered = True | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1395 | retval = self.rqexe.execute() | 
|  | 1396 |  | 
|  | 1397 | if self.state is runQueueRunInit: | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1398 | if self.cooker.configuration.setsceneonly: | 
|  | 1399 | self.state = runQueueComplete | 
|  | 1400 | else: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1401 | # Just in case we didn't setscene | 
|  | 1402 | self.rqdata.init_progress_reporter.finish() | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1403 | logger.info("Executing RunQueue Tasks") | 
|  | 1404 | self.rqexe = RunQueueExecuteTasks(self) | 
|  | 1405 | self.state = runQueueRunning | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1406 |  | 
|  | 1407 | if self.state is runQueueRunning: | 
|  | 1408 | retval = self.rqexe.execute() | 
|  | 1409 |  | 
|  | 1410 | if self.state is runQueueCleanUp: | 
|  | 1411 | retval = self.rqexe.finish() | 
|  | 1412 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1413 | build_done = self.state is runQueueComplete or self.state is runQueueFailed | 
|  | 1414 |  | 
|  | 1415 | if build_done and self.dm_event_handler_registered: | 
|  | 1416 | bb.event.remove(self.dm_event_handler_name, None) | 
|  | 1417 | self.dm_event_handler_registered = False | 
|  | 1418 |  | 
|  | 1419 | if build_done and self.rqexe: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1420 | self.teardown_workers() | 
|  | 1421 | if self.rqexe.stats.failed: | 
|  | 1422 | logger.info("Tasks Summary: Attempted %d tasks of which %d didn't need to be rerun and %d failed.", self.rqexe.stats.completed + self.rqexe.stats.failed, self.rqexe.stats.skipped, self.rqexe.stats.failed) | 
|  | 1423 | else: | 
|  | 1424 | # Let's avoid the word "failed" if nothing actually did | 
|  | 1425 | logger.info("Tasks Summary: Attempted %d tasks of which %d didn't need to be rerun and all succeeded.", self.rqexe.stats.completed, self.rqexe.stats.skipped) | 
|  | 1426 |  | 
|  | 1427 | if self.state is runQueueFailed: | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1428 | raise bb.runqueue.TaskFailure(self.rqexe.failed_tids) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1429 |  | 
|  | 1430 | if self.state is runQueueComplete: | 
|  | 1431 | # All done | 
|  | 1432 | return False | 
|  | 1433 |  | 
|  | 1434 | # Loop | 
|  | 1435 | return retval | 
|  | 1436 |  | 
|  | 1437 | def execute_runqueue(self): | 
|  | 1438 | # Catch unexpected exceptions and ensure we exit when an error occurs, not loop. | 
|  | 1439 | try: | 
|  | 1440 | return self._execute_runqueue() | 
|  | 1441 | except bb.runqueue.TaskFailure: | 
|  | 1442 | raise | 
|  | 1443 | except SystemExit: | 
|  | 1444 | raise | 
|  | 1445 | except bb.BBHandledException: | 
|  | 1446 | try: | 
|  | 1447 | self.teardown_workers() | 
|  | 1448 | except: | 
|  | 1449 | pass | 
|  | 1450 | self.state = runQueueComplete | 
|  | 1451 | raise | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1452 | except Exception as err: | 
|  | 1453 | logger.exception("An uncaught exception occurred in runqueue") | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1454 | try: | 
|  | 1455 | self.teardown_workers() | 
|  | 1456 | except: | 
|  | 1457 | pass | 
|  | 1458 | self.state = runQueueComplete | 
|  | 1459 | raise | 
|  | 1460 |  | 
|  | 1461 | def finish_runqueue(self, now = False): | 
|  | 1462 | if not self.rqexe: | 
|  | 1463 | self.state = runQueueComplete | 
|  | 1464 | return | 
|  | 1465 |  | 
|  | 1466 | if now: | 
|  | 1467 | self.rqexe.finish_now() | 
|  | 1468 | else: | 
|  | 1469 | self.rqexe.finish() | 
|  | 1470 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1471 | def rq_dump_sigfn(self, fn, options): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1472 | bb_cache = bb.cache.NoCache(self.cooker.databuilder) | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1473 | the_data = bb_cache.loadDataFull(fn, self.cooker.collection.get_file_appends(fn)) | 
|  | 1474 | siggen = bb.parse.siggen | 
|  | 1475 | dataCaches = self.rqdata.dataCaches | 
|  | 1476 | siggen.dump_sigfn(fn, dataCaches, options) | 
|  | 1477 |  | 
|  | 1478 | def dump_signatures(self, options): | 
|  | 1479 | fns = set() | 
|  | 1480 | bb.note("Reparsing files to collect dependency data") | 
|  | 1481 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1482 | for tid in self.rqdata.runtaskentries: | 
|  | 1483 | fn = fn_from_tid(tid) | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1484 | fns.add(fn) | 
|  | 1485 |  | 
|  | 1486 | max_process = int(self.cfgData.getVar("BB_NUMBER_PARSE_THREADS") or os.cpu_count() or 1) | 
|  | 1487 | # We cannot use the real multiprocessing.Pool easily due to some local data | 
|  | 1488 | # that can't be pickled. This is a cheap multi-process solution. | 
|  | 1489 | launched = [] | 
|  | 1490 | while fns: | 
|  | 1491 | if len(launched) < max_process: | 
|  | 1492 | p = Process(target=self.rq_dump_sigfn, args=(fns.pop(), options)) | 
|  | 1493 | p.start() | 
|  | 1494 | launched.append(p) | 
|  | 1495 | for q in launched: | 
|  | 1496 | # The finished processes are joined when calling is_alive() | 
|  | 1497 | if not q.is_alive(): | 
|  | 1498 | launched.remove(q) | 
|  | 1499 | for p in launched: | 
|  | 1500 | p.join() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1501 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1502 | bb.parse.siggen.dump_sigs(self.rqdata.dataCaches, options) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1503 |  | 
|  | 1504 | return | 
|  | 1505 |  | 
|  | 1506 | def print_diffscenetasks(self): | 
|  | 1507 |  | 
|  | 1508 | valid = [] | 
|  | 1509 | sq_hash = [] | 
|  | 1510 | sq_hashfn = [] | 
|  | 1511 | sq_fn = [] | 
|  | 1512 | sq_taskname = [] | 
|  | 1513 | sq_task = [] | 
|  | 1514 | noexec = [] | 
|  | 1515 | stamppresent = [] | 
|  | 1516 | valid_new = set() | 
|  | 1517 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1518 | for tid in self.rqdata.runtaskentries: | 
|  | 1519 | (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) | 
|  | 1520 | taskdep = self.rqdata.dataCaches[mc].task_deps[taskfn] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1521 |  | 
|  | 1522 | if 'noexec' in taskdep and taskname in taskdep['noexec']: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1523 | noexec.append(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1524 | continue | 
|  | 1525 |  | 
|  | 1526 | sq_fn.append(fn) | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1527 | sq_hashfn.append(self.rqdata.dataCaches[mc].hashfn[taskfn]) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1528 | sq_hash.append(self.rqdata.runtaskentries[tid].hash) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1529 | sq_taskname.append(taskname) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1530 | sq_task.append(tid) | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1531 | locs = { "sq_fn" : sq_fn, "sq_task" : sq_taskname, "sq_hash" : sq_hash, "sq_hashfn" : sq_hashfn, "d" : self.cooker.data } | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1532 | try: | 
|  | 1533 | call = self.hashvalidate + "(sq_fn, sq_task, sq_hash, sq_hashfn, d, siginfo=True)" | 
|  | 1534 | valid = bb.utils.better_eval(call, locs) | 
|  | 1535 | # Handle version with no siginfo parameter | 
|  | 1536 | except TypeError: | 
|  | 1537 | call = self.hashvalidate + "(sq_fn, sq_task, sq_hash, sq_hashfn, d)" | 
|  | 1538 | valid = bb.utils.better_eval(call, locs) | 
|  | 1539 | for v in valid: | 
|  | 1540 | valid_new.add(sq_task[v]) | 
|  | 1541 |  | 
|  | 1542 | # Tasks which are both setscene and noexec never care about dependencies | 
|  | 1543 | # We therefore find tasks which are setscene and noexec and mark their | 
|  | 1544 | # unique dependencies as valid. | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1545 | for tid in noexec: | 
|  | 1546 | if tid not in self.rqdata.runq_setscene_tids: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1547 | continue | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1548 | for dep in self.rqdata.runtaskentries[tid].depends: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1549 | hasnoexecparents = True | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1550 | for dep2 in self.rqdata.runtaskentries[dep].revdeps: | 
|  | 1551 | if dep2 in self.rqdata.runq_setscene_tids and dep2 in noexec: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1552 | continue | 
|  | 1553 | hasnoexecparents = False | 
|  | 1554 | break | 
|  | 1555 | if hasnoexecparents: | 
|  | 1556 | valid_new.add(dep) | 
|  | 1557 |  | 
|  | 1558 | invalidtasks = set() | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1559 | for tid in self.rqdata.runtaskentries: | 
|  | 1560 | if tid not in valid_new and tid not in noexec: | 
|  | 1561 | invalidtasks.add(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1562 |  | 
|  | 1563 | found = set() | 
|  | 1564 | processed = set() | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1565 | for tid in invalidtasks: | 
|  | 1566 | toprocess = set([tid]) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1567 | while toprocess: | 
|  | 1568 | next = set() | 
|  | 1569 | for t in toprocess: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1570 | for dep in self.rqdata.runtaskentries[t].depends: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1571 | if dep in invalidtasks: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1572 | found.add(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1573 | if dep not in processed: | 
|  | 1574 | processed.add(dep) | 
|  | 1575 | next.add(dep) | 
|  | 1576 | toprocess = next | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1577 | if tid in found: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1578 | toprocess = set() | 
|  | 1579 |  | 
|  | 1580 | tasklist = [] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1581 | for tid in invalidtasks.difference(found): | 
|  | 1582 | tasklist.append(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1583 |  | 
|  | 1584 | if tasklist: | 
|  | 1585 | bb.plain("The differences between the current build and any cached tasks start at the following tasks:\n" + "\n".join(tasklist)) | 
|  | 1586 |  | 
|  | 1587 | return invalidtasks.difference(found) | 
|  | 1588 |  | 
|  | 1589 | def write_diffscenetasks(self, invalidtasks): | 
|  | 1590 |  | 
|  | 1591 | # Define recursion callback | 
|  | 1592 | def recursecb(key, hash1, hash2): | 
|  | 1593 | hashes = [hash1, hash2] | 
|  | 1594 | hashfiles = bb.siggen.find_siginfo(key, None, hashes, self.cfgData) | 
|  | 1595 |  | 
|  | 1596 | recout = [] | 
|  | 1597 | if len(hashfiles) == 2: | 
|  | 1598 | out2 = bb.siggen.compare_sigfiles(hashfiles[hash1], hashfiles[hash2], recursecb) | 
|  | 1599 | recout.extend(list('  ' + l for l in out2)) | 
|  | 1600 | else: | 
|  | 1601 | recout.append("Unable to find matching sigdata for %s with hashes %s or %s" % (key, hash1, hash2)) | 
|  | 1602 |  | 
|  | 1603 | return recout | 
|  | 1604 |  | 
|  | 1605 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1606 | for tid in invalidtasks: | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1607 | (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) | 
|  | 1608 | pn = self.rqdata.dataCaches[mc].pkg_fn[taskfn] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1609 | h = self.rqdata.runtaskentries[tid].hash | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1610 | matches = bb.siggen.find_siginfo(pn, taskname, [], self.cfgData) | 
|  | 1611 | match = None | 
|  | 1612 | for m in matches: | 
|  | 1613 | if h in m: | 
|  | 1614 | match = m | 
|  | 1615 | if match is None: | 
|  | 1616 | bb.fatal("Can't find a task we're supposed to have written out? (hash: %s)?" % h) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1617 | matches = {k : v for k, v in iter(matches.items()) if h not in k} | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1618 | if matches: | 
|  | 1619 | latestmatch = sorted(matches.keys(), key=lambda f: matches[f])[-1] | 
|  | 1620 | prevh = __find_md5__.search(latestmatch).group(0) | 
|  | 1621 | output = bb.siggen.compare_sigfiles(latestmatch, match, recursecb) | 
|  | 1622 | bb.plain("\nTask %s:%s couldn't be used from the cache because:\n  We need hash %s, closest matching task was %s\n  " % (pn, taskname, h, prevh) + '\n  '.join(output)) | 
|  | 1623 |  | 
|  | 1624 | class RunQueueExecute: | 
|  | 1625 |  | 
|  | 1626 | def __init__(self, rq): | 
|  | 1627 | self.rq = rq | 
|  | 1628 | self.cooker = rq.cooker | 
|  | 1629 | self.cfgData = rq.cfgData | 
|  | 1630 | self.rqdata = rq.rqdata | 
|  | 1631 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1632 | self.number_tasks = int(self.cfgData.getVar("BB_NUMBER_THREADS") or 1) | 
|  | 1633 | self.scheduler = self.cfgData.getVar("BB_SCHEDULER") or "speed" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1634 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1635 | self.runq_buildable = set() | 
|  | 1636 | self.runq_running = set() | 
|  | 1637 | self.runq_complete = set() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1638 |  | 
|  | 1639 | self.build_stamps = {} | 
|  | 1640 | self.build_stamps2 = [] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1641 | self.failed_tids = [] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1642 |  | 
|  | 1643 | self.stampcache = {} | 
|  | 1644 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1645 | for mc in rq.worker: | 
|  | 1646 | rq.worker[mc].pipe.setrunqueueexec(self) | 
|  | 1647 | for mc in rq.fakeworker: | 
|  | 1648 | rq.fakeworker[mc].pipe.setrunqueueexec(self) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1649 |  | 
|  | 1650 | if self.number_tasks <= 0: | 
|  | 1651 | bb.fatal("Invalid BB_NUMBER_THREADS %s" % self.number_tasks) | 
|  | 1652 |  | 
|  | 1653 | def runqueue_process_waitpid(self, task, status): | 
|  | 1654 |  | 
|  | 1655 | # self.build_stamps[pid] may not exist when use shared work directory. | 
|  | 1656 | if task in self.build_stamps: | 
|  | 1657 | self.build_stamps2.remove(self.build_stamps[task]) | 
|  | 1658 | del self.build_stamps[task] | 
|  | 1659 |  | 
|  | 1660 | if status != 0: | 
|  | 1661 | self.task_fail(task, status) | 
|  | 1662 | else: | 
|  | 1663 | self.task_complete(task) | 
|  | 1664 | return True | 
|  | 1665 |  | 
|  | 1666 | def finish_now(self): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1667 | for mc in self.rq.worker: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1668 | try: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1669 | self.rq.worker[mc].process.stdin.write(b"<finishnow></finishnow>") | 
|  | 1670 | self.rq.worker[mc].process.stdin.flush() | 
|  | 1671 | except IOError: | 
|  | 1672 | # worker must have died? | 
|  | 1673 | pass | 
|  | 1674 | for mc in self.rq.fakeworker: | 
|  | 1675 | try: | 
|  | 1676 | self.rq.fakeworker[mc].process.stdin.write(b"<finishnow></finishnow>") | 
|  | 1677 | self.rq.fakeworker[mc].process.stdin.flush() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1678 | except IOError: | 
|  | 1679 | # worker must have died? | 
|  | 1680 | pass | 
|  | 1681 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1682 | if len(self.failed_tids) != 0: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1683 | self.rq.state = runQueueFailed | 
|  | 1684 | return | 
|  | 1685 |  | 
|  | 1686 | self.rq.state = runQueueComplete | 
|  | 1687 | return | 
|  | 1688 |  | 
|  | 1689 | def finish(self): | 
|  | 1690 | self.rq.state = runQueueCleanUp | 
|  | 1691 |  | 
|  | 1692 | if self.stats.active > 0: | 
|  | 1693 | bb.event.fire(runQueueExitWait(self.stats.active), self.cfgData) | 
|  | 1694 | self.rq.read_workers() | 
|  | 1695 | return self.rq.active_fds() | 
|  | 1696 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1697 | if len(self.failed_tids) != 0: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1698 | self.rq.state = runQueueFailed | 
|  | 1699 | return True | 
|  | 1700 |  | 
|  | 1701 | self.rq.state = runQueueComplete | 
|  | 1702 | return True | 
|  | 1703 |  | 
|  | 1704 | def check_dependencies(self, task, taskdeps, setscene = False): | 
|  | 1705 | if not self.rq.depvalidate: | 
|  | 1706 | return False | 
|  | 1707 |  | 
|  | 1708 | taskdata = {} | 
|  | 1709 | taskdeps.add(task) | 
|  | 1710 | for dep in taskdeps: | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1711 | (mc, fn, taskname, taskfn) = split_tid_mcfn(dep) | 
|  | 1712 | pn = self.rqdata.dataCaches[mc].pkg_fn[taskfn] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1713 | taskdata[dep] = [pn, taskname, fn] | 
|  | 1714 | call = self.rq.depvalidate + "(task, taskdata, notneeded, d)" | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1715 | locs = { "task" : task, "taskdata" : taskdata, "notneeded" : self.scenequeue_notneeded, "d" : self.cooker.data } | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1716 | valid = bb.utils.better_eval(call, locs) | 
|  | 1717 | return valid | 
|  | 1718 |  | 
|  | 1719 | class RunQueueExecuteDummy(RunQueueExecute): | 
|  | 1720 | def __init__(self, rq): | 
|  | 1721 | self.rq = rq | 
|  | 1722 | self.stats = RunQueueStats(0) | 
|  | 1723 |  | 
|  | 1724 | def finish(self): | 
|  | 1725 | self.rq.state = runQueueComplete | 
|  | 1726 | return | 
|  | 1727 |  | 
|  | 1728 | class RunQueueExecuteTasks(RunQueueExecute): | 
|  | 1729 | def __init__(self, rq): | 
|  | 1730 | RunQueueExecute.__init__(self, rq) | 
|  | 1731 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1732 | self.stats = RunQueueStats(len(self.rqdata.runtaskentries)) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1733 |  | 
|  | 1734 | self.stampcache = {} | 
|  | 1735 |  | 
|  | 1736 | initial_covered = self.rq.scenequeue_covered.copy() | 
|  | 1737 |  | 
|  | 1738 | # Mark initial buildable tasks | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1739 | for tid in self.rqdata.runtaskentries: | 
|  | 1740 | if len(self.rqdata.runtaskentries[tid].depends) == 0: | 
|  | 1741 | self.runq_buildable.add(tid) | 
|  | 1742 | if len(self.rqdata.runtaskentries[tid].revdeps) > 0 and self.rqdata.runtaskentries[tid].revdeps.issubset(self.rq.scenequeue_covered): | 
|  | 1743 | self.rq.scenequeue_covered.add(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1744 |  | 
|  | 1745 | found = True | 
|  | 1746 | while found: | 
|  | 1747 | found = False | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1748 | for tid in self.rqdata.runtaskentries: | 
|  | 1749 | if tid in self.rq.scenequeue_covered: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1750 | continue | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1751 | logger.debug(1, 'Considering %s: %s' % (tid, str(self.rqdata.runtaskentries[tid].revdeps))) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1752 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1753 | if len(self.rqdata.runtaskentries[tid].revdeps) > 0 and self.rqdata.runtaskentries[tid].revdeps.issubset(self.rq.scenequeue_covered): | 
|  | 1754 | if tid in self.rq.scenequeue_notcovered: | 
|  | 1755 | continue | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1756 | found = True | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1757 | self.rq.scenequeue_covered.add(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1758 |  | 
|  | 1759 | logger.debug(1, 'Skip list (pre setsceneverify) %s', sorted(self.rq.scenequeue_covered)) | 
|  | 1760 |  | 
|  | 1761 | # Allow the metadata to elect for setscene tasks to run anyway | 
|  | 1762 | covered_remove = set() | 
|  | 1763 | if self.rq.setsceneverify: | 
|  | 1764 | invalidtasks = [] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1765 | tasknames = {} | 
|  | 1766 | fns = {} | 
|  | 1767 | for tid in self.rqdata.runtaskentries: | 
|  | 1768 | (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) | 
|  | 1769 | taskdep = self.rqdata.dataCaches[mc].task_deps[taskfn] | 
|  | 1770 | fns[tid] = taskfn | 
|  | 1771 | tasknames[tid] = taskname | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1772 | if 'noexec' in taskdep and taskname in taskdep['noexec']: | 
|  | 1773 | continue | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1774 | if self.rq.check_stamp_task(tid, taskname + "_setscene", cache=self.stampcache): | 
|  | 1775 | logger.debug(2, 'Setscene stamp current for task %s', tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1776 | continue | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1777 | if self.rq.check_stamp_task(tid, taskname, recurse = True, cache=self.stampcache): | 
|  | 1778 | logger.debug(2, 'Normal stamp current for task %s', tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1779 | continue | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1780 | invalidtasks.append(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1781 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1782 | call = self.rq.setsceneverify + "(covered, tasknames, fns, d, invalidtasks=invalidtasks)" | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1783 | locs = { "covered" : self.rq.scenequeue_covered, "tasknames" : tasknames, "fns" : fns, "d" : self.cooker.data, "invalidtasks" : invalidtasks } | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1784 | covered_remove = bb.utils.better_eval(call, locs) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1785 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1786 | def removecoveredtask(tid): | 
|  | 1787 | (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) | 
|  | 1788 | taskname = taskname + '_setscene' | 
|  | 1789 | bb.build.del_stamp(taskname, self.rqdata.dataCaches[mc], taskfn) | 
|  | 1790 | self.rq.scenequeue_covered.remove(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1791 |  | 
|  | 1792 | toremove = covered_remove | 
|  | 1793 | for task in toremove: | 
|  | 1794 | logger.debug(1, 'Not skipping task %s due to setsceneverify', task) | 
|  | 1795 | while toremove: | 
|  | 1796 | covered_remove = [] | 
|  | 1797 | for task in toremove: | 
|  | 1798 | removecoveredtask(task) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1799 | for deptask in self.rqdata.runtaskentries[task].depends: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1800 | if deptask not in self.rq.scenequeue_covered: | 
|  | 1801 | continue | 
|  | 1802 | if deptask in toremove or deptask in covered_remove or deptask in initial_covered: | 
|  | 1803 | continue | 
|  | 1804 | logger.debug(1, 'Task %s depends on task %s so not skipping' % (task, deptask)) | 
|  | 1805 | covered_remove.append(deptask) | 
|  | 1806 | toremove = covered_remove | 
|  | 1807 |  | 
|  | 1808 | logger.debug(1, 'Full skip list %s', self.rq.scenequeue_covered) | 
|  | 1809 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1810 |  | 
|  | 1811 | for mc in self.rqdata.dataCaches: | 
|  | 1812 | target_pairs = [] | 
|  | 1813 | for tid in self.rqdata.target_tids: | 
|  | 1814 | (tidmc, fn, taskname, _) = split_tid_mcfn(tid) | 
|  | 1815 | if tidmc == mc: | 
|  | 1816 | target_pairs.append((fn, taskname)) | 
|  | 1817 |  | 
|  | 1818 | event.fire(bb.event.StampUpdate(target_pairs, self.rqdata.dataCaches[mc].stamp), self.cfgData) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1819 |  | 
|  | 1820 | schedulers = self.get_schedulers() | 
|  | 1821 | for scheduler in schedulers: | 
|  | 1822 | if self.scheduler == scheduler.name: | 
|  | 1823 | self.sched = scheduler(self, self.rqdata) | 
|  | 1824 | logger.debug(1, "Using runqueue scheduler '%s'", scheduler.name) | 
|  | 1825 | break | 
|  | 1826 | else: | 
|  | 1827 | bb.fatal("Invalid scheduler '%s'.  Available schedulers: %s" % | 
|  | 1828 | (self.scheduler, ", ".join(obj.name for obj in schedulers))) | 
|  | 1829 |  | 
|  | 1830 | def get_schedulers(self): | 
|  | 1831 | schedulers = set(obj for obj in globals().values() | 
|  | 1832 | if type(obj) is type and | 
|  | 1833 | issubclass(obj, RunQueueScheduler)) | 
|  | 1834 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1835 | user_schedulers = self.cfgData.getVar("BB_SCHEDULERS") | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1836 | if user_schedulers: | 
|  | 1837 | for sched in user_schedulers.split(): | 
|  | 1838 | if not "." in sched: | 
|  | 1839 | bb.note("Ignoring scheduler '%s' from BB_SCHEDULERS: not an import" % sched) | 
|  | 1840 | continue | 
|  | 1841 |  | 
|  | 1842 | modname, name = sched.rsplit(".", 1) | 
|  | 1843 | try: | 
|  | 1844 | module = __import__(modname, fromlist=(name,)) | 
|  | 1845 | except ImportError as exc: | 
|  | 1846 | logger.critical("Unable to import scheduler '%s' from '%s': %s" % (name, modname, exc)) | 
|  | 1847 | raise SystemExit(1) | 
|  | 1848 | else: | 
|  | 1849 | schedulers.add(getattr(module, name)) | 
|  | 1850 | return schedulers | 
|  | 1851 |  | 
|  | 1852 | def setbuildable(self, task): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1853 | self.runq_buildable.add(task) | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1854 | self.sched.newbuildable(task) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1855 |  | 
|  | 1856 | def task_completeoutright(self, task): | 
|  | 1857 | """ | 
|  | 1858 | Mark a task as completed | 
|  | 1859 | Look at the reverse dependencies and mark any task with | 
|  | 1860 | completed dependencies as buildable | 
|  | 1861 | """ | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1862 | self.runq_complete.add(task) | 
|  | 1863 | for revdep in self.rqdata.runtaskentries[task].revdeps: | 
|  | 1864 | if revdep in self.runq_running: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1865 | continue | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1866 | if revdep in self.runq_buildable: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1867 | continue | 
|  | 1868 | alldeps = 1 | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1869 | for dep in self.rqdata.runtaskentries[revdep].depends: | 
|  | 1870 | if dep not in self.runq_complete: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1871 | alldeps = 0 | 
|  | 1872 | if alldeps == 1: | 
|  | 1873 | self.setbuildable(revdep) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1874 | fn = fn_from_tid(revdep) | 
|  | 1875 | taskname = taskname_from_tid(revdep) | 
|  | 1876 | logger.debug(1, "Marking task %s as buildable", revdep) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1877 |  | 
|  | 1878 | def task_complete(self, task): | 
|  | 1879 | self.stats.taskCompleted() | 
|  | 1880 | bb.event.fire(runQueueTaskCompleted(task, self.stats, self.rq), self.cfgData) | 
|  | 1881 | self.task_completeoutright(task) | 
|  | 1882 |  | 
|  | 1883 | def task_fail(self, task, exitcode): | 
|  | 1884 | """ | 
|  | 1885 | Called when a task has failed | 
|  | 1886 | Updates the state engine with the failure | 
|  | 1887 | """ | 
|  | 1888 | self.stats.taskFailed() | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1889 | self.failed_tids.append(task) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1890 | bb.event.fire(runQueueTaskFailed(task, self.stats, exitcode, self.rq), self.cfgData) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1891 | if self.rqdata.taskData[''].abort: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1892 | self.rq.state = runQueueCleanUp | 
|  | 1893 |  | 
|  | 1894 | def task_skip(self, task, reason): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1895 | self.runq_running.add(task) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1896 | self.setbuildable(task) | 
|  | 1897 | bb.event.fire(runQueueTaskSkipped(task, self.stats, self.rq, reason), self.cfgData) | 
|  | 1898 | self.task_completeoutright(task) | 
|  | 1899 | self.stats.taskCompleted() | 
|  | 1900 | self.stats.taskSkipped() | 
|  | 1901 |  | 
|  | 1902 | def execute(self): | 
|  | 1903 | """ | 
|  | 1904 | Run the tasks in a queue prepared by rqdata.prepare() | 
|  | 1905 | """ | 
|  | 1906 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1907 | if self.rqdata.setscenewhitelist is not None and not self.rqdata.setscenewhitelist_checked: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1908 | self.rqdata.setscenewhitelist_checked = True | 
|  | 1909 |  | 
|  | 1910 | # Check tasks that are going to run against the whitelist | 
|  | 1911 | def check_norun_task(tid, showerror=False): | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1912 | (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1913 | # Ignore covered tasks | 
|  | 1914 | if tid in self.rq.scenequeue_covered: | 
|  | 1915 | return False | 
|  | 1916 | # Ignore stamped tasks | 
|  | 1917 | if self.rq.check_stamp_task(tid, taskname, cache=self.stampcache): | 
|  | 1918 | return False | 
|  | 1919 | # Ignore noexec tasks | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1920 | taskdep = self.rqdata.dataCaches[mc].task_deps[taskfn] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1921 | if 'noexec' in taskdep and taskname in taskdep['noexec']: | 
|  | 1922 | return False | 
|  | 1923 |  | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1924 | pn = self.rqdata.dataCaches[mc].pkg_fn[taskfn] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1925 | if not check_setscene_enforce_whitelist(pn, taskname, self.rqdata.setscenewhitelist): | 
|  | 1926 | if showerror: | 
|  | 1927 | if tid in self.rqdata.runq_setscene_tids: | 
|  | 1928 | logger.error('Task %s.%s attempted to execute unexpectedly and should have been setscened' % (pn, taskname)) | 
|  | 1929 | else: | 
|  | 1930 | logger.error('Task %s.%s attempted to execute unexpectedly' % (pn, taskname)) | 
|  | 1931 | return True | 
|  | 1932 | return False | 
|  | 1933 | # Look to see if any tasks that we think shouldn't run are going to | 
|  | 1934 | unexpected = False | 
|  | 1935 | for tid in self.rqdata.runtaskentries: | 
|  | 1936 | if check_norun_task(tid): | 
|  | 1937 | unexpected = True | 
|  | 1938 | break | 
|  | 1939 | if unexpected: | 
|  | 1940 | # Run through the tasks in the rough order they'd have executed and print errors | 
|  | 1941 | # (since the order can be useful - usually missing sstate for the last few tasks | 
|  | 1942 | # is the cause of the problem) | 
|  | 1943 | task = self.sched.next() | 
|  | 1944 | while task is not None: | 
|  | 1945 | check_norun_task(task, showerror=True) | 
|  | 1946 | self.task_skip(task, 'Setscene enforcement check') | 
|  | 1947 | task = self.sched.next() | 
|  | 1948 |  | 
|  | 1949 | self.rq.state = runQueueCleanUp | 
|  | 1950 | return True | 
|  | 1951 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1952 | self.rq.read_workers() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1953 |  | 
|  | 1954 | if self.stats.total == 0: | 
|  | 1955 | # nothing to do | 
|  | 1956 | self.rq.state = runQueueCleanUp | 
|  | 1957 |  | 
|  | 1958 | task = self.sched.next() | 
|  | 1959 | if task is not None: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1960 | (mc, fn, taskname, taskfn) = split_tid_mcfn(task) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1961 |  | 
|  | 1962 | if task in self.rq.scenequeue_covered: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1963 | logger.debug(2, "Setscene covered task %s", task) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1964 | self.task_skip(task, "covered") | 
|  | 1965 | return True | 
|  | 1966 |  | 
|  | 1967 | if self.rq.check_stamp_task(task, taskname, cache=self.stampcache): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1968 | logger.debug(2, "Stamp current task %s", task) | 
|  | 1969 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1970 | self.task_skip(task, "existing") | 
|  | 1971 | return True | 
|  | 1972 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1973 | taskdep = self.rqdata.dataCaches[mc].task_deps[taskfn] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1974 | if 'noexec' in taskdep and taskname in taskdep['noexec']: | 
|  | 1975 | startevent = runQueueTaskStarted(task, self.stats, self.rq, | 
|  | 1976 | noexec=True) | 
|  | 1977 | bb.event.fire(startevent, self.cfgData) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1978 | self.runq_running.add(task) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1979 | self.stats.taskActive() | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1980 | if not (self.cooker.configuration.dry_run or self.rqdata.setscene_enforce): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1981 | bb.build.make_stamp(taskname, self.rqdata.dataCaches[mc], taskfn) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1982 | self.task_complete(task) | 
|  | 1983 | return True | 
|  | 1984 | else: | 
|  | 1985 | startevent = runQueueTaskStarted(task, self.stats, self.rq) | 
|  | 1986 | bb.event.fire(startevent, self.cfgData) | 
|  | 1987 |  | 
|  | 1988 | taskdepdata = self.build_taskdepdata(task) | 
|  | 1989 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1990 | taskdep = self.rqdata.dataCaches[mc].task_deps[taskfn] | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1991 | if 'fakeroot' in taskdep and taskname in taskdep['fakeroot'] and not (self.cooker.configuration.dry_run or self.rqdata.setscene_enforce): | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1992 | if not mc in self.rq.fakeworker: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1993 | try: | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1994 | self.rq.start_fakeworker(self, mc) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1995 | except OSError as exc: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1996 | logger.critical("Failed to spawn fakeroot worker to run %s: %s" % (task, str(exc))) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1997 | self.rq.state = runQueueFailed | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1998 | self.stats.taskFailed() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1999 | return True | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2000 | self.rq.fakeworker[mc].process.stdin.write(b"<runtask>" + pickle.dumps((taskfn, task, taskname, False, self.cooker.collection.get_file_appends(taskfn), taskdepdata, self.rqdata.setscene_enforce)) + b"</runtask>") | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2001 | self.rq.fakeworker[mc].process.stdin.flush() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2002 | else: | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2003 | self.rq.worker[mc].process.stdin.write(b"<runtask>" + pickle.dumps((taskfn, task, taskname, False, self.cooker.collection.get_file_appends(taskfn), taskdepdata, self.rqdata.setscene_enforce)) + b"</runtask>") | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2004 | self.rq.worker[mc].process.stdin.flush() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2005 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2006 | self.build_stamps[task] = bb.build.stampfile(taskname, self.rqdata.dataCaches[mc], taskfn, noextra=True) | 
|  | 2007 | self.build_stamps2.append(self.build_stamps[task]) | 
|  | 2008 | self.runq_running.add(task) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2009 | self.stats.taskActive() | 
|  | 2010 | if self.stats.active < self.number_tasks: | 
|  | 2011 | return True | 
|  | 2012 |  | 
|  | 2013 | if self.stats.active > 0: | 
|  | 2014 | self.rq.read_workers() | 
|  | 2015 | return self.rq.active_fds() | 
|  | 2016 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2017 | if len(self.failed_tids) != 0: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2018 | self.rq.state = runQueueFailed | 
|  | 2019 | return True | 
|  | 2020 |  | 
|  | 2021 | # Sanity Checks | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2022 | for task in self.rqdata.runtaskentries: | 
|  | 2023 | if task not in self.runq_buildable: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2024 | logger.error("Task %s never buildable!", task) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2025 | if task not in self.runq_running: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2026 | logger.error("Task %s never ran!", task) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2027 | if task not in self.runq_complete: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2028 | logger.error("Task %s never completed!", task) | 
|  | 2029 | self.rq.state = runQueueComplete | 
|  | 2030 |  | 
|  | 2031 | return True | 
|  | 2032 |  | 
|  | 2033 | def build_taskdepdata(self, task): | 
|  | 2034 | taskdepdata = {} | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2035 | next = self.rqdata.runtaskentries[task].depends | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2036 | next.add(task) | 
|  | 2037 | while next: | 
|  | 2038 | additional = [] | 
|  | 2039 | for revdep in next: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2040 | (mc, fn, taskname, taskfn) = split_tid_mcfn(revdep) | 
|  | 2041 | pn = self.rqdata.dataCaches[mc].pkg_fn[taskfn] | 
|  | 2042 | deps = self.rqdata.runtaskentries[revdep].depends | 
|  | 2043 | provides = self.rqdata.dataCaches[mc].fn_provides[taskfn] | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2044 | taskhash = self.rqdata.runtaskentries[revdep].hash | 
|  | 2045 | taskdepdata[revdep] = [pn, taskname, fn, deps, provides, taskhash] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2046 | for revdep2 in deps: | 
|  | 2047 | if revdep2 not in taskdepdata: | 
|  | 2048 | additional.append(revdep2) | 
|  | 2049 | next = additional | 
|  | 2050 |  | 
|  | 2051 | #bb.note("Task %s: " % task + str(taskdepdata).replace("], ", "],\n")) | 
|  | 2052 | return taskdepdata | 
|  | 2053 |  | 
|  | 2054 | class RunQueueExecuteScenequeue(RunQueueExecute): | 
|  | 2055 | def __init__(self, rq): | 
|  | 2056 | RunQueueExecute.__init__(self, rq) | 
|  | 2057 |  | 
|  | 2058 | self.scenequeue_covered = set() | 
|  | 2059 | self.scenequeue_notcovered = set() | 
|  | 2060 | self.scenequeue_notneeded = set() | 
|  | 2061 |  | 
|  | 2062 | # If we don't have any setscene functions, skip this step | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2063 | if len(self.rqdata.runq_setscene_tids) == 0: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2064 | rq.scenequeue_covered = set() | 
|  | 2065 | rq.state = runQueueRunInit | 
|  | 2066 | return | 
|  | 2067 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2068 | self.stats = RunQueueStats(len(self.rqdata.runq_setscene_tids)) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2069 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2070 | sq_revdeps = {} | 
|  | 2071 | sq_revdeps_new = {} | 
|  | 2072 | sq_revdeps_squash = {} | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2073 | self.sq_harddeps = {} | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 2074 | self.stamps = {} | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2075 |  | 
|  | 2076 | # We need to construct a dependency graph for the setscene functions. Intermediate | 
|  | 2077 | # dependencies between the setscene tasks only complicate the code. This code | 
|  | 2078 | # therefore aims to collapse the huge runqueue dependency tree into a smaller one | 
|  | 2079 | # only containing the setscene functions. | 
|  | 2080 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2081 | self.rqdata.init_progress_reporter.next_stage() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2082 |  | 
|  | 2083 | # First process the chains up to the first setscene task. | 
|  | 2084 | endpoints = {} | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2085 | for tid in self.rqdata.runtaskentries: | 
|  | 2086 | sq_revdeps[tid] = copy.copy(self.rqdata.runtaskentries[tid].revdeps) | 
|  | 2087 | sq_revdeps_new[tid] = set() | 
|  | 2088 | if (len(sq_revdeps[tid]) == 0) and tid not in self.rqdata.runq_setscene_tids: | 
|  | 2089 | #bb.warn("Added endpoint %s" % (tid)) | 
|  | 2090 | endpoints[tid] = set() | 
|  | 2091 |  | 
|  | 2092 | self.rqdata.init_progress_reporter.next_stage() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2093 |  | 
|  | 2094 | # Secondly process the chains between setscene tasks. | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2095 | for tid in self.rqdata.runq_setscene_tids: | 
|  | 2096 | #bb.warn("Added endpoint 2 %s" % (tid)) | 
|  | 2097 | for dep in self.rqdata.runtaskentries[tid].depends: | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2098 | if tid in sq_revdeps[dep]: | 
|  | 2099 | sq_revdeps[dep].remove(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2100 | if dep not in endpoints: | 
|  | 2101 | endpoints[dep] = set() | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2102 | #bb.warn("  Added endpoint 3 %s" % (dep)) | 
|  | 2103 | endpoints[dep].add(tid) | 
|  | 2104 |  | 
|  | 2105 | self.rqdata.init_progress_reporter.next_stage() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2106 |  | 
|  | 2107 | def process_endpoints(endpoints): | 
|  | 2108 | newendpoints = {} | 
|  | 2109 | for point, task in endpoints.items(): | 
|  | 2110 | tasks = set() | 
|  | 2111 | if task: | 
|  | 2112 | tasks |= task | 
|  | 2113 | if sq_revdeps_new[point]: | 
|  | 2114 | tasks |= sq_revdeps_new[point] | 
|  | 2115 | sq_revdeps_new[point] = set() | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2116 | if point in self.rqdata.runq_setscene_tids: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2117 | sq_revdeps_new[point] = tasks | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 2118 | tasks = set() | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2119 | continue | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2120 | for dep in self.rqdata.runtaskentries[point].depends: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2121 | if point in sq_revdeps[dep]: | 
|  | 2122 | sq_revdeps[dep].remove(point) | 
|  | 2123 | if tasks: | 
|  | 2124 | sq_revdeps_new[dep] |= tasks | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2125 | if len(sq_revdeps[dep]) == 0 and dep not in self.rqdata.runq_setscene_tids: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2126 | newendpoints[dep] = task | 
|  | 2127 | if len(newendpoints) != 0: | 
|  | 2128 | process_endpoints(newendpoints) | 
|  | 2129 |  | 
|  | 2130 | process_endpoints(endpoints) | 
|  | 2131 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2132 | self.rqdata.init_progress_reporter.next_stage() | 
|  | 2133 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2134 | # Build a list of setscene tasks which are "unskippable" | 
|  | 2135 | # These are direct endpoints referenced by the build | 
|  | 2136 | endpoints2 = {} | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2137 | sq_revdeps2 = {} | 
|  | 2138 | sq_revdeps_new2 = {} | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2139 | def process_endpoints2(endpoints): | 
|  | 2140 | newendpoints = {} | 
|  | 2141 | for point, task in endpoints.items(): | 
|  | 2142 | tasks = set([point]) | 
|  | 2143 | if task: | 
|  | 2144 | tasks |= task | 
|  | 2145 | if sq_revdeps_new2[point]: | 
|  | 2146 | tasks |= sq_revdeps_new2[point] | 
|  | 2147 | sq_revdeps_new2[point] = set() | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2148 | if point in self.rqdata.runq_setscene_tids: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2149 | sq_revdeps_new2[point] = tasks | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2150 | for dep in self.rqdata.runtaskentries[point].depends: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2151 | if point in sq_revdeps2[dep]: | 
|  | 2152 | sq_revdeps2[dep].remove(point) | 
|  | 2153 | if tasks: | 
|  | 2154 | sq_revdeps_new2[dep] |= tasks | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2155 | if (len(sq_revdeps2[dep]) == 0 or len(sq_revdeps_new2[dep]) != 0) and dep not in self.rqdata.runq_setscene_tids: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2156 | newendpoints[dep] = tasks | 
|  | 2157 | if len(newendpoints) != 0: | 
|  | 2158 | process_endpoints2(newendpoints) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2159 | for tid in self.rqdata.runtaskentries: | 
|  | 2160 | sq_revdeps2[tid] = copy.copy(self.rqdata.runtaskentries[tid].revdeps) | 
|  | 2161 | sq_revdeps_new2[tid] = set() | 
|  | 2162 | if (len(sq_revdeps2[tid]) == 0) and tid not in self.rqdata.runq_setscene_tids: | 
|  | 2163 | endpoints2[tid] = set() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2164 | process_endpoints2(endpoints2) | 
|  | 2165 | self.unskippable = [] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2166 | for tid in self.rqdata.runq_setscene_tids: | 
|  | 2167 | if sq_revdeps_new2[tid]: | 
|  | 2168 | self.unskippable.append(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2169 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2170 | self.rqdata.init_progress_reporter.next_stage(len(self.rqdata.runtaskentries)) | 
|  | 2171 |  | 
|  | 2172 | for taskcounter, tid in enumerate(self.rqdata.runtaskentries): | 
|  | 2173 | if tid in self.rqdata.runq_setscene_tids: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2174 | deps = set() | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2175 | for dep in sq_revdeps_new[tid]: | 
|  | 2176 | deps.add(dep) | 
|  | 2177 | sq_revdeps_squash[tid] = deps | 
|  | 2178 | elif len(sq_revdeps_new[tid]) != 0: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2179 | bb.msg.fatal("RunQueue", "Something went badly wrong during scenequeue generation, aborting. Please report this problem.") | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2180 | self.rqdata.init_progress_reporter.update(taskcounter) | 
|  | 2181 |  | 
|  | 2182 | self.rqdata.init_progress_reporter.next_stage() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2183 |  | 
|  | 2184 | # Resolve setscene inter-task dependencies | 
|  | 2185 | # e.g. do_sometask_setscene[depends] = "targetname:do_someothertask_setscene" | 
|  | 2186 | # Note that anything explicitly depended upon will have its reverse dependencies removed to avoid circular dependencies | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2187 | for tid in self.rqdata.runq_setscene_tids: | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 2188 | (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) | 
|  | 2189 | realtid = tid + "_setscene" | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2190 | idepends = self.rqdata.taskData[mc].taskentries[realtid].idepends | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 2191 | self.stamps[tid] = bb.build.stampfile(taskname + "_setscene", self.rqdata.dataCaches[mc], taskfn, noextra=True) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2192 | for (depname, idependtask) in idepends: | 
|  | 2193 |  | 
|  | 2194 | if depname not in self.rqdata.taskData[mc].build_targets: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2195 | continue | 
|  | 2196 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2197 | depfn = self.rqdata.taskData[mc].build_targets[depname][0] | 
|  | 2198 | if depfn is None: | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2199 | continue | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2200 | deptid = depfn + ":" + idependtask.replace("_setscene", "") | 
|  | 2201 | if deptid not in self.rqdata.runtaskentries: | 
|  | 2202 | bb.msg.fatal("RunQueue", "Task %s depends upon non-existent task %s:%s" % (realtid, depfn, idependtask)) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2203 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2204 | if not deptid in self.sq_harddeps: | 
|  | 2205 | self.sq_harddeps[deptid] = set() | 
|  | 2206 | self.sq_harddeps[deptid].add(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2207 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2208 | sq_revdeps_squash[tid].add(deptid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2209 | # Have to zero this to avoid circular dependencies | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2210 | sq_revdeps_squash[deptid] = set() | 
|  | 2211 |  | 
|  | 2212 | self.rqdata.init_progress_reporter.next_stage() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2213 |  | 
|  | 2214 | for task in self.sq_harddeps: | 
|  | 2215 | for dep in self.sq_harddeps[task]: | 
|  | 2216 | sq_revdeps_squash[dep].add(task) | 
|  | 2217 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2218 | self.rqdata.init_progress_reporter.next_stage() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2219 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2220 | #for tid in sq_revdeps_squash: | 
|  | 2221 | #    for dep in sq_revdeps_squash[tid]: | 
|  | 2222 | #        data = data + "\n   %s" % dep | 
|  | 2223 | #    bb.warn("Task %s_setscene: is %s " % (tid, data | 
|  | 2224 |  | 
|  | 2225 | self.sq_deps = {} | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2226 | self.sq_revdeps = sq_revdeps_squash | 
|  | 2227 | self.sq_revdeps2 = copy.deepcopy(self.sq_revdeps) | 
|  | 2228 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2229 | for tid in self.sq_revdeps: | 
|  | 2230 | self.sq_deps[tid] = set() | 
|  | 2231 | for tid in self.sq_revdeps: | 
|  | 2232 | for dep in self.sq_revdeps[tid]: | 
|  | 2233 | self.sq_deps[dep].add(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2234 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2235 | self.rqdata.init_progress_reporter.next_stage() | 
|  | 2236 |  | 
|  | 2237 | for tid in self.sq_revdeps: | 
|  | 2238 | if len(self.sq_revdeps[tid]) == 0: | 
|  | 2239 | self.runq_buildable.add(tid) | 
|  | 2240 |  | 
|  | 2241 | self.rqdata.init_progress_reporter.finish() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2242 |  | 
|  | 2243 | self.outrightfail = [] | 
|  | 2244 | if self.rq.hashvalidate: | 
|  | 2245 | sq_hash = [] | 
|  | 2246 | sq_hashfn = [] | 
|  | 2247 | sq_fn = [] | 
|  | 2248 | sq_taskname = [] | 
|  | 2249 | sq_task = [] | 
|  | 2250 | noexec = [] | 
|  | 2251 | stamppresent = [] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2252 | for tid in self.sq_revdeps: | 
|  | 2253 | (mc, fn, taskname, taskfn) = split_tid_mcfn(tid) | 
|  | 2254 |  | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 2255 | taskdep = self.rqdata.dataCaches[mc].task_deps[taskfn] | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2256 |  | 
|  | 2257 | if 'noexec' in taskdep and taskname in taskdep['noexec']: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2258 | noexec.append(tid) | 
|  | 2259 | self.task_skip(tid) | 
|  | 2260 | bb.build.make_stamp(taskname + "_setscene", self.rqdata.dataCaches[mc], taskfn) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2261 | continue | 
|  | 2262 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2263 | if self.rq.check_stamp_task(tid, taskname + "_setscene", cache=self.stampcache): | 
|  | 2264 | logger.debug(2, 'Setscene stamp current for task %s', tid) | 
|  | 2265 | stamppresent.append(tid) | 
|  | 2266 | self.task_skip(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2267 | continue | 
|  | 2268 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2269 | if self.rq.check_stamp_task(tid, taskname, recurse = True, cache=self.stampcache): | 
|  | 2270 | logger.debug(2, 'Normal stamp current for task %s', tid) | 
|  | 2271 | stamppresent.append(tid) | 
|  | 2272 | self.task_skip(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2273 | continue | 
|  | 2274 |  | 
|  | 2275 | sq_fn.append(fn) | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 2276 | sq_hashfn.append(self.rqdata.dataCaches[mc].hashfn[taskfn]) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2277 | sq_hash.append(self.rqdata.runtaskentries[tid].hash) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2278 | sq_taskname.append(taskname) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2279 | sq_task.append(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2280 | call = self.rq.hashvalidate + "(sq_fn, sq_task, sq_hash, sq_hashfn, d)" | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2281 | locs = { "sq_fn" : sq_fn, "sq_task" : sq_taskname, "sq_hash" : sq_hash, "sq_hashfn" : sq_hashfn, "d" : self.cooker.data } | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2282 | valid = bb.utils.better_eval(call, locs) | 
|  | 2283 |  | 
|  | 2284 | valid_new = stamppresent | 
|  | 2285 | for v in valid: | 
|  | 2286 | valid_new.append(sq_task[v]) | 
|  | 2287 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2288 | for tid in self.sq_revdeps: | 
|  | 2289 | if tid not in valid_new and tid not in noexec: | 
|  | 2290 | logger.debug(2, 'No package found, so skipping setscene task %s', tid) | 
|  | 2291 | self.outrightfail.append(tid) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2292 |  | 
|  | 2293 | logger.info('Executing SetScene Tasks') | 
|  | 2294 |  | 
|  | 2295 | self.rq.state = runQueueSceneRun | 
|  | 2296 |  | 
|  | 2297 | def scenequeue_updatecounters(self, task, fail = False): | 
|  | 2298 | for dep in self.sq_deps[task]: | 
|  | 2299 | if fail and task in self.sq_harddeps and dep in self.sq_harddeps[task]: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2300 | logger.debug(2, "%s was unavailable and is a hard dependency of %s so skipping" % (task, dep)) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2301 | self.scenequeue_updatecounters(dep, fail) | 
|  | 2302 | continue | 
|  | 2303 | if task not in self.sq_revdeps2[dep]: | 
|  | 2304 | # May already have been removed by the fail case above | 
|  | 2305 | continue | 
|  | 2306 | self.sq_revdeps2[dep].remove(task) | 
|  | 2307 | if len(self.sq_revdeps2[dep]) == 0: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2308 | self.runq_buildable.add(dep) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2309 |  | 
|  | 2310 | def task_completeoutright(self, task): | 
|  | 2311 | """ | 
|  | 2312 | Mark a task as completed | 
|  | 2313 | Look at the reverse dependencies and mark any task with | 
|  | 2314 | completed dependencies as buildable | 
|  | 2315 | """ | 
|  | 2316 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2317 | logger.debug(1, 'Found task %s which could be accelerated', task) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2318 | self.scenequeue_covered.add(task) | 
|  | 2319 | self.scenequeue_updatecounters(task) | 
|  | 2320 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2321 | def check_taskfail(self, task): | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2322 | if self.rqdata.setscenewhitelist is not None: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2323 | realtask = task.split('_setscene')[0] | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 2324 | (mc, fn, taskname, taskfn) = split_tid_mcfn(realtask) | 
|  | 2325 | pn = self.rqdata.dataCaches[mc].pkg_fn[taskfn] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2326 | if not check_setscene_enforce_whitelist(pn, taskname, self.rqdata.setscenewhitelist): | 
|  | 2327 | logger.error('Task %s.%s failed' % (pn, taskname + "_setscene")) | 
|  | 2328 | self.rq.state = runQueueCleanUp | 
|  | 2329 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2330 | def task_complete(self, task): | 
|  | 2331 | self.stats.taskCompleted() | 
|  | 2332 | bb.event.fire(sceneQueueTaskCompleted(task, self.stats, self.rq), self.cfgData) | 
|  | 2333 | self.task_completeoutright(task) | 
|  | 2334 |  | 
|  | 2335 | def task_fail(self, task, result): | 
|  | 2336 | self.stats.taskFailed() | 
|  | 2337 | bb.event.fire(sceneQueueTaskFailed(task, self.stats, result, self), self.cfgData) | 
|  | 2338 | self.scenequeue_notcovered.add(task) | 
|  | 2339 | self.scenequeue_updatecounters(task, True) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2340 | self.check_taskfail(task) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2341 |  | 
|  | 2342 | def task_failoutright(self, task): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2343 | self.runq_running.add(task) | 
|  | 2344 | self.runq_buildable.add(task) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2345 | self.stats.taskCompleted() | 
|  | 2346 | self.stats.taskSkipped() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2347 | self.scenequeue_notcovered.add(task) | 
|  | 2348 | self.scenequeue_updatecounters(task, True) | 
|  | 2349 |  | 
|  | 2350 | def task_skip(self, task): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2351 | self.runq_running.add(task) | 
|  | 2352 | self.runq_buildable.add(task) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2353 | self.task_completeoutright(task) | 
|  | 2354 | self.stats.taskCompleted() | 
|  | 2355 | self.stats.taskSkipped() | 
|  | 2356 |  | 
|  | 2357 | def execute(self): | 
|  | 2358 | """ | 
|  | 2359 | Run the tasks in a queue prepared by prepare_runqueue | 
|  | 2360 | """ | 
|  | 2361 |  | 
|  | 2362 | self.rq.read_workers() | 
|  | 2363 |  | 
|  | 2364 | task = None | 
|  | 2365 | if self.stats.active < self.number_tasks: | 
|  | 2366 | # Find the next setscene to run | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2367 | for nexttask in self.rqdata.runq_setscene_tids: | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 2368 | if nexttask in self.runq_buildable and nexttask not in self.runq_running and self.stamps[nexttask] not in self.build_stamps.values(): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2369 | if nexttask in self.unskippable: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2370 | logger.debug(2, "Setscene task %s is unskippable" % nexttask) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2371 | if nexttask not in self.unskippable and len(self.sq_revdeps[nexttask]) > 0 and self.sq_revdeps[nexttask].issubset(self.scenequeue_covered) and self.check_dependencies(nexttask, self.sq_revdeps[nexttask], True): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2372 | fn = fn_from_tid(nexttask) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2373 | foundtarget = False | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2374 |  | 
|  | 2375 | if nexttask in self.rqdata.target_tids: | 
|  | 2376 | foundtarget = True | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2377 | if not foundtarget: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2378 | logger.debug(2, "Skipping setscene for task %s" % nexttask) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2379 | self.task_skip(nexttask) | 
|  | 2380 | self.scenequeue_notneeded.add(nexttask) | 
|  | 2381 | return True | 
|  | 2382 | if nexttask in self.outrightfail: | 
|  | 2383 | self.task_failoutright(nexttask) | 
|  | 2384 | return True | 
|  | 2385 | task = nexttask | 
|  | 2386 | break | 
|  | 2387 | if task is not None: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2388 | (mc, fn, taskname, taskfn) = split_tid_mcfn(task) | 
|  | 2389 | taskname = taskname + "_setscene" | 
|  | 2390 | if self.rq.check_stamp_task(task, taskname_from_tid(task), recurse = True, cache=self.stampcache): | 
|  | 2391 | logger.debug(2, 'Stamp for underlying task %s is current, so skipping setscene variant', task) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2392 | self.task_failoutright(task) | 
|  | 2393 | return True | 
|  | 2394 |  | 
|  | 2395 | if self.cooker.configuration.force: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2396 | if task in self.rqdata.target_tids: | 
|  | 2397 | self.task_failoutright(task) | 
|  | 2398 | return True | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2399 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2400 | if self.rq.check_stamp_task(task, taskname, cache=self.stampcache): | 
|  | 2401 | logger.debug(2, 'Setscene stamp current task %s, so skip it and its dependencies', task) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2402 | self.task_skip(task) | 
|  | 2403 | return True | 
|  | 2404 |  | 
|  | 2405 | startevent = sceneQueueTaskStarted(task, self.stats, self.rq) | 
|  | 2406 | bb.event.fire(startevent, self.cfgData) | 
|  | 2407 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2408 | taskdepdata = self.build_taskdepdata(task) | 
|  | 2409 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2410 | taskdep = self.rqdata.dataCaches[mc].task_deps[taskfn] | 
|  | 2411 | if 'fakeroot' in taskdep and taskname in taskdep['fakeroot'] and not self.cooker.configuration.dry_run: | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 2412 | if not mc in self.rq.fakeworker: | 
|  | 2413 | self.rq.start_fakeworker(self, mc) | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2414 | self.rq.fakeworker[mc].process.stdin.write(b"<runtask>" + pickle.dumps((taskfn, task, taskname, True, self.cooker.collection.get_file_appends(taskfn), taskdepdata, False)) + b"</runtask>") | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2415 | self.rq.fakeworker[mc].process.stdin.flush() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2416 | else: | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2417 | self.rq.worker[mc].process.stdin.write(b"<runtask>" + pickle.dumps((taskfn, task, taskname, True, self.cooker.collection.get_file_appends(taskfn), taskdepdata, False)) + b"</runtask>") | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2418 | self.rq.worker[mc].process.stdin.flush() | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2419 |  | 
| Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 2420 | self.build_stamps[task] = bb.build.stampfile(taskname, self.rqdata.dataCaches[mc], taskfn, noextra=True) | 
|  | 2421 | self.build_stamps2.append(self.build_stamps[task]) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2422 | self.runq_running.add(task) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2423 | self.stats.taskActive() | 
|  | 2424 | if self.stats.active < self.number_tasks: | 
|  | 2425 | return True | 
|  | 2426 |  | 
|  | 2427 | if self.stats.active > 0: | 
|  | 2428 | self.rq.read_workers() | 
|  | 2429 | return self.rq.active_fds() | 
|  | 2430 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2431 | #for tid in self.sq_revdeps: | 
|  | 2432 | #    if tid not in self.runq_running: | 
|  | 2433 | #        buildable = tid in self.runq_buildable | 
|  | 2434 | #        revdeps = self.sq_revdeps[tid] | 
|  | 2435 | #        bb.warn("Found we didn't run %s %s %s" % (tid, buildable, str(revdeps))) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2436 |  | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2437 | self.rq.scenequeue_covered = self.scenequeue_covered | 
|  | 2438 | self.rq.scenequeue_notcovered = self.scenequeue_notcovered | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2439 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2440 | logger.debug(1, 'We can skip tasks %s', "\n".join(sorted(self.rq.scenequeue_covered))) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2441 |  | 
|  | 2442 | self.rq.state = runQueueRunInit | 
|  | 2443 |  | 
|  | 2444 | completeevent = sceneQueueComplete(self.stats, self.rq) | 
|  | 2445 | bb.event.fire(completeevent, self.cfgData) | 
|  | 2446 |  | 
|  | 2447 | return True | 
|  | 2448 |  | 
|  | 2449 | def runqueue_process_waitpid(self, task, status): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2450 | RunQueueExecute.runqueue_process_waitpid(self, task, status) | 
|  | 2451 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2452 |  | 
|  | 2453 | def build_taskdepdata(self, task): | 
|  | 2454 | def getsetscenedeps(tid): | 
|  | 2455 | deps = set() | 
|  | 2456 | (mc, fn, taskname, _) = split_tid_mcfn(tid) | 
|  | 2457 | realtid = tid + "_setscene" | 
|  | 2458 | idepends = self.rqdata.taskData[mc].taskentries[realtid].idepends | 
|  | 2459 | for (depname, idependtask) in idepends: | 
|  | 2460 | if depname not in self.rqdata.taskData[mc].build_targets: | 
|  | 2461 | continue | 
|  | 2462 |  | 
|  | 2463 | depfn = self.rqdata.taskData[mc].build_targets[depname][0] | 
|  | 2464 | if depfn is None: | 
|  | 2465 | continue | 
|  | 2466 | deptid = depfn + ":" + idependtask.replace("_setscene", "") | 
|  | 2467 | deps.add(deptid) | 
|  | 2468 | return deps | 
|  | 2469 |  | 
|  | 2470 | taskdepdata = {} | 
|  | 2471 | next = getsetscenedeps(task) | 
|  | 2472 | next.add(task) | 
|  | 2473 | while next: | 
|  | 2474 | additional = [] | 
|  | 2475 | for revdep in next: | 
|  | 2476 | (mc, fn, taskname, taskfn) = split_tid_mcfn(revdep) | 
|  | 2477 | pn = self.rqdata.dataCaches[mc].pkg_fn[taskfn] | 
|  | 2478 | deps = getsetscenedeps(revdep) | 
|  | 2479 | provides = self.rqdata.dataCaches[mc].fn_provides[taskfn] | 
|  | 2480 | taskhash = self.rqdata.runtaskentries[revdep].hash | 
|  | 2481 | taskdepdata[revdep] = [pn, taskname, fn, deps, provides, taskhash] | 
|  | 2482 | for revdep2 in deps: | 
|  | 2483 | if revdep2 not in taskdepdata: | 
|  | 2484 | additional.append(revdep2) | 
|  | 2485 | next = additional | 
|  | 2486 |  | 
|  | 2487 | #bb.note("Task %s: " % task + str(taskdepdata).replace("], ", "],\n")) | 
|  | 2488 | return taskdepdata | 
|  | 2489 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2490 | class TaskFailure(Exception): | 
|  | 2491 | """ | 
|  | 2492 | Exception raised when a task in a runqueue fails | 
|  | 2493 | """ | 
|  | 2494 | def __init__(self, x): | 
|  | 2495 | self.args = x | 
|  | 2496 |  | 
|  | 2497 |  | 
|  | 2498 | class runQueueExitWait(bb.event.Event): | 
|  | 2499 | """ | 
|  | 2500 | Event when waiting for task processes to exit | 
|  | 2501 | """ | 
|  | 2502 |  | 
|  | 2503 | def __init__(self, remain): | 
|  | 2504 | self.remain = remain | 
|  | 2505 | self.message = "Waiting for %s active tasks to finish" % remain | 
|  | 2506 | bb.event.Event.__init__(self) | 
|  | 2507 |  | 
|  | 2508 | class runQueueEvent(bb.event.Event): | 
|  | 2509 | """ | 
|  | 2510 | Base runQueue event class | 
|  | 2511 | """ | 
|  | 2512 | def __init__(self, task, stats, rq): | 
|  | 2513 | self.taskid = task | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2514 | self.taskstring = task | 
|  | 2515 | self.taskname = taskname_from_tid(task) | 
|  | 2516 | self.taskfile = fn_from_tid(task) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2517 | self.taskhash = rq.rqdata.get_task_hash(task) | 
|  | 2518 | self.stats = stats.copy() | 
|  | 2519 | bb.event.Event.__init__(self) | 
|  | 2520 |  | 
|  | 2521 | class sceneQueueEvent(runQueueEvent): | 
|  | 2522 | """ | 
|  | 2523 | Base sceneQueue event class | 
|  | 2524 | """ | 
|  | 2525 | def __init__(self, task, stats, rq, noexec=False): | 
|  | 2526 | runQueueEvent.__init__(self, task, stats, rq) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2527 | self.taskstring = task + "_setscene" | 
|  | 2528 | self.taskname = taskname_from_tid(task) + "_setscene" | 
|  | 2529 | self.taskfile = fn_from_tid(task) | 
|  | 2530 | self.taskhash = rq.rqdata.get_task_hash(task) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2531 |  | 
|  | 2532 | class runQueueTaskStarted(runQueueEvent): | 
|  | 2533 | """ | 
|  | 2534 | Event notifying a task was started | 
|  | 2535 | """ | 
|  | 2536 | def __init__(self, task, stats, rq, noexec=False): | 
|  | 2537 | runQueueEvent.__init__(self, task, stats, rq) | 
|  | 2538 | self.noexec = noexec | 
|  | 2539 |  | 
|  | 2540 | class sceneQueueTaskStarted(sceneQueueEvent): | 
|  | 2541 | """ | 
|  | 2542 | Event notifying a setscene task was started | 
|  | 2543 | """ | 
|  | 2544 | def __init__(self, task, stats, rq, noexec=False): | 
|  | 2545 | sceneQueueEvent.__init__(self, task, stats, rq) | 
|  | 2546 | self.noexec = noexec | 
|  | 2547 |  | 
|  | 2548 | class runQueueTaskFailed(runQueueEvent): | 
|  | 2549 | """ | 
|  | 2550 | Event notifying a task failed | 
|  | 2551 | """ | 
|  | 2552 | def __init__(self, task, stats, exitcode, rq): | 
|  | 2553 | runQueueEvent.__init__(self, task, stats, rq) | 
|  | 2554 | self.exitcode = exitcode | 
|  | 2555 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2556 | def __str__(self): | 
|  | 2557 | return "Task (%s) failed with exit code '%s'" % (self.taskstring, self.exitcode) | 
|  | 2558 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2559 | class sceneQueueTaskFailed(sceneQueueEvent): | 
|  | 2560 | """ | 
|  | 2561 | Event notifying a setscene task failed | 
|  | 2562 | """ | 
|  | 2563 | def __init__(self, task, stats, exitcode, rq): | 
|  | 2564 | sceneQueueEvent.__init__(self, task, stats, rq) | 
|  | 2565 | self.exitcode = exitcode | 
|  | 2566 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2567 | def __str__(self): | 
|  | 2568 | return "Setscene task (%s) failed with exit code '%s' - real task will be run instead" % (self.taskstring, self.exitcode) | 
|  | 2569 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2570 | class sceneQueueComplete(sceneQueueEvent): | 
|  | 2571 | """ | 
|  | 2572 | Event when all the sceneQueue tasks are complete | 
|  | 2573 | """ | 
|  | 2574 | def __init__(self, stats, rq): | 
|  | 2575 | self.stats = stats.copy() | 
|  | 2576 | bb.event.Event.__init__(self) | 
|  | 2577 |  | 
|  | 2578 | class runQueueTaskCompleted(runQueueEvent): | 
|  | 2579 | """ | 
|  | 2580 | Event notifying a task completed | 
|  | 2581 | """ | 
|  | 2582 |  | 
|  | 2583 | class sceneQueueTaskCompleted(sceneQueueEvent): | 
|  | 2584 | """ | 
|  | 2585 | Event notifying a setscene task completed | 
|  | 2586 | """ | 
|  | 2587 |  | 
|  | 2588 | class runQueueTaskSkipped(runQueueEvent): | 
|  | 2589 | """ | 
|  | 2590 | Event notifying a task was skipped | 
|  | 2591 | """ | 
|  | 2592 | def __init__(self, task, stats, rq, reason): | 
|  | 2593 | runQueueEvent.__init__(self, task, stats, rq) | 
|  | 2594 | self.reason = reason | 
|  | 2595 |  | 
|  | 2596 | class runQueuePipe(): | 
|  | 2597 | """ | 
|  | 2598 | Abstraction for a pipe between a worker thread and the server | 
|  | 2599 | """ | 
|  | 2600 | def __init__(self, pipein, pipeout, d, rq, rqexec): | 
|  | 2601 | self.input = pipein | 
|  | 2602 | if pipeout: | 
|  | 2603 | pipeout.close() | 
|  | 2604 | bb.utils.nonblockingfd(self.input) | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2605 | self.queue = b"" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2606 | self.d = d | 
|  | 2607 | self.rq = rq | 
|  | 2608 | self.rqexec = rqexec | 
|  | 2609 |  | 
|  | 2610 | def setrunqueueexec(self, rqexec): | 
|  | 2611 | self.rqexec = rqexec | 
|  | 2612 |  | 
|  | 2613 | def read(self): | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2614 | for workers, name in [(self.rq.worker, "Worker"), (self.rq.fakeworker, "Fakeroot")]: | 
|  | 2615 | for worker in workers.values(): | 
|  | 2616 | worker.process.poll() | 
|  | 2617 | if worker.process.returncode is not None and not self.rq.teardown: | 
|  | 2618 | bb.error("%s process (%s) exited unexpectedly (%s), shutting down..." % (name, worker.process.pid, str(worker.process.returncode))) | 
|  | 2619 | self.rq.finish_runqueue(True) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2620 |  | 
|  | 2621 | start = len(self.queue) | 
|  | 2622 | try: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2623 | self.queue = self.queue + (self.input.read(102400) or b"") | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2624 | except (OSError, IOError) as e: | 
|  | 2625 | if e.errno != errno.EAGAIN: | 
|  | 2626 | raise | 
|  | 2627 | end = len(self.queue) | 
|  | 2628 | found = True | 
|  | 2629 | while found and len(self.queue): | 
|  | 2630 | found = False | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2631 | index = self.queue.find(b"</event>") | 
|  | 2632 | while index != -1 and self.queue.startswith(b"<event>"): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2633 | try: | 
|  | 2634 | event = pickle.loads(self.queue[7:index]) | 
|  | 2635 | except ValueError as e: | 
|  | 2636 | bb.msg.fatal("RunQueue", "failed load pickle '%s': '%s'" % (e, self.queue[7:index])) | 
|  | 2637 | bb.event.fire_from_worker(event, self.d) | 
|  | 2638 | found = True | 
|  | 2639 | self.queue = self.queue[index+8:] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2640 | index = self.queue.find(b"</event>") | 
|  | 2641 | index = self.queue.find(b"</exitcode>") | 
|  | 2642 | while index != -1 and self.queue.startswith(b"<exitcode>"): | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2643 | try: | 
|  | 2644 | task, status = pickle.loads(self.queue[10:index]) | 
|  | 2645 | except ValueError as e: | 
|  | 2646 | bb.msg.fatal("RunQueue", "failed load pickle '%s': '%s'" % (e, self.queue[10:index])) | 
|  | 2647 | self.rqexec.runqueue_process_waitpid(task, status) | 
|  | 2648 | found = True | 
|  | 2649 | self.queue = self.queue[index+11:] | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2650 | index = self.queue.find(b"</exitcode>") | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2651 | return (end > start) | 
|  | 2652 |  | 
|  | 2653 | def close(self): | 
|  | 2654 | while self.read(): | 
|  | 2655 | continue | 
|  | 2656 | if len(self.queue) > 0: | 
|  | 2657 | print("Warning, worker left partial message: %s" % self.queue) | 
|  | 2658 | self.input.close() | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2659 |  | 
|  | 2660 | def get_setscene_enforce_whitelist(d): | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2661 | if d.getVar('BB_SETSCENE_ENFORCE') != '1': | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2662 | return None | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2663 | whitelist = (d.getVar("BB_SETSCENE_ENFORCE_WHITELIST") or "").split() | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2664 | outlist = [] | 
|  | 2665 | for item in whitelist[:]: | 
|  | 2666 | if item.startswith('%:'): | 
|  | 2667 | for target in sys.argv[1:]: | 
|  | 2668 | if not target.startswith('-'): | 
|  | 2669 | outlist.append(target.split(':')[0] + ':' + item.split(':')[1]) | 
|  | 2670 | else: | 
|  | 2671 | outlist.append(item) | 
|  | 2672 | return outlist | 
|  | 2673 |  | 
|  | 2674 | def check_setscene_enforce_whitelist(pn, taskname, whitelist): | 
|  | 2675 | import fnmatch | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2676 | if whitelist is not None: | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2677 | item = '%s:%s' % (pn, taskname) | 
|  | 2678 | for whitelist_item in whitelist: | 
|  | 2679 | if fnmatch.fnmatch(item, whitelist_item): | 
|  | 2680 | return True | 
|  | 2681 | return False | 
|  | 2682 | return True |