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