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