summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2016-06-20 14:00:48 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-06-20 17:23:57 +0100
commit3e7edc303cfcb08d16b357b04441fb295099f314 (patch)
treef6bf6c7fe25baa8bb69f35cd4c3bae9decf962da
parent90d7b09af2cc5c6e92c103aa40e554f586110ecf (diff)
downloadpoky-3e7edc303cfcb08d16b357b04441fb295099f314.tar.gz
bitbake: cooker: move EventLogWriteHandler to the top module level
EventLogWriteHandler object was created and used in BBCooker.initConfigurationData. This causes creation of multiple EventLogWriteHandler objects and results in duplicated entries in the output event file as BBCooker.initConfigurationData is called multiple times. Added eventlogfile parameter to EventLogWriteHandler to avoid using global variable DEFAULT_EVENTFILE. Moved EventLogWriteHandler to the module level. Created EventLogWriteHandler object in BBCooker.__init__ to ensure that only one handler object is created. (Bitbake rev: d3ad8eee850ec2df54aa09fae44cc7e69c12f32a) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/bb/cooker.py126
1 files changed, 64 insertions, 62 deletions
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index 60ee5d7c4a..b2cf0cda17 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -42,6 +42,8 @@ import subprocess
42import errno 42import errno
43import prserv.serv 43import prserv.serv
44import pyinotify 44import pyinotify
45import json
46import pickle
45 47
46logger = logging.getLogger("BitBake") 48logger = logging.getLogger("BitBake")
47collectlog = logging.getLogger("BitBake.Collection") 49collectlog = logging.getLogger("BitBake.Collection")
@@ -114,6 +116,63 @@ class CookerFeatures(object):
114 return next(self._features) 116 return next(self._features)
115 117
116 118
119class EventLogWriteHandler:
120
121 def __init__(self, cooker, eventfile):
122 # set our handler's event processor
123 self.event = self.EventWriter(cooker, eventfile)
124
125 class EventWriter:
126 def __init__(self, cooker, eventfile):
127 self.file_inited = None
128 self.cooker = cooker
129 self.eventfile = eventfile
130 self.event_queue = []
131
132 def init_file(self):
133 try:
134 # delete the old log
135 os.remove(self.eventfile)
136 except:
137 pass
138
139 # write current configuration data
140 with open(eventfile, "w") as f:
141 f.write("%s\n" % json.dumps({ "allvariables" : self.cooker.getAllKeysWithFlags(["doc", "func"])}))
142
143 def write_event(self, event):
144 with open(self.eventfile, "a") as f:
145 try:
146 f.write("%s\n" % json.dumps({"class":event.__module__ + "." + event.__class__.__name__, "vars":json.dumps(pickle.dumps(event)) }))
147 except Exception as e:
148 import traceback
149 print(e, traceback.format_exc())
150
151
152 def send(self, event):
153 event_class = event.__module__ + "." + event.__class__.__name__
154
155 # init on bb.event.BuildStarted
156 if self.file_inited is None:
157 if event_class == "bb.event.BuildStarted":
158 self.init_file()
159 self.file_inited = True
160
161 # write pending events
162 for e in self.event_queue:
163 self.write_event(e)
164
165 # also write the current event
166 self.write_event(event)
167
168 else:
169 # queue all events until the file is inited
170 self.event_queue.append(event)
171
172 else:
173 # we have the file, just write the event
174 self.write_event(event)
175
117#============================================================================# 176#============================================================================#
118# BBCooker 177# BBCooker
119#============================================================================# 178#============================================================================#
@@ -151,6 +210,11 @@ class BBCooker:
151 210
152 self.initConfigurationData() 211 self.initConfigurationData()
153 212
213 # we log all events to a file if so directed
214 if self.configuration.writeeventlog:
215 # register the log file writer as UI Handler
216 bb.event.register_UIHhandler(EventLogWriteHandler(self, self.configuration.writeeventlog))
217
154 self.inotify_modified_files = [] 218 self.inotify_modified_files = []
155 219
156 def _process_inotify_updates(server, notifier_list, abort): 220 def _process_inotify_updates(server, notifier_list, abort):
@@ -301,68 +365,6 @@ class BBCooker:
301 if consolelog: 365 if consolelog:
302 self.data.setVar("BB_CONSOLELOG", consolelog) 366 self.data.setVar("BB_CONSOLELOG", consolelog)
303 367
304 # we log all events to a file if so directed
305 if self.configuration.writeeventlog:
306 import json, pickle
307 DEFAULT_EVENTFILE = self.configuration.writeeventlog
308 class EventLogWriteHandler():
309
310 class EventWriter():
311 def __init__(self, cooker):
312 self.file_inited = None
313 self.cooker = cooker
314 self.event_queue = []
315
316 def init_file(self):
317 try:
318 # delete the old log
319 os.remove(DEFAULT_EVENTFILE)
320 except:
321 pass
322
323 # write current configuration data
324 with open(DEFAULT_EVENTFILE, "w") as f:
325 f.write("%s\n" % json.dumps({ "allvariables" : self.cooker.getAllKeysWithFlags(["doc", "func"])}))
326
327 def write_event(self, event):
328 with open(DEFAULT_EVENTFILE, "a") as f:
329 try:
330 f.write("%s\n" % json.dumps({"class":event.__module__ + "." + event.__class__.__name__, "vars":json.dumps(pickle.dumps(event)) }))
331 except Exception as e:
332 import traceback
333 print(e, traceback.format_exc())
334
335
336 def send(self, event):
337 event_class = event.__module__ + "." + event.__class__.__name__
338
339 # init on bb.event.BuildStarted
340 if self.file_inited is None:
341 if event_class == "bb.event.BuildStarted":
342 self.init_file()
343 self.file_inited = True
344
345 # write pending events
346 for e in self.event_queue:
347 self.write_event(e)
348
349 # also write the current event
350 self.write_event(event)
351
352 else:
353 # queue all events until the file is inited
354 self.event_queue.append(event)
355
356 else:
357 # we have the file, just write the event
358 self.write_event(event)
359
360 # set our handler's event processor
361 event = EventWriter(self) # self is the cooker here
362
363 # register the log file writer as UI Handler
364 bb.event.register_UIHhandler(EventLogWriteHandler())
365
366 # 368 #
367 # Copy of the data store which has been expanded. 369 # Copy of the data store which has been expanded.
368 # Used for firing events and accessing variables where expansion needs to be accounted for 370 # Used for firing events and accessing variables where expansion needs to be accounted for