prserv/cooker: Drop unused param
PATCH 1/10 prserv/cooker: Drop unused param
Drop pointless unused function parameter.
--- lib/bb/cooker.py | 2 +- lib/prserv/serv.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
lib/bb/cooker.py +1 -1
@@ -1576,7 +1576,7 @@ class BBCooker: return def post_serve(self): - prserv.serv.auto_shutdown(self.data) + prserv.serv.auto_shutdown() bb.event.fire(CookerExit(), self.data)
lib/prserv/serv.py +1 -1
@@ -478,7 +478,7 @@ def auto_start(d): logger.critical("PRservice %s:%d not available" % (host, port)) raise PRServiceConfigError -def auto_shutdown(d=None): +def auto_shutdown(): global singleton if singleton: host, port = singleton.getinfo()
Signature · 1 line
2.7.4
PATCH 2/10 cooker: Handle datastore tracking for showEnvironment server side only
The current passing of "tracking" backwards and forwards, client to server is ugly and complex and error prone. Instead, set this during showEnvironment commands triggering a reset there if/as required.
--- lib/bb/cooker.py | 11 ++++++++++- lib/bb/cookerdata.py | 7 +------ 2 files changed, 11 insertions(+), 7 deletions(-)
lib/bb/cooker.py +10 -1
@@ -415,7 +415,7 @@ class BBCooker: self.ui_cmdline = cmdline clean = True for o in options: - if o in ['prefile', 'postfile', 'tracking']: + if o in ['prefile', 'postfile']: server_val = getattr(self.configuration, "%s_server" % o, None) if not options[o] and server_val: # restore value provided on server start
@@ -486,6 +486,12 @@ class BBCooker: if not pkgs_to_build: pkgs_to_build = [] + orig_tracking = self.configuration.tracking + if not orig_tracking: + self.enableDataTracking() + self.reset() + + if buildfile: # Parse the configuration here. We need to do it explicitly here since # this showEnvironment() code path doesn't use the cache
@@ -530,6 +536,9 @@ class BBCooker: if envdata.getVarFlag(e, 'func', False) and envdata.getVarFlag(e, 'python', False): logger.plain("\npython %s () {\n%s}\n", e, envdata.getVar(e, False)) + if not orig_tracking: + self.disableDataTracking() + self.reset() def buildTaskData(self, pkgs_to_build, task, abort, allowincomplete=False): """
lib/bb/cookerdata.py +1 -6
@@ -41,10 +41,6 @@ class ConfigParameters(object): self.options.pkgs_to_build = targets or [] - self.options.tracking = False - if hasattr(self.options, "show_environment") and self.options.show_environment: - self.options.tracking = True - for key, val in self.options.__dict__.items(): setattr(self, key, val)
@@ -76,7 +72,7 @@ class ConfigParameters(object): for o in ["abort", "tryaltconfigs", "force", "invalidate_stamp", "verbose", "debug", "dry_run", "dump_signatures", "debug_domains", "extra_assume_provided", "profile", - "prefile", "postfile", "tracking", "server_timeout"]: + "prefile", "postfile", "server_timeout"]: options[o] = getattr(self.options, o) ret, error = server.runCommand(["updateConfig", options, environment, sys.argv])
@@ -158,7 +154,6 @@ class CookerConfiguration(object): if key in parameters.options.__dict__: setattr(self, key, parameters.options.__dict__[key]) self.env = parameters.environment.copy() - self.tracking = parameters.tracking def setServerRegIdleCallback(self, srcb): self.server_register_idlecallback = srcb
Signature · 1 line
2.7.4
PATCH 3/10 cooker: Change to consistent prefile/postfile handling
In reply to Richard PurdieCurrently the original prefile and postfile passed when starting bitbake server are 'sticky'. With the new memory resident model this doesn't make sense as the server the system is started with isn't special.
This patch changes the code so the prefile/postfile are used if specified on the commandline and not used otherwise. This makes the behaviour much more predictable and expected and as an added bonus simplifies the code.
--- lib/bb/cooker.py | 23 ++++++++++------------- lib/bb/cookerdata.py | 2 -- lib/bb/server/process.py | 6 ------ 3 files changed, 10 insertions(+), 21 deletions(-)
lib/bb/cooker.py +10 -13
@@ -416,19 +416,16 @@ class BBCooker: clean = True for o in options: if o in ['prefile', 'postfile']: - server_val = getattr(self.configuration, "%s_server" % o, None) - if not options[o] and server_val: - # restore value provided on server start - logger.debug(1, "Restoring server value for option '%s'" % o) - setattr(self.configuration, o, server_val) - clean = False - continue - if getattr(self.configuration, o) == options[o]: - # Value is the same, no need to mark dirty - continue - else: - logger.debug(1, "Marking as dirty due to '%s' option change to '%s'" % (o, options[o])) - clean = False + # Only these options may require a reparse + try: + if getattr(self.configuration, o) == options[o]: + # Value is the same, no need to mark dirty + continue + except AttributeError: + pass + logger.debug(1, "Marking as dirty due to '%s' option change to '%s'" % (o, options[o])) + print("Marking as dirty due to '%s' option change to '%s'" % (o, options[o])) + clean = False setattr(self.configuration, o, options[o]) for k in bb.utils.approved_variables(): if k in environment and k not in self.configuration.env:
lib/bb/cookerdata.py +0 -2
@@ -127,8 +127,6 @@ class CookerConfiguration(object): self.extra_assume_provided = [] self.prefile = [] self.postfile = [] - self.prefile_server = [] - self.postfile_server = [] self.debug = 0 self.cmd = None self.abort = True
lib/bb/server/process.py +0 -6
@@ -405,12 +405,6 @@ class BitBakeServer(object): server = ProcessServer(self.bitbake_lock, self.sock, self.sockname) self.configuration.setServerRegIdleCallback(server.register_idle_function) - # Copy prefile and postfile to _server variants - for param in ('prefile', 'postfile'): - value = getattr(self.configuration, param) - if value: - setattr(self.configuration, "%s_server" % param, value) - self.cooker = bb.cooker.BBCooker(self.configuration, self.featureset, self.readypipein) server.cooker = self.cooker server.server_timeout = self.configuration.server_timeout
Signature · 1 line
2.7.4
PATCH 4/10 prserv/serv: Shut down any existing server before restarting
In reply to Richard PurdieThis allows for cleaner code in cooker as any existing server is dealt with before a new one is started.
--- lib/prserv/serv.py | 3 +++ 1 file changed, 3 insertions(+)
lib/prserv/serv.py +3 -0
@@ -442,6 +442,9 @@ class PRServiceConfigError(Exception): def auto_start(d): global singleton + # Shutdown any existing PR Server + auto_shutdown() + host_params = list(filter(None, (d.getVar('PRSERV_HOST') or '').split(':'))) if not host_params: return None
Signature · 1 line
2.7.4
PATCH 5/10 cooker: Allow changes in PRSERV_HOST to be responded to
In reply to Richard PurdieWhen we reload the configuration, PRSERV_HOST can change. Therefore restart the PR Server depending on the new configuration at reparse.
Note that the server has to be started from the right process, it can't be in the UI which shuts down as that shutdown triggers a shutdown of its children and the PR Server shuts down too. This is why we need pre_serve() which ensures its executed in the right context.
--- lib/bb/cooker.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
lib/bb/cooker.py +11 -8
@@ -379,6 +379,13 @@ class BBCooker: self.baseconfig_valid = True self.parsecache_valid = False + def handlePRServ(self): + # Setup a PR Server based on the new configuration + try: + self.prhost = prserv.serv.auto_start(self.data) + except prserv.serv.PRServiceConfigError as e: + bb.fatal("Unable to start PR Server, exitting") + def enableDataTracking(self): self.configuration.tracking = True if hasattr(self, "data"):
@@ -1468,6 +1475,7 @@ class BBCooker: if not self.baseconfig_valid: logger.debug(1, "Reloading base configuration data") self.initConfigurationData() + self.handlePRServ() # This is called for all async commands when self.state != running def updateCache(self):
@@ -1571,14 +1579,9 @@ class BBCooker: return pkgs_to_build def pre_serve(self): - # Empty the environment. The environment will be populated as - # necessary from the data store. - #bb.utils.empty_environment() - try: - self.prhost = prserv.serv.auto_start(self.data) - except prserv.serv.PRServiceConfigError: - bb.event.fire(CookerExit(), self.data) - self.state = state.error + # We now are in our own process so we can call this here. + # PRServ exits if its parent process exits + self.handlePRServ() return def post_serve(self):
Signature · 1 line
2.7.4
PATCH 6/10 cookerdata: Avoid tracebacks from early reset() calls
In reply to Richard Purdiecooker.reset() can be called before we've actually setup the datastore. Gracefully handle this case instead of the current traceback+exit.
--- lib/bb/cookerdata.py | 3 +++ 1 file changed, 3 insertions(+)
lib/bb/cookerdata.py +3 -0
@@ -327,6 +327,9 @@ class CookerDataBuilder(object): self.mcdata[''] = self.data def reset(self): + # We may not have run parseBaseConfiguration() yet + if not hasattr(self, 'origdata'): + return self.data = bb.data.createCopy(self.origdata) self.mcdata[''] = self.data
Signature · 1 line
2.7.4
PATCH 7/10 ui/knotty: Send updateConfig early
In reply to Richard PurdieIf for example you run:
bitbake -r somefile.inc
rm somefile.inc
bitbake -e
bitbake will crash with an error about not being able to find somefile.inc. This is because it tries to reparse the base config for the early getVariable requests before it sees the updated missing -r option.
Send the updateConfig command earlier to avoid this.
--- lib/bb/ui/knotty.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/bb/ui/knotty.py +3 -1
@@ -344,6 +344,9 @@ _evt_list = [ "bb.runqueue.runQueueExitWait", "bb.event.LogExecTTY", "logging.Lo def main(server, eventHandler, params, tf = TerminalFilter): + if not params.observe_only: + params.updateToServer(server, os.environ.copy()) + includelogs, loglines, consolelogfile = _log_settings_from_server(server, params.observe_only) if sys.stdin.isatty() and sys.stdout.isatty():
@@ -398,7 +401,6 @@ def main(server, eventHandler, params, tf = TerminalFilter): universe = False if not params.observe_only: params.updateFromServer(server) - params.updateToServer(server, os.environ.copy()) cmdline = params.parseActions() if not cmdline: print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.")
Signature · 1 line
2.7.4
PATCH 8/10 prserv/serv: Send sentinel to stop handler thread
In reply to Richard PurdieShutdown from SIGTERM currently has to wait for the handler thread to timeout. Add a sentinel value which triggers it to loop and allows for a quick exit.
--- lib/prserv/serv.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
lib/prserv/serv.py +4 -1
@@ -84,6 +84,8 @@ class PRServer(SimpleXMLRPCServer): except queue.Empty: self.table.sync_if_dirty() continue + if request is None: + continue try: self.finish_request(request, client_address) self.shutdown_request(request)
@@ -103,7 +105,8 @@ class PRServer(SimpleXMLRPCServer): def sigterm_handler(self, signum, stack): if self.table: self.table.sync() - self.quit=True + self.quit() + self.requestqueue.put((None, None)) def process_request(self, request, client_address): self.requestqueue.put((request, client_address))
Signature · 1 line
2.7.4
PATCH 9/10 prserv/serv: Rename self.quit -> self.quitflag
In reply to Richard Purdieself has a quit function and a variable. Separate this to two different things as the current setup is prone to breakage.
--- lib/prserv/serv.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
lib/prserv/serv.py +6 -6
@@ -78,7 +78,7 @@ class PRServer(SimpleXMLRPCServer): bb.utils.set_process_name("PRServ Handler") - while not self.quit: + while not self.quitflag: try: (request, client_address) = self.requestqueue.get(True, 30) except queue.Empty:
@@ -142,7 +142,7 @@ class PRServer(SimpleXMLRPCServer): return self.table.importone(version, pkgarch, checksum, value) def ping(self): - return not self.quit + return not self.quitflag def getinfo(self): return (self.host, self.port)
@@ -158,13 +158,13 @@ class PRServer(SimpleXMLRPCServer): return None def quit(self): - self.quit=True + self.quitflag=True os.write(self.quitpipeout, b"q") os.close(self.quitpipeout) return def work_forever(self,): - self.quit = False + self.quitflag = False # This timeout applies to the poll in TCPServer, we need the select # below to wake on our quit pipe closing. We only ever call into handle_request # if there is data there.
@@ -180,9 +180,9 @@ class PRServer(SimpleXMLRPCServer): (self.dbfile, self.host, self.port, str(os.getpid()))) self.handlerthread.start() - while not self.quit: + while not self.quitflag: ready = select.select([self.fileno(), self.quitpipein], [], [], 30) - if self.quit: + if self.quitflag: break if self.fileno() in ready[0]: self.handle_request()
Signature · 1 line
2.7.4
PATCH 10/10 prserv/serv: Gracefully handle the PR server exiting quickly
In reply to Richard PurdieIf the server exits quickly its PID may no longer exist. Handle this gracefully.
--- lib/prserv/serv.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
lib/prserv/serv.py +5 -1
@@ -492,7 +492,11 @@ def auto_shutdown(): PRServerConnection(host, port).terminate() except: logger.critical("Stop PRService %s:%d failed" % (host,port)) - os.waitpid(singleton.prserv.pid, 0) + + try: + os.waitpid(singleton.prserv.pid, 0) + except ChildProcessError: + pass singleton = None def ping(host, port):
Signature · 1 line
2.7.4