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