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