summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake')
-rwxr-xr-xbitbake/bin/bitbake6
-rw-r--r--bitbake/lib/bb/server/process.py107
2 files changed, 79 insertions, 34 deletions
diff --git a/bitbake/bin/bitbake b/bitbake/bin/bitbake
index 8f2fece2ca..acd2f790dc 100755
--- a/bitbake/bin/bitbake
+++ b/bitbake/bin/bitbake
@@ -40,7 +40,8 @@ from bb import cooker
40from bb import ui 40from bb import ui
41from bb import server 41from bb import server
42from bb.server import none 42from bb.server import none
43from bb.server import xmlrpc 43#from bb.server import process
44#from bb.server import xmlrpc
44 45
45__version__ = "1.13.0" 46__version__ = "1.13.0"
46logger = logging.getLogger("BitBake") 47logger = logging.getLogger("BitBake")
@@ -189,8 +190,9 @@ Default BBFILES are the .bb files in the current directory.""")
189 # of the UIs (e.g. for DISPLAY, etc.) 190 # of the UIs (e.g. for DISPLAY, etc.)
190 bb.utils.clean_environment() 191 bb.utils.clean_environment()
191 192
193 server = bb.server.none.BitBakeServer()
194 #server = bb.server.process.BitBakeServer()
192 #server = bb.server.xmlrpc.BitBakeServer() 195 #server = bb.server.xmlrpc.BitBakeServer()
193 server = bb.server.none.BitBakeServer()
194 196
195 server.initServer() 197 server.initServer()
196 idle = server.getServerIdleCB() 198 idle = server.getServerIdleCB()
diff --git a/bitbake/lib/bb/server/process.py b/bitbake/lib/bb/server/process.py
index 5d7f8aa9de..12f368f80f 100644
--- a/bitbake/lib/bb/server/process.py
+++ b/bitbake/lib/bb/server/process.py
@@ -29,8 +29,8 @@ import os
29import signal 29import signal
30import sys 30import sys
31import time 31import time
32from bb.cooker import BBCooker 32from Queue import Empty
33from multiprocessing import Event, Process, util 33from multiprocessing import Event, Process, util, Queue, Pipe, queues
34 34
35logger = logging.getLogger('BitBake') 35logger = logging.getLogger('BitBake')
36 36
@@ -72,13 +72,11 @@ class ProcessServer(Process):
72 profile_filename = "profile.log" 72 profile_filename = "profile.log"
73 profile_processed_filename = "profile.log.processed" 73 profile_processed_filename = "profile.log.processed"
74 74
75 def __init__(self, command_channel, event_queue, configuration): 75 def __init__(self, command_channel, event_queue):
76 Process.__init__(self) 76 Process.__init__(self)
77 self.command_channel = command_channel 77 self.command_channel = command_channel
78 self.event_queue = event_queue 78 self.event_queue = event_queue
79 self.event = EventAdapter(event_queue) 79 self.event = EventAdapter(event_queue)
80 self.configuration = configuration
81 self.cooker = BBCooker(configuration, self.register_idle_function)
82 self._idlefunctions = {} 80 self._idlefunctions = {}
83 self.event_handle = bb.event.register_UIHhandler(self) 81 self.event_handle = bb.event.register_UIHhandler(self)
84 self.quit = False 82 self.quit = False
@@ -95,33 +93,7 @@ class ProcessServer(Process):
95 self._idlefunctions[function] = data 93 self._idlefunctions[function] = data
96 94
97 def run(self): 95 def run(self):
98 if self.configuration.profile: 96 bb.cooker.server_main(self.cooker, self.main)
99 return self.profile_main()
100 else:
101 return self.main()
102
103 def profile_main(self):
104 import cProfile
105 profiler = cProfile.Profile()
106 try:
107 return profiler.runcall(self.main)
108 finally:
109 profiler.dump_stats(self.profile_filename)
110 self.write_profile_stats()
111 sys.__stderr__.write("Raw profiling information saved to %s and "
112 "processed statistics to %s\n" %
113 (self.profile_filename,
114 self.profile_processed_filename))
115
116 def write_profile_stats(self):
117 import pstats
118 with open(self.profile_processed_filename, 'w') as outfile:
119 stats = pstats.Stats(self.profile_filename, stream=outfile)
120 stats.sort_stats('time')
121 stats.print_stats()
122 stats.print_callers()
123 stats.sort_stats('cumulative')
124 stats.print_stats()
125 97
126 def main(self): 98 def main(self):
127 # Ignore SIGINT within the server, as all SIGINT handling is done by 99 # Ignore SIGINT within the server, as all SIGINT handling is done by
@@ -219,3 +191,74 @@ class ProcessServer(Process):
219 # which can result in a bitbake server hang during the parsing process 191 # which can result in a bitbake server hang during the parsing process
220 if (2, 6, 0) <= sys.version_info < (2, 6, 3): 192 if (2, 6, 0) <= sys.version_info < (2, 6, 3):
221 _bootstrap = bootstrap_2_6_6 193 _bootstrap = bootstrap_2_6_6
194
195class BitBakeServerConnection():
196 def __init__(self, server):
197 self.server = server
198 self.procserver = server.server
199 self.connection = ServerCommunicator(server.ui_channel)
200 self.events = server.event_queue
201
202 def terminate(self, force = False):
203 signal.signal(signal.SIGINT, signal.SIG_IGN)
204 self.procserver.stop()
205 if force:
206 self.procserver.join(0.5)
207 if self.procserver.is_alive():
208 self.procserver.terminate()
209 self.procserver.join()
210 else:
211 self.procserver.join()
212 while True:
213 try:
214 event = self.server.event_queue.get(block=False)
215 except (Empty, IOError):
216 break
217 if isinstance(event, logging.LogRecord):
218 logger.handle(event)
219 self.server.ui_channel.close()
220 self.server.event_queue.close()
221 if force:
222 sys.exit(1)
223
224# Wrap Queue to provide API which isn't server implementation specific
225class ProcessEventQueue(multiprocessing.queues.Queue):
226 def waitEvent(self, timeout):
227 try:
228 return self.get(True, timeout)
229 except Empty:
230 return None
231
232class BitBakeServer(object):
233 def initServer(self):
234 # establish communication channels. We use bidirectional pipes for
235 # ui <--> server command/response pairs
236 # and a queue for server -> ui event notifications
237 #
238 self.ui_channel, self.server_channel = Pipe()
239 self.event_queue = ProcessEventQueue(0)
240
241 self.server = ProcessServer(self.server_channel, self.event_queue)
242
243 def addcooker(self, cooker):
244 self.cooker = cooker
245 self.server.cooker = cooker
246
247 def getServerIdleCB(self):
248 return self.server.register_idle_function
249
250 def saveConnectionDetails(self):
251 return
252
253 def detach(self, cooker_logfile):
254 self.server.start()
255 return
256
257 def establishConnection(self):
258 self.connection = BitBakeServerConnection(self)
259 signal.signal(signal.SIGTERM, lambda i, s: self.connection.terminate(force=True))
260 return self.connection
261
262 def launchUI(self, uifunc, *args):
263 return bb.cooker.server_main(self.cooker, uifunc, *args)
264