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