Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | """ |
| 2 | BitBake 'Command' module |
| 3 | |
| 4 | Provide an interface to interact with the bitbake server through 'commands' |
| 5 | """ |
| 6 | |
| 7 | # Copyright (C) 2006-2007 Richard Purdie |
| 8 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 9 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | |
| 12 | """ |
| 13 | The bitbake server takes 'commands' from its UI/commandline. |
| 14 | Commands are either synchronous or asynchronous. |
| 15 | Async commands return data to the client in the form of events. |
| 16 | Sync commands must only return data through the function return value |
| 17 | and must not trigger events, directly or indirectly. |
| 18 | Commands are queued in a CommandQueue |
| 19 | """ |
| 20 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 21 | from collections import OrderedDict, defaultdict |
| 22 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 23 | import io |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | import bb.event |
| 25 | import bb.cooker |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 26 | import bb.remotedata |
| 27 | |
| 28 | class DataStoreConnectionHandle(object): |
| 29 | def __init__(self, dsindex=0): |
| 30 | self.dsindex = dsindex |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 31 | |
| 32 | class CommandCompleted(bb.event.Event): |
| 33 | pass |
| 34 | |
| 35 | class CommandExit(bb.event.Event): |
| 36 | def __init__(self, exitcode): |
| 37 | bb.event.Event.__init__(self) |
| 38 | self.exitcode = int(exitcode) |
| 39 | |
| 40 | class CommandFailed(CommandExit): |
| 41 | def __init__(self, message): |
| 42 | self.error = message |
| 43 | CommandExit.__init__(self, 1) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 44 | def __str__(self): |
| 45 | return "Command execution failed: %s" % self.error |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | |
| 47 | class CommandError(Exception): |
| 48 | pass |
| 49 | |
| 50 | class Command: |
| 51 | """ |
| 52 | A queue of asynchronous commands for bitbake |
| 53 | """ |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 54 | def __init__(self, cooker, process_server): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 55 | self.cooker = cooker |
| 56 | self.cmds_sync = CommandsSync() |
| 57 | self.cmds_async = CommandsAsync() |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 58 | self.remotedatastores = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 59 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 60 | self.process_server = process_server |
| 61 | # Access with locking using process_server.{get/set/clear}_async_cmd() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 62 | self.currentAsyncCommand = None |
| 63 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 64 | def runCommand(self, commandline, process_server, ro_only=False): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 65 | command = commandline.pop(0) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 66 | |
| 67 | # Ensure cooker is ready for commands |
| 68 | if command != "updateConfig" and command != "setFeatures": |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 69 | try: |
| 70 | self.cooker.init_configdata() |
| 71 | if not self.remotedatastores: |
| 72 | self.remotedatastores = bb.remotedata.RemoteDatastores(self.cooker) |
| 73 | except (Exception, SystemExit) as exc: |
| 74 | import traceback |
| 75 | if isinstance(exc, bb.BBHandledException): |
| 76 | # We need to start returning real exceptions here. Until we do, we can't |
| 77 | # tell if an exception is an instance of bb.BBHandledException |
| 78 | return None, "bb.BBHandledException()\n" + traceback.format_exc() |
| 79 | return None, traceback.format_exc() |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 80 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 81 | if hasattr(CommandsSync, command): |
| 82 | # Can run synchronous commands straight away |
| 83 | command_method = getattr(self.cmds_sync, command) |
| 84 | if ro_only: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 85 | if not hasattr(command_method, 'readonly') or not getattr(command_method, 'readonly'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 86 | return None, "Not able to execute not readonly commands in readonly mode" |
| 87 | try: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 88 | self.cooker.process_inotify_updates_apply() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 89 | if getattr(command_method, 'needconfig', True): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 90 | self.cooker.updateCacheSync() |
| 91 | result = command_method(self, commandline) |
| 92 | except CommandError as exc: |
| 93 | return None, exc.args[0] |
Andrew Geissler | f034379 | 2020-11-18 10:42:21 -0600 | [diff] [blame] | 94 | except (Exception, SystemExit) as exc: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 95 | import traceback |
Andrew Geissler | f034379 | 2020-11-18 10:42:21 -0600 | [diff] [blame] | 96 | if isinstance(exc, bb.BBHandledException): |
| 97 | # We need to start returning real exceptions here. Until we do, we can't |
| 98 | # tell if an exception is an instance of bb.BBHandledException |
| 99 | return None, "bb.BBHandledException()\n" + traceback.format_exc() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 100 | return None, traceback.format_exc() |
| 101 | else: |
| 102 | return result, None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 103 | if command not in CommandsAsync.__dict__: |
| 104 | return None, "No such command" |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 105 | if not process_server.set_async_cmd((command, commandline)): |
| 106 | return None, "Busy (%s in progress)" % self.process_server.get_async_cmd()[0] |
| 107 | self.cooker.idleCallBackRegister(self.runAsyncCommand, process_server) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 108 | return True, None |
| 109 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 110 | def runAsyncCommand(self, _, process_server, halt): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 111 | try: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 112 | self.cooker.process_inotify_updates_apply() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 113 | if self.cooker.state in (bb.cooker.state.error, bb.cooker.state.shutdown, bb.cooker.state.forceshutdown): |
| 114 | # updateCache will trigger a shutdown of the parser |
| 115 | # and then raise BBHandledException triggering an exit |
| 116 | self.cooker.updateCache() |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 117 | return bb.server.process.idleFinish("Cooker in error state") |
| 118 | cmd = process_server.get_async_cmd() |
| 119 | if cmd is not None: |
| 120 | (command, options) = cmd |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 121 | commandmethod = getattr(CommandsAsync, command) |
| 122 | needcache = getattr( commandmethod, "needcache" ) |
| 123 | if needcache and self.cooker.state != bb.cooker.state.running: |
| 124 | self.cooker.updateCache() |
| 125 | return True |
| 126 | else: |
| 127 | commandmethod(self.cmds_async, self, options) |
| 128 | return False |
| 129 | else: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 130 | return bb.server.process.idleFinish("Nothing to do, no async command?") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 131 | except KeyboardInterrupt as exc: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 132 | return bb.server.process.idleFinish("Interrupted") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 133 | except SystemExit as exc: |
| 134 | arg = exc.args[0] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 135 | if isinstance(arg, str): |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 136 | return bb.server.process.idleFinish(arg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 137 | else: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 138 | return bb.server.process.idleFinish("Exited with %s" % arg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 139 | except Exception as exc: |
| 140 | import traceback |
| 141 | if isinstance(exc, bb.BBHandledException): |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 142 | return bb.server.process.idleFinish("") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 143 | else: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 144 | return bb.server.process.idleFinish(traceback.format_exc()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 145 | |
| 146 | def finishAsyncCommand(self, msg=None, code=None): |
| 147 | if msg or msg == "": |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 148 | bb.event.fire(CommandFailed(msg), self.cooker.data) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 149 | elif code: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 150 | bb.event.fire(CommandExit(code), self.cooker.data) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 151 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 152 | bb.event.fire(CommandCompleted(), self.cooker.data) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 153 | self.cooker.finishcommand() |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 154 | self.process_server.clear_async_cmd() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 155 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 156 | def reset(self): |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 157 | if self.remotedatastores: |
| 158 | self.remotedatastores = bb.remotedata.RemoteDatastores(self.cooker) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 159 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 160 | class CommandsSync: |
| 161 | """ |
| 162 | A class of synchronous commands |
| 163 | These should run quickly so as not to hurt interactive performance. |
| 164 | These must not influence any running synchronous command. |
| 165 | """ |
| 166 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 167 | def ping(self, command, params): |
| 168 | """ |
| 169 | Allow a UI to check the server is still alive |
| 170 | """ |
| 171 | return "Still alive!" |
| 172 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 173 | def stateShutdown(self, command, params): |
| 174 | """ |
| 175 | Trigger cooker 'shutdown' mode |
| 176 | """ |
| 177 | command.cooker.shutdown(False) |
| 178 | |
| 179 | def stateForceShutdown(self, command, params): |
| 180 | """ |
| 181 | Stop the cooker |
| 182 | """ |
| 183 | command.cooker.shutdown(True) |
| 184 | |
| 185 | def getAllKeysWithFlags(self, command, params): |
| 186 | """ |
| 187 | Returns a dump of the global state. Call with |
| 188 | variable flags to be retrieved as params. |
| 189 | """ |
| 190 | flaglist = params[0] |
| 191 | return command.cooker.getAllKeysWithFlags(flaglist) |
| 192 | getAllKeysWithFlags.readonly = True |
| 193 | |
| 194 | def getVariable(self, command, params): |
| 195 | """ |
| 196 | Read the value of a variable from data |
| 197 | """ |
| 198 | varname = params[0] |
| 199 | expand = True |
| 200 | if len(params) > 1: |
| 201 | expand = (params[1] == "True") |
| 202 | |
| 203 | return command.cooker.data.getVar(varname, expand) |
| 204 | getVariable.readonly = True |
| 205 | |
| 206 | def setVariable(self, command, params): |
| 207 | """ |
| 208 | Set the value of variable in data |
| 209 | """ |
| 210 | varname = params[0] |
| 211 | value = str(params[1]) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 212 | command.cooker.extraconfigdata[varname] = value |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 213 | command.cooker.data.setVar(varname, value) |
| 214 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 215 | def getSetVariable(self, command, params): |
| 216 | """ |
| 217 | Read the value of a variable from data and set it into the datastore |
| 218 | which effectively expands and locks the value. |
| 219 | """ |
| 220 | varname = params[0] |
| 221 | result = self.getVariable(command, params) |
| 222 | command.cooker.data.setVar(varname, result) |
| 223 | return result |
| 224 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 225 | def setConfig(self, command, params): |
| 226 | """ |
| 227 | Set the value of variable in configuration |
| 228 | """ |
| 229 | varname = params[0] |
| 230 | value = str(params[1]) |
| 231 | setattr(command.cooker.configuration, varname, value) |
| 232 | |
| 233 | def enableDataTracking(self, command, params): |
| 234 | """ |
| 235 | Enable history tracking for variables |
| 236 | """ |
| 237 | command.cooker.enableDataTracking() |
| 238 | |
| 239 | def disableDataTracking(self, command, params): |
| 240 | """ |
| 241 | Disable history tracking for variables |
| 242 | """ |
| 243 | command.cooker.disableDataTracking() |
| 244 | |
| 245 | def setPrePostConfFiles(self, command, params): |
| 246 | prefiles = params[0].split() |
| 247 | postfiles = params[1].split() |
| 248 | command.cooker.configuration.prefile = prefiles |
| 249 | command.cooker.configuration.postfile = postfiles |
| 250 | setPrePostConfFiles.needconfig = False |
| 251 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 252 | def matchFile(self, command, params): |
| 253 | fMatch = params[0] |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 254 | try: |
| 255 | mc = params[0] |
| 256 | except IndexError: |
| 257 | mc = '' |
| 258 | return command.cooker.matchFile(fMatch, mc) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 259 | matchFile.needconfig = False |
| 260 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 261 | def getUIHandlerNum(self, command, params): |
| 262 | return bb.event.get_uihandler() |
| 263 | getUIHandlerNum.needconfig = False |
| 264 | getUIHandlerNum.readonly = True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 265 | |
| 266 | def setEventMask(self, command, params): |
| 267 | handlerNum = params[0] |
| 268 | llevel = params[1] |
| 269 | debug_domains = params[2] |
| 270 | mask = params[3] |
| 271 | return bb.event.set_UIHmask(handlerNum, llevel, debug_domains, mask) |
| 272 | setEventMask.needconfig = False |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 273 | setEventMask.readonly = True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 274 | |
| 275 | def setFeatures(self, command, params): |
| 276 | """ |
| 277 | Set the cooker features to include the passed list of features |
| 278 | """ |
| 279 | features = params[0] |
| 280 | command.cooker.setFeatures(features) |
| 281 | setFeatures.needconfig = False |
| 282 | # although we change the internal state of the cooker, this is transparent since |
| 283 | # we always take and leave the cooker in state.initial |
| 284 | setFeatures.readonly = True |
| 285 | |
| 286 | def updateConfig(self, command, params): |
| 287 | options = params[0] |
| 288 | environment = params[1] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 289 | cmdline = params[2] |
| 290 | command.cooker.updateConfigOpts(options, environment, cmdline) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 291 | updateConfig.needconfig = False |
| 292 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 293 | def parseConfiguration(self, command, params): |
| 294 | """Instruct bitbake to parse its configuration |
| 295 | NOTE: it is only necessary to call this if you aren't calling any normal action |
| 296 | (otherwise parsing is taken care of automatically) |
| 297 | """ |
| 298 | command.cooker.parseConfiguration() |
| 299 | parseConfiguration.needconfig = False |
| 300 | |
| 301 | def getLayerPriorities(self, command, params): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 302 | command.cooker.parseConfiguration() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 303 | ret = [] |
| 304 | # regex objects cannot be marshalled by xmlrpc |
| 305 | for collection, pattern, regex, pri in command.cooker.bbfile_config_priorities: |
| 306 | ret.append((collection, pattern, regex.pattern, pri)) |
| 307 | return ret |
| 308 | getLayerPriorities.readonly = True |
| 309 | |
| 310 | def getRecipes(self, command, params): |
| 311 | try: |
| 312 | mc = params[0] |
| 313 | except IndexError: |
| 314 | mc = '' |
| 315 | return list(command.cooker.recipecaches[mc].pkg_pn.items()) |
| 316 | getRecipes.readonly = True |
| 317 | |
| 318 | def getRecipeDepends(self, command, params): |
| 319 | try: |
| 320 | mc = params[0] |
| 321 | except IndexError: |
| 322 | mc = '' |
| 323 | return list(command.cooker.recipecaches[mc].deps.items()) |
| 324 | getRecipeDepends.readonly = True |
| 325 | |
| 326 | def getRecipeVersions(self, command, params): |
| 327 | try: |
| 328 | mc = params[0] |
| 329 | except IndexError: |
| 330 | mc = '' |
| 331 | return command.cooker.recipecaches[mc].pkg_pepvpr |
| 332 | getRecipeVersions.readonly = True |
| 333 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 334 | def getRecipeProvides(self, command, params): |
| 335 | try: |
| 336 | mc = params[0] |
| 337 | except IndexError: |
| 338 | mc = '' |
| 339 | return command.cooker.recipecaches[mc].fn_provides |
| 340 | getRecipeProvides.readonly = True |
| 341 | |
| 342 | def getRecipePackages(self, command, params): |
| 343 | try: |
| 344 | mc = params[0] |
| 345 | except IndexError: |
| 346 | mc = '' |
| 347 | return command.cooker.recipecaches[mc].packages |
| 348 | getRecipePackages.readonly = True |
| 349 | |
| 350 | def getRecipePackagesDynamic(self, command, params): |
| 351 | try: |
| 352 | mc = params[0] |
| 353 | except IndexError: |
| 354 | mc = '' |
| 355 | return command.cooker.recipecaches[mc].packages_dynamic |
| 356 | getRecipePackagesDynamic.readonly = True |
| 357 | |
| 358 | def getRProviders(self, command, params): |
| 359 | try: |
| 360 | mc = params[0] |
| 361 | except IndexError: |
| 362 | mc = '' |
| 363 | return command.cooker.recipecaches[mc].rproviders |
| 364 | getRProviders.readonly = True |
| 365 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 366 | def getRuntimeDepends(self, command, params): |
| 367 | ret = [] |
| 368 | try: |
| 369 | mc = params[0] |
| 370 | except IndexError: |
| 371 | mc = '' |
| 372 | rundeps = command.cooker.recipecaches[mc].rundeps |
| 373 | for key, value in rundeps.items(): |
| 374 | if isinstance(value, defaultdict): |
| 375 | value = dict(value) |
| 376 | ret.append((key, value)) |
| 377 | return ret |
| 378 | getRuntimeDepends.readonly = True |
| 379 | |
| 380 | def getRuntimeRecommends(self, command, params): |
| 381 | ret = [] |
| 382 | try: |
| 383 | mc = params[0] |
| 384 | except IndexError: |
| 385 | mc = '' |
| 386 | runrecs = command.cooker.recipecaches[mc].runrecs |
| 387 | for key, value in runrecs.items(): |
| 388 | if isinstance(value, defaultdict): |
| 389 | value = dict(value) |
| 390 | ret.append((key, value)) |
| 391 | return ret |
| 392 | getRuntimeRecommends.readonly = True |
| 393 | |
| 394 | def getRecipeInherits(self, command, params): |
| 395 | try: |
| 396 | mc = params[0] |
| 397 | except IndexError: |
| 398 | mc = '' |
| 399 | return command.cooker.recipecaches[mc].inherits |
| 400 | getRecipeInherits.readonly = True |
| 401 | |
| 402 | def getBbFilePriority(self, command, params): |
| 403 | try: |
| 404 | mc = params[0] |
| 405 | except IndexError: |
| 406 | mc = '' |
| 407 | return command.cooker.recipecaches[mc].bbfile_priority |
| 408 | getBbFilePriority.readonly = True |
| 409 | |
| 410 | def getDefaultPreference(self, command, params): |
| 411 | try: |
| 412 | mc = params[0] |
| 413 | except IndexError: |
| 414 | mc = '' |
| 415 | return command.cooker.recipecaches[mc].pkg_dp |
| 416 | getDefaultPreference.readonly = True |
| 417 | |
| 418 | def getSkippedRecipes(self, command, params): |
| 419 | # Return list sorted by reverse priority order |
| 420 | import bb.cache |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 421 | def sortkey(x): |
| 422 | vfn, _ = x |
| 423 | realfn, _, mc = bb.cache.virtualfn2realfn(vfn) |
Andrew Geissler | b7d2861 | 2020-07-24 16:15:54 -0500 | [diff] [blame] | 424 | return (-command.cooker.collections[mc].calc_bbfile_priority(realfn)[0], vfn) |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 425 | |
| 426 | skipdict = OrderedDict(sorted(command.cooker.skiplist.items(), key=sortkey)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 427 | return list(skipdict.items()) |
| 428 | getSkippedRecipes.readonly = True |
| 429 | |
| 430 | def getOverlayedRecipes(self, command, params): |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 431 | try: |
| 432 | mc = params[0] |
| 433 | except IndexError: |
| 434 | mc = '' |
| 435 | return list(command.cooker.collections[mc].overlayed.items()) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 436 | getOverlayedRecipes.readonly = True |
| 437 | |
| 438 | def getFileAppends(self, command, params): |
| 439 | fn = params[0] |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 440 | try: |
| 441 | mc = params[1] |
| 442 | except IndexError: |
| 443 | mc = '' |
| 444 | return command.cooker.collections[mc].get_file_appends(fn) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 445 | getFileAppends.readonly = True |
| 446 | |
| 447 | def getAllAppends(self, command, params): |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 448 | try: |
| 449 | mc = params[0] |
| 450 | except IndexError: |
| 451 | mc = '' |
| 452 | return command.cooker.collections[mc].bbappends |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 453 | getAllAppends.readonly = True |
| 454 | |
| 455 | def findProviders(self, command, params): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 456 | try: |
| 457 | mc = params[0] |
| 458 | except IndexError: |
| 459 | mc = '' |
| 460 | return command.cooker.findProviders(mc) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 461 | findProviders.readonly = True |
| 462 | |
| 463 | def findBestProvider(self, command, params): |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 464 | (mc, pn) = bb.runqueue.split_mc(params[0]) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 465 | return command.cooker.findBestProvider(pn, mc) |
| 466 | findBestProvider.readonly = True |
| 467 | |
| 468 | def allProviders(self, command, params): |
| 469 | try: |
| 470 | mc = params[0] |
| 471 | except IndexError: |
| 472 | mc = '' |
| 473 | return list(bb.providers.allProviders(command.cooker.recipecaches[mc]).items()) |
| 474 | allProviders.readonly = True |
| 475 | |
| 476 | def getRuntimeProviders(self, command, params): |
| 477 | rprovide = params[0] |
| 478 | try: |
| 479 | mc = params[1] |
| 480 | except IndexError: |
| 481 | mc = '' |
| 482 | all_p = bb.providers.getRuntimeProviders(command.cooker.recipecaches[mc], rprovide) |
| 483 | if all_p: |
| 484 | best = bb.providers.filterProvidersRunTime(all_p, rprovide, |
| 485 | command.cooker.data, |
| 486 | command.cooker.recipecaches[mc])[0][0] |
| 487 | else: |
| 488 | best = None |
| 489 | return all_p, best |
| 490 | getRuntimeProviders.readonly = True |
| 491 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 492 | def dataStoreConnectorCmd(self, command, params): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 493 | dsindex = params[0] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 494 | method = params[1] |
| 495 | args = params[2] |
| 496 | kwargs = params[3] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 497 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 498 | d = command.remotedatastores[dsindex] |
| 499 | ret = getattr(d, method)(*args, **kwargs) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 500 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 501 | if isinstance(ret, bb.data_smart.DataSmart): |
| 502 | idx = command.remotedatastores.store(ret) |
| 503 | return DataStoreConnectionHandle(idx) |
| 504 | |
| 505 | return ret |
| 506 | |
| 507 | def dataStoreConnectorVarHistCmd(self, command, params): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 508 | dsindex = params[0] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 509 | method = params[1] |
| 510 | args = params[2] |
| 511 | kwargs = params[3] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 512 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 513 | d = command.remotedatastores[dsindex].varhistory |
| 514 | return getattr(d, method)(*args, **kwargs) |
| 515 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 516 | def dataStoreConnectorVarHistCmdEmit(self, command, params): |
| 517 | dsindex = params[0] |
| 518 | var = params[1] |
| 519 | oval = params[2] |
| 520 | val = params[3] |
| 521 | d = command.remotedatastores[params[4]] |
| 522 | |
| 523 | o = io.StringIO() |
| 524 | command.remotedatastores[dsindex].varhistory.emit(var, oval, val, o, d) |
| 525 | return o.getvalue() |
| 526 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 527 | def dataStoreConnectorIncHistCmd(self, command, params): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 528 | dsindex = params[0] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 529 | method = params[1] |
| 530 | args = params[2] |
| 531 | kwargs = params[3] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 532 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 533 | d = command.remotedatastores[dsindex].inchistory |
| 534 | return getattr(d, method)(*args, **kwargs) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 535 | |
| 536 | def dataStoreConnectorRelease(self, command, params): |
| 537 | dsindex = params[0] |
| 538 | if dsindex <= 0: |
| 539 | raise CommandError('dataStoreConnectorRelease: invalid index %d' % dsindex) |
| 540 | command.remotedatastores.release(dsindex) |
| 541 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 542 | def parseRecipeFile(self, command, params): |
| 543 | """ |
| 544 | Parse the specified recipe file (with or without bbappends) |
| 545 | and return a datastore object representing the environment |
| 546 | for the recipe. |
| 547 | """ |
| 548 | fn = params[0] |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 549 | mc = bb.runqueue.mc_from_tid(fn) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 550 | appends = params[1] |
| 551 | appendlist = params[2] |
| 552 | if len(params) > 3: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 553 | config_data = command.remotedatastores[params[3]] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 554 | else: |
| 555 | config_data = None |
| 556 | |
| 557 | if appends: |
| 558 | if appendlist is not None: |
| 559 | appendfiles = appendlist |
| 560 | else: |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 561 | appendfiles = command.cooker.collections[mc].get_file_appends(fn) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 562 | else: |
| 563 | appendfiles = [] |
| 564 | # We are calling bb.cache locally here rather than on the server, |
| 565 | # but that's OK because it doesn't actually need anything from |
| 566 | # the server barring the global datastore (which we have a remote |
| 567 | # version of) |
| 568 | if config_data: |
| 569 | # We have to use a different function here if we're passing in a datastore |
| 570 | # NOTE: we took a copy above, so we don't do it here again |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 571 | envdata = command.cooker.databuilder._parse_recipe(config_data, fn, appendfiles, mc)[''] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 572 | else: |
| 573 | # Use the standard path |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 574 | envdata = command.cooker.databuilder.parseRecipe(fn, appendfiles) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 575 | idx = command.remotedatastores.store(envdata) |
| 576 | return DataStoreConnectionHandle(idx) |
| 577 | parseRecipeFile.readonly = True |
| 578 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 579 | class CommandsAsync: |
| 580 | """ |
| 581 | A class of asynchronous commands |
| 582 | These functions communicate via generated events. |
| 583 | Any function that requires metadata parsing should be here. |
| 584 | """ |
| 585 | |
| 586 | def buildFile(self, command, params): |
| 587 | """ |
| 588 | Build a single specified .bb file |
| 589 | """ |
| 590 | bfile = params[0] |
| 591 | task = params[1] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 592 | if len(params) > 2: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 593 | internal = params[2] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 594 | else: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 595 | internal = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 596 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 597 | if internal: |
| 598 | command.cooker.buildFileInternal(bfile, task, fireevents=False, quietlog=True) |
| 599 | else: |
| 600 | command.cooker.buildFile(bfile, task) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 601 | buildFile.needcache = False |
| 602 | |
| 603 | def buildTargets(self, command, params): |
| 604 | """ |
| 605 | Build a set of targets |
| 606 | """ |
| 607 | pkgs_to_build = params[0] |
| 608 | task = params[1] |
| 609 | |
| 610 | command.cooker.buildTargets(pkgs_to_build, task) |
| 611 | buildTargets.needcache = True |
| 612 | |
| 613 | def generateDepTreeEvent(self, command, params): |
| 614 | """ |
| 615 | Generate an event containing the dependency information |
| 616 | """ |
| 617 | pkgs_to_build = params[0] |
| 618 | task = params[1] |
| 619 | |
| 620 | command.cooker.generateDepTreeEvent(pkgs_to_build, task) |
| 621 | command.finishAsyncCommand() |
| 622 | generateDepTreeEvent.needcache = True |
| 623 | |
| 624 | def generateDotGraph(self, command, params): |
| 625 | """ |
| 626 | Dump dependency information to disk as .dot files |
| 627 | """ |
| 628 | pkgs_to_build = params[0] |
| 629 | task = params[1] |
| 630 | |
| 631 | command.cooker.generateDotGraphFiles(pkgs_to_build, task) |
| 632 | command.finishAsyncCommand() |
| 633 | generateDotGraph.needcache = True |
| 634 | |
| 635 | def generateTargetsTree(self, command, params): |
| 636 | """ |
| 637 | Generate a tree of buildable targets. |
| 638 | If klass is provided ensure all recipes that inherit the class are |
| 639 | included in the package list. |
| 640 | If pkg_list provided use that list (plus any extras brought in by |
| 641 | klass) rather than generating a tree for all packages. |
| 642 | """ |
| 643 | klass = params[0] |
| 644 | pkg_list = params[1] |
| 645 | |
| 646 | command.cooker.generateTargetsTree(klass, pkg_list) |
| 647 | command.finishAsyncCommand() |
| 648 | generateTargetsTree.needcache = True |
| 649 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 650 | def findConfigFiles(self, command, params): |
| 651 | """ |
| 652 | Find config files which provide appropriate values |
| 653 | for the passed configuration variable. i.e. MACHINE |
| 654 | """ |
| 655 | varname = params[0] |
| 656 | |
| 657 | command.cooker.findConfigFiles(varname) |
| 658 | command.finishAsyncCommand() |
| 659 | findConfigFiles.needcache = False |
| 660 | |
| 661 | def findFilesMatchingInDir(self, command, params): |
| 662 | """ |
| 663 | Find implementation files matching the specified pattern |
| 664 | in the requested subdirectory of a BBPATH |
| 665 | """ |
| 666 | pattern = params[0] |
| 667 | directory = params[1] |
| 668 | |
| 669 | command.cooker.findFilesMatchingInDir(pattern, directory) |
| 670 | command.finishAsyncCommand() |
| 671 | findFilesMatchingInDir.needcache = False |
| 672 | |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 673 | def testCookerCommandEvent(self, command, params): |
| 674 | """ |
| 675 | Dummy command used by OEQA selftest to test tinfoil without IO |
| 676 | """ |
| 677 | pattern = params[0] |
| 678 | |
| 679 | command.cooker.testCookerCommandEvent(pattern) |
| 680 | command.finishAsyncCommand() |
| 681 | testCookerCommandEvent.needcache = False |
| 682 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 683 | def findConfigFilePath(self, command, params): |
| 684 | """ |
| 685 | Find the path of the requested configuration file |
| 686 | """ |
| 687 | configfile = params[0] |
| 688 | |
| 689 | command.cooker.findConfigFilePath(configfile) |
| 690 | command.finishAsyncCommand() |
| 691 | findConfigFilePath.needcache = False |
| 692 | |
| 693 | def showVersions(self, command, params): |
| 694 | """ |
| 695 | Show the currently selected versions |
| 696 | """ |
| 697 | command.cooker.showVersions() |
| 698 | command.finishAsyncCommand() |
| 699 | showVersions.needcache = True |
| 700 | |
| 701 | def showEnvironmentTarget(self, command, params): |
| 702 | """ |
| 703 | Print the environment of a target recipe |
| 704 | (needs the cache to work out which recipe to use) |
| 705 | """ |
| 706 | pkg = params[0] |
| 707 | |
| 708 | command.cooker.showEnvironment(None, pkg) |
| 709 | command.finishAsyncCommand() |
| 710 | showEnvironmentTarget.needcache = True |
| 711 | |
| 712 | def showEnvironment(self, command, params): |
| 713 | """ |
| 714 | Print the standard environment |
| 715 | or if specified the environment for a specified recipe |
| 716 | """ |
| 717 | bfile = params[0] |
| 718 | |
| 719 | command.cooker.showEnvironment(bfile) |
| 720 | command.finishAsyncCommand() |
| 721 | showEnvironment.needcache = False |
| 722 | |
| 723 | def parseFiles(self, command, params): |
| 724 | """ |
| 725 | Parse the .bb files |
| 726 | """ |
| 727 | command.cooker.updateCache() |
| 728 | command.finishAsyncCommand() |
| 729 | parseFiles.needcache = True |
| 730 | |
| 731 | def compareRevisions(self, command, params): |
| 732 | """ |
| 733 | Parse the .bb files |
| 734 | """ |
| 735 | if bb.fetch.fetcher_compare_revisions(command.cooker.data): |
| 736 | command.finishAsyncCommand(code=1) |
| 737 | else: |
| 738 | command.finishAsyncCommand() |
| 739 | compareRevisions.needcache = True |
| 740 | |
| 741 | def triggerEvent(self, command, params): |
| 742 | """ |
| 743 | Trigger a certain event |
| 744 | """ |
| 745 | event = params[0] |
| 746 | bb.event.fire(eval(event), command.cooker.data) |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 747 | process_server.clear_async_cmd() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 748 | triggerEvent.needcache = False |
| 749 | |
| 750 | def resetCooker(self, command, params): |
| 751 | """ |
| 752 | Reset the cooker to its initial state, thus forcing a reparse for |
| 753 | any async command that has the needcache property set to True |
| 754 | """ |
| 755 | command.cooker.reset() |
| 756 | command.finishAsyncCommand() |
| 757 | resetCooker.needcache = False |
| 758 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 759 | def clientComplete(self, command, params): |
| 760 | """ |
| 761 | Do the right thing when the controlling client exits |
| 762 | """ |
| 763 | command.cooker.clientComplete() |
| 764 | command.finishAsyncCommand() |
| 765 | clientComplete.needcache = False |
| 766 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 767 | def findSigInfo(self, command, params): |
| 768 | """ |
| 769 | Find signature info files via the signature generator |
| 770 | """ |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 771 | (mc, pn) = bb.runqueue.split_mc(params[0]) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 772 | taskname = params[1] |
| 773 | sigs = params[2] |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 774 | res = bb.siggen.find_siginfo(pn, taskname, sigs, command.cooker.databuilder.mcdata[mc]) |
| 775 | bb.event.fire(bb.event.FindSigInfoResult(res), command.cooker.databuilder.mcdata[mc]) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 776 | command.finishAsyncCommand() |
| 777 | findSigInfo.needcache = False |