Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | # |
| 3 | # Copyright (C) 2003, 2004 Chris Larson |
| 4 | # Copyright (C) 2003, 2004 Phil Blundell |
| 5 | # Copyright (C) 2003 - 2005 Michael 'Mickey' Lauer |
| 6 | # Copyright (C) 2005 Holger Hans Peter Freyther |
| 7 | # Copyright (C) 2005 ROAD GmbH |
| 8 | # Copyright (C) 2006 Richard Purdie |
| 9 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 10 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | import logging |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 14 | import os |
| 15 | import re |
| 16 | import sys |
| 17 | from functools import wraps |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 18 | import bb |
| 19 | from bb import data |
| 20 | import bb.parse |
| 21 | |
| 22 | logger = logging.getLogger("BitBake") |
| 23 | parselog = logging.getLogger("BitBake.Parsing") |
| 24 | |
| 25 | class ConfigParameters(object): |
| 26 | def __init__(self, argv=sys.argv): |
| 27 | self.options, targets = self.parseCommandLine(argv) |
| 28 | self.environment = self.parseEnvironment() |
| 29 | |
| 30 | self.options.pkgs_to_build = targets or [] |
| 31 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 32 | for key, val in self.options.__dict__.items(): |
| 33 | setattr(self, key, val) |
| 34 | |
| 35 | def parseCommandLine(self, argv=sys.argv): |
| 36 | raise Exception("Caller must implement commandline option parsing") |
| 37 | |
| 38 | def parseEnvironment(self): |
| 39 | return os.environ.copy() |
| 40 | |
| 41 | def updateFromServer(self, server): |
| 42 | if not self.options.cmd: |
| 43 | defaulttask, error = server.runCommand(["getVariable", "BB_DEFAULT_TASK"]) |
| 44 | if error: |
| 45 | raise Exception("Unable to get the value of BB_DEFAULT_TASK from the server: %s" % error) |
| 46 | self.options.cmd = defaulttask or "build" |
| 47 | _, error = server.runCommand(["setConfig", "cmd", self.options.cmd]) |
| 48 | if error: |
| 49 | raise Exception("Unable to set configuration option 'cmd' on the server: %s" % error) |
| 50 | |
| 51 | if not self.options.pkgs_to_build: |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 52 | bbpkgs, error = server.runCommand(["getVariable", "BBTARGETS"]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 | if error: |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 54 | raise Exception("Unable to get the value of BBTARGETS from the server: %s" % error) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 55 | if bbpkgs: |
| 56 | self.options.pkgs_to_build.extend(bbpkgs.split()) |
| 57 | |
| 58 | def updateToServer(self, server, environment): |
| 59 | options = {} |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 60 | for o in ["abort", "force", "invalidate_stamp", |
| 61 | "verbose", "debug", "dry_run", "dump_signatures", |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 62 | "debug_domains", "extra_assume_provided", "profile", |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 63 | "prefile", "postfile", "server_timeout"]: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 64 | options[o] = getattr(self.options, o) |
| 65 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 66 | ret, error = server.runCommand(["updateConfig", options, environment, sys.argv]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 67 | if error: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 68 | raise Exception("Unable to update the server configuration with local parameters: %s" % error) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 69 | |
| 70 | def parseActions(self): |
| 71 | # Parse any commandline into actions |
| 72 | action = {'action':None, 'msg':None} |
| 73 | if self.options.show_environment: |
| 74 | if 'world' in self.options.pkgs_to_build: |
| 75 | action['msg'] = "'world' is not a valid target for --environment." |
| 76 | elif 'universe' in self.options.pkgs_to_build: |
| 77 | action['msg'] = "'universe' is not a valid target for --environment." |
| 78 | elif len(self.options.pkgs_to_build) > 1: |
| 79 | action['msg'] = "Only one target can be used with the --environment option." |
| 80 | elif self.options.buildfile and len(self.options.pkgs_to_build) > 0: |
| 81 | action['msg'] = "No target should be used with the --environment and --buildfile options." |
| 82 | elif len(self.options.pkgs_to_build) > 0: |
| 83 | action['action'] = ["showEnvironmentTarget", self.options.pkgs_to_build] |
| 84 | else: |
| 85 | action['action'] = ["showEnvironment", self.options.buildfile] |
| 86 | elif self.options.buildfile is not None: |
| 87 | action['action'] = ["buildFile", self.options.buildfile, self.options.cmd] |
| 88 | elif self.options.revisions_changed: |
| 89 | action['action'] = ["compareRevisions"] |
| 90 | elif self.options.show_versions: |
| 91 | action['action'] = ["showVersions"] |
| 92 | elif self.options.parse_only: |
| 93 | action['action'] = ["parseFiles"] |
| 94 | elif self.options.dot_graph: |
| 95 | if self.options.pkgs_to_build: |
| 96 | action['action'] = ["generateDotGraph", self.options.pkgs_to_build, self.options.cmd] |
| 97 | else: |
| 98 | action['msg'] = "Please specify a package name for dependency graph generation." |
| 99 | else: |
| 100 | if self.options.pkgs_to_build: |
| 101 | action['action'] = ["buildTargets", self.options.pkgs_to_build, self.options.cmd] |
| 102 | else: |
| 103 | #action['msg'] = "Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information." |
| 104 | action = None |
| 105 | self.options.initialaction = action |
| 106 | return action |
| 107 | |
| 108 | class CookerConfiguration(object): |
| 109 | """ |
| 110 | Manages build options and configurations for one run |
| 111 | """ |
| 112 | |
| 113 | def __init__(self): |
| 114 | self.debug_domains = [] |
| 115 | self.extra_assume_provided = [] |
| 116 | self.prefile = [] |
| 117 | self.postfile = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 118 | self.debug = 0 |
| 119 | self.cmd = None |
| 120 | self.abort = True |
| 121 | self.force = False |
| 122 | self.profile = False |
| 123 | self.nosetscene = False |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 124 | self.setsceneonly = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 125 | self.invalidate_stamp = False |
| 126 | self.dump_signatures = [] |
| 127 | self.dry_run = False |
| 128 | self.tracking = False |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 129 | self.xmlrpcinterface = [] |
| 130 | self.server_timeout = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 131 | self.writeeventlog = False |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 132 | self.server_only = False |
| 133 | self.limited_deps = False |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 134 | self.runall = [] |
| 135 | self.runonly = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 136 | |
| 137 | self.env = {} |
| 138 | |
| 139 | def setConfigParameters(self, parameters): |
| 140 | for key in self.__dict__.keys(): |
| 141 | if key in parameters.options.__dict__: |
| 142 | setattr(self, key, parameters.options.__dict__[key]) |
| 143 | self.env = parameters.environment.copy() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 144 | |
| 145 | def setServerRegIdleCallback(self, srcb): |
| 146 | self.server_register_idlecallback = srcb |
| 147 | |
| 148 | def __getstate__(self): |
| 149 | state = {} |
| 150 | for key in self.__dict__.keys(): |
| 151 | if key == "server_register_idlecallback": |
| 152 | state[key] = None |
| 153 | else: |
| 154 | state[key] = getattr(self, key) |
| 155 | return state |
| 156 | |
| 157 | def __setstate__(self,state): |
| 158 | for k in state: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 159 | setattr(self, k, state[k]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 160 | |
| 161 | |
| 162 | def catch_parse_error(func): |
| 163 | """Exception handling bits for our parsing""" |
| 164 | @wraps(func) |
| 165 | def wrapped(fn, *args): |
| 166 | try: |
| 167 | return func(fn, *args) |
| 168 | except IOError as exc: |
| 169 | import traceback |
| 170 | parselog.critical(traceback.format_exc()) |
| 171 | parselog.critical("Unable to parse %s: %s" % (fn, exc)) |
| 172 | sys.exit(1) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 173 | except bb.data_smart.ExpansionError as exc: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 174 | import traceback |
| 175 | |
| 176 | bbdir = os.path.dirname(__file__) + os.sep |
| 177 | exc_class, exc, tb = sys.exc_info() |
| 178 | for tb in iter(lambda: tb.tb_next, None): |
| 179 | # Skip frames in bitbake itself, we only want the metadata |
| 180 | fn, _, _, _ = traceback.extract_tb(tb, 1)[0] |
| 181 | if not fn.startswith(bbdir): |
| 182 | break |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 183 | parselog.critical("Unable to parse %s" % fn, exc_info=(exc_class, exc, tb)) |
| 184 | sys.exit(1) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 185 | except bb.parse.ParseError as exc: |
| 186 | parselog.critical(str(exc)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 187 | sys.exit(1) |
| 188 | return wrapped |
| 189 | |
| 190 | @catch_parse_error |
| 191 | def parse_config_file(fn, data, include=True): |
| 192 | return bb.parse.handle(fn, data, include) |
| 193 | |
| 194 | @catch_parse_error |
| 195 | def _inherit(bbclass, data): |
| 196 | bb.parse.BBHandler.inherit(bbclass, "configuration INHERITs", 0, data) |
| 197 | return data |
| 198 | |
| 199 | def findConfigFile(configfile, data): |
| 200 | search = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 201 | bbpath = data.getVar("BBPATH") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 202 | if bbpath: |
| 203 | for i in bbpath.split(":"): |
| 204 | search.append(os.path.join(i, "conf", configfile)) |
| 205 | path = os.getcwd() |
| 206 | while path != "/": |
| 207 | search.append(os.path.join(path, "conf", configfile)) |
| 208 | path, _ = os.path.split(path) |
| 209 | |
| 210 | for i in search: |
| 211 | if os.path.exists(i): |
| 212 | return i |
| 213 | |
| 214 | return None |
| 215 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 216 | # |
| 217 | # We search for a conf/bblayers.conf under an entry in BBPATH or in cwd working |
| 218 | # up to /. If that fails, we search for a conf/bitbake.conf in BBPATH. |
| 219 | # |
| 220 | |
| 221 | def findTopdir(): |
| 222 | d = bb.data.init() |
| 223 | bbpath = None |
| 224 | if 'BBPATH' in os.environ: |
| 225 | bbpath = os.environ['BBPATH'] |
| 226 | d.setVar('BBPATH', bbpath) |
| 227 | |
| 228 | layerconf = findConfigFile("bblayers.conf", d) |
| 229 | if layerconf: |
| 230 | return os.path.dirname(os.path.dirname(layerconf)) |
| 231 | if bbpath: |
| 232 | bitbakeconf = bb.utils.which(bbpath, "conf/bitbake.conf") |
| 233 | if bitbakeconf: |
| 234 | return os.path.dirname(os.path.dirname(bitbakeconf)) |
| 235 | return None |
| 236 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 237 | class CookerDataBuilder(object): |
| 238 | |
| 239 | def __init__(self, cookercfg, worker = False): |
| 240 | |
| 241 | self.prefiles = cookercfg.prefile |
| 242 | self.postfiles = cookercfg.postfile |
| 243 | self.tracking = cookercfg.tracking |
| 244 | |
| 245 | bb.utils.set_context(bb.utils.clean_context()) |
| 246 | bb.event.set_class_handlers(bb.event.clean_class_handlers()) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 247 | self.basedata = bb.data.init() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 248 | if self.tracking: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 249 | self.basedata.enableTracking() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 250 | |
| 251 | # Keep a datastore of the initial environment variables and their |
| 252 | # values from when BitBake was launched to enable child processes |
| 253 | # to use environment variables which have been cleaned from the |
| 254 | # BitBake processes env |
| 255 | self.savedenv = bb.data.init() |
| 256 | for k in cookercfg.env: |
| 257 | self.savedenv.setVar(k, cookercfg.env[k]) |
| 258 | |
| 259 | filtered_keys = bb.utils.approved_variables() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 260 | bb.data.inheritFromOS(self.basedata, self.savedenv, filtered_keys) |
| 261 | self.basedata.setVar("BB_ORIGENV", self.savedenv) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 262 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 263 | if worker: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 264 | self.basedata.setVar("BB_WORKERCONTEXT", "1") |
| 265 | |
| 266 | self.data = self.basedata |
| 267 | self.mcdata = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 268 | |
| 269 | def parseBaseConfiguration(self): |
| 270 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 271 | bb.parse.init_parser(self.basedata) |
| 272 | self.data = self.parseConfigurationFiles(self.prefiles, self.postfiles) |
| 273 | |
| 274 | if self.data.getVar("BB_WORKERCONTEXT", False) is None: |
| 275 | bb.fetch.fetcher_init(self.data) |
| 276 | bb.codeparser.parser_cache_init(self.data) |
| 277 | |
| 278 | bb.event.fire(bb.event.ConfigParsed(), self.data) |
| 279 | |
| 280 | reparse_cnt = 0 |
| 281 | while self.data.getVar("BB_INVALIDCONF", False) is True: |
| 282 | if reparse_cnt > 20: |
| 283 | logger.error("Configuration has been re-parsed over 20 times, " |
| 284 | "breaking out of the loop...") |
| 285 | raise Exception("Too deep config re-parse loop. Check locations where " |
| 286 | "BB_INVALIDCONF is being set (ConfigParsed event handlers)") |
| 287 | self.data.setVar("BB_INVALIDCONF", False) |
| 288 | self.data = self.parseConfigurationFiles(self.prefiles, self.postfiles) |
| 289 | reparse_cnt += 1 |
| 290 | bb.event.fire(bb.event.ConfigParsed(), self.data) |
| 291 | |
| 292 | bb.parse.init_parser(self.data) |
| 293 | self.data_hash = self.data.get_hash() |
| 294 | self.mcdata[''] = self.data |
| 295 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 296 | multiconfig = (self.data.getVar("BBMULTICONFIG") or "").split() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 297 | for config in multiconfig: |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 298 | mcdata = self.parseConfigurationFiles(self.prefiles, self.postfiles, config) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 299 | bb.event.fire(bb.event.ConfigParsed(), mcdata) |
| 300 | self.mcdata[config] = mcdata |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 301 | if multiconfig: |
| 302 | bb.event.fire(bb.event.MultiConfigParsed(self.mcdata), self.data) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 303 | |
| 304 | except (SyntaxError, bb.BBHandledException): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 305 | raise bb.BBHandledException |
| 306 | except bb.data_smart.ExpansionError as e: |
| 307 | logger.error(str(e)) |
| 308 | raise bb.BBHandledException |
| 309 | except Exception: |
| 310 | logger.exception("Error parsing configuration files") |
| 311 | raise bb.BBHandledException |
| 312 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 313 | # Create a copy so we can reset at a later date when UIs disconnect |
| 314 | self.origdata = self.data |
| 315 | self.data = bb.data.createCopy(self.origdata) |
| 316 | self.mcdata[''] = self.data |
| 317 | |
| 318 | def reset(self): |
| 319 | # We may not have run parseBaseConfiguration() yet |
| 320 | if not hasattr(self, 'origdata'): |
| 321 | return |
| 322 | self.data = bb.data.createCopy(self.origdata) |
| 323 | self.mcdata[''] = self.data |
| 324 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 325 | def _findLayerConf(self, data): |
| 326 | return findConfigFile("bblayers.conf", data) |
| 327 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 328 | def parseConfigurationFiles(self, prefiles, postfiles, mc = "default"): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 329 | data = bb.data.createCopy(self.basedata) |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 330 | data.setVar("BB_CURRENT_MC", mc) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 331 | |
| 332 | # Parse files for loading *before* bitbake.conf and any includes |
| 333 | for f in prefiles: |
| 334 | data = parse_config_file(f, data) |
| 335 | |
| 336 | layerconf = self._findLayerConf(data) |
| 337 | if layerconf: |
| 338 | parselog.debug(2, "Found bblayers.conf (%s)", layerconf) |
| 339 | # By definition bblayers.conf is in conf/ of TOPDIR. |
| 340 | # We may have been called with cwd somewhere else so reset TOPDIR |
| 341 | data.setVar("TOPDIR", os.path.dirname(os.path.dirname(layerconf))) |
| 342 | data = parse_config_file(layerconf, data) |
| 343 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 344 | layers = (data.getVar('BBLAYERS') or "").split() |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 345 | broken_layers = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 346 | |
| 347 | data = bb.data.createCopy(data) |
| 348 | approved = bb.utils.approved_variables() |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 349 | |
| 350 | # Check whether present layer directories exist |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 351 | for layer in layers: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 352 | if not os.path.isdir(layer): |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 353 | broken_layers.append(layer) |
| 354 | |
| 355 | if broken_layers: |
| 356 | parselog.critical("The following layer directories do not exist:") |
| 357 | for layer in broken_layers: |
| 358 | parselog.critical(" %s", layer) |
| 359 | parselog.critical("Please check BBLAYERS in %s" % (layerconf)) |
| 360 | sys.exit(1) |
| 361 | |
| 362 | for layer in layers: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 363 | parselog.debug(2, "Adding layer %s", layer) |
| 364 | if 'HOME' in approved and '~' in layer: |
| 365 | layer = os.path.expanduser(layer) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 366 | if layer.endswith('/'): |
| 367 | layer = layer.rstrip('/') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 368 | data.setVar('LAYERDIR', layer) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 369 | data.setVar('LAYERDIR_RE', re.escape(layer)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 370 | data = parse_config_file(os.path.join(layer, "conf", "layer.conf"), data) |
| 371 | data.expandVarref('LAYERDIR') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 372 | data.expandVarref('LAYERDIR_RE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 373 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 374 | data.delVar('LAYERDIR_RE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 375 | data.delVar('LAYERDIR') |
| 376 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 377 | bbfiles_dynamic = (data.getVar('BBFILES_DYNAMIC') or "").split() |
| 378 | collections = (data.getVar('BBFILE_COLLECTIONS') or "").split() |
| 379 | invalid = [] |
| 380 | for entry in bbfiles_dynamic: |
| 381 | parts = entry.split(":", 1) |
| 382 | if len(parts) != 2: |
| 383 | invalid.append(entry) |
| 384 | continue |
| 385 | l, f = parts |
| 386 | if l in collections: |
| 387 | data.appendVar("BBFILES", " " + f) |
| 388 | if invalid: |
| 389 | bb.fatal("BBFILES_DYNAMIC entries must be of the form <collection name>:<filename pattern>, not:\n %s" % "\n ".join(invalid)) |
| 390 | |
| 391 | layerseries = set((data.getVar("LAYERSERIES_CORENAMES") or "").split()) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 392 | collections_tmp = collections[:] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 393 | for c in collections: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 394 | collections_tmp.remove(c) |
| 395 | if c in collections_tmp: |
| 396 | bb.fatal("Found duplicated BBFILE_COLLECTIONS '%s', check bblayers.conf or layer.conf to fix it." % c) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 397 | compat = set((data.getVar("LAYERSERIES_COMPAT_%s" % c) or "").split()) |
| 398 | if compat and not (compat & layerseries): |
| 399 | bb.fatal("Layer %s is not compatible with the core layer which only supports these series: %s (layer is compatible with %s)" |
| 400 | % (c, " ".join(layerseries), " ".join(compat))) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 401 | elif not compat and not data.getVar("BB_WORKERCONTEXT"): |
| 402 | bb.warn("Layer %s should set LAYERSERIES_COMPAT_%s in its conf/layer.conf file to list the core layer names it is compatible with." % (c, c)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 403 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 404 | if not data.getVar("BBPATH"): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 405 | msg = "The BBPATH variable is not set" |
| 406 | if not layerconf: |
| 407 | msg += (" and bitbake did not find a conf/bblayers.conf file in" |
| 408 | " the expected location.\nMaybe you accidentally" |
| 409 | " invoked bitbake from the wrong directory?") |
| 410 | raise SystemExit(msg) |
| 411 | |
| 412 | data = parse_config_file(os.path.join("conf", "bitbake.conf"), data) |
| 413 | |
| 414 | # Parse files for loading *after* bitbake.conf and any includes |
| 415 | for p in postfiles: |
| 416 | data = parse_config_file(p, data) |
| 417 | |
| 418 | # Handle any INHERITs and inherit the base class |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 419 | bbclasses = ["base"] + (data.getVar('INHERIT') or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 420 | for bbclass in bbclasses: |
| 421 | data = _inherit(bbclass, data) |
| 422 | |
| 423 | # Nomally we only register event handlers at the end of parsing .bb files |
| 424 | # We register any handlers we've found so far here... |
| 425 | for var in data.getVar('__BBHANDLERS', False) or []: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 426 | handlerfn = data.getVarFlag(var, "filename", False) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 427 | if not handlerfn: |
| 428 | parselog.critical("Undefined event handler function '%s'" % var) |
| 429 | sys.exit(1) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 430 | handlerln = int(data.getVarFlag(var, "lineno", False)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 431 | bb.event.register(var, data.getVar(var, False), (data.getVarFlag(var, "eventmask") or "").split(), handlerfn, handlerln) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 432 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 433 | data.setVar('BBINCLUDED',bb.parse.get_file_depends(data)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 434 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 435 | return data |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 436 | |