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