Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2003, 2004 Chris Larson |
| 3 | # Copyright (C) 2003, 2004 Phil Blundell |
| 4 | # Copyright (C) 2003 - 2005 Michael 'Mickey' Lauer |
| 5 | # Copyright (C) 2005 Holger Hans Peter Freyther |
| 6 | # Copyright (C) 2005 ROAD GmbH |
| 7 | # Copyright (C) 2006 Richard Purdie |
| 8 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 9 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | import logging |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 13 | import os |
| 14 | import re |
| 15 | import sys |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 16 | import hashlib |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 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): |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 26 | def __init__(self, argv=None): |
| 27 | self.options, targets = self.parseCommandLine(argv or sys.argv) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 = {} |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 60 | for o in ["halt", "force", "invalidate_stamp", |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 61 | "dry_run", "dump_signatures", |
| 62 | "extra_assume_provided", "profile", |
| 63 | "prefile", "postfile", "server_timeout", |
| 64 | "nosetscene", "setsceneonly", "skipsetscene", |
| 65 | "runall", "runonly", "writeeventlog"]: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 66 | options[o] = getattr(self.options, o) |
| 67 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 68 | options['build_verbose_shell'] = self.options.verbose |
| 69 | options['build_verbose_stdout'] = self.options.verbose |
| 70 | options['default_loglevel'] = bb.msg.loggerDefaultLogLevel |
| 71 | options['debug_domains'] = bb.msg.loggerDefaultDomains |
| 72 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 73 | ret, error = server.runCommand(["updateConfig", options, environment, sys.argv]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 74 | if error: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 75 | 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] | 76 | |
| 77 | def parseActions(self): |
| 78 | # Parse any commandline into actions |
| 79 | action = {'action':None, 'msg':None} |
| 80 | if self.options.show_environment: |
| 81 | if 'world' in self.options.pkgs_to_build: |
| 82 | action['msg'] = "'world' is not a valid target for --environment." |
| 83 | elif 'universe' in self.options.pkgs_to_build: |
| 84 | action['msg'] = "'universe' is not a valid target for --environment." |
| 85 | elif len(self.options.pkgs_to_build) > 1: |
| 86 | action['msg'] = "Only one target can be used with the --environment option." |
| 87 | elif self.options.buildfile and len(self.options.pkgs_to_build) > 0: |
| 88 | action['msg'] = "No target should be used with the --environment and --buildfile options." |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 89 | elif self.options.pkgs_to_build: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 90 | action['action'] = ["showEnvironmentTarget", self.options.pkgs_to_build] |
| 91 | else: |
| 92 | action['action'] = ["showEnvironment", self.options.buildfile] |
| 93 | elif self.options.buildfile is not None: |
| 94 | action['action'] = ["buildFile", self.options.buildfile, self.options.cmd] |
| 95 | elif self.options.revisions_changed: |
| 96 | action['action'] = ["compareRevisions"] |
| 97 | elif self.options.show_versions: |
| 98 | action['action'] = ["showVersions"] |
| 99 | elif self.options.parse_only: |
| 100 | action['action'] = ["parseFiles"] |
| 101 | elif self.options.dot_graph: |
| 102 | if self.options.pkgs_to_build: |
| 103 | action['action'] = ["generateDotGraph", self.options.pkgs_to_build, self.options.cmd] |
| 104 | else: |
| 105 | action['msg'] = "Please specify a package name for dependency graph generation." |
| 106 | else: |
| 107 | if self.options.pkgs_to_build: |
| 108 | action['action'] = ["buildTargets", self.options.pkgs_to_build, self.options.cmd] |
| 109 | else: |
| 110 | #action['msg'] = "Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information." |
| 111 | action = None |
| 112 | self.options.initialaction = action |
| 113 | return action |
| 114 | |
| 115 | class CookerConfiguration(object): |
| 116 | """ |
| 117 | Manages build options and configurations for one run |
| 118 | """ |
| 119 | |
| 120 | def __init__(self): |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 121 | self.debug_domains = bb.msg.loggerDefaultDomains |
| 122 | self.default_loglevel = bb.msg.loggerDefaultLogLevel |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 123 | self.extra_assume_provided = [] |
| 124 | self.prefile = [] |
| 125 | self.postfile = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 126 | self.cmd = None |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 127 | self.halt = True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 128 | self.force = False |
| 129 | self.profile = False |
| 130 | self.nosetscene = False |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 131 | self.setsceneonly = False |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 132 | self.skipsetscene = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 133 | self.invalidate_stamp = False |
| 134 | self.dump_signatures = [] |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 135 | self.build_verbose_shell = False |
| 136 | self.build_verbose_stdout = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 137 | self.dry_run = False |
| 138 | self.tracking = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 139 | self.writeeventlog = False |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 140 | self.limited_deps = False |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 141 | self.runall = [] |
| 142 | self.runonly = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 143 | |
| 144 | self.env = {} |
| 145 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 146 | def __getstate__(self): |
| 147 | state = {} |
| 148 | for key in self.__dict__.keys(): |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 149 | state[key] = getattr(self, key) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 150 | return state |
| 151 | |
| 152 | def __setstate__(self,state): |
| 153 | for k in state: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 154 | setattr(self, k, state[k]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 155 | |
| 156 | |
| 157 | def catch_parse_error(func): |
| 158 | """Exception handling bits for our parsing""" |
| 159 | @wraps(func) |
| 160 | def wrapped(fn, *args): |
| 161 | try: |
| 162 | return func(fn, *args) |
| 163 | except IOError as exc: |
| 164 | import traceback |
| 165 | parselog.critical(traceback.format_exc()) |
| 166 | parselog.critical("Unable to parse %s: %s" % (fn, exc)) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 167 | raise bb.BBHandledException() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 168 | except bb.data_smart.ExpansionError as exc: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 169 | import traceback |
| 170 | |
| 171 | bbdir = os.path.dirname(__file__) + os.sep |
| 172 | exc_class, exc, tb = sys.exc_info() |
| 173 | for tb in iter(lambda: tb.tb_next, None): |
| 174 | # Skip frames in bitbake itself, we only want the metadata |
| 175 | fn, _, _, _ = traceback.extract_tb(tb, 1)[0] |
| 176 | if not fn.startswith(bbdir): |
| 177 | break |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 178 | parselog.critical("Unable to parse %s" % fn, exc_info=(exc_class, exc, tb)) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 179 | raise bb.BBHandledException() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 180 | except bb.parse.ParseError as exc: |
| 181 | parselog.critical(str(exc)) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 182 | raise bb.BBHandledException() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 183 | return wrapped |
| 184 | |
| 185 | @catch_parse_error |
| 186 | def parse_config_file(fn, data, include=True): |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 187 | return bb.parse.handle(fn, data, include, baseconfig=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 188 | |
| 189 | @catch_parse_error |
| 190 | def _inherit(bbclass, data): |
| 191 | bb.parse.BBHandler.inherit(bbclass, "configuration INHERITs", 0, data) |
| 192 | return data |
| 193 | |
| 194 | def findConfigFile(configfile, data): |
| 195 | search = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 196 | bbpath = data.getVar("BBPATH") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 197 | if bbpath: |
| 198 | for i in bbpath.split(":"): |
| 199 | search.append(os.path.join(i, "conf", configfile)) |
| 200 | path = os.getcwd() |
| 201 | while path != "/": |
| 202 | search.append(os.path.join(path, "conf", configfile)) |
| 203 | path, _ = os.path.split(path) |
| 204 | |
| 205 | for i in search: |
| 206 | if os.path.exists(i): |
| 207 | return i |
| 208 | |
| 209 | return None |
| 210 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 211 | # |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 212 | # We search for a conf/bblayers.conf under an entry in BBPATH or in cwd working |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 213 | # up to /. If that fails, bitbake would fall back to cwd. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 214 | # |
| 215 | |
| 216 | def findTopdir(): |
| 217 | d = bb.data.init() |
| 218 | bbpath = None |
| 219 | if 'BBPATH' in os.environ: |
| 220 | bbpath = os.environ['BBPATH'] |
| 221 | d.setVar('BBPATH', bbpath) |
| 222 | |
| 223 | layerconf = findConfigFile("bblayers.conf", d) |
| 224 | if layerconf: |
| 225 | return os.path.dirname(os.path.dirname(layerconf)) |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 226 | |
| 227 | return os.path.abspath(os.getcwd()) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 228 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 229 | class CookerDataBuilder(object): |
| 230 | |
| 231 | def __init__(self, cookercfg, worker = False): |
| 232 | |
| 233 | self.prefiles = cookercfg.prefile |
| 234 | self.postfiles = cookercfg.postfile |
| 235 | self.tracking = cookercfg.tracking |
| 236 | |
| 237 | bb.utils.set_context(bb.utils.clean_context()) |
| 238 | bb.event.set_class_handlers(bb.event.clean_class_handlers()) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 239 | self.basedata = bb.data.init() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 240 | if self.tracking: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 241 | self.basedata.enableTracking() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 242 | |
| 243 | # Keep a datastore of the initial environment variables and their |
| 244 | # values from when BitBake was launched to enable child processes |
| 245 | # to use environment variables which have been cleaned from the |
| 246 | # BitBake processes env |
| 247 | self.savedenv = bb.data.init() |
| 248 | for k in cookercfg.env: |
| 249 | self.savedenv.setVar(k, cookercfg.env[k]) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 250 | if k in bb.data_smart.bitbake_renamed_vars: |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 251 | bb.error('Shell environment variable %s has been renamed to %s' % (k, bb.data_smart.bitbake_renamed_vars[k])) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 252 | bb.fatal("Exiting to allow enviroment variables to be corrected") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 253 | |
| 254 | filtered_keys = bb.utils.approved_variables() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 255 | bb.data.inheritFromOS(self.basedata, self.savedenv, filtered_keys) |
| 256 | self.basedata.setVar("BB_ORIGENV", self.savedenv) |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 257 | self.basedata.setVar("__bbclasstype", "global") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 258 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 259 | if worker: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 260 | self.basedata.setVar("BB_WORKERCONTEXT", "1") |
| 261 | |
| 262 | self.data = self.basedata |
| 263 | self.mcdata = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 264 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 265 | def parseBaseConfiguration(self, worker=False): |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 266 | mcdata = {} |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 267 | data_hash = hashlib.sha256() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 268 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 269 | self.data = self.parseConfigurationFiles(self.prefiles, self.postfiles) |
| 270 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 271 | if self.data.getVar("BB_WORKERCONTEXT", False) is None and not worker: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 272 | bb.fetch.fetcher_init(self.data) |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 273 | bb.parse.init_parser(self.data) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 274 | |
| 275 | bb.event.fire(bb.event.ConfigParsed(), self.data) |
| 276 | |
| 277 | reparse_cnt = 0 |
| 278 | while self.data.getVar("BB_INVALIDCONF", False) is True: |
| 279 | if reparse_cnt > 20: |
| 280 | logger.error("Configuration has been re-parsed over 20 times, " |
| 281 | "breaking out of the loop...") |
| 282 | raise Exception("Too deep config re-parse loop. Check locations where " |
| 283 | "BB_INVALIDCONF is being set (ConfigParsed event handlers)") |
| 284 | self.data.setVar("BB_INVALIDCONF", False) |
| 285 | self.data = self.parseConfigurationFiles(self.prefiles, self.postfiles) |
| 286 | reparse_cnt += 1 |
| 287 | bb.event.fire(bb.event.ConfigParsed(), self.data) |
| 288 | |
| 289 | bb.parse.init_parser(self.data) |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 290 | data_hash.update(self.data.get_hash().encode('utf-8')) |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 291 | mcdata[''] = self.data |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 292 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 293 | multiconfig = (self.data.getVar("BBMULTICONFIG") or "").split() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 294 | for config in multiconfig: |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 295 | if config[0].isdigit(): |
| 296 | bb.fatal("Multiconfig name '%s' is invalid as multiconfigs cannot start with a digit" % config) |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 297 | parsed_mcdata = self.parseConfigurationFiles(self.prefiles, self.postfiles, config) |
| 298 | bb.event.fire(bb.event.ConfigParsed(), parsed_mcdata) |
| 299 | mcdata[config] = parsed_mcdata |
| 300 | data_hash.update(parsed_mcdata.get_hash().encode('utf-8')) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 301 | if multiconfig: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 302 | bb.event.fire(bb.event.MultiConfigParsed(mcdata), self.data) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 303 | |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 304 | self.data_hash = data_hash.hexdigest() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 305 | except (SyntaxError, bb.BBHandledException): |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 306 | raise bb.BBHandledException() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 307 | except bb.data_smart.ExpansionError as e: |
| 308 | logger.error(str(e)) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 309 | raise bb.BBHandledException() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 310 | except Exception: |
| 311 | logger.exception("Error parsing configuration files") |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 312 | raise bb.BBHandledException() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 313 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 314 | bb.codeparser.update_module_dependencies(self.data) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 315 | |
| 316 | # Handle obsolete variable names |
| 317 | d = self.data |
| 318 | renamedvars = d.getVarFlags('BB_RENAMED_VARIABLES') or {} |
| 319 | renamedvars.update(bb.data_smart.bitbake_renamed_vars) |
| 320 | issues = False |
| 321 | for v in renamedvars: |
| 322 | if d.getVar(v) != None or d.hasOverrides(v): |
| 323 | issues = True |
| 324 | loginfo = {} |
| 325 | history = d.varhistory.get_variable_refs(v) |
| 326 | for h in history: |
| 327 | for line in history[h]: |
| 328 | loginfo = {'file' : h, 'line' : line} |
| 329 | bb.data.data_smart._print_rename_error(v, loginfo, renamedvars) |
| 330 | if not history: |
| 331 | bb.data.data_smart._print_rename_error(v, loginfo, renamedvars) |
| 332 | if issues: |
| 333 | raise bb.BBHandledException() |
| 334 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 335 | for mc in mcdata: |
| 336 | mcdata[mc].renameVar("__depends", "__base_depends") |
| 337 | mcdata[mc].setVar("__bbclasstype", "recipe") |
| 338 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 339 | # Create a copy so we can reset at a later date when UIs disconnect |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 340 | self.mcorigdata = mcdata |
| 341 | for mc in mcdata: |
| 342 | self.mcdata[mc] = bb.data.createCopy(mcdata[mc]) |
| 343 | self.data = self.mcdata[''] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 344 | |
| 345 | def reset(self): |
| 346 | # We may not have run parseBaseConfiguration() yet |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 347 | if not hasattr(self, 'mcorigdata'): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 348 | return |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 349 | for mc in self.mcorigdata: |
| 350 | self.mcdata[mc] = bb.data.createCopy(self.mcorigdata[mc]) |
| 351 | self.data = self.mcdata[''] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 352 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 353 | def _findLayerConf(self, data): |
| 354 | return findConfigFile("bblayers.conf", data) |
| 355 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 356 | def parseConfigurationFiles(self, prefiles, postfiles, mc = "default"): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 357 | data = bb.data.createCopy(self.basedata) |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 358 | data.setVar("BB_CURRENT_MC", mc) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 359 | |
| 360 | # Parse files for loading *before* bitbake.conf and any includes |
| 361 | for f in prefiles: |
| 362 | data = parse_config_file(f, data) |
| 363 | |
| 364 | layerconf = self._findLayerConf(data) |
| 365 | if layerconf: |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 366 | parselog.debug2("Found bblayers.conf (%s)", layerconf) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 367 | # By definition bblayers.conf is in conf/ of TOPDIR. |
| 368 | # We may have been called with cwd somewhere else so reset TOPDIR |
| 369 | data.setVar("TOPDIR", os.path.dirname(os.path.dirname(layerconf))) |
| 370 | data = parse_config_file(layerconf, data) |
| 371 | |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 372 | if not data.getVar("BB_CACHEDIR"): |
| 373 | data.setVar("BB_CACHEDIR", "${TOPDIR}/cache") |
| 374 | |
| 375 | bb.codeparser.parser_cache_init(data.getVar("BB_CACHEDIR")) |
| 376 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 377 | layers = (data.getVar('BBLAYERS') or "").split() |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 378 | broken_layers = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 379 | |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 380 | if not layers: |
| 381 | bb.fatal("The bblayers.conf file doesn't contain any BBLAYERS definition") |
| 382 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 383 | data = bb.data.createCopy(data) |
| 384 | approved = bb.utils.approved_variables() |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 385 | |
| 386 | # Check whether present layer directories exist |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 387 | for layer in layers: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 388 | if not os.path.isdir(layer): |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 389 | broken_layers.append(layer) |
| 390 | |
| 391 | if broken_layers: |
| 392 | parselog.critical("The following layer directories do not exist:") |
| 393 | for layer in broken_layers: |
| 394 | parselog.critical(" %s", layer) |
| 395 | parselog.critical("Please check BBLAYERS in %s" % (layerconf)) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 396 | raise bb.BBHandledException() |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 397 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 398 | layerseries = None |
| 399 | compat_entries = {} |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 400 | for layer in layers: |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 401 | parselog.debug2("Adding layer %s", layer) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 402 | if 'HOME' in approved and '~' in layer: |
| 403 | layer = os.path.expanduser(layer) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 404 | if layer.endswith('/'): |
| 405 | layer = layer.rstrip('/') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 406 | data.setVar('LAYERDIR', layer) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 407 | data.setVar('LAYERDIR_RE', re.escape(layer)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 408 | data = parse_config_file(os.path.join(layer, "conf", "layer.conf"), data) |
| 409 | data.expandVarref('LAYERDIR') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 410 | data.expandVarref('LAYERDIR_RE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 411 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 412 | # Sadly we can't have nice things. |
| 413 | # Some layers think they're going to be 'clever' and copy the values from |
| 414 | # another layer, e.g. using ${LAYERSERIES_COMPAT_core}. The whole point of |
| 415 | # this mechanism is to make it clear which releases a layer supports and |
| 416 | # show when a layer master branch is bitrotting and is unmaintained. |
| 417 | # We therefore avoid people doing this here. |
| 418 | collections = (data.getVar('BBFILE_COLLECTIONS') or "").split() |
| 419 | for c in collections: |
| 420 | compat_entry = data.getVar("LAYERSERIES_COMPAT_%s" % c) |
| 421 | if compat_entry: |
| 422 | compat_entries[c] = set(compat_entry.split()) |
| 423 | data.delVar("LAYERSERIES_COMPAT_%s" % c) |
| 424 | if not layerseries: |
| 425 | layerseries = set((data.getVar("LAYERSERIES_CORENAMES") or "").split()) |
| 426 | if layerseries: |
| 427 | data.delVar("LAYERSERIES_CORENAMES") |
| 428 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 429 | data.delVar('LAYERDIR_RE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 430 | data.delVar('LAYERDIR') |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 431 | for c in compat_entries: |
| 432 | data.setVar("LAYERSERIES_COMPAT_%s" % c, " ".join(sorted(compat_entries[c]))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 433 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 434 | bbfiles_dynamic = (data.getVar('BBFILES_DYNAMIC') or "").split() |
| 435 | collections = (data.getVar('BBFILE_COLLECTIONS') or "").split() |
| 436 | invalid = [] |
| 437 | for entry in bbfiles_dynamic: |
| 438 | parts = entry.split(":", 1) |
| 439 | if len(parts) != 2: |
| 440 | invalid.append(entry) |
| 441 | continue |
| 442 | l, f = parts |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 443 | invert = l[0] == "!" |
| 444 | if invert: |
| 445 | l = l[1:] |
| 446 | if (l in collections and not invert) or (l not in collections and invert): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 447 | data.appendVar("BBFILES", " " + f) |
| 448 | if invalid: |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 449 | bb.fatal("BBFILES_DYNAMIC entries must be of the form {!}<collection name>:<filename pattern>, not:\n %s" % "\n ".join(invalid)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 450 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 451 | collections_tmp = collections[:] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 452 | for c in collections: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 453 | collections_tmp.remove(c) |
| 454 | if c in collections_tmp: |
| 455 | bb.fatal("Found duplicated BBFILE_COLLECTIONS '%s', check bblayers.conf or layer.conf to fix it." % c) |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 456 | |
| 457 | compat = set() |
| 458 | if c in compat_entries: |
| 459 | compat = compat_entries[c] |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 460 | if compat and not layerseries: |
| 461 | bb.fatal("No core layer found to work with layer '%s'. Missing entry in bblayers.conf?" % c) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 462 | if compat and not (compat & layerseries): |
| 463 | bb.fatal("Layer %s is not compatible with the core layer which only supports these series: %s (layer is compatible with %s)" |
| 464 | % (c, " ".join(layerseries), " ".join(compat))) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 465 | elif not compat and not data.getVar("BB_WORKERCONTEXT"): |
| 466 | 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] | 467 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 468 | data.setVar("LAYERSERIES_CORENAMES", " ".join(sorted(layerseries))) |
| 469 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 470 | if not data.getVar("BBPATH"): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 471 | msg = "The BBPATH variable is not set" |
| 472 | if not layerconf: |
| 473 | msg += (" and bitbake did not find a conf/bblayers.conf file in" |
| 474 | " the expected location.\nMaybe you accidentally" |
| 475 | " invoked bitbake from the wrong directory?") |
| 476 | raise SystemExit(msg) |
| 477 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 478 | if not data.getVar("TOPDIR"): |
| 479 | data.setVar("TOPDIR", os.path.abspath(os.getcwd())) |
Andrew Geissler | c5535c9 | 2023-01-27 16:10:19 -0600 | [diff] [blame] | 480 | if not data.getVar("BB_CACHEDIR"): |
| 481 | data.setVar("BB_CACHEDIR", "${TOPDIR}/cache") |
| 482 | bb.codeparser.parser_cache_init(data.getVar("BB_CACHEDIR")) |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 483 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 484 | data = parse_config_file(os.path.join("conf", "bitbake.conf"), data) |
| 485 | |
| 486 | # Parse files for loading *after* bitbake.conf and any includes |
| 487 | for p in postfiles: |
| 488 | data = parse_config_file(p, data) |
| 489 | |
| 490 | # Handle any INHERITs and inherit the base class |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 491 | bbclasses = ["base"] + (data.getVar('INHERIT') or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 492 | for bbclass in bbclasses: |
| 493 | data = _inherit(bbclass, data) |
| 494 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 495 | # Normally we only register event handlers at the end of parsing .bb files |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 496 | # We register any handlers we've found so far here... |
| 497 | for var in data.getVar('__BBHANDLERS', False) or []: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 498 | handlerfn = data.getVarFlag(var, "filename", False) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 499 | if not handlerfn: |
| 500 | parselog.critical("Undefined event handler function '%s'" % var) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 501 | raise bb.BBHandledException() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 502 | handlerln = int(data.getVarFlag(var, "lineno", False)) |
Andrew Geissler | 9b4d8b0 | 2021-02-19 12:26:16 -0600 | [diff] [blame] | 503 | bb.event.register(var, data.getVar(var, False), (data.getVarFlag(var, "eventmask") or "").split(), handlerfn, handlerln, data) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 504 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 505 | data.setVar('BBINCLUDED',bb.parse.get_file_depends(data)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 506 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 507 | return data |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 508 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 509 | @staticmethod |
| 510 | def _parse_recipe(bb_data, bbfile, appends, mc=''): |
| 511 | bb_data.setVar("__BBMULTICONFIG", mc) |
| 512 | |
| 513 | bbfile_loc = os.path.abspath(os.path.dirname(bbfile)) |
| 514 | bb.parse.cached_mtime_noerror(bbfile_loc) |
| 515 | |
| 516 | if appends: |
| 517 | bb_data.setVar('__BBAPPEND', " ".join(appends)) |
| 518 | bb_data = bb.parse.handle(bbfile, bb_data) |
| 519 | return bb_data |
| 520 | |
| 521 | def parseRecipeVariants(self, bbfile, appends, virtonly=False, mc=None): |
| 522 | """ |
| 523 | Load and parse one .bb build file |
| 524 | Return the data and whether parsing resulted in the file being skipped |
| 525 | """ |
| 526 | |
| 527 | if virtonly: |
| 528 | (bbfile, virtual, mc) = bb.cache.virtualfn2realfn(bbfile) |
| 529 | bb_data = self.mcdata[mc].createCopy() |
| 530 | bb_data.setVar("__ONLYFINALISE", virtual or "default") |
| 531 | datastores = self._parse_recipe(bb_data, bbfile, appends, mc) |
| 532 | return datastores |
| 533 | |
| 534 | if mc is not None: |
| 535 | bb_data = self.mcdata[mc].createCopy() |
| 536 | return self._parse_recipe(bb_data, bbfile, appends, mc) |
| 537 | |
| 538 | bb_data = self.data.createCopy() |
| 539 | datastores = self._parse_recipe(bb_data, bbfile, appends) |
| 540 | |
| 541 | for mc in self.mcdata: |
| 542 | if not mc: |
| 543 | continue |
| 544 | bb_data = self.mcdata[mc].createCopy() |
| 545 | newstores = self._parse_recipe(bb_data, bbfile, appends, mc) |
| 546 | for ns in newstores: |
| 547 | datastores["mc:%s:%s" % (mc, ns)] = newstores[ns] |
| 548 | |
| 549 | return datastores |
| 550 | |
| 551 | def parseRecipe(self, virtualfn, appends): |
| 552 | """ |
| 553 | Return a complete set of data for fn. |
| 554 | To do this, we need to parse the file. |
| 555 | """ |
| 556 | logger.debug("Parsing %s (full)" % virtualfn) |
| 557 | (fn, virtual, mc) = bb.cache.virtualfn2realfn(virtualfn) |
| 558 | bb_data = self.parseRecipeVariants(virtualfn, appends, virtonly=True) |
| 559 | return bb_data[virtual] |