mirror of
https://git.yoctoproject.org/poky
synced 2026-02-05 16:28:43 +01:00
Implementing feature set selection that allows a client to enable specific features in the server at connection time. Only enabling of features is supported, as there is no way to safely remove data loaded into the cooker. Once enabled, a feature will remain enabled for the life of the cooker. Client-server connection now supports specifying the feature set required by the client. This is implemented in the Process server using a managed proxy list, so the server cooker will now load dynamically needed features based on what client connects to it. In the XMLRPC server the feature set is requested by using a parameter for registerUIHandler function. This allows observer-only clients to also specify features for the server. The server code configuration now is completly separated from the client code. All hardcoding of client knowledge is removed from the server. The extra_caches is removed as the client can now specify the caches it needs using the feature. The UI modules now need to specify the desired featureSet. HOB is modified to conform to the featureSet specification. The only feature available is CookerFeatures.HOB_EXTRA_CACHES which forces loading the bb.cache_extra:HobRecipeInfo class. (Bitbake rev: 98e594837aab89ea042cfa9f3740d20a661b14e2) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
224 lines
7.3 KiB
Python
224 lines
7.3 KiB
Python
#
|
|
# BitBake Process based server.
|
|
#
|
|
# Copyright (C) 2010 Bob Foerster <robert@erafx.com>
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
# published by the Free Software Foundation.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
"""
|
|
This module implements a multiprocessing.Process based server for bitbake.
|
|
"""
|
|
|
|
import bb
|
|
import bb.event
|
|
import itertools
|
|
import logging
|
|
import multiprocessing
|
|
import os
|
|
import signal
|
|
import sys
|
|
import time
|
|
import select
|
|
from Queue import Empty
|
|
from multiprocessing import Event, Process, util, Queue, Pipe, queues, Manager
|
|
|
|
from . import BitBakeBaseServer, BitBakeBaseServerConnection, BaseImplServer
|
|
|
|
logger = logging.getLogger('BitBake')
|
|
|
|
class ServerCommunicator():
|
|
def __init__(self, connection, event_handle):
|
|
self.connection = connection
|
|
self.event_handle = event_handle
|
|
|
|
def runCommand(self, command):
|
|
# @todo try/except
|
|
self.connection.send(command)
|
|
|
|
while True:
|
|
# don't let the user ctrl-c while we're waiting for a response
|
|
try:
|
|
if self.connection.poll(20):
|
|
return self.connection.recv()
|
|
else:
|
|
bb.fatal("Timeout while attempting to communicate with bitbake server")
|
|
except KeyboardInterrupt:
|
|
pass
|
|
|
|
def getEventHandle(self):
|
|
return self.event_handle.value
|
|
|
|
class EventAdapter():
|
|
"""
|
|
Adapter to wrap our event queue since the caller (bb.event) expects to
|
|
call a send() method, but our actual queue only has put()
|
|
"""
|
|
def __init__(self, queue):
|
|
self.queue = queue
|
|
|
|
def send(self, event):
|
|
try:
|
|
self.queue.put(event)
|
|
except Exception as err:
|
|
print("EventAdapter puked: %s" % str(err))
|
|
|
|
|
|
class ProcessServer(Process, BaseImplServer):
|
|
profile_filename = "profile.log"
|
|
profile_processed_filename = "profile.log.processed"
|
|
|
|
def __init__(self, command_channel, event_queue, featurelist):
|
|
BaseImplServer.__init__(self)
|
|
Process.__init__(self, args=(featurelist))
|
|
self.command_channel = command_channel
|
|
self.event_queue = event_queue
|
|
self.event = EventAdapter(event_queue)
|
|
self.featurelist = featurelist
|
|
self.quit = False
|
|
|
|
self.keep_running = Event()
|
|
self.keep_running.set()
|
|
self.event_handle = multiprocessing.Value("i")
|
|
|
|
def run(self):
|
|
for event in bb.event.ui_queue:
|
|
self.event_queue.put(event)
|
|
self.event_handle.value = bb.event.register_UIHhandler(self)
|
|
|
|
# process any feature changes based on what UI requested
|
|
original_featureset = list(self.cooker.featureset)
|
|
while len(self.featurelist)> 0:
|
|
self.cooker.featureset.setFeature(self.featurelist.pop())
|
|
if (original_featureset != list(self.cooker.featureset)):
|
|
self.cooker.reset()
|
|
|
|
bb.cooker.server_main(self.cooker, self.main)
|
|
|
|
def main(self):
|
|
# Ignore SIGINT within the server, as all SIGINT handling is done by
|
|
# the UI and communicated to us
|
|
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
|
while self.keep_running.is_set():
|
|
try:
|
|
if self.command_channel.poll():
|
|
command = self.command_channel.recv()
|
|
self.runCommand(command)
|
|
|
|
self.idle_commands(.1, [self.event_queue._reader, self.command_channel])
|
|
except Exception:
|
|
logger.exception('Running command %s', command)
|
|
|
|
self.event_queue.close()
|
|
bb.event.unregister_UIHhandler(self.event_handle.value)
|
|
self.command_channel.close()
|
|
self.cooker.shutdown(True)
|
|
self.idle_commands(.1)
|
|
|
|
def idle_commands(self, delay, fds = []):
|
|
nextsleep = delay
|
|
|
|
for function, data in self._idlefuns.items():
|
|
try:
|
|
retval = function(self, data, False)
|
|
if retval is False:
|
|
del self._idlefuns[function]
|
|
elif retval is True:
|
|
nextsleep = None
|
|
elif nextsleep is None:
|
|
continue
|
|
else:
|
|
fds = fds + retval
|
|
except SystemExit:
|
|
raise
|
|
except Exception:
|
|
logger.exception('Running idle function')
|
|
|
|
if nextsleep is not None:
|
|
select.select(fds,[],[],nextsleep)
|
|
|
|
def runCommand(self, command):
|
|
"""
|
|
Run a cooker command on the server
|
|
"""
|
|
self.command_channel.send(self.cooker.command.runCommand(command))
|
|
|
|
def stop(self):
|
|
self.keep_running.clear()
|
|
|
|
class BitBakeProcessServerConnection(BitBakeBaseServerConnection):
|
|
def __init__(self, serverImpl, ui_channel, event_queue):
|
|
self.procserver = serverImpl
|
|
self.ui_channel = ui_channel
|
|
self.event_queue = event_queue
|
|
self.connection = ServerCommunicator(self.ui_channel, self.procserver.event_handle)
|
|
self.events = self.event_queue
|
|
|
|
def terminate(self):
|
|
def flushevents():
|
|
while True:
|
|
try:
|
|
event = self.event_queue.get(block=False)
|
|
except (Empty, IOError):
|
|
break
|
|
if isinstance(event, logging.LogRecord):
|
|
logger.handle(event)
|
|
|
|
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
|
self.procserver.stop()
|
|
|
|
while self.procserver.is_alive():
|
|
flushevents()
|
|
self.procserver.join(0.1)
|
|
|
|
self.ui_channel.close()
|
|
self.event_queue.close()
|
|
|
|
# Wrap Queue to provide API which isn't server implementation specific
|
|
class ProcessEventQueue(multiprocessing.queues.Queue):
|
|
def waitEvent(self, timeout):
|
|
try:
|
|
return self.get(True, timeout)
|
|
except Empty:
|
|
return None
|
|
|
|
def getEvent(self):
|
|
try:
|
|
return self.get(False)
|
|
except Empty:
|
|
return None
|
|
|
|
|
|
class BitBakeServer(BitBakeBaseServer):
|
|
def initServer(self):
|
|
# establish communication channels. We use bidirectional pipes for
|
|
# ui <--> server command/response pairs
|
|
# and a queue for server -> ui event notifications
|
|
#
|
|
self.ui_channel, self.server_channel = Pipe()
|
|
self.event_queue = ProcessEventQueue(0)
|
|
manager = Manager()
|
|
self.featurelist = manager.list()
|
|
self.serverImpl = ProcessServer(self.server_channel, self.event_queue, self.featurelist)
|
|
|
|
def detach(self):
|
|
self.serverImpl.start()
|
|
return
|
|
|
|
def establishConnection(self, featureset):
|
|
for f in featureset:
|
|
self.featurelist.append(f)
|
|
self.connection = BitBakeProcessServerConnection(self.serverImpl, self.ui_channel, self.event_queue)
|
|
signal.signal(signal.SIGTERM, lambda i, s: self.connection.terminate())
|
|
return self.connection
|