Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2003, 2004 Chris Larson |
| 3 | # Copyright (C) 2003, 2004 Phil Blundell |
| 4 | # Copyright (C) 2003 - 2005 Michael 'Mickey' Lauer |
| 5 | # Copyright (C) 2005 Holger Hans Peter Freyther |
| 6 | # Copyright (C) 2005 ROAD GmbH |
| 7 | # Copyright (C) 2006 - 2007 Richard Purdie |
| 8 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 9 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 11 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | import sys, os, glob, os.path, re, time |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | import itertools |
| 14 | import logging |
| 15 | import multiprocessing |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 16 | import threading |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 17 | from io import StringIO, UnsupportedOperation |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 18 | from contextlib import closing |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 19 | from collections import defaultdict, namedtuple |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 20 | import bb, bb.exceptions, bb.command |
| 21 | from bb import utils, data, parse, event, cache, providers, taskdata, runqueue, build |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 22 | import queue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | import signal |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | import prserv.serv |
| 25 | import pyinotify |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 26 | import json |
| 27 | import pickle |
| 28 | import codecs |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 29 | import hashserv |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | |
| 31 | logger = logging.getLogger("BitBake") |
| 32 | collectlog = logging.getLogger("BitBake.Collection") |
| 33 | buildlog = logging.getLogger("BitBake.Build") |
| 34 | parselog = logging.getLogger("BitBake.Parsing") |
| 35 | providerlog = logging.getLogger("BitBake.Provider") |
| 36 | |
| 37 | class NoSpecificMatch(bb.BBHandledException): |
| 38 | """ |
| 39 | Exception raised when no or multiple file matches are found |
| 40 | """ |
| 41 | |
| 42 | class NothingToBuild(Exception): |
| 43 | """ |
| 44 | Exception raised when there is nothing to build |
| 45 | """ |
| 46 | |
| 47 | class CollectionError(bb.BBHandledException): |
| 48 | """ |
| 49 | Exception raised when layer configuration is incorrect |
| 50 | """ |
| 51 | |
| 52 | class state: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 53 | initial, parsing, running, shutdown, forceshutdown, stopped, error = list(range(7)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 54 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 55 | @classmethod |
| 56 | def get_name(cls, code): |
| 57 | for name in dir(cls): |
| 58 | value = getattr(cls, name) |
| 59 | if type(value) == type(cls.initial) and value == code: |
| 60 | return name |
| 61 | raise ValueError("Invalid status code: %s" % code) |
| 62 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 63 | |
| 64 | class SkippedPackage: |
| 65 | def __init__(self, info = None, reason = None): |
| 66 | self.pn = None |
| 67 | self.skipreason = None |
| 68 | self.provides = None |
| 69 | self.rprovides = None |
| 70 | |
| 71 | if info: |
| 72 | self.pn = info.pn |
| 73 | self.skipreason = info.skipreason |
| 74 | self.provides = info.provides |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 75 | self.rprovides = info.packages + info.rprovides |
| 76 | for package in info.packages: |
| 77 | self.rprovides += info.rprovides_pkg[package] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 78 | elif reason: |
| 79 | self.skipreason = reason |
| 80 | |
| 81 | |
| 82 | class CookerFeatures(object): |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 83 | _feature_list = [HOB_EXTRA_CACHES, BASEDATASTORE_TRACKING, SEND_SANITYEVENTS, RECIPE_SIGGEN_INFO] = list(range(4)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 84 | |
| 85 | def __init__(self): |
| 86 | self._features=set() |
| 87 | |
| 88 | def setFeature(self, f): |
| 89 | # validate we got a request for a feature we support |
| 90 | if f not in CookerFeatures._feature_list: |
| 91 | return |
| 92 | self._features.add(f) |
| 93 | |
| 94 | def __contains__(self, f): |
| 95 | return f in self._features |
| 96 | |
| 97 | def __iter__(self): |
| 98 | return self._features.__iter__() |
| 99 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 100 | def __next__(self): |
| 101 | return next(self._features) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 102 | |
| 103 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 104 | class EventWriter: |
| 105 | def __init__(self, cooker, eventfile): |
| 106 | self.file_inited = None |
| 107 | self.cooker = cooker |
| 108 | self.eventfile = eventfile |
| 109 | self.event_queue = [] |
| 110 | |
| 111 | def write_event(self, event): |
| 112 | with open(self.eventfile, "a") as f: |
| 113 | try: |
| 114 | str_event = codecs.encode(pickle.dumps(event), 'base64').decode('utf-8') |
| 115 | f.write("%s\n" % json.dumps({"class": event.__module__ + "." + event.__class__.__name__, |
| 116 | "vars": str_event})) |
| 117 | except Exception as err: |
| 118 | import traceback |
| 119 | print(err, traceback.format_exc()) |
| 120 | |
| 121 | def send(self, event): |
| 122 | if self.file_inited: |
| 123 | # we have the file, just write the event |
| 124 | self.write_event(event) |
| 125 | else: |
| 126 | # init on bb.event.BuildStarted |
| 127 | name = "%s.%s" % (event.__module__, event.__class__.__name__) |
| 128 | if name in ("bb.event.BuildStarted", "bb.cooker.CookerExit"): |
| 129 | with open(self.eventfile, "w") as f: |
| 130 | f.write("%s\n" % json.dumps({ "allvariables" : self.cooker.getAllKeysWithFlags(["doc", "func"])})) |
| 131 | |
| 132 | self.file_inited = True |
| 133 | |
| 134 | # write pending events |
| 135 | for evt in self.event_queue: |
| 136 | self.write_event(evt) |
| 137 | |
| 138 | # also write the current event |
| 139 | self.write_event(event) |
| 140 | else: |
| 141 | # queue all events until the file is inited |
| 142 | self.event_queue.append(event) |
| 143 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 144 | #============================================================================# |
| 145 | # BBCooker |
| 146 | #============================================================================# |
| 147 | class BBCooker: |
| 148 | """ |
| 149 | Manages one bitbake build run |
| 150 | """ |
| 151 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 152 | def __init__(self, featureSet=None, server=None): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 153 | self.recipecaches = None |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 154 | self.eventlog = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 155 | self.skiplist = {} |
| 156 | self.featureset = CookerFeatures() |
| 157 | if featureSet: |
| 158 | for f in featureSet: |
| 159 | self.featureset.setFeature(f) |
| 160 | |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame] | 161 | self.orig_syspath = sys.path.copy() |
| 162 | self.orig_sysmodules = [*sys.modules] |
| 163 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 164 | self.configuration = bb.cookerdata.CookerConfiguration() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 165 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 166 | self.process_server = server |
| 167 | self.idleCallBackRegister = None |
| 168 | self.waitIdle = None |
| 169 | if server: |
| 170 | self.idleCallBackRegister = server.register_idle_function |
| 171 | self.waitIdle = server.wait_for_idle |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 172 | |
Brad Bishop | f058f49 | 2019-01-28 23:50:33 -0500 | [diff] [blame] | 173 | bb.debug(1, "BBCooker starting %s" % time.time()) |
| 174 | sys.stdout.flush() |
| 175 | |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 176 | self.configwatcher = None |
| 177 | self.confignotifier = None |
Brad Bishop | f058f49 | 2019-01-28 23:50:33 -0500 | [diff] [blame] | 178 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 179 | self.watchmask = pyinotify.IN_CLOSE_WRITE | pyinotify.IN_CREATE | pyinotify.IN_DELETE | \ |
| 180 | pyinotify.IN_DELETE_SELF | pyinotify.IN_MODIFY | pyinotify.IN_MOVE_SELF | \ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 181 | pyinotify.IN_MOVED_FROM | pyinotify.IN_MOVED_TO |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 182 | |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 183 | self.watcher = None |
| 184 | self.notifier = None |
Brad Bishop | f058f49 | 2019-01-28 23:50:33 -0500 | [diff] [blame] | 185 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 186 | # If being called by something like tinfoil, we need to clean cached data |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 187 | # which may now be invalid |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 188 | bb.parse.clear_cache() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 189 | bb.parse.BBHandler.cached_statements = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 190 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 191 | self.ui_cmdline = None |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 192 | self.hashserv = None |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 193 | self.hashservaddr = None |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 194 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 195 | self.inotify_modified_files = [] |
| 196 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 197 | # TOSTOP must not be set or our children will hang when they output |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 198 | try: |
| 199 | fd = sys.stdout.fileno() |
| 200 | if os.isatty(fd): |
| 201 | import termios |
| 202 | tcattr = termios.tcgetattr(fd) |
| 203 | if tcattr[3] & termios.TOSTOP: |
| 204 | buildlog.info("The terminal had the TOSTOP bit set, clearing...") |
| 205 | tcattr[3] = tcattr[3] & ~termios.TOSTOP |
| 206 | termios.tcsetattr(fd, termios.TCSANOW, tcattr) |
| 207 | except UnsupportedOperation: |
| 208 | pass |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 209 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 210 | self.command = bb.command.Command(self, self.process_server) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 211 | self.state = state.initial |
| 212 | |
| 213 | self.parser = None |
| 214 | |
| 215 | signal.signal(signal.SIGTERM, self.sigterm_exception) |
| 216 | # Let SIGHUP exit as SIGTERM |
| 217 | signal.signal(signal.SIGHUP, self.sigterm_exception) |
| 218 | |
Brad Bishop | f058f49 | 2019-01-28 23:50:33 -0500 | [diff] [blame] | 219 | bb.debug(1, "BBCooker startup complete %s" % time.time()) |
| 220 | sys.stdout.flush() |
| 221 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 222 | self.inotify_threadlock = threading.Lock() |
| 223 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 224 | def init_configdata(self): |
| 225 | if not hasattr(self, "data"): |
| 226 | self.initConfigurationData() |
| 227 | bb.debug(1, "BBCooker parsed base configuration %s" % time.time()) |
| 228 | sys.stdout.flush() |
| 229 | self.handlePRServ() |
| 230 | |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 231 | def setupConfigWatcher(self): |
| 232 | if self.configwatcher: |
| 233 | self.configwatcher.close() |
| 234 | self.confignotifier = None |
| 235 | self.configwatcher = None |
| 236 | self.configwatcher = pyinotify.WatchManager() |
| 237 | self.configwatcher.bbseen = set() |
| 238 | self.configwatcher.bbwatchedfiles = set() |
| 239 | self.confignotifier = pyinotify.Notifier(self.configwatcher, self.config_notifications) |
| 240 | |
| 241 | def setupParserWatcher(self): |
| 242 | if self.watcher: |
| 243 | self.watcher.close() |
| 244 | self.notifier = None |
| 245 | self.watcher = None |
| 246 | self.watcher = pyinotify.WatchManager() |
| 247 | self.watcher.bbseen = set() |
| 248 | self.watcher.bbwatchedfiles = set() |
| 249 | self.notifier = pyinotify.Notifier(self.watcher, self.notifications) |
| 250 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 251 | def process_inotify_updates(self): |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 252 | with bb.utils.lock_timeout(self.inotify_threadlock): |
| 253 | for n in [self.confignotifier, self.notifier]: |
| 254 | if n and n.check_events(timeout=0): |
| 255 | # read notified events and enqueue them |
| 256 | n.read_events() |
| 257 | |
| 258 | def process_inotify_updates_apply(self): |
| 259 | with bb.utils.lock_timeout(self.inotify_threadlock): |
| 260 | for n in [self.confignotifier, self.notifier]: |
| 261 | if n and n.check_events(timeout=0): |
| 262 | n.read_events() |
| 263 | n.process_events() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 264 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 265 | def config_notifications(self, event): |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 266 | if event.maskname == "IN_Q_OVERFLOW": |
| 267 | bb.warn("inotify event queue overflowed, invalidating caches.") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 268 | self.parsecache_valid = False |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 269 | self.baseconfig_valid = False |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 270 | bb.parse.clear_cache() |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 271 | return |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 272 | if not event.pathname in self.configwatcher.bbwatchedfiles: |
| 273 | return |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 274 | if "IN_ISDIR" in event.maskname: |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame] | 275 | if "IN_CREATE" in event.maskname or "IN_DELETE" in event.maskname: |
| 276 | if event.pathname in self.configwatcher.bbseen: |
| 277 | self.configwatcher.bbseen.remove(event.pathname) |
| 278 | # Could remove all entries starting with the directory but for now... |
| 279 | bb.parse.clear_cache() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 280 | if not event.pathname in self.inotify_modified_files: |
| 281 | self.inotify_modified_files.append(event.pathname) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 282 | self.baseconfig_valid = False |
| 283 | |
| 284 | def notifications(self, event): |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 285 | if event.maskname == "IN_Q_OVERFLOW": |
| 286 | bb.warn("inotify event queue overflowed, invalidating caches.") |
| 287 | self.parsecache_valid = False |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 288 | bb.parse.clear_cache() |
| 289 | return |
| 290 | if event.pathname.endswith("bitbake-cookerdaemon.log") \ |
| 291 | or event.pathname.endswith("bitbake.lock"): |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 292 | return |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 293 | if "IN_ISDIR" in event.maskname: |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame] | 294 | if "IN_CREATE" in event.maskname or "IN_DELETE" in event.maskname: |
| 295 | if event.pathname in self.watcher.bbseen: |
| 296 | self.watcher.bbseen.remove(event.pathname) |
| 297 | # Could remove all entries starting with the directory but for now... |
| 298 | bb.parse.clear_cache() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 299 | if not event.pathname in self.inotify_modified_files: |
| 300 | self.inotify_modified_files.append(event.pathname) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 301 | self.parsecache_valid = False |
| 302 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 303 | def add_filewatch(self, deps, watcher=None, dirs=False): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 304 | if not watcher: |
| 305 | watcher = self.watcher |
| 306 | for i in deps: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 307 | watcher.bbwatchedfiles.add(i[0]) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 308 | if dirs: |
| 309 | f = i[0] |
| 310 | else: |
| 311 | f = os.path.dirname(i[0]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 312 | if f in watcher.bbseen: |
| 313 | continue |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 314 | watcher.bbseen.add(f) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 315 | watchtarget = None |
| 316 | while True: |
| 317 | # We try and add watches for files that don't exist but if they did, would influence |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 318 | # the parser. The parent directory of these files may not exist, in which case we need |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 319 | # to watch any parent that does exist for changes. |
| 320 | try: |
| 321 | watcher.add_watch(f, self.watchmask, quiet=False) |
| 322 | if watchtarget: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 323 | watcher.bbwatchedfiles.add(watchtarget) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 324 | break |
| 325 | except pyinotify.WatchManagerError as e: |
| 326 | if 'ENOENT' in str(e): |
| 327 | watchtarget = f |
| 328 | f = os.path.dirname(f) |
| 329 | if f in watcher.bbseen: |
| 330 | break |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 331 | watcher.bbseen.add(f) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 332 | continue |
| 333 | if 'ENOSPC' in str(e): |
| 334 | providerlog.error("No space left on device or exceeds fs.inotify.max_user_watches?") |
| 335 | providerlog.error("To check max_user_watches: sysctl -n fs.inotify.max_user_watches.") |
| 336 | providerlog.error("To modify max_user_watches: sysctl -n -w fs.inotify.max_user_watches=<value>.") |
| 337 | providerlog.error("Root privilege is required to modify max_user_watches.") |
| 338 | raise |
| 339 | |
| 340 | def sigterm_exception(self, signum, stackframe): |
| 341 | if signum == signal.SIGTERM: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 342 | bb.warn("Cooker received SIGTERM, shutting down...") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 343 | elif signum == signal.SIGHUP: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 344 | bb.warn("Cooker received SIGHUP, shutting down...") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 345 | self.state = state.forceshutdown |
| 346 | |
| 347 | def setFeatures(self, features): |
| 348 | # we only accept a new feature set if we're in state initial, so we can reset without problems |
| 349 | if not self.state in [state.initial, state.shutdown, state.forceshutdown, state.stopped, state.error]: |
| 350 | raise Exception("Illegal state for feature set change") |
| 351 | original_featureset = list(self.featureset) |
| 352 | for feature in features: |
| 353 | self.featureset.setFeature(feature) |
| 354 | bb.debug(1, "Features set %s (was %s)" % (original_featureset, list(self.featureset))) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 355 | if (original_featureset != list(self.featureset)) and self.state != state.error and hasattr(self, "data"): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 356 | self.reset() |
| 357 | |
| 358 | def initConfigurationData(self): |
| 359 | |
| 360 | self.state = state.initial |
| 361 | self.caches_array = [] |
| 362 | |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame] | 363 | sys.path = self.orig_syspath.copy() |
| 364 | for mod in [*sys.modules]: |
| 365 | if mod not in self.orig_sysmodules: |
| 366 | del sys.modules[mod] |
| 367 | |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 368 | self.setupConfigWatcher() |
| 369 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 370 | # Need to preserve BB_CONSOLELOG over resets |
| 371 | consolelog = None |
| 372 | if hasattr(self, "data"): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 373 | consolelog = self.data.getVar("BB_CONSOLELOG") |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 374 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 375 | if CookerFeatures.BASEDATASTORE_TRACKING in self.featureset: |
| 376 | self.enableDataTracking() |
| 377 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 378 | caches_name_array = ['bb.cache:CoreRecipeInfo'] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 379 | # We hardcode all known cache types in a single place, here. |
| 380 | if CookerFeatures.HOB_EXTRA_CACHES in self.featureset: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 381 | caches_name_array.append("bb.cache_extra:HobRecipeInfo") |
| 382 | if CookerFeatures.RECIPE_SIGGEN_INFO in self.featureset: |
| 383 | caches_name_array.append("bb.cache:SiggenRecipeInfo") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 384 | |
| 385 | # At least CoreRecipeInfo will be loaded, so caches_array will never be empty! |
| 386 | # This is the entry point, no further check needed! |
| 387 | for var in caches_name_array: |
| 388 | try: |
| 389 | module_name, cache_name = var.split(':') |
| 390 | module = __import__(module_name, fromlist=(cache_name,)) |
| 391 | self.caches_array.append(getattr(module, cache_name)) |
| 392 | except ImportError as exc: |
| 393 | logger.critical("Unable to import extra RecipeInfo '%s' from '%s': %s" % (cache_name, module_name, exc)) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 394 | raise bb.BBHandledException() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 395 | |
| 396 | self.databuilder = bb.cookerdata.CookerDataBuilder(self.configuration, False) |
| 397 | self.databuilder.parseBaseConfiguration() |
| 398 | self.data = self.databuilder.data |
| 399 | self.data_hash = self.databuilder.data_hash |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 400 | self.extraconfigdata = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 401 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 402 | if consolelog: |
| 403 | self.data.setVar("BB_CONSOLELOG", consolelog) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 404 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 405 | self.data.setVar('BB_CMDLINE', self.ui_cmdline) |
| 406 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 407 | if CookerFeatures.BASEDATASTORE_TRACKING in self.featureset: |
| 408 | self.disableDataTracking() |
| 409 | |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 410 | for mc in self.databuilder.mcdata.values(): |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 411 | self.add_filewatch(mc.getVar("__base_depends", False), self.configwatcher) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 412 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 413 | self.baseconfig_valid = True |
| 414 | self.parsecache_valid = False |
| 415 | |
| 416 | def handlePRServ(self): |
| 417 | # Setup a PR Server based on the new configuration |
| 418 | try: |
| 419 | self.prhost = prserv.serv.auto_start(self.data) |
| 420 | except prserv.serv.PRServiceConfigError as e: |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 421 | bb.fatal("Unable to start PR Server, exiting, check the bitbake-cookerdaemon.log") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 422 | |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 423 | if self.data.getVar("BB_HASHSERVE") == "auto": |
| 424 | # Create a new hash server bound to a unix domain socket |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 425 | if not self.hashserv: |
| 426 | dbfile = (self.data.getVar("PERSISTENT_DIR") or self.data.getVar("CACHE")) + "/hashserv.db" |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 427 | upstream = self.data.getVar("BB_HASHSERVE_UPSTREAM") or None |
| 428 | if upstream: |
| 429 | import socket |
| 430 | try: |
| 431 | sock = socket.create_connection(upstream.split(":"), 5) |
| 432 | sock.close() |
| 433 | except socket.error as e: |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 434 | bb.warn("BB_HASHSERVE_UPSTREAM is not valid, unable to connect hash equivalence server at '%s': %s" |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 435 | % (upstream, repr(e))) |
| 436 | |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 437 | self.hashservaddr = "unix://%s/hashserve.sock" % self.data.getVar("TOPDIR") |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 438 | self.hashserv = hashserv.create_server( |
| 439 | self.hashservaddr, |
| 440 | dbfile, |
| 441 | sync=False, |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 442 | upstream=upstream, |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 443 | ) |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 444 | self.hashserv.serve_as_process() |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 445 | for mc in self.databuilder.mcdata: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 446 | self.databuilder.mcorigdata[mc].setVar("BB_HASHSERVE", self.hashservaddr) |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 447 | self.databuilder.mcdata[mc].setVar("BB_HASHSERVE", self.hashservaddr) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 448 | |
| 449 | bb.parse.init_parser(self.data) |
| 450 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 451 | def enableDataTracking(self): |
| 452 | self.configuration.tracking = True |
| 453 | if hasattr(self, "data"): |
| 454 | self.data.enableTracking() |
| 455 | |
| 456 | def disableDataTracking(self): |
| 457 | self.configuration.tracking = False |
| 458 | if hasattr(self, "data"): |
| 459 | self.data.disableTracking() |
| 460 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 461 | def parseConfiguration(self): |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 462 | self.updateCacheSync() |
| 463 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 464 | # Change nice level if we're asked to |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 465 | nice = self.data.getVar("BB_NICE_LEVEL") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 466 | if nice: |
| 467 | curnice = os.nice(0) |
| 468 | nice = int(nice) - curnice |
| 469 | buildlog.verbose("Renice to %s " % os.nice(nice)) |
| 470 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 471 | if self.recipecaches: |
| 472 | del self.recipecaches |
| 473 | self.multiconfigs = self.databuilder.mcdata.keys() |
| 474 | self.recipecaches = {} |
| 475 | for mc in self.multiconfigs: |
| 476 | self.recipecaches[mc] = bb.cache.CacheData(self.caches_array) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 477 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 478 | self.handleCollections(self.data.getVar("BBFILE_COLLECTIONS")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 479 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 480 | self.parsecache_valid = False |
| 481 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 482 | def updateConfigOpts(self, options, environment, cmdline): |
| 483 | self.ui_cmdline = cmdline |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 484 | clean = True |
| 485 | for o in options: |
| 486 | if o in ['prefile', 'postfile']: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 487 | # Only these options may require a reparse |
| 488 | try: |
| 489 | if getattr(self.configuration, o) == options[o]: |
| 490 | # Value is the same, no need to mark dirty |
| 491 | continue |
| 492 | except AttributeError: |
| 493 | pass |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 494 | logger.debug("Marking as dirty due to '%s' option change to '%s'" % (o, options[o])) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 495 | print("Marking as dirty due to '%s' option change to '%s'" % (o, options[o])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 496 | clean = False |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 497 | if hasattr(self.configuration, o): |
| 498 | setattr(self.configuration, o, options[o]) |
| 499 | |
| 500 | if self.configuration.writeeventlog: |
| 501 | if self.eventlog and self.eventlog[0] != self.configuration.writeeventlog: |
| 502 | bb.event.unregister_UIHhandler(self.eventlog[1]) |
| 503 | if not self.eventlog or self.eventlog[0] != self.configuration.writeeventlog: |
| 504 | # we log all events to a file if so directed |
| 505 | # register the log file writer as UI Handler |
| 506 | writer = EventWriter(self, self.configuration.writeeventlog) |
| 507 | EventLogWriteHandler = namedtuple('EventLogWriteHandler', ['event']) |
| 508 | self.eventlog = (self.configuration.writeeventlog, bb.event.register_UIHhandler(EventLogWriteHandler(writer))) |
| 509 | |
| 510 | bb.msg.loggerDefaultLogLevel = self.configuration.default_loglevel |
| 511 | bb.msg.loggerDefaultDomains = self.configuration.debug_domains |
| 512 | |
| 513 | if hasattr(self, "data"): |
| 514 | origenv = bb.data.init() |
| 515 | for k in environment: |
| 516 | origenv.setVar(k, environment[k]) |
| 517 | self.data.setVar("BB_ORIGENV", origenv) |
| 518 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 519 | for k in bb.utils.approved_variables(): |
| 520 | if k in environment and k not in self.configuration.env: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 521 | logger.debug("Updating new environment variable %s to %s" % (k, environment[k])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 522 | self.configuration.env[k] = environment[k] |
| 523 | clean = False |
| 524 | if k in self.configuration.env and k not in environment: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 525 | logger.debug("Updating environment variable %s (deleted)" % (k)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 526 | del self.configuration.env[k] |
| 527 | clean = False |
| 528 | if k not in self.configuration.env and k not in environment: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 529 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 530 | if environment[k] != self.configuration.env[k]: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 531 | logger.debug("Updating environment variable %s from %s to %s" % (k, self.configuration.env[k], environment[k])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 532 | self.configuration.env[k] = environment[k] |
| 533 | clean = False |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 534 | |
| 535 | # Now update all the variables not in the datastore to match |
| 536 | self.configuration.env = environment |
| 537 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 538 | if not clean: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 539 | logger.debug("Base environment change, triggering reparse") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 540 | self.reset() |
| 541 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 542 | def showVersions(self): |
| 543 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 544 | (latest_versions, preferred_versions, required) = self.findProviders() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 545 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 546 | logger.plain("%-35s %25s %25s %25s", "Recipe Name", "Latest Version", "Preferred Version", "Required Version") |
| 547 | logger.plain("%-35s %25s %25s %25s\n", "===========", "==============", "=================", "================") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 548 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 549 | for p in sorted(self.recipecaches[''].pkg_pn): |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 550 | preferred = preferred_versions[p] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 551 | latest = latest_versions[p] |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 552 | requiredstr = "" |
| 553 | preferredstr = "" |
| 554 | if required[p]: |
| 555 | if preferred[0] is not None: |
| 556 | requiredstr = preferred[0][0] + ":" + preferred[0][1] + '-' + preferred[0][2] |
| 557 | else: |
| 558 | bb.fatal("REQUIRED_VERSION of package %s not available" % p) |
| 559 | else: |
| 560 | preferredstr = preferred[0][0] + ":" + preferred[0][1] + '-' + preferred[0][2] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 561 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 562 | lateststr = latest[0][0] + ":" + latest[0][1] + "-" + latest[0][2] |
| 563 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 564 | if preferred == latest: |
| 565 | preferredstr = "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 566 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 567 | logger.plain("%-35s %25s %25s %25s", p, lateststr, preferredstr, requiredstr) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 568 | |
| 569 | def showEnvironment(self, buildfile=None, pkgs_to_build=None): |
| 570 | """ |
| 571 | Show the outer or per-recipe environment |
| 572 | """ |
| 573 | fn = None |
| 574 | envdata = None |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 575 | mc = '' |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 576 | if not pkgs_to_build: |
| 577 | pkgs_to_build = [] |
| 578 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 579 | orig_tracking = self.configuration.tracking |
| 580 | if not orig_tracking: |
| 581 | self.enableDataTracking() |
| 582 | self.reset() |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 583 | # reset() resets to the UI requested value so we have to redo this |
| 584 | self.enableDataTracking() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 585 | |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 586 | def mc_base(p): |
| 587 | if p.startswith('mc:'): |
| 588 | s = p.split(':') |
| 589 | if len(s) == 2: |
| 590 | return s[1] |
| 591 | return None |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 592 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 593 | if buildfile: |
| 594 | # Parse the configuration here. We need to do it explicitly here since |
| 595 | # this showEnvironment() code path doesn't use the cache |
| 596 | self.parseConfiguration() |
| 597 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 598 | fn, cls, mc = bb.cache.virtualfn2realfn(buildfile) |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 599 | fn = self.matchFile(fn, mc) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 600 | fn = bb.cache.realfn2virtual(fn, cls, mc) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 601 | elif len(pkgs_to_build) == 1: |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 602 | mc = mc_base(pkgs_to_build[0]) |
| 603 | if not mc: |
| 604 | ignore = self.data.getVar("ASSUME_PROVIDED") or "" |
| 605 | if pkgs_to_build[0] in set(ignore.split()): |
| 606 | bb.fatal("%s is in ASSUME_PROVIDED" % pkgs_to_build[0]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 607 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 608 | taskdata, runlist = self.buildTaskData(pkgs_to_build, None, self.configuration.halt, allowincomplete=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 609 | |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 610 | mc = runlist[0][0] |
| 611 | fn = runlist[0][3] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 612 | |
| 613 | if fn: |
| 614 | try: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 615 | envdata = self.databuilder.parseRecipe(fn, self.collections[mc].get_file_appends(fn)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 616 | except Exception as e: |
| 617 | parselog.exception("Unable to read %s", fn) |
| 618 | raise |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 619 | else: |
| 620 | if not mc in self.databuilder.mcdata: |
| 621 | bb.fatal('Not multiconfig named "%s" found' % mc) |
| 622 | envdata = self.databuilder.mcdata[mc] |
| 623 | data.expandKeys(envdata) |
| 624 | parse.ast.runAnonFuncs(envdata) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 625 | |
| 626 | # Display history |
| 627 | with closing(StringIO()) as env: |
| 628 | self.data.inchistory.emit(env) |
| 629 | logger.plain(env.getvalue()) |
| 630 | |
| 631 | # emit variables and shell functions |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 632 | with closing(StringIO()) as env: |
| 633 | data.emit_env(env, envdata, True) |
| 634 | logger.plain(env.getvalue()) |
| 635 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 636 | # emit the metadata which isn't valid shell |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 637 | for e in sorted(envdata.keys()): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 638 | if envdata.getVarFlag(e, 'func', False) and envdata.getVarFlag(e, 'python', False): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 639 | logger.plain("\npython %s () {\n%s}\n", e, envdata.getVar(e, False)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 640 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 641 | if not orig_tracking: |
| 642 | self.disableDataTracking() |
| 643 | self.reset() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 644 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 645 | def buildTaskData(self, pkgs_to_build, task, halt, allowincomplete=False): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 646 | """ |
| 647 | Prepare a runqueue and taskdata object for iteration over pkgs_to_build |
| 648 | """ |
| 649 | bb.event.fire(bb.event.TreeDataPreparationStarted(), self.data) |
| 650 | |
| 651 | # A task of None means use the default task |
| 652 | if task is None: |
| 653 | task = self.configuration.cmd |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 654 | if not task.startswith("do_"): |
| 655 | task = "do_%s" % task |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 656 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 657 | targetlist = self.checkPackages(pkgs_to_build, task) |
| 658 | fulltargetlist = [] |
| 659 | defaulttask_implicit = '' |
| 660 | defaulttask_explicit = False |
| 661 | wildcard = False |
| 662 | |
| 663 | # Wild card expansion: |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 664 | # Replace string such as "mc:*:bash" |
| 665 | # into "mc:A:bash mc:B:bash bash" |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 666 | for k in targetlist: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 667 | if k.startswith("mc:") and k.count(':') >= 2: |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 668 | if wildcard: |
| 669 | bb.fatal('multiconfig conflict') |
| 670 | if k.split(":")[1] == "*": |
| 671 | wildcard = True |
| 672 | for mc in self.multiconfigs: |
| 673 | if mc: |
| 674 | fulltargetlist.append(k.replace('*', mc)) |
| 675 | # implicit default task |
| 676 | else: |
| 677 | defaulttask_implicit = k.split(":")[2] |
| 678 | else: |
| 679 | fulltargetlist.append(k) |
| 680 | else: |
| 681 | defaulttask_explicit = True |
| 682 | fulltargetlist.append(k) |
| 683 | |
| 684 | if not defaulttask_explicit and defaulttask_implicit != '': |
| 685 | fulltargetlist.append(defaulttask_implicit) |
| 686 | |
| 687 | bb.debug(1,"Target list: %s" % (str(fulltargetlist))) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 688 | taskdata = {} |
| 689 | localdata = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 690 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 691 | for mc in self.multiconfigs: |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 692 | taskdata[mc] = bb.taskdata.TaskData(halt, skiplist=self.skiplist, allowincomplete=allowincomplete) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 693 | localdata[mc] = data.createCopy(self.databuilder.mcdata[mc]) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 694 | bb.data.expandKeys(localdata[mc]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 695 | |
| 696 | current = 0 |
| 697 | runlist = [] |
| 698 | for k in fulltargetlist: |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 699 | origk = k |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 700 | mc = "" |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 701 | if k.startswith("mc:") and k.count(':') >= 2: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 702 | mc = k.split(":")[1] |
| 703 | k = ":".join(k.split(":")[2:]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 704 | ktask = task |
| 705 | if ":do_" in k: |
| 706 | k2 = k.split(":do_") |
| 707 | k = k2[0] |
| 708 | ktask = k2[1] |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 709 | |
| 710 | if mc not in self.multiconfigs: |
| 711 | bb.fatal("Multiconfig dependency %s depends on nonexistent multiconfig configuration named %s" % (origk, mc)) |
| 712 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 713 | taskdata[mc].add_provider(localdata[mc], self.recipecaches[mc], k) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 714 | current += 1 |
| 715 | if not ktask.startswith("do_"): |
| 716 | ktask = "do_%s" % ktask |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 717 | if k not in taskdata[mc].build_targets or not taskdata[mc].build_targets[k]: |
| 718 | # e.g. in ASSUME_PROVIDED |
| 719 | continue |
| 720 | fn = taskdata[mc].build_targets[k][0] |
| 721 | runlist.append([mc, k, ktask, fn]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 722 | bb.event.fire(bb.event.TreeDataPreparationProgress(current, len(fulltargetlist)), self.data) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 723 | |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 724 | havemc = False |
| 725 | for mc in self.multiconfigs: |
| 726 | if taskdata[mc].get_mcdepends(): |
| 727 | havemc = True |
Brad Bishop | f058f49 | 2019-01-28 23:50:33 -0500 | [diff] [blame] | 728 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 729 | # No need to do check providers if there are no mcdeps or not an mc build |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 730 | if havemc or len(self.multiconfigs) > 1: |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame] | 731 | seen = set() |
| 732 | new = True |
| 733 | # Make sure we can provide the multiconfig dependency |
| 734 | while new: |
| 735 | mcdeps = set() |
| 736 | # Add unresolved first, so we can get multiconfig indirect dependencies on time |
| 737 | for mc in self.multiconfigs: |
| 738 | taskdata[mc].add_unresolved(localdata[mc], self.recipecaches[mc]) |
| 739 | mcdeps |= set(taskdata[mc].get_mcdepends()) |
| 740 | new = False |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 741 | for k in mcdeps: |
| 742 | if k in seen: |
| 743 | continue |
| 744 | l = k.split(':') |
| 745 | depmc = l[2] |
| 746 | if depmc not in self.multiconfigs: |
| 747 | bb.fatal("Multiconfig dependency %s depends on nonexistent multiconfig configuration named configuration %s" % (k,depmc)) |
| 748 | else: |
| 749 | logger.debug("Adding providers for multiconfig dependency %s" % l[3]) |
| 750 | taskdata[depmc].add_provider(localdata[depmc], self.recipecaches[depmc], l[3]) |
| 751 | seen.add(k) |
| 752 | new = True |
Brad Bishop | f058f49 | 2019-01-28 23:50:33 -0500 | [diff] [blame] | 753 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 754 | for mc in self.multiconfigs: |
| 755 | taskdata[mc].add_unresolved(localdata[mc], self.recipecaches[mc]) |
| 756 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 757 | bb.event.fire(bb.event.TreeDataPreparationCompleted(len(fulltargetlist)), self.data) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 758 | return taskdata, runlist |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 759 | |
| 760 | def prepareTreeData(self, pkgs_to_build, task): |
| 761 | """ |
| 762 | Prepare a runqueue and taskdata object for iteration over pkgs_to_build |
| 763 | """ |
| 764 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 765 | # We set halt to False here to prevent unbuildable targets raising |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 766 | # an exception when we're just generating data |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 767 | taskdata, runlist = self.buildTaskData(pkgs_to_build, task, False, allowincomplete=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 768 | |
| 769 | return runlist, taskdata |
| 770 | |
| 771 | ######## WARNING : this function requires cache_extra to be enabled ######## |
| 772 | |
| 773 | def generateTaskDepTreeData(self, pkgs_to_build, task): |
| 774 | """ |
| 775 | Create a dependency graph of pkgs_to_build including reverse dependency |
| 776 | information. |
| 777 | """ |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 778 | if not task.startswith("do_"): |
| 779 | task = "do_%s" % task |
| 780 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 781 | runlist, taskdata = self.prepareTreeData(pkgs_to_build, task) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 782 | rq = bb.runqueue.RunQueue(self, self.data, self.recipecaches, taskdata, runlist) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 783 | rq.rqdata.prepare() |
| 784 | return self.buildDependTree(rq, taskdata) |
| 785 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 786 | @staticmethod |
| 787 | def add_mc_prefix(mc, pn): |
| 788 | if mc: |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 789 | return "mc:%s:%s" % (mc, pn) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 790 | return pn |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 791 | |
| 792 | def buildDependTree(self, rq, taskdata): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 793 | seen_fns = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 794 | depend_tree = {} |
| 795 | depend_tree["depends"] = {} |
| 796 | depend_tree["tdepends"] = {} |
| 797 | depend_tree["pn"] = {} |
| 798 | depend_tree["rdepends-pn"] = {} |
| 799 | depend_tree["packages"] = {} |
| 800 | depend_tree["rdepends-pkg"] = {} |
| 801 | depend_tree["rrecs-pkg"] = {} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 802 | depend_tree['providermap'] = {} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 803 | depend_tree["layer-priorities"] = self.bbfile_config_priorities |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 804 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 805 | for mc in taskdata: |
| 806 | for name, fn in list(taskdata[mc].get_providermap().items()): |
| 807 | pn = self.recipecaches[mc].pkg_fn[fn] |
| 808 | pn = self.add_mc_prefix(mc, pn) |
| 809 | if name != pn: |
| 810 | version = "%s:%s-%s" % self.recipecaches[mc].pkg_pepvpr[fn] |
| 811 | depend_tree['providermap'][name] = (pn, version) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 812 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 813 | for tid in rq.rqdata.runtaskentries: |
| 814 | (mc, fn, taskname, taskfn) = bb.runqueue.split_tid_mcfn(tid) |
| 815 | pn = self.recipecaches[mc].pkg_fn[taskfn] |
| 816 | pn = self.add_mc_prefix(mc, pn) |
| 817 | version = "%s:%s-%s" % self.recipecaches[mc].pkg_pepvpr[taskfn] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 818 | if pn not in depend_tree["pn"]: |
| 819 | depend_tree["pn"][pn] = {} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 820 | depend_tree["pn"][pn]["filename"] = taskfn |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 821 | depend_tree["pn"][pn]["version"] = version |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 822 | depend_tree["pn"][pn]["inherits"] = self.recipecaches[mc].inherits.get(taskfn, None) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 823 | |
| 824 | # if we have extra caches, list all attributes they bring in |
| 825 | extra_info = [] |
| 826 | for cache_class in self.caches_array: |
| 827 | if type(cache_class) is type and issubclass(cache_class, bb.cache.RecipeInfoCommon) and hasattr(cache_class, 'cachefields'): |
| 828 | cachefields = getattr(cache_class, 'cachefields', []) |
| 829 | extra_info = extra_info + cachefields |
| 830 | |
| 831 | # for all attributes stored, add them to the dependency tree |
| 832 | for ei in extra_info: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 833 | depend_tree["pn"][pn][ei] = vars(self.recipecaches[mc])[ei][taskfn] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 834 | |
| 835 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 836 | dotname = "%s.%s" % (pn, bb.runqueue.taskname_from_tid(tid)) |
| 837 | if not dotname in depend_tree["tdepends"]: |
| 838 | depend_tree["tdepends"][dotname] = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 839 | for dep in rq.rqdata.runtaskentries[tid].depends: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 840 | (depmc, depfn, _, deptaskfn) = bb.runqueue.split_tid_mcfn(dep) |
| 841 | deppn = self.recipecaches[depmc].pkg_fn[deptaskfn] |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 842 | if depmc: |
| 843 | depmc = "mc:" + depmc + ":" |
| 844 | depend_tree["tdepends"][dotname].append("%s%s.%s" % (depmc, deppn, bb.runqueue.taskname_from_tid(dep))) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 845 | if taskfn not in seen_fns: |
| 846 | seen_fns.append(taskfn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 847 | packages = [] |
| 848 | |
| 849 | depend_tree["depends"][pn] = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 850 | for dep in taskdata[mc].depids[taskfn]: |
| 851 | depend_tree["depends"][pn].append(dep) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 852 | |
| 853 | depend_tree["rdepends-pn"][pn] = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 854 | for rdep in taskdata[mc].rdepids[taskfn]: |
| 855 | depend_tree["rdepends-pn"][pn].append(rdep) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 856 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 857 | rdepends = self.recipecaches[mc].rundeps[taskfn] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 858 | for package in rdepends: |
| 859 | depend_tree["rdepends-pkg"][package] = [] |
| 860 | for rdepend in rdepends[package]: |
| 861 | depend_tree["rdepends-pkg"][package].append(rdepend) |
| 862 | packages.append(package) |
| 863 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 864 | rrecs = self.recipecaches[mc].runrecs[taskfn] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 865 | for package in rrecs: |
| 866 | depend_tree["rrecs-pkg"][package] = [] |
| 867 | for rdepend in rrecs[package]: |
| 868 | depend_tree["rrecs-pkg"][package].append(rdepend) |
| 869 | if not package in packages: |
| 870 | packages.append(package) |
| 871 | |
| 872 | for package in packages: |
| 873 | if package not in depend_tree["packages"]: |
| 874 | depend_tree["packages"][package] = {} |
| 875 | depend_tree["packages"][package]["pn"] = pn |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 876 | depend_tree["packages"][package]["filename"] = taskfn |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 877 | depend_tree["packages"][package]["version"] = version |
| 878 | |
| 879 | return depend_tree |
| 880 | |
| 881 | ######## WARNING : this function requires cache_extra to be enabled ######## |
| 882 | def generatePkgDepTreeData(self, pkgs_to_build, task): |
| 883 | """ |
| 884 | Create a dependency tree of pkgs_to_build, returning the data. |
| 885 | """ |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 886 | if not task.startswith("do_"): |
| 887 | task = "do_%s" % task |
| 888 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 889 | _, taskdata = self.prepareTreeData(pkgs_to_build, task) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 890 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 891 | seen_fns = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 892 | depend_tree = {} |
| 893 | depend_tree["depends"] = {} |
| 894 | depend_tree["pn"] = {} |
| 895 | depend_tree["rdepends-pn"] = {} |
| 896 | depend_tree["rdepends-pkg"] = {} |
| 897 | depend_tree["rrecs-pkg"] = {} |
| 898 | |
| 899 | # if we have extra caches, list all attributes they bring in |
| 900 | extra_info = [] |
| 901 | for cache_class in self.caches_array: |
| 902 | if type(cache_class) is type and issubclass(cache_class, bb.cache.RecipeInfoCommon) and hasattr(cache_class, 'cachefields'): |
| 903 | cachefields = getattr(cache_class, 'cachefields', []) |
| 904 | extra_info = extra_info + cachefields |
| 905 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 906 | tids = [] |
| 907 | for mc in taskdata: |
| 908 | for tid in taskdata[mc].taskentries: |
| 909 | tids.append(tid) |
| 910 | |
| 911 | for tid in tids: |
| 912 | (mc, fn, taskname, taskfn) = bb.runqueue.split_tid_mcfn(tid) |
| 913 | |
| 914 | pn = self.recipecaches[mc].pkg_fn[taskfn] |
| 915 | pn = self.add_mc_prefix(mc, pn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 916 | |
| 917 | if pn not in depend_tree["pn"]: |
| 918 | depend_tree["pn"][pn] = {} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 919 | depend_tree["pn"][pn]["filename"] = taskfn |
| 920 | version = "%s:%s-%s" % self.recipecaches[mc].pkg_pepvpr[taskfn] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 921 | depend_tree["pn"][pn]["version"] = version |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 922 | rdepends = self.recipecaches[mc].rundeps[taskfn] |
| 923 | rrecs = self.recipecaches[mc].runrecs[taskfn] |
| 924 | depend_tree["pn"][pn]["inherits"] = self.recipecaches[mc].inherits.get(taskfn, None) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 925 | |
| 926 | # for all extra attributes stored, add them to the dependency tree |
| 927 | for ei in extra_info: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 928 | depend_tree["pn"][pn][ei] = vars(self.recipecaches[mc])[ei][taskfn] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 929 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 930 | if taskfn not in seen_fns: |
| 931 | seen_fns.append(taskfn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 932 | |
| 933 | depend_tree["depends"][pn] = [] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 934 | for dep in taskdata[mc].depids[taskfn]: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 935 | pn_provider = "" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 936 | if dep in taskdata[mc].build_targets and taskdata[mc].build_targets[dep]: |
| 937 | fn_provider = taskdata[mc].build_targets[dep][0] |
| 938 | pn_provider = self.recipecaches[mc].pkg_fn[fn_provider] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 939 | else: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 940 | pn_provider = dep |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 941 | pn_provider = self.add_mc_prefix(mc, pn_provider) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 942 | depend_tree["depends"][pn].append(pn_provider) |
| 943 | |
| 944 | depend_tree["rdepends-pn"][pn] = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 945 | for rdep in taskdata[mc].rdepids[taskfn]: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 946 | pn_rprovider = "" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 947 | if rdep in taskdata[mc].run_targets and taskdata[mc].run_targets[rdep]: |
| 948 | fn_rprovider = taskdata[mc].run_targets[rdep][0] |
| 949 | pn_rprovider = self.recipecaches[mc].pkg_fn[fn_rprovider] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 950 | else: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 951 | pn_rprovider = rdep |
| 952 | pn_rprovider = self.add_mc_prefix(mc, pn_rprovider) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 953 | depend_tree["rdepends-pn"][pn].append(pn_rprovider) |
| 954 | |
| 955 | depend_tree["rdepends-pkg"].update(rdepends) |
| 956 | depend_tree["rrecs-pkg"].update(rrecs) |
| 957 | |
| 958 | return depend_tree |
| 959 | |
| 960 | def generateDepTreeEvent(self, pkgs_to_build, task): |
| 961 | """ |
| 962 | Create a task dependency graph of pkgs_to_build. |
| 963 | Generate an event with the result |
| 964 | """ |
| 965 | depgraph = self.generateTaskDepTreeData(pkgs_to_build, task) |
| 966 | bb.event.fire(bb.event.DepTreeGenerated(depgraph), self.data) |
| 967 | |
| 968 | def generateDotGraphFiles(self, pkgs_to_build, task): |
| 969 | """ |
| 970 | Create a task dependency graph of pkgs_to_build. |
| 971 | Save the result to a set of .dot files. |
| 972 | """ |
| 973 | |
| 974 | depgraph = self.generateTaskDepTreeData(pkgs_to_build, task) |
| 975 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 976 | with open('pn-buildlist', 'w') as f: |
| 977 | for pn in depgraph["pn"]: |
| 978 | f.write(pn + "\n") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 979 | logger.info("PN build list saved to 'pn-buildlist'") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 980 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 981 | # Remove old format output files to ensure no confusion with stale data |
| 982 | try: |
| 983 | os.unlink('pn-depends.dot') |
| 984 | except FileNotFoundError: |
| 985 | pass |
| 986 | try: |
| 987 | os.unlink('package-depends.dot') |
| 988 | except FileNotFoundError: |
| 989 | pass |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 990 | try: |
| 991 | os.unlink('recipe-depends.dot') |
| 992 | except FileNotFoundError: |
| 993 | pass |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 994 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 995 | with open('task-depends.dot', 'w') as f: |
| 996 | f.write("digraph depends {\n") |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 997 | for task in sorted(depgraph["tdepends"]): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 998 | (pn, taskname) = task.rsplit(".", 1) |
| 999 | fn = depgraph["pn"][pn]["filename"] |
| 1000 | version = depgraph["pn"][pn]["version"] |
| 1001 | f.write('"%s.%s" [label="%s %s\\n%s\\n%s"]\n' % (pn, taskname, pn, taskname, version, fn)) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1002 | for dep in sorted(depgraph["tdepends"][task]): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1003 | f.write('"%s" -> "%s"\n' % (task, dep)) |
| 1004 | f.write("}\n") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1005 | logger.info("Task dependencies saved to 'task-depends.dot'") |
| 1006 | |
| 1007 | def show_appends_with_no_recipes(self): |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1008 | appends_without_recipes = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1009 | # Determine which bbappends haven't been applied |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1010 | for mc in self.multiconfigs: |
| 1011 | # First get list of recipes, including skipped |
| 1012 | recipefns = list(self.recipecaches[mc].pkg_fn.keys()) |
| 1013 | recipefns.extend(self.skiplist.keys()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1014 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1015 | # Work out list of bbappends that have been applied |
| 1016 | applied_appends = [] |
| 1017 | for fn in recipefns: |
| 1018 | applied_appends.extend(self.collections[mc].get_file_appends(fn)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1019 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1020 | appends_without_recipes[mc] = [] |
| 1021 | for _, appendfn in self.collections[mc].bbappends: |
| 1022 | if not appendfn in applied_appends: |
| 1023 | appends_without_recipes[mc].append(appendfn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1024 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1025 | msgs = [] |
| 1026 | for mc in sorted(appends_without_recipes.keys()): |
| 1027 | if appends_without_recipes[mc]: |
| 1028 | msgs.append('No recipes in %s available for:\n %s' % (mc if mc else 'default', |
| 1029 | '\n '.join(appends_without_recipes[mc]))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1030 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1031 | if msgs: |
| 1032 | msg = "\n".join(msgs) |
| 1033 | warn_only = self.databuilder.mcdata[mc].getVar("BB_DANGLINGAPPENDS_WARNONLY", \ |
| 1034 | False) or "no" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1035 | if warn_only.lower() in ("1", "yes", "true"): |
| 1036 | bb.warn(msg) |
| 1037 | else: |
| 1038 | bb.fatal(msg) |
| 1039 | |
| 1040 | def handlePrefProviders(self): |
| 1041 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1042 | for mc in self.multiconfigs: |
| 1043 | localdata = data.createCopy(self.databuilder.mcdata[mc]) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1044 | bb.data.expandKeys(localdata) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1045 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1046 | # Handle PREFERRED_PROVIDERS |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1047 | for p in (localdata.getVar('PREFERRED_PROVIDERS') or "").split(): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1048 | try: |
| 1049 | (providee, provider) = p.split(':') |
| 1050 | except: |
| 1051 | providerlog.critical("Malformed option in PREFERRED_PROVIDERS variable: %s" % p) |
| 1052 | continue |
| 1053 | if providee in self.recipecaches[mc].preferred and self.recipecaches[mc].preferred[providee] != provider: |
| 1054 | providerlog.error("conflicting preferences for %s: both %s and %s specified", providee, provider, self.recipecaches[mc].preferred[providee]) |
| 1055 | self.recipecaches[mc].preferred[providee] = provider |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1056 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1057 | def findConfigFilePath(self, configfile): |
| 1058 | """ |
| 1059 | Find the location on disk of configfile and if it exists and was parsed by BitBake |
| 1060 | emit the ConfigFilePathFound event with the path to the file. |
| 1061 | """ |
| 1062 | path = bb.cookerdata.findConfigFile(configfile, self.data) |
| 1063 | if not path: |
| 1064 | return |
| 1065 | |
| 1066 | # Generate a list of parsed configuration files by searching the files |
| 1067 | # listed in the __depends and __base_depends variables with a .conf suffix. |
| 1068 | conffiles = [] |
| 1069 | dep_files = self.data.getVar('__base_depends', False) or [] |
| 1070 | dep_files = dep_files + (self.data.getVar('__depends', False) or []) |
| 1071 | |
| 1072 | for f in dep_files: |
| 1073 | if f[0].endswith(".conf"): |
| 1074 | conffiles.append(f[0]) |
| 1075 | |
| 1076 | _, conf, conffile = path.rpartition("conf/") |
| 1077 | match = os.path.join(conf, conffile) |
| 1078 | # Try and find matches for conf/conffilename.conf as we don't always |
| 1079 | # have the full path to the file. |
| 1080 | for cfg in conffiles: |
| 1081 | if cfg.endswith(match): |
| 1082 | bb.event.fire(bb.event.ConfigFilePathFound(path), |
| 1083 | self.data) |
| 1084 | break |
| 1085 | |
| 1086 | def findFilesMatchingInDir(self, filepattern, directory): |
| 1087 | """ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1088 | Searches for files containing the substring 'filepattern' which are children of |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1089 | 'directory' in each BBPATH. i.e. to find all rootfs package classes available |
| 1090 | to BitBake one could call findFilesMatchingInDir(self, 'rootfs_', 'classes') |
| 1091 | or to find all machine configuration files one could call: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1092 | findFilesMatchingInDir(self, '.conf', 'conf/machine') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1093 | """ |
| 1094 | |
| 1095 | matches = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1096 | bbpaths = self.data.getVar('BBPATH').split(':') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1097 | for path in bbpaths: |
| 1098 | dirpath = os.path.join(path, directory) |
| 1099 | if os.path.exists(dirpath): |
| 1100 | for root, dirs, files in os.walk(dirpath): |
| 1101 | for f in files: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1102 | if filepattern in f: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1103 | matches.append(f) |
| 1104 | |
| 1105 | if matches: |
| 1106 | bb.event.fire(bb.event.FilesMatchingFound(filepattern, matches), self.data) |
| 1107 | |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 1108 | def testCookerCommandEvent(self, filepattern): |
| 1109 | # Dummy command used by OEQA selftest to test tinfoil without IO |
| 1110 | matches = ["A", "B"] |
| 1111 | bb.event.fire(bb.event.FilesMatchingFound(filepattern, matches), self.data) |
| 1112 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1113 | def findProviders(self, mc=''): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1114 | return bb.providers.findProviders(self.databuilder.mcdata[mc], self.recipecaches[mc], self.recipecaches[mc].pkg_pn) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1115 | |
| 1116 | def findBestProvider(self, pn, mc=''): |
| 1117 | if pn in self.recipecaches[mc].providers: |
| 1118 | filenames = self.recipecaches[mc].providers[pn] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1119 | eligible, foundUnique = bb.providers.filterProviders(filenames, pn, self.databuilder.mcdata[mc], self.recipecaches[mc]) |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 1120 | if eligible is not None: |
| 1121 | filename = eligible[0] |
| 1122 | else: |
| 1123 | filename = None |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1124 | return None, None, None, filename |
| 1125 | elif pn in self.recipecaches[mc].pkg_pn: |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 1126 | (latest, latest_f, preferred_ver, preferred_file, required) = bb.providers.findBestProvider(pn, self.databuilder.mcdata[mc], self.recipecaches[mc], self.recipecaches[mc].pkg_pn) |
| 1127 | if required and preferred_file is None: |
| 1128 | return None, None, None, None |
| 1129 | return (latest, latest_f, preferred_ver, preferred_file) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1130 | else: |
| 1131 | return None, None, None, None |
| 1132 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1133 | def findConfigFiles(self, varname): |
| 1134 | """ |
| 1135 | Find config files which are appropriate values for varname. |
| 1136 | i.e. MACHINE, DISTRO |
| 1137 | """ |
| 1138 | possible = [] |
| 1139 | var = varname.lower() |
| 1140 | |
| 1141 | data = self.data |
| 1142 | # iterate configs |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1143 | bbpaths = data.getVar('BBPATH').split(':') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1144 | for path in bbpaths: |
| 1145 | confpath = os.path.join(path, "conf", var) |
| 1146 | if os.path.exists(confpath): |
| 1147 | for root, dirs, files in os.walk(confpath): |
| 1148 | # get all child files, these are appropriate values |
| 1149 | for f in files: |
| 1150 | val, sep, end = f.rpartition('.') |
| 1151 | if end == 'conf': |
| 1152 | possible.append(val) |
| 1153 | |
| 1154 | if possible: |
| 1155 | bb.event.fire(bb.event.ConfigFilesFound(var, possible), self.data) |
| 1156 | |
| 1157 | def findInheritsClass(self, klass): |
| 1158 | """ |
| 1159 | Find all recipes which inherit the specified class |
| 1160 | """ |
| 1161 | pkg_list = [] |
| 1162 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1163 | for pfn in self.recipecaches[''].pkg_fn: |
| 1164 | inherits = self.recipecaches[''].inherits.get(pfn, None) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1165 | if inherits and klass in inherits: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1166 | pkg_list.append(self.recipecaches[''].pkg_fn[pfn]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1167 | |
| 1168 | return pkg_list |
| 1169 | |
| 1170 | def generateTargetsTree(self, klass=None, pkgs=None): |
| 1171 | """ |
| 1172 | Generate a dependency tree of buildable targets |
| 1173 | Generate an event with the result |
| 1174 | """ |
| 1175 | # if the caller hasn't specified a pkgs list default to universe |
| 1176 | if not pkgs: |
| 1177 | pkgs = ['universe'] |
| 1178 | # if inherited_class passed ensure all recipes which inherit the |
| 1179 | # specified class are included in pkgs |
| 1180 | if klass: |
| 1181 | extra_pkgs = self.findInheritsClass(klass) |
| 1182 | pkgs = pkgs + extra_pkgs |
| 1183 | |
| 1184 | # generate a dependency tree for all our packages |
| 1185 | tree = self.generatePkgDepTreeData(pkgs, 'build') |
| 1186 | bb.event.fire(bb.event.TargetsTreeGenerated(tree), self.data) |
| 1187 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1188 | def interactiveMode( self ): |
| 1189 | """Drop off into a shell""" |
| 1190 | try: |
| 1191 | from bb import shell |
| 1192 | except ImportError: |
| 1193 | parselog.exception("Interactive mode not available") |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1194 | raise bb.BBHandledException() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1195 | else: |
| 1196 | shell.start( self ) |
| 1197 | |
| 1198 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1199 | def handleCollections(self, collections): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1200 | """Handle collections""" |
| 1201 | errors = False |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1202 | self.bbfile_config_priorities = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1203 | if collections: |
| 1204 | collection_priorities = {} |
| 1205 | collection_depends = {} |
| 1206 | collection_list = collections.split() |
| 1207 | min_prio = 0 |
| 1208 | for c in collection_list: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1209 | bb.debug(1,'Processing %s in collection list' % (c)) |
| 1210 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1211 | # Get collection priority if defined explicitly |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1212 | priority = self.data.getVar("BBFILE_PRIORITY_%s" % c) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1213 | if priority: |
| 1214 | try: |
| 1215 | prio = int(priority) |
| 1216 | except ValueError: |
| 1217 | parselog.error("invalid value for BBFILE_PRIORITY_%s: \"%s\"", c, priority) |
| 1218 | errors = True |
| 1219 | if min_prio == 0 or prio < min_prio: |
| 1220 | min_prio = prio |
| 1221 | collection_priorities[c] = prio |
| 1222 | else: |
| 1223 | collection_priorities[c] = None |
| 1224 | |
| 1225 | # Check dependencies and store information for priority calculation |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1226 | deps = self.data.getVar("LAYERDEPENDS_%s" % c) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1227 | if deps: |
| 1228 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1229 | depDict = bb.utils.explode_dep_versions2(deps) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1230 | except bb.utils.VersionStringException as vse: |
| 1231 | bb.fatal('Error parsing LAYERDEPENDS_%s: %s' % (c, str(vse))) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1232 | for dep, oplist in list(depDict.items()): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1233 | if dep in collection_list: |
| 1234 | for opstr in oplist: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1235 | layerver = self.data.getVar("LAYERVERSION_%s" % dep) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1236 | (op, depver) = opstr.split() |
| 1237 | if layerver: |
| 1238 | try: |
| 1239 | res = bb.utils.vercmp_string_op(layerver, depver, op) |
| 1240 | except bb.utils.VersionStringException as vse: |
| 1241 | bb.fatal('Error parsing LAYERDEPENDS_%s: %s' % (c, str(vse))) |
| 1242 | if not res: |
| 1243 | parselog.error("Layer '%s' depends on version %s of layer '%s', but version %s is currently enabled in your configuration. Check that you are using the correct matching versions/branches of these two layers.", c, opstr, dep, layerver) |
| 1244 | errors = True |
| 1245 | else: |
| 1246 | parselog.error("Layer '%s' depends on version %s of layer '%s', which exists in your configuration but does not specify a version. Check that you are using the correct matching versions/branches of these two layers.", c, opstr, dep) |
| 1247 | errors = True |
| 1248 | else: |
| 1249 | parselog.error("Layer '%s' depends on layer '%s', but this layer is not enabled in your configuration", c, dep) |
| 1250 | errors = True |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1251 | collection_depends[c] = list(depDict.keys()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1252 | else: |
| 1253 | collection_depends[c] = [] |
| 1254 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1255 | # Check recommends and store information for priority calculation |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1256 | recs = self.data.getVar("LAYERRECOMMENDS_%s" % c) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1257 | if recs: |
| 1258 | try: |
| 1259 | recDict = bb.utils.explode_dep_versions2(recs) |
| 1260 | except bb.utils.VersionStringException as vse: |
| 1261 | bb.fatal('Error parsing LAYERRECOMMENDS_%s: %s' % (c, str(vse))) |
| 1262 | for rec, oplist in list(recDict.items()): |
| 1263 | if rec in collection_list: |
| 1264 | if oplist: |
| 1265 | opstr = oplist[0] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1266 | layerver = self.data.getVar("LAYERVERSION_%s" % rec) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1267 | if layerver: |
| 1268 | (op, recver) = opstr.split() |
| 1269 | try: |
| 1270 | res = bb.utils.vercmp_string_op(layerver, recver, op) |
| 1271 | except bb.utils.VersionStringException as vse: |
| 1272 | bb.fatal('Error parsing LAYERRECOMMENDS_%s: %s' % (c, str(vse))) |
| 1273 | if not res: |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 1274 | parselog.debug3("Layer '%s' recommends version %s of layer '%s', but version %s is currently enabled in your configuration. Check that you are using the correct matching versions/branches of these two layers.", c, opstr, rec, layerver) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1275 | continue |
| 1276 | else: |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 1277 | parselog.debug3("Layer '%s' recommends version %s of layer '%s', which exists in your configuration but does not specify a version. Check that you are using the correct matching versions/branches of these two layers.", c, opstr, rec) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1278 | continue |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 1279 | parselog.debug3("Layer '%s' recommends layer '%s', so we are adding it", c, rec) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1280 | collection_depends[c].append(rec) |
| 1281 | else: |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 1282 | parselog.debug3("Layer '%s' recommends layer '%s', but this layer is not enabled in your configuration", c, rec) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1283 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1284 | # Recursively work out collection priorities based on dependencies |
| 1285 | def calc_layer_priority(collection): |
| 1286 | if not collection_priorities[collection]: |
| 1287 | max_depprio = min_prio |
| 1288 | for dep in collection_depends[collection]: |
| 1289 | calc_layer_priority(dep) |
| 1290 | depprio = collection_priorities[dep] |
| 1291 | if depprio > max_depprio: |
| 1292 | max_depprio = depprio |
| 1293 | max_depprio += 1 |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 1294 | parselog.debug("Calculated priority of layer %s as %d", collection, max_depprio) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1295 | collection_priorities[collection] = max_depprio |
| 1296 | |
| 1297 | # Calculate all layer priorities using calc_layer_priority and store in bbfile_config_priorities |
| 1298 | for c in collection_list: |
| 1299 | calc_layer_priority(c) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1300 | regex = self.data.getVar("BBFILE_PATTERN_%s" % c) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1301 | if regex is None: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1302 | parselog.error("BBFILE_PATTERN_%s not defined" % c) |
| 1303 | errors = True |
| 1304 | continue |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1305 | elif regex == "": |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 1306 | parselog.debug("BBFILE_PATTERN_%s is empty" % c) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1307 | cre = re.compile('^NULL$') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1308 | errors = False |
| 1309 | else: |
| 1310 | try: |
| 1311 | cre = re.compile(regex) |
| 1312 | except re.error: |
| 1313 | parselog.error("BBFILE_PATTERN_%s \"%s\" is not a valid regular expression", c, regex) |
| 1314 | errors = True |
| 1315 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1316 | self.bbfile_config_priorities.append((c, regex, cre, collection_priorities[c])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1317 | if errors: |
| 1318 | # We've already printed the actual error(s) |
| 1319 | raise CollectionError("Errors during parsing layer configuration") |
| 1320 | |
| 1321 | def buildSetVars(self): |
| 1322 | """ |
| 1323 | Setup any variables needed before starting a build |
| 1324 | """ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1325 | t = time.gmtime() |
| 1326 | for mc in self.databuilder.mcdata: |
| 1327 | ds = self.databuilder.mcdata[mc] |
| 1328 | if not ds.getVar("BUILDNAME", False): |
| 1329 | ds.setVar("BUILDNAME", "${DATE}${TIME}") |
| 1330 | ds.setVar("BUILDSTART", time.strftime('%m/%d/%Y %H:%M:%S', t)) |
| 1331 | ds.setVar("DATE", time.strftime('%Y%m%d', t)) |
| 1332 | ds.setVar("TIME", time.strftime('%H%M%S', t)) |
| 1333 | |
| 1334 | def reset_mtime_caches(self): |
| 1335 | """ |
| 1336 | Reset mtime caches - this is particularly important when memory resident as something |
| 1337 | which is cached is not unlikely to have changed since the last invocation (e.g. a |
| 1338 | file associated with a recipe might have been modified by the user). |
| 1339 | """ |
| 1340 | build.reset_cache() |
| 1341 | bb.fetch._checksum_cache.mtime_cache.clear() |
| 1342 | siggen_cache = getattr(bb.parse.siggen, 'checksum_cache', None) |
| 1343 | if siggen_cache: |
| 1344 | bb.parse.siggen.checksum_cache.mtime_cache.clear() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1345 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1346 | def matchFiles(self, bf, mc=''): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1347 | """ |
| 1348 | Find the .bb files which match the expression in 'buildfile'. |
| 1349 | """ |
| 1350 | if bf.startswith("/") or bf.startswith("../"): |
| 1351 | bf = os.path.abspath(bf) |
| 1352 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1353 | self.collections = {mc: CookerCollectFiles(self.bbfile_config_priorities, mc)} |
| 1354 | filelist, masked, searchdirs = self.collections[mc].collect_bbfiles(self.databuilder.mcdata[mc], self.databuilder.mcdata[mc]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1355 | try: |
| 1356 | os.stat(bf) |
| 1357 | bf = os.path.abspath(bf) |
| 1358 | return [bf] |
| 1359 | except OSError: |
| 1360 | regexp = re.compile(bf) |
| 1361 | matches = [] |
| 1362 | for f in filelist: |
| 1363 | if regexp.search(f) and os.path.isfile(f): |
| 1364 | matches.append(f) |
| 1365 | return matches |
| 1366 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1367 | def matchFile(self, buildfile, mc=''): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1368 | """ |
| 1369 | Find the .bb file which matches the expression in 'buildfile'. |
| 1370 | Raise an error if multiple files |
| 1371 | """ |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1372 | matches = self.matchFiles(buildfile, mc) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1373 | if len(matches) != 1: |
| 1374 | if matches: |
| 1375 | msg = "Unable to match '%s' to a specific recipe file - %s matches found:" % (buildfile, len(matches)) |
| 1376 | if matches: |
| 1377 | for f in matches: |
| 1378 | msg += "\n %s" % f |
| 1379 | parselog.error(msg) |
| 1380 | else: |
| 1381 | parselog.error("Unable to find any recipe file matching '%s'" % buildfile) |
| 1382 | raise NoSpecificMatch |
| 1383 | return matches[0] |
| 1384 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1385 | def buildFile(self, buildfile, task): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1386 | """ |
| 1387 | Build the file matching regexp buildfile |
| 1388 | """ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1389 | bb.event.fire(bb.event.BuildInit(), self.data) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1390 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1391 | # Too many people use -b because they think it's how you normally |
| 1392 | # specify a target to be built, so show a warning |
| 1393 | bb.warn("Buildfile specified, dependencies will not be handled. If this is not what you want, do not use -b / --buildfile.") |
| 1394 | |
| 1395 | self.buildFileInternal(buildfile, task) |
| 1396 | |
| 1397 | def buildFileInternal(self, buildfile, task, fireevents=True, quietlog=False): |
| 1398 | """ |
| 1399 | Build the file matching regexp buildfile |
| 1400 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1401 | |
| 1402 | # Parse the configuration here. We need to do it explicitly here since |
| 1403 | # buildFile() doesn't use the cache |
| 1404 | self.parseConfiguration() |
| 1405 | |
| 1406 | # If we are told to do the None task then query the default task |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1407 | if task is None: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1408 | task = self.configuration.cmd |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1409 | if not task.startswith("do_"): |
| 1410 | task = "do_%s" % task |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1411 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1412 | fn, cls, mc = bb.cache.virtualfn2realfn(buildfile) |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1413 | fn = self.matchFile(fn, mc) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1414 | |
| 1415 | self.buildSetVars() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1416 | self.reset_mtime_caches() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1417 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1418 | bb_caches = bb.cache.MulticonfigCache(self.databuilder, self.data_hash, self.caches_array) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1419 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1420 | infos = bb_caches[mc].parse(fn, self.collections[mc].get_file_appends(fn)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1421 | infos = dict(infos) |
| 1422 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1423 | fn = bb.cache.realfn2virtual(fn, cls, mc) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1424 | try: |
| 1425 | info_array = infos[fn] |
| 1426 | except KeyError: |
| 1427 | bb.fatal("%s does not exist" % fn) |
| 1428 | |
| 1429 | if info_array[0].skipped: |
| 1430 | bb.fatal("%s was skipped: %s" % (fn, info_array[0].skipreason)) |
| 1431 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1432 | self.recipecaches[mc].add_from_recipeinfo(fn, info_array) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1433 | |
| 1434 | # Tweak some variables |
| 1435 | item = info_array[0].pn |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1436 | self.recipecaches[mc].ignored_dependencies = set() |
| 1437 | self.recipecaches[mc].bbfile_priority[fn] = 1 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1438 | self.configuration.limited_deps = True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1439 | |
| 1440 | # Remove external dependencies |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1441 | self.recipecaches[mc].task_deps[fn]['depends'] = {} |
| 1442 | self.recipecaches[mc].deps[fn] = [] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1443 | self.recipecaches[mc].rundeps[fn] = defaultdict(list) |
| 1444 | self.recipecaches[mc].runrecs[fn] = defaultdict(list) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1445 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1446 | bb.parse.siggen.setup_datacache(self.recipecaches) |
| 1447 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1448 | # Invalidate task for target if force mode active |
| 1449 | if self.configuration.force: |
| 1450 | logger.verbose("Invalidate task %s, %s", task, fn) |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1451 | bb.parse.siggen.invalidate_task(task, fn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1452 | |
| 1453 | # Setup taskdata structure |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1454 | taskdata = {} |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1455 | taskdata[mc] = bb.taskdata.TaskData(self.configuration.halt) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1456 | taskdata[mc].add_provider(self.databuilder.mcdata[mc], self.recipecaches[mc], item) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1457 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1458 | if quietlog: |
| 1459 | rqloglevel = bb.runqueue.logger.getEffectiveLevel() |
| 1460 | bb.runqueue.logger.setLevel(logging.WARNING) |
| 1461 | |
| 1462 | buildname = self.databuilder.mcdata[mc].getVar("BUILDNAME") |
| 1463 | if fireevents: |
| 1464 | bb.event.fire(bb.event.BuildStarted(buildname, [item]), self.databuilder.mcdata[mc]) |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1465 | bb.event.enable_heartbeat() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1466 | |
| 1467 | # Execute the runqueue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1468 | runlist = [[mc, item, task, fn]] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1469 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1470 | rq = bb.runqueue.RunQueue(self, self.data, self.recipecaches, taskdata, runlist) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1471 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1472 | def buildFileIdle(server, rq, halt): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1473 | |
| 1474 | msg = None |
| 1475 | interrupted = 0 |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1476 | if halt or self.state == state.forceshutdown: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1477 | rq.finish_runqueue(True) |
| 1478 | msg = "Forced shutdown" |
| 1479 | interrupted = 2 |
| 1480 | elif self.state == state.shutdown: |
| 1481 | rq.finish_runqueue(False) |
| 1482 | msg = "Stopped build" |
| 1483 | interrupted = 1 |
| 1484 | failures = 0 |
| 1485 | try: |
| 1486 | retval = rq.execute_runqueue() |
| 1487 | except runqueue.TaskFailure as exc: |
| 1488 | failures += len(exc.args) |
| 1489 | retval = False |
| 1490 | except SystemExit as exc: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1491 | if quietlog: |
| 1492 | bb.runqueue.logger.setLevel(rqloglevel) |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1493 | return bb.server.process.idleFinish(str(exc)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1494 | |
| 1495 | if not retval: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1496 | if fireevents: |
| 1497 | bb.event.fire(bb.event.BuildCompleted(len(rq.rqdata.runtaskentries), buildname, item, failures, interrupted), self.databuilder.mcdata[mc]) |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1498 | bb.event.disable_heartbeat() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1499 | # We trashed self.recipecaches above |
| 1500 | self.parsecache_valid = False |
| 1501 | self.configuration.limited_deps = False |
| 1502 | bb.parse.siggen.reset(self.data) |
| 1503 | if quietlog: |
| 1504 | bb.runqueue.logger.setLevel(rqloglevel) |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1505 | return bb.server.process.idleFinish(msg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1506 | if retval is True: |
| 1507 | return True |
| 1508 | return retval |
| 1509 | |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 1510 | self.idleCallBackRegister(buildFileIdle, rq) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1511 | |
| 1512 | def buildTargets(self, targets, task): |
| 1513 | """ |
| 1514 | Attempt to build the targets specified |
| 1515 | """ |
| 1516 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1517 | def buildTargetsIdle(server, rq, halt): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1518 | msg = None |
| 1519 | interrupted = 0 |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1520 | if halt or self.state == state.forceshutdown: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1521 | rq.finish_runqueue(True) |
| 1522 | msg = "Forced shutdown" |
| 1523 | interrupted = 2 |
| 1524 | elif self.state == state.shutdown: |
| 1525 | rq.finish_runqueue(False) |
| 1526 | msg = "Stopped build" |
| 1527 | interrupted = 1 |
| 1528 | failures = 0 |
| 1529 | try: |
| 1530 | retval = rq.execute_runqueue() |
| 1531 | except runqueue.TaskFailure as exc: |
| 1532 | failures += len(exc.args) |
| 1533 | retval = False |
| 1534 | except SystemExit as exc: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1535 | return bb.server.process.idleFinish(str(exc)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1536 | |
| 1537 | if not retval: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1538 | try: |
| 1539 | for mc in self.multiconfigs: |
| 1540 | bb.event.fire(bb.event.BuildCompleted(len(rq.rqdata.runtaskentries), buildname, targets, failures, interrupted), self.databuilder.mcdata[mc]) |
| 1541 | finally: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1542 | bb.event.disable_heartbeat() |
| 1543 | return bb.server.process.idleFinish(msg) |
| 1544 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1545 | if retval is True: |
| 1546 | return True |
| 1547 | return retval |
| 1548 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1549 | self.reset_mtime_caches() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1550 | self.buildSetVars() |
| 1551 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1552 | # If we are told to do the None task then query the default task |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1553 | if task is None: |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1554 | task = self.configuration.cmd |
| 1555 | |
| 1556 | if not task.startswith("do_"): |
| 1557 | task = "do_%s" % task |
| 1558 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1559 | packages = [target if ':' in target else '%s:%s' % (target, task) for target in targets] |
| 1560 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1561 | bb.event.fire(bb.event.BuildInit(packages), self.data) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1562 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1563 | taskdata, runlist = self.buildTaskData(targets, task, self.configuration.halt) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1564 | |
| 1565 | buildname = self.data.getVar("BUILDNAME", False) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1566 | |
| 1567 | # make targets to always look as <target>:do_<task> |
| 1568 | ntargets = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1569 | for target in runlist: |
| 1570 | if target[0]: |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 1571 | ntargets.append("mc:%s:%s:%s" % (target[0], target[1], target[2])) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1572 | ntargets.append("%s:%s" % (target[1], target[2])) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1573 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1574 | for mc in self.multiconfigs: |
| 1575 | bb.event.fire(bb.event.BuildStarted(buildname, ntargets), self.databuilder.mcdata[mc]) |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1576 | bb.event.enable_heartbeat() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1577 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1578 | rq = bb.runqueue.RunQueue(self, self.data, self.recipecaches, taskdata, runlist) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1579 | if 'universe' in targets: |
| 1580 | rq.rqdata.warn_multi_bb = True |
| 1581 | |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 1582 | self.idleCallBackRegister(buildTargetsIdle, rq) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1583 | |
| 1584 | |
| 1585 | def getAllKeysWithFlags(self, flaglist): |
| 1586 | dump = {} |
| 1587 | for k in self.data.keys(): |
| 1588 | try: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1589 | expand = True |
| 1590 | flags = self.data.getVarFlags(k) |
| 1591 | if flags and "func" in flags and "python" in flags: |
| 1592 | expand = False |
| 1593 | v = self.data.getVar(k, expand) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1594 | if not k.startswith("__") and not isinstance(v, bb.data_smart.DataSmart): |
| 1595 | dump[k] = { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1596 | 'v' : str(v) , |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1597 | 'history' : self.data.varhistory.variable(k), |
| 1598 | } |
| 1599 | for d in flaglist: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1600 | if flags and d in flags: |
| 1601 | dump[k][d] = flags[d] |
| 1602 | else: |
| 1603 | dump[k][d] = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1604 | except Exception as e: |
| 1605 | print(e) |
| 1606 | return dump |
| 1607 | |
| 1608 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1609 | def updateCacheSync(self): |
| 1610 | if self.state == state.running: |
| 1611 | return |
| 1612 | |
| 1613 | # reload files for which we got notifications |
| 1614 | for p in self.inotify_modified_files: |
| 1615 | bb.parse.update_cache(p) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1616 | if p in bb.parse.BBHandler.cached_statements: |
| 1617 | del bb.parse.BBHandler.cached_statements[p] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1618 | self.inotify_modified_files = [] |
| 1619 | |
| 1620 | if not self.baseconfig_valid: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 1621 | logger.debug("Reloading base configuration data") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1622 | self.initConfigurationData() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1623 | self.handlePRServ() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1624 | |
| 1625 | # This is called for all async commands when self.state != running |
| 1626 | def updateCache(self): |
| 1627 | if self.state == state.running: |
| 1628 | return |
| 1629 | |
| 1630 | if self.state in (state.shutdown, state.forceshutdown, state.error): |
| 1631 | if hasattr(self.parser, 'shutdown'): |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 1632 | self.parser.shutdown(clean=False) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1633 | self.parser.final_cleanup() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1634 | raise bb.BBHandledException() |
| 1635 | |
| 1636 | if self.state != state.parsing: |
| 1637 | self.updateCacheSync() |
| 1638 | |
| 1639 | if self.state != state.parsing and not self.parsecache_valid: |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 1640 | self.setupParserWatcher() |
| 1641 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1642 | bb.parse.siggen.reset(self.data) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1643 | self.parseConfiguration () |
| 1644 | if CookerFeatures.SEND_SANITYEVENTS in self.featureset: |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1645 | for mc in self.multiconfigs: |
| 1646 | bb.event.fire(bb.event.SanityCheck(False), self.databuilder.mcdata[mc]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1647 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1648 | for mc in self.multiconfigs: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1649 | ignore = self.databuilder.mcdata[mc].getVar("ASSUME_PROVIDED") or "" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1650 | self.recipecaches[mc].ignored_dependencies = set(ignore.split()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1651 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1652 | for dep in self.configuration.extra_assume_provided: |
| 1653 | self.recipecaches[mc].ignored_dependencies.add(dep) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1654 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1655 | self.collections = {} |
| 1656 | |
| 1657 | mcfilelist = {} |
| 1658 | total_masked = 0 |
| 1659 | searchdirs = set() |
| 1660 | for mc in self.multiconfigs: |
| 1661 | self.collections[mc] = CookerCollectFiles(self.bbfile_config_priorities, mc) |
| 1662 | (filelist, masked, search) = self.collections[mc].collect_bbfiles(self.databuilder.mcdata[mc], self.databuilder.mcdata[mc]) |
| 1663 | |
| 1664 | mcfilelist[mc] = filelist |
| 1665 | total_masked += masked |
| 1666 | searchdirs |= set(search) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1667 | |
| 1668 | # Add inotify watches for directories searched for bb/bbappend files |
| 1669 | for dirent in searchdirs: |
| 1670 | self.add_filewatch([[dirent]], dirs=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1671 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1672 | self.parser = CookerParser(self, mcfilelist, total_masked) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1673 | self.parsecache_valid = True |
| 1674 | |
| 1675 | self.state = state.parsing |
| 1676 | |
| 1677 | if not self.parser.parse_next(): |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 1678 | collectlog.debug("parsing complete") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1679 | if self.parser.error: |
| 1680 | raise bb.BBHandledException() |
| 1681 | self.show_appends_with_no_recipes() |
| 1682 | self.handlePrefProviders() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1683 | for mc in self.multiconfigs: |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 1684 | self.recipecaches[mc].bbfile_priority = self.collections[mc].collection_priorities(self.recipecaches[mc].pkg_fn, self.parser.mcfilelist[mc], self.data) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1685 | self.state = state.running |
| 1686 | |
| 1687 | # Send an event listing all stamps reachable after parsing |
| 1688 | # which the metadata may use to clean up stale data |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1689 | for mc in self.multiconfigs: |
| 1690 | event = bb.event.ReachableStamps(self.recipecaches[mc].stamp) |
| 1691 | bb.event.fire(event, self.databuilder.mcdata[mc]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1692 | return None |
| 1693 | |
| 1694 | return True |
| 1695 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1696 | def checkPackages(self, pkgs_to_build, task=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1697 | |
| 1698 | # Return a copy, don't modify the original |
| 1699 | pkgs_to_build = pkgs_to_build[:] |
| 1700 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1701 | if not pkgs_to_build: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1702 | raise NothingToBuild |
| 1703 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1704 | ignore = (self.data.getVar("ASSUME_PROVIDED") or "").split() |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 1705 | for pkg in pkgs_to_build.copy(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1706 | if pkg in ignore: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1707 | parselog.warning("Explicit target \"%s\" is in ASSUME_PROVIDED, ignoring" % pkg) |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 1708 | if pkg.startswith("multiconfig:"): |
| 1709 | pkgs_to_build.remove(pkg) |
| 1710 | pkgs_to_build.append(pkg.replace("multiconfig:", "mc:")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1711 | |
| 1712 | if 'world' in pkgs_to_build: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1713 | pkgs_to_build.remove('world') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1714 | for mc in self.multiconfigs: |
| 1715 | bb.providers.buildWorldTargetList(self.recipecaches[mc], task) |
| 1716 | for t in self.recipecaches[mc].world_target: |
| 1717 | if mc: |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 1718 | t = "mc:" + mc + ":" + t |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1719 | pkgs_to_build.append(t) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1720 | |
| 1721 | if 'universe' in pkgs_to_build: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1722 | parselog.verbnote("The \"universe\" target is only intended for testing and may produce errors.") |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 1723 | parselog.debug("collating packages for \"universe\"") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1724 | pkgs_to_build.remove('universe') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1725 | for mc in self.multiconfigs: |
| 1726 | for t in self.recipecaches[mc].universe_target: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1727 | if task: |
| 1728 | foundtask = False |
| 1729 | for provider_fn in self.recipecaches[mc].providers[t]: |
| 1730 | if task in self.recipecaches[mc].task_deps[provider_fn]['tasks']: |
| 1731 | foundtask = True |
| 1732 | break |
| 1733 | if not foundtask: |
| 1734 | bb.debug(1, "Skipping %s for universe tasks as task %s doesn't exist" % (t, task)) |
| 1735 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1736 | if mc: |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 1737 | t = "mc:" + mc + ":" + t |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1738 | pkgs_to_build.append(t) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1739 | |
| 1740 | return pkgs_to_build |
| 1741 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1742 | def pre_serve(self): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1743 | return |
| 1744 | |
| 1745 | def post_serve(self): |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1746 | self.shutdown(force=True) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1747 | prserv.serv.auto_shutdown() |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame] | 1748 | if hasattr(bb.parse, "siggen"): |
| 1749 | bb.parse.siggen.exit() |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 1750 | if self.hashserv: |
| 1751 | self.hashserv.process.terminate() |
| 1752 | self.hashserv.process.join() |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 1753 | if hasattr(self, "data"): |
| 1754 | bb.event.fire(CookerExit(), self.data) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1755 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1756 | def shutdown(self, force=False): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1757 | if force: |
| 1758 | self.state = state.forceshutdown |
| 1759 | else: |
| 1760 | self.state = state.shutdown |
| 1761 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1762 | if self.parser: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1763 | self.parser.shutdown(clean=False) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1764 | self.parser.final_cleanup() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1765 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1766 | def finishcommand(self): |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1767 | if hasattr(self.parser, 'shutdown'): |
| 1768 | self.parser.shutdown(clean=False) |
| 1769 | self.parser.final_cleanup() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1770 | self.state = state.initial |
| 1771 | |
| 1772 | def reset(self): |
Patrick Williams | 4585273 | 2022-04-02 08:58:32 -0500 | [diff] [blame] | 1773 | if hasattr(bb.parse, "siggen"): |
| 1774 | bb.parse.siggen.exit() |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1775 | self.finishcommand() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1776 | self.initConfigurationData() |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 1777 | self.handlePRServ() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1778 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1779 | def clientComplete(self): |
| 1780 | """Called when the client is done using the server""" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1781 | self.finishcommand() |
| 1782 | self.extraconfigdata = {} |
| 1783 | self.command.reset() |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1784 | if hasattr(self, "data"): |
| 1785 | self.databuilder.reset() |
| 1786 | self.data = self.databuilder.data |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1787 | # In theory tinfoil could have modified the base data before parsing, |
| 1788 | # ideally need to track if anything did modify the datastore |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1789 | self.parsecache_valid = False |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1790 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1791 | |
| 1792 | class CookerExit(bb.event.Event): |
| 1793 | """ |
| 1794 | Notify clients of the Cooker shutdown |
| 1795 | """ |
| 1796 | |
| 1797 | def __init__(self): |
| 1798 | bb.event.Event.__init__(self) |
| 1799 | |
| 1800 | |
| 1801 | class CookerCollectFiles(object): |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1802 | def __init__(self, priorities, mc=''): |
| 1803 | self.mc = mc |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1804 | self.bbappends = [] |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1805 | # Priorities is a list of tuples, with the second element as the pattern. |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1806 | # We need to sort the list with the longest pattern first, and so on to |
| 1807 | # the shortest. This allows nested layers to be properly evaluated. |
| 1808 | self.bbfile_config_priorities = sorted(priorities, key=lambda tup: tup[1], reverse=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1809 | |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 1810 | def calc_bbfile_priority(self, filename): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1811 | for _, _, regex, pri in self.bbfile_config_priorities: |
| 1812 | if regex.match(filename): |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 1813 | return pri, regex |
| 1814 | return 0, None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1815 | |
| 1816 | def get_bbfiles(self): |
| 1817 | """Get list of default .bb files by reading out the current directory""" |
| 1818 | path = os.getcwd() |
| 1819 | contents = os.listdir(path) |
| 1820 | bbfiles = [] |
| 1821 | for f in contents: |
| 1822 | if f.endswith(".bb"): |
| 1823 | bbfiles.append(os.path.abspath(os.path.join(path, f))) |
| 1824 | return bbfiles |
| 1825 | |
| 1826 | def find_bbfiles(self, path): |
| 1827 | """Find all the .bb and .bbappend files in a directory""" |
| 1828 | found = [] |
| 1829 | for dir, dirs, files in os.walk(path): |
| 1830 | for ignored in ('SCCS', 'CVS', '.svn'): |
| 1831 | if ignored in dirs: |
| 1832 | dirs.remove(ignored) |
| 1833 | found += [os.path.join(dir, f) for f in files if (f.endswith(['.bb', '.bbappend']))] |
| 1834 | |
| 1835 | return found |
| 1836 | |
| 1837 | def collect_bbfiles(self, config, eventdata): |
| 1838 | """Collect all available .bb build files""" |
| 1839 | masked = 0 |
| 1840 | |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 1841 | collectlog.debug("collecting .bb files") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1842 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1843 | files = (config.getVar( "BBFILES") or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1844 | |
| 1845 | # Sort files by priority |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 1846 | files.sort( key=lambda fileitem: self.calc_bbfile_priority(fileitem)[0] ) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1847 | config.setVar("BBFILES_PRIORITIZED", " ".join(files)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1848 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1849 | if not files: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1850 | files = self.get_bbfiles() |
| 1851 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1852 | if not files: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1853 | collectlog.error("no recipe files to build, check your BBPATH and BBFILES?") |
| 1854 | bb.event.fire(CookerExit(), eventdata) |
| 1855 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1856 | # We need to track where we look so that we can add inotify watches. There |
| 1857 | # is no nice way to do this, this is horrid. We intercept the os.listdir() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1858 | # (or os.scandir() for python 3.6+) calls while we run glob(). |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1859 | origlistdir = os.listdir |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1860 | if hasattr(os, 'scandir'): |
| 1861 | origscandir = os.scandir |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1862 | searchdirs = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1863 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1864 | def ourlistdir(d): |
| 1865 | searchdirs.append(d) |
| 1866 | return origlistdir(d) |
| 1867 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1868 | def ourscandir(d): |
| 1869 | searchdirs.append(d) |
| 1870 | return origscandir(d) |
| 1871 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1872 | os.listdir = ourlistdir |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1873 | if hasattr(os, 'scandir'): |
| 1874 | os.scandir = ourscandir |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1875 | try: |
| 1876 | # Can't use set here as order is important |
| 1877 | newfiles = [] |
| 1878 | for f in files: |
| 1879 | if os.path.isdir(f): |
| 1880 | dirfiles = self.find_bbfiles(f) |
| 1881 | for g in dirfiles: |
| 1882 | if g not in newfiles: |
| 1883 | newfiles.append(g) |
| 1884 | else: |
| 1885 | globbed = glob.glob(f) |
| 1886 | if not globbed and os.path.exists(f): |
| 1887 | globbed = [f] |
| 1888 | # glob gives files in order on disk. Sort to be deterministic. |
| 1889 | for g in sorted(globbed): |
| 1890 | if g not in newfiles: |
| 1891 | newfiles.append(g) |
| 1892 | finally: |
| 1893 | os.listdir = origlistdir |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1894 | if hasattr(os, 'scandir'): |
| 1895 | os.scandir = origscandir |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1896 | |
| 1897 | bbmask = config.getVar('BBMASK') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1898 | |
| 1899 | if bbmask: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1900 | # First validate the individual regular expressions and ignore any |
| 1901 | # that do not compile |
| 1902 | bbmasks = [] |
| 1903 | for mask in bbmask.split(): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1904 | # When constructing an older style single regex, it's possible for BBMASK |
| 1905 | # to end up beginning with '|', which matches and masks _everything_. |
| 1906 | if mask.startswith("|"): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1907 | collectlog.warning("BBMASK contains regular expression beginning with '|', fixing: %s" % mask) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1908 | mask = mask[1:] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1909 | try: |
| 1910 | re.compile(mask) |
| 1911 | bbmasks.append(mask) |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 1912 | except re.error: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1913 | collectlog.critical("BBMASK contains an invalid regular expression, ignoring: %s" % mask) |
| 1914 | |
| 1915 | # Then validate the combined regular expressions. This should never |
| 1916 | # fail, but better safe than sorry... |
| 1917 | bbmask = "|".join(bbmasks) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1918 | try: |
| 1919 | bbmask_compiled = re.compile(bbmask) |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 1920 | except re.error: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1921 | collectlog.critical("BBMASK is not a valid regular expression, ignoring: %s" % bbmask) |
| 1922 | bbmask = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1923 | |
| 1924 | bbfiles = [] |
| 1925 | bbappend = [] |
| 1926 | for f in newfiles: |
| 1927 | if bbmask and bbmask_compiled.search(f): |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 1928 | collectlog.debug("skipping masked file %s", f) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1929 | masked += 1 |
| 1930 | continue |
| 1931 | if f.endswith('.bb'): |
| 1932 | bbfiles.append(f) |
| 1933 | elif f.endswith('.bbappend'): |
| 1934 | bbappend.append(f) |
| 1935 | else: |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 1936 | collectlog.debug("skipping %s: unknown file extension", f) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1937 | |
| 1938 | # Build a list of .bbappend files for each .bb file |
| 1939 | for f in bbappend: |
| 1940 | base = os.path.basename(f).replace('.bbappend', '.bb') |
| 1941 | self.bbappends.append((base, f)) |
| 1942 | |
| 1943 | # Find overlayed recipes |
| 1944 | # bbfiles will be in priority order which makes this easy |
| 1945 | bbfile_seen = dict() |
| 1946 | self.overlayed = defaultdict(list) |
| 1947 | for f in reversed(bbfiles): |
| 1948 | base = os.path.basename(f) |
| 1949 | if base not in bbfile_seen: |
| 1950 | bbfile_seen[base] = f |
| 1951 | else: |
| 1952 | topfile = bbfile_seen[base] |
| 1953 | self.overlayed[topfile].append(f) |
| 1954 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1955 | return (bbfiles, masked, searchdirs) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1956 | |
| 1957 | def get_file_appends(self, fn): |
| 1958 | """ |
| 1959 | Returns a list of .bbappend files to apply to fn |
| 1960 | """ |
| 1961 | filelist = [] |
| 1962 | f = os.path.basename(fn) |
| 1963 | for b in self.bbappends: |
| 1964 | (bbappend, filename) = b |
| 1965 | if (bbappend == f) or ('%' in bbappend and bbappend.startswith(f[:bbappend.index('%')])): |
| 1966 | filelist.append(filename) |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1967 | return tuple(filelist) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1968 | |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 1969 | def collection_priorities(self, pkgfns, fns, d): |
| 1970 | # Return the priorities of the entries in pkgfns |
| 1971 | # Also check that all the regexes in self.bbfile_config_priorities are used |
| 1972 | # (but to do that we need to ensure skipped recipes aren't counted, nor |
| 1973 | # collections in BBFILE_PATTERN_IGNORE_EMPTY) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1974 | |
| 1975 | priorities = {} |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 1976 | seen = set() |
| 1977 | matched = set() |
| 1978 | |
| 1979 | matched_regex = set() |
| 1980 | unmatched_regex = set() |
| 1981 | for _, _, regex, _ in self.bbfile_config_priorities: |
| 1982 | unmatched_regex.add(regex) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1983 | |
| 1984 | # Calculate priorities for each file |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1985 | for p in pkgfns: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1986 | realfn, cls, mc = bb.cache.virtualfn2realfn(p) |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 1987 | priorities[p], regex = self.calc_bbfile_priority(realfn) |
| 1988 | if regex in unmatched_regex: |
| 1989 | matched_regex.add(regex) |
| 1990 | unmatched_regex.remove(regex) |
| 1991 | seen.add(realfn) |
| 1992 | if regex: |
| 1993 | matched.add(realfn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1994 | |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 1995 | if unmatched_regex: |
| 1996 | # Account for bbappend files |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1997 | for b in self.bbappends: |
| 1998 | (bbfile, append) = b |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 1999 | seen.add(append) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2000 | |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 2001 | # Account for skipped recipes |
| 2002 | seen.update(fns) |
| 2003 | |
| 2004 | seen.difference_update(matched) |
| 2005 | |
| 2006 | def already_matched(fn): |
| 2007 | for regex in matched_regex: |
| 2008 | if regex.match(fn): |
| 2009 | return True |
| 2010 | return False |
| 2011 | |
| 2012 | for unmatch in unmatched_regex.copy(): |
| 2013 | for fn in seen: |
| 2014 | if unmatch.match(fn): |
| 2015 | # If the bbappend or file was already matched by another regex, skip it |
| 2016 | # e.g. for a layer within a layer, the outer regex could match, the inner |
| 2017 | # regex may match nothing and we should warn about that |
| 2018 | if already_matched(fn): |
| 2019 | continue |
| 2020 | unmatched_regex.remove(unmatch) |
| 2021 | break |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2022 | |
| 2023 | for collection, pattern, regex, _ in self.bbfile_config_priorities: |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 2024 | if regex in unmatched_regex: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2025 | if d.getVar('BBFILE_PATTERN_IGNORE_EMPTY_%s' % collection) != '1': |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 2026 | collectlog.warning("No bb files in %s matched BBFILE_PATTERN_%s '%s'" % (self.mc if self.mc else 'default', |
| 2027 | collection, pattern)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2028 | |
| 2029 | return priorities |
| 2030 | |
| 2031 | class ParsingFailure(Exception): |
| 2032 | def __init__(self, realexception, recipe): |
| 2033 | self.realexception = realexception |
| 2034 | self.recipe = recipe |
| 2035 | Exception.__init__(self, realexception, recipe) |
| 2036 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2037 | class Parser(multiprocessing.Process): |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2038 | def __init__(self, jobs, results, quit, profile): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2039 | self.jobs = jobs |
| 2040 | self.results = results |
| 2041 | self.quit = quit |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2042 | multiprocessing.Process.__init__(self) |
| 2043 | self.context = bb.utils.get_context().copy() |
| 2044 | self.handlers = bb.event.get_class_handlers().copy() |
| 2045 | self.profile = profile |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2046 | self.queue_signals = False |
| 2047 | self.signal_received = [] |
| 2048 | self.signal_threadlock = threading.Lock() |
| 2049 | |
| 2050 | def catch_sig(self, signum, frame): |
| 2051 | if self.queue_signals: |
| 2052 | self.signal_received.append(signum) |
| 2053 | else: |
| 2054 | self.handle_sig(signum, frame) |
| 2055 | |
| 2056 | def handle_sig(self, signum, frame): |
| 2057 | if signum == signal.SIGTERM: |
| 2058 | signal.signal(signal.SIGTERM, signal.SIG_DFL) |
| 2059 | os.kill(os.getpid(), signal.SIGTERM) |
| 2060 | elif signum == signal.SIGINT: |
| 2061 | signal.default_int_handler(signum, frame) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2062 | |
| 2063 | def run(self): |
| 2064 | |
| 2065 | if not self.profile: |
| 2066 | self.realrun() |
| 2067 | return |
| 2068 | |
| 2069 | try: |
| 2070 | import cProfile as profile |
| 2071 | except: |
| 2072 | import profile |
| 2073 | prof = profile.Profile() |
| 2074 | try: |
| 2075 | profile.Profile.runcall(prof, self.realrun) |
| 2076 | finally: |
| 2077 | logfile = "profile-parse-%s.log" % multiprocessing.current_process().name |
| 2078 | prof.dump_stats(logfile) |
| 2079 | |
| 2080 | def realrun(self): |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2081 | # Signal handling here is hard. We must not terminate any process or thread holding the write |
| 2082 | # lock for the event stream as it will not be released, ever, and things will hang. |
| 2083 | # Python handles signals in the main thread/process but they can be raised from any thread and |
| 2084 | # we want to defer processing of any SIGTERM/SIGINT signal until we're outside the critical section |
| 2085 | # and don't hold the lock (see server/process.py). We therefore always catch the signals (so any |
| 2086 | # new thread should also do so) and we defer handling but we handle with the local thread lock |
| 2087 | # held (a threading lock, not a multiprocessing one) so that no other thread in the process |
| 2088 | # can be in the critical section. |
| 2089 | signal.signal(signal.SIGTERM, self.catch_sig) |
| 2090 | signal.signal(signal.SIGHUP, signal.SIG_DFL) |
| 2091 | signal.signal(signal.SIGINT, self.catch_sig) |
| 2092 | bb.utils.set_process_name(multiprocessing.current_process().name) |
| 2093 | multiprocessing.util.Finalize(None, bb.codeparser.parser_cache_save, exitpriority=1) |
| 2094 | multiprocessing.util.Finalize(None, bb.fetch.fetcher_parse_save, exitpriority=1) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2095 | |
| 2096 | pending = [] |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 2097 | havejobs = True |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2098 | try: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 2099 | while havejobs or pending: |
| 2100 | if self.quit.is_set(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2101 | break |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2102 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 2103 | job = None |
| 2104 | try: |
| 2105 | job = self.jobs.pop() |
| 2106 | except IndexError: |
| 2107 | havejobs = False |
| 2108 | if job: |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2109 | result = self.parse(*job) |
| 2110 | # Clear the siggen cache after parsing to control memory usage, its huge |
| 2111 | bb.parse.siggen.postparsing_clean_cache() |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2112 | pending.append(result) |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 2113 | |
| 2114 | if pending: |
| 2115 | try: |
| 2116 | result = pending.pop() |
| 2117 | self.results.put(result, timeout=0.05) |
| 2118 | except queue.Full: |
| 2119 | pending.append(result) |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2120 | finally: |
| 2121 | self.results.close() |
| 2122 | self.results.join_thread() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2123 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 2124 | def parse(self, mc, cache, filename, appends): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2125 | try: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2126 | origfilter = bb.event.LogHandler.filter |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 2127 | # Record the filename we're parsing into any events generated |
| 2128 | def parse_filter(self, record): |
| 2129 | record.taskpid = bb.event.worker_pid |
| 2130 | record.fn = filename |
| 2131 | return True |
| 2132 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2133 | # Reset our environment and handlers to the original settings |
| 2134 | bb.utils.set_context(self.context.copy()) |
| 2135 | bb.event.set_class_handlers(self.handlers.copy()) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 2136 | bb.event.LogHandler.filter = parse_filter |
| 2137 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 2138 | return True, mc, cache.parse(filename, appends) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2139 | except Exception as exc: |
| 2140 | tb = sys.exc_info()[2] |
| 2141 | exc.recipe = filename |
| 2142 | exc.traceback = list(bb.exceptions.extract_traceback(tb, context=3)) |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2143 | return True, None, exc |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2144 | # Need to turn BaseExceptions into Exceptions here so we gracefully shutdown |
| 2145 | # and for example a worker thread doesn't just exit on its own in response to |
| 2146 | # a SystemExit event for example. |
| 2147 | except BaseException as exc: |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2148 | return True, None, ParsingFailure(exc, filename) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2149 | finally: |
| 2150 | bb.event.LogHandler.filter = origfilter |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2151 | |
| 2152 | class CookerParser(object): |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 2153 | def __init__(self, cooker, mcfilelist, masked): |
| 2154 | self.mcfilelist = mcfilelist |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2155 | self.cooker = cooker |
| 2156 | self.cfgdata = cooker.data |
| 2157 | self.cfghash = cooker.data_hash |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2158 | self.cfgbuilder = cooker.databuilder |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2159 | |
| 2160 | # Accounting statistics |
| 2161 | self.parsed = 0 |
| 2162 | self.cached = 0 |
| 2163 | self.error = 0 |
| 2164 | self.masked = masked |
| 2165 | |
| 2166 | self.skipped = 0 |
| 2167 | self.virtuals = 0 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2168 | |
| 2169 | self.current = 0 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2170 | self.process_names = [] |
| 2171 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 2172 | self.bb_caches = bb.cache.MulticonfigCache(self.cfgbuilder, self.cfghash, cooker.caches_array) |
| 2173 | self.fromcache = set() |
| 2174 | self.willparse = set() |
| 2175 | for mc in self.cooker.multiconfigs: |
| 2176 | for filename in self.mcfilelist[mc]: |
| 2177 | appends = self.cooker.collections[mc].get_file_appends(filename) |
| 2178 | if not self.bb_caches[mc].cacheValid(filename, appends): |
| 2179 | self.willparse.add((mc, self.bb_caches[mc], filename, appends)) |
| 2180 | else: |
| 2181 | self.fromcache.add((mc, self.bb_caches[mc], filename, appends)) |
| 2182 | |
| 2183 | self.total = len(self.fromcache) + len(self.willparse) |
| 2184 | self.toparse = len(self.willparse) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2185 | self.progress_chunk = int(max(self.toparse / 100, 1)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2186 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2187 | self.num_processes = min(int(self.cfgdata.getVar("BB_NUMBER_PARSE_THREADS") or |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 2188 | multiprocessing.cpu_count()), self.toparse) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 2189 | |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 2190 | bb.cache.SiggenRecipeInfo.reset() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2191 | self.start() |
| 2192 | self.haveshutdown = False |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2193 | self.syncthread = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2194 | |
| 2195 | def start(self): |
| 2196 | self.results = self.load_cached() |
| 2197 | self.processes = [] |
| 2198 | if self.toparse: |
| 2199 | bb.event.fire(bb.event.ParseStarted(self.toparse), self.cfgdata) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2200 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 2201 | self.parser_quit = multiprocessing.Event() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2202 | self.result_queue = multiprocessing.Queue() |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2203 | |
| 2204 | def chunkify(lst,n): |
| 2205 | return [lst[i::n] for i in range(n)] |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 2206 | self.jobs = chunkify(list(self.willparse), self.num_processes) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2207 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2208 | for i in range(0, self.num_processes): |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2209 | parser = Parser(self.jobs[i], self.result_queue, self.parser_quit, self.cooker.configuration.profile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2210 | parser.start() |
| 2211 | self.process_names.append(parser.name) |
| 2212 | self.processes.append(parser) |
| 2213 | |
| 2214 | self.results = itertools.chain(self.results, self.parse_generator()) |
| 2215 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2216 | def shutdown(self, clean=True): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2217 | if not self.toparse: |
| 2218 | return |
| 2219 | if self.haveshutdown: |
| 2220 | return |
| 2221 | self.haveshutdown = True |
| 2222 | |
| 2223 | if clean: |
| 2224 | event = bb.event.ParseCompleted(self.cached, self.parsed, |
| 2225 | self.skipped, self.masked, |
| 2226 | self.virtuals, self.error, |
| 2227 | self.total) |
| 2228 | |
| 2229 | bb.event.fire(event, self.cfgdata) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2230 | else: |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2231 | bb.error("Parsing halted due to errors, see error messages above") |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2232 | |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 2233 | # Cleanup the queue before call process.join(), otherwise there might be |
| 2234 | # deadlocks. |
| 2235 | while True: |
| 2236 | try: |
| 2237 | self.result_queue.get(timeout=0.25) |
| 2238 | except queue.Empty: |
| 2239 | break |
| 2240 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 2241 | def sync_caches(): |
| 2242 | for c in self.bb_caches.values(): |
| 2243 | bb.cache.SiggenRecipeInfo.reset() |
| 2244 | c.sync() |
| 2245 | |
| 2246 | self.syncthread = threading.Thread(target=sync_caches, name="SyncThread") |
| 2247 | self.syncthread.start() |
| 2248 | |
| 2249 | self.parser_quit.set() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2250 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2251 | for process in self.processes: |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2252 | process.join(0.5) |
| 2253 | |
| 2254 | for process in self.processes: |
| 2255 | if process.exitcode is None: |
| 2256 | os.kill(process.pid, signal.SIGINT) |
| 2257 | |
| 2258 | for process in self.processes: |
| 2259 | process.join(0.5) |
| 2260 | |
| 2261 | for process in self.processes: |
| 2262 | if process.exitcode is None: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2263 | process.terminate() |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2264 | |
| 2265 | for process in self.processes: |
| 2266 | process.join() |
| 2267 | # Added in 3.7, cleans up zombies |
| 2268 | if hasattr(process, "close"): |
| 2269 | process.close() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2270 | |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 2271 | bb.codeparser.parser_cache_save() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 2272 | bb.codeparser.parser_cache_savemerge() |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 2273 | bb.cache.SiggenRecipeInfo.reset() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 2274 | bb.fetch.fetcher_parse_done() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2275 | if self.cooker.configuration.profile: |
| 2276 | profiles = [] |
| 2277 | for i in self.process_names: |
| 2278 | logfile = "profile-parse-%s.log" % i |
| 2279 | if os.path.exists(logfile): |
| 2280 | profiles.append(logfile) |
| 2281 | |
| 2282 | pout = "profile-parse.log.processed" |
| 2283 | bb.utils.process_profilelog(profiles, pout = pout) |
| 2284 | print("Processed parsing statistics saved to %s" % (pout)) |
| 2285 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 2286 | def final_cleanup(self): |
| 2287 | if self.syncthread: |
| 2288 | self.syncthread.join() |
| 2289 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2290 | def load_cached(self): |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 2291 | for mc, cache, filename, appends in self.fromcache: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 2292 | infos = cache.loadCached(filename, appends) |
| 2293 | yield False, mc, infos |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2294 | |
| 2295 | def parse_generator(self): |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 2296 | empty = False |
| 2297 | while self.processes or not empty: |
| 2298 | for process in self.processes.copy(): |
| 2299 | if not process.is_alive(): |
| 2300 | process.join() |
| 2301 | self.processes.remove(process) |
| 2302 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2303 | if self.parsed >= self.toparse: |
| 2304 | break |
| 2305 | |
| 2306 | try: |
| 2307 | result = self.result_queue.get(timeout=0.25) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2308 | except queue.Empty: |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 2309 | empty = True |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2310 | yield None, None, None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2311 | else: |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 2312 | empty = False |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2313 | yield result |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2314 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 2315 | if not (self.parsed >= self.toparse): |
| 2316 | raise bb.parse.ParseError("Not all recipes parsed, parser thread killed/died? Exiting.", None) |
| 2317 | |
| 2318 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2319 | def parse_next(self): |
| 2320 | result = [] |
| 2321 | parsed = None |
| 2322 | try: |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 2323 | parsed, mc, result = next(self.results) |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2324 | if isinstance(result, BaseException): |
| 2325 | # Turn exceptions back into exceptions |
| 2326 | raise result |
| 2327 | if parsed is None: |
| 2328 | # Timeout, loop back through the main loop |
| 2329 | return True |
| 2330 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2331 | except StopIteration: |
| 2332 | self.shutdown() |
| 2333 | return False |
| 2334 | except bb.BBHandledException as exc: |
| 2335 | self.error += 1 |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2336 | logger.debug('Failed to parse recipe: %s' % exc.recipe) |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2337 | self.shutdown(clean=False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2338 | return False |
| 2339 | except ParsingFailure as exc: |
| 2340 | self.error += 1 |
| 2341 | logger.error('Unable to parse %s: %s' % |
| 2342 | (exc.recipe, bb.exceptions.to_string(exc.realexception))) |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2343 | self.shutdown(clean=False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2344 | return False |
| 2345 | except bb.parse.ParseError as exc: |
| 2346 | self.error += 1 |
| 2347 | logger.error(str(exc)) |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2348 | self.shutdown(clean=False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2349 | return False |
| 2350 | except bb.data_smart.ExpansionError as exc: |
| 2351 | self.error += 1 |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2352 | bbdir = os.path.dirname(__file__) + os.sep |
| 2353 | etype, value, _ = sys.exc_info() |
| 2354 | tb = list(itertools.dropwhile(lambda e: e.filename.startswith(bbdir), exc.traceback)) |
| 2355 | logger.error('ExpansionError during parsing %s', value.recipe, |
| 2356 | exc_info=(etype, value, tb)) |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2357 | self.shutdown(clean=False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2358 | return False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2359 | except Exception as exc: |
| 2360 | self.error += 1 |
| 2361 | etype, value, tb = sys.exc_info() |
| 2362 | if hasattr(value, "recipe"): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2363 | logger.error('Unable to parse %s' % value.recipe, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2364 | exc_info=(etype, value, exc.traceback)) |
| 2365 | else: |
| 2366 | # Most likely, an exception occurred during raising an exception |
| 2367 | import traceback |
| 2368 | logger.error('Exception during parse: %s' % traceback.format_exc()) |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 2369 | self.shutdown(clean=False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2370 | return False |
| 2371 | |
| 2372 | self.current += 1 |
| 2373 | self.virtuals += len(result) |
| 2374 | if parsed: |
| 2375 | self.parsed += 1 |
| 2376 | if self.parsed % self.progress_chunk == 0: |
| 2377 | bb.event.fire(bb.event.ParseProgress(self.parsed, self.toparse), |
| 2378 | self.cfgdata) |
| 2379 | else: |
| 2380 | self.cached += 1 |
| 2381 | |
| 2382 | for virtualfn, info_array in result: |
| 2383 | if info_array[0].skipped: |
| 2384 | self.skipped += 1 |
| 2385 | self.cooker.skiplist[virtualfn] = SkippedPackage(info_array[0]) |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 2386 | self.bb_caches[mc].add_info(virtualfn, info_array, self.cooker.recipecaches[mc], |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2387 | parsed=parsed, watcher = self.cooker.add_filewatch) |
| 2388 | return True |
| 2389 | |
| 2390 | def reparse(self, filename): |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 2391 | bb.cache.SiggenRecipeInfo.reset() |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 2392 | to_reparse = set() |
| 2393 | for mc in self.cooker.multiconfigs: |
| 2394 | to_reparse.add((mc, filename, self.cooker.collections[mc].get_file_appends(filename))) |
| 2395 | |
| 2396 | for mc, filename, appends in to_reparse: |
| 2397 | infos = self.bb_caches[mc].parse(filename, appends) |
| 2398 | for vfn, info_array in infos: |
| 2399 | self.cooker.recipecaches[mc].add_from_recipeinfo(vfn, info_array) |