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