aboutsummaryrefslogtreecommitdiffstats
path: root/bitbake
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 /bitbake
parent90d7b09af2cc5c6e92c103aa40e554f586110ecf (diff)
downloadopenembedded-core-contrib-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>
Diffstat (limited to 'bitbake')
-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
import errno
import prserv.serv
import pyinotify
+import json
+import pickle
logger = logging.getLogger("BitBake")
collectlog = logging.getLogger("BitBake.Collection")
@@ -114,6 +116,63 @@ class CookerFeatures(object):
return next(self._features)
+class EventLogWriteHandler:
+
+ def __init__(self, cooker, eventfile):
+ # set our handler's event processor
+ self.event = self.EventWriter(cooker, eventfile)
+
+ class EventWriter:
+ def __init__(self, cooker, eventfile):
+ self.file_inited = None
+ self.cooker = cooker
+ self.eventfile = eventfile
+ self.event_queue = []
+
+ def init_file(self):
+ try:
+ # delete the old log
+ os.remove(self.eventfile)
+ except:
+ pass
+
+ # write current configuration data
+ with open(eventfile, "w") as f:
+ f.write("%s\n" % json.dumps({ "allvariables" : self.cooker.getAllKeysWithFlags(["doc", "func"])}))
+
+ def write_event(self, event):
+ with open(self.eventfile, "a") as f:
+ try:
+ f.write("%s\n" % json.dumps({"class":event.__module__ + "." + event.__class__.__name__, "vars":json.dumps(pickle.dumps(event)) }))
+ except Exception as e:
+ import traceback
+ print(e, traceback.format_exc())
+
+
+ def send(self, event):
+ event_class = event.__module__ + "." + event.__class__.__name__
+
+ # init on bb.event.BuildStarted
+ if self.file_inited is None:
+ if event_class == "bb.event.BuildStarted":
+ self.init_file()
+ self.file_inited = True
+
+ # write pending events
+ for e in self.event_queue:
+ self.write_event(e)
+
+ # also write the current event
+ self.write_event(event)
+
+ else:
+ # queue all events until the file is inited
+ self.event_queue.append(event)
+
+ else:
+ # we have the file, just write the event
+ self.write_event(event)
+
#============================================================================#
# BBCooker
#============================================================================#
@@ -151,6 +210,11 @@ class BBCooker:
self.initConfigurationData()
+ # we log all events to a file if so directed
+ if self.configuration.writeeventlog:
+ # register the log file writer as UI Handler
+ bb.event.register_UIHhandler(EventLogWriteHandler(self, self.configuration.writeeventlog))
+
self.inotify_modified_files = []
def _process_inotify_updates(server, notifier_list, abort):
@@ -301,68 +365,6 @@ class BBCooker:
if consolelog:
self.data.setVar("BB_CONSOLELOG", consolelog)
- # we log all events to a file if so directed
- if self.configuration.writeeventlog:
- import json, pickle
- DEFAULT_EVENTFILE = self.configuration.writeeventlog
- class EventLogWriteHandler():
-
- class EventWriter():
- def __init__(self, cooker):
- self.file_inited = None
- self.cooker = cooker
- self.event_queue = []
-
- def init_file(self):
- try:
- # delete the old log
- os.remove(DEFAULT_EVENTFILE)
- except:
- pass
-
- # write current configuration data
- with open(DEFAULT_EVENTFILE, "w") as f:
- f.write("%s\n" % json.dumps({ "allvariables" : self.cooker.getAllKeysWithFlags(["doc", "func"])}))
-
- def write_event(self, event):
- with open(DEFAULT_EVENTFILE, "a") as f:
- try:
- f.write("%s\n" % json.dumps({"class":event.__module__ + "." + event.__class__.__name__, "vars":json.dumps(pickle.dumps(event)) }))
- except Exception as e:
- import traceback
- print(e, traceback.format_exc())
-
-
- def send(self, event):
- event_class = event.__module__ + "." + event.__class__.__name__
-
- # init on bb.event.BuildStarted
- if self.file_inited is None:
- if event_class == "bb.event.BuildStarted":
- self.init_file()
- self.file_inited = True
-
- # write pending events
- for e in self.event_queue:
- self.write_event(e)
-
- # also write the current event
- self.write_event(event)
-
- else:
- # queue all events until the file is inited
- self.event_queue.append(event)
-
- else:
- # we have the file, just write the event
- self.write_event(event)
-
- # set our handler's event processor
- event = EventWriter(self) # self is the cooker here
-
- # register the log file writer as UI Handler
- bb.event.register_UIHhandler(EventLogWriteHandler())
-
#
# Copy of the data store which has been expanded.
# Used for firing events and accessing variables where expansion needs to be accounted for