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