diff options
Diffstat (limited to 'bitbake-dev/lib/bb/event.py')
-rw-r--r-- | bitbake-dev/lib/bb/event.py | 108 |
1 files changed, 40 insertions, 68 deletions
diff --git a/bitbake-dev/lib/bb/event.py b/bitbake-dev/lib/bb/event.py index 86b566febf..3062dc51be 100644 --- a/bitbake-dev/lib/bb/event.py +++ b/bitbake-dev/lib/bb/event.py | |||
@@ -24,27 +24,19 @@ BitBake build tools. | |||
24 | 24 | ||
25 | import os, re | 25 | import os, re |
26 | import bb.utils | 26 | import bb.utils |
27 | import pickle | ||
27 | 28 | ||
28 | # This is the pid for which we should generate the event. This is set when | 29 | # This is the pid for which we should generate the event. This is set when |
29 | # the runqueue forks off. | 30 | # the runqueue forks off. |
30 | worker_pid = 0 | 31 | worker_pid = 0 |
32 | worker_pipe = None | ||
31 | 33 | ||
32 | class Event: | 34 | class Event: |
33 | """Base class for events""" | 35 | """Base class for events""" |
34 | type = "Event" | ||
35 | 36 | ||
36 | def __init__(self, d): | 37 | def __init__(self): |
37 | self._data = d | ||
38 | self.pid = worker_pid | 38 | self.pid = worker_pid |
39 | 39 | ||
40 | def getData(self): | ||
41 | return self._data | ||
42 | |||
43 | def setData(self, data): | ||
44 | self._data = data | ||
45 | |||
46 | data = property(getData, setData, None, "data property") | ||
47 | |||
48 | NotHandled = 0 | 40 | NotHandled = 0 |
49 | Handled = 1 | 41 | Handled = 1 |
50 | 42 | ||
@@ -56,33 +48,48 @@ _handlers = {} | |||
56 | _ui_handlers = {} | 48 | _ui_handlers = {} |
57 | _ui_handler_seq = 0 | 49 | _ui_handler_seq = 0 |
58 | 50 | ||
59 | def fire(event): | 51 | def fire(event, d): |
60 | """Fire off an Event""" | 52 | """Fire off an Event""" |
61 | 53 | ||
54 | if worker_pid != 0: | ||
55 | worker_fire(event, d) | ||
56 | return | ||
57 | |||
62 | for handler in _handlers: | 58 | for handler in _handlers: |
63 | h = _handlers[handler] | 59 | h = _handlers[handler] |
60 | event.data = d | ||
64 | if type(h).__name__ == "code": | 61 | if type(h).__name__ == "code": |
65 | exec(h) | 62 | exec(h) |
66 | tmpHandler(event) | 63 | tmpHandler(event) |
67 | else: | 64 | else: |
68 | h(event) | 65 | h(event) |
69 | 66 | del event.data | |
70 | # Remove the event data elements for UI handlers - too much data otherwise | ||
71 | # They can request data if they need it | ||
72 | event.data = None | ||
73 | event._data = None | ||
74 | 67 | ||
75 | errors = [] | 68 | errors = [] |
76 | for h in _ui_handlers: | 69 | for h in _ui_handlers: |
77 | #print "Sending event %s" % event | 70 | #print "Sending event %s" % event |
78 | classid = "%s.%s" % (event.__class__.__module__, event.__class__.__name__) | ||
79 | try: | 71 | try: |
80 | _ui_handlers[h].event.send((classid, event)) | 72 | # We use pickle here since it better handles object instances |
73 | # which xmlrpc's marshaller does not. Events *must* be serializable | ||
74 | # by pickle. | ||
75 | _ui_handlers[h].event.send((pickle.dumps(event))) | ||
81 | except: | 76 | except: |
82 | errors.append(h) | 77 | errors.append(h) |
83 | for h in errors: | 78 | for h in errors: |
84 | del _ui_handlers[h] | 79 | del _ui_handlers[h] |
85 | 80 | ||
81 | def worker_fire(event, d): | ||
82 | data = "<event>" + pickle.dumps(event) + "</event>" | ||
83 | if os.write(worker_pipe, data) != len (data): | ||
84 | print "Error sending event to server (short write)" | ||
85 | |||
86 | def fire_from_worker(event, d): | ||
87 | if not event.startswith("<event>") or not event.endswith("</event>"): | ||
88 | print "Error, not an event" | ||
89 | return | ||
90 | event = pickle.loads(event[7:-8]) | ||
91 | bb.event.fire(event, d) | ||
92 | |||
86 | def register(name, handler): | 93 | def register(name, handler): |
87 | """Register an Event handler""" | 94 | """Register an Event handler""" |
88 | 95 | ||
@@ -128,17 +135,17 @@ class ConfigParsed(Event): | |||
128 | class RecipeParsed(Event): | 135 | class RecipeParsed(Event): |
129 | """ Recipe Parsing Complete """ | 136 | """ Recipe Parsing Complete """ |
130 | 137 | ||
131 | def __init__(self, fn, d): | 138 | def __init__(self, fn): |
132 | self.fn = fn | 139 | self.fn = fn |
133 | Event.__init__(self, d) | 140 | Event.__init__(self) |
134 | 141 | ||
135 | class StampUpdate(Event): | 142 | class StampUpdate(Event): |
136 | """Trigger for any adjustment of the stamp files to happen""" | 143 | """Trigger for any adjustment of the stamp files to happen""" |
137 | 144 | ||
138 | def __init__(self, targets, stampfns, d): | 145 | def __init__(self, targets, stampfns): |
139 | self._targets = targets | 146 | self._targets = targets |
140 | self._stampfns = stampfns | 147 | self._stampfns = stampfns |
141 | Event.__init__(self, d) | 148 | Event.__init__(self) |
142 | 149 | ||
143 | def getStampPrefix(self): | 150 | def getStampPrefix(self): |
144 | return self._stampfns | 151 | return self._stampfns |
@@ -149,30 +156,13 @@ class StampUpdate(Event): | |||
149 | stampPrefix = property(getStampPrefix) | 156 | stampPrefix = property(getStampPrefix) |
150 | targets = property(getTargets) | 157 | targets = property(getTargets) |
151 | 158 | ||
152 | class PkgBase(Event): | ||
153 | """Base class for package events""" | ||
154 | |||
155 | def __init__(self, t, d): | ||
156 | self._pkg = t | ||
157 | Event.__init__(self, d) | ||
158 | self._message = "package %s: %s" % (bb.data.getVar("P", d, 1), getName(self)[3:]) | ||
159 | |||
160 | def getPkg(self): | ||
161 | return self._pkg | ||
162 | |||
163 | def setPkg(self, pkg): | ||
164 | self._pkg = pkg | ||
165 | |||
166 | pkg = property(getPkg, setPkg, None, "pkg property") | ||
167 | |||
168 | |||
169 | class BuildBase(Event): | 159 | class BuildBase(Event): |
170 | """Base class for bbmake run events""" | 160 | """Base class for bbmake run events""" |
171 | 161 | ||
172 | def __init__(self, n, p, c, failures = 0): | 162 | def __init__(self, n, p, failures = 0): |
173 | self._name = n | 163 | self._name = n |
174 | self._pkgs = p | 164 | self._pkgs = p |
175 | Event.__init__(self, c) | 165 | Event.__init__(self) |
176 | self._failures = failures | 166 | self._failures = failures |
177 | 167 | ||
178 | def getPkgs(self): | 168 | def getPkgs(self): |
@@ -204,20 +194,7 @@ class BuildBase(Event): | |||
204 | cfg = property(getCfg, setCfg, None, "cfg property") | 194 | cfg = property(getCfg, setCfg, None, "cfg property") |
205 | 195 | ||
206 | 196 | ||
207 | class DepBase(PkgBase): | ||
208 | """Base class for dependency events""" | ||
209 | 197 | ||
210 | def __init__(self, t, data, d): | ||
211 | self._dep = d | ||
212 | PkgBase.__init__(self, t, data) | ||
213 | |||
214 | def getDep(self): | ||
215 | return self._dep | ||
216 | |||
217 | def setDep(self, dep): | ||
218 | self._dep = dep | ||
219 | |||
220 | dep = property(getDep, setDep, None, "dep property") | ||
221 | 198 | ||
222 | 199 | ||
223 | class BuildStarted(BuildBase): | 200 | class BuildStarted(BuildBase): |
@@ -228,18 +205,13 @@ class BuildCompleted(BuildBase): | |||
228 | """bbmake build run completed""" | 205 | """bbmake build run completed""" |
229 | 206 | ||
230 | 207 | ||
231 | class UnsatisfiedDep(DepBase): | ||
232 | """Unsatisfied Dependency""" | ||
233 | |||
234 | 208 | ||
235 | class RecursiveDep(DepBase): | ||
236 | """Recursive Dependency""" | ||
237 | 209 | ||
238 | class NoProvider(Event): | 210 | class NoProvider(Event): |
239 | """No Provider for an Event""" | 211 | """No Provider for an Event""" |
240 | 212 | ||
241 | def __init__(self, item, data, runtime=False): | 213 | def __init__(self, item, runtime=False): |
242 | Event.__init__(self, data) | 214 | Event.__init__(self) |
243 | self._item = item | 215 | self._item = item |
244 | self._runtime = runtime | 216 | self._runtime = runtime |
245 | 217 | ||
@@ -252,8 +224,8 @@ class NoProvider(Event): | |||
252 | class MultipleProviders(Event): | 224 | class MultipleProviders(Event): |
253 | """Multiple Providers""" | 225 | """Multiple Providers""" |
254 | 226 | ||
255 | def __init__(self, item, candidates, data, runtime = False): | 227 | def __init__(self, item, candidates, runtime = False): |
256 | Event.__init__(self, data) | 228 | Event.__init__(self) |
257 | self._item = item | 229 | self._item = item |
258 | self._candidates = candidates | 230 | self._candidates = candidates |
259 | self._is_runtime = runtime | 231 | self._is_runtime = runtime |
@@ -281,8 +253,8 @@ class ParseProgress(Event): | |||
281 | Parsing Progress Event | 253 | Parsing Progress Event |
282 | """ | 254 | """ |
283 | 255 | ||
284 | def __init__(self, d, cached, parsed, skipped, masked, errors, total): | 256 | def __init__(self, cached, parsed, skipped, masked, errors, total): |
285 | Event.__init__(self, d) | 257 | Event.__init__(self) |
286 | self.cached = cached | 258 | self.cached = cached |
287 | self.parsed = parsed | 259 | self.parsed = parsed |
288 | self.skipped = skipped | 260 | self.skipped = skipped |
@@ -296,7 +268,7 @@ class DepTreeGenerated(Event): | |||
296 | Event when a dependency tree has been generated | 268 | Event when a dependency tree has been generated |
297 | """ | 269 | """ |
298 | 270 | ||
299 | def __init__(self, d, depgraph): | 271 | def __init__(self, depgraph): |
300 | Event.__init__(self, d) | 272 | Event.__init__(self) |
301 | self._depgraph = depgraph | 273 | self._depgraph = depgraph |
302 | 274 | ||