1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
#
# BitBake Graphical GTK User Interface
#
# Copyright (C) 2011 Intel Corporation
#
# Authored by Joshua Lock <josh@linux.intel.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.
import gobject
import logging
progress_total = 0
class HobHandler(gobject.GObject):
"""
This object does BitBake event handling for the hob gui.
"""
__gsignals__ = {
"machines-updated" : (gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
(gobject.TYPE_PYOBJECT,)),
"sdk-machines-updated": (gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
(gobject.TYPE_PYOBJECT,)),
"distros-updated" : (gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
(gobject.TYPE_PYOBJECT,)),
"package-formats-found" : (gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
(gobject.TYPE_PYOBJECT,)),
"config-found" : (gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
(gobject.TYPE_STRING,)),
"generating-data" : (gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
()),
"data-generated" : (gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
()),
"fatal-error" : (gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
(gobject.TYPE_STRING,
gobject.TYPE_STRING,)),
(gobject.TYPE_STRING,)),
"reload-triggered" : (gobject.SIGNAL_RUN_LAST,
gobject.TYPE_NONE,
(gobject.TYPE_STRING,
gobject.TYPE_STRING)),
}
(CFG_PATH_LOCAL, CFG_PATH_HOB, CFG_PATH_LAYERS, CFG_FILES_DISTRO, CFG_FILES_MACH, CFG_FILES_SDK, FILES_MATCH_CLASS, GENERATE_TGTS, REPARSE_FILES, BUILD_IMAGE) = range(10)
def __init__(self, taskmodel, server):
gobject.GObject.__init__(self)
self.current_command = None
self.building = None
self.build_toolchain = False
self.build_toolchain_headers = False
self.generating = False
self.build_queue = []
self.current_phase = None
self.model = taskmodel
self.server = server
self.image_output_types = self.server.runCommand(["getVariable", "IMAGE_FSTYPES"]).split(" ")
def run_next_command(self):
if self.current_command and not self.generating:
self.emit("generating-data")
self.generating = True
if self.current_command == self.CFG_PATH_LOCAL:
self.current_command = self.CFG_PATH_HOB
self.server.runCommand(["findConfigFilePath", "hob.local.conf"])
elif self.current_command == self.CFG_PATH_HOB:
self.current_command = self.CFG_PATH_LAYERS
self.server.runCommand(["findConfigFilePath", "bblayers.conf"])
elif self.current_command == self.CFG_PATH_LAYERS:
self.current_command = self.CFG_FILES_DISTRO
self.server.runCommand(["findConfigFiles", "DISTRO"])
elif self.current_command == self.CFG_FILES_DISTRO:
self.current_command = self.CFG_FILES_MACH
self.server.runCommand(["findConfigFiles", "MACHINE"])
elif self.current_command == self.CFG_FILES_MACH:
self.current_command = self.CFG_FILES_SDK
self.server.runCommand(["findConfigFiles", "MACHINE-SDK"])
elif self.current_command == self.CFG_FILES_SDK:
self.current_command = self.FILES_MATCH_CLASS
self.server.runCommand(["findFilesMatchingInDir", "rootfs_", "classes"])
elif self.current_command == self.FILES_MATCH_CLASS:
self.current_command = self.GENERATE_TGTS
self.server.runCommand(["generateTargetsTree", "classes/image.bbclass"])
elif self.current_command == self.GENERATE_TGTS:
if self.generating:
self.emit("data-generated")
self.generating = False
self.current_command = None
elif self.current_command == self.REPARSE_FILES:
if self.build_queue:
self.current_command = self.BUILD_IMAGE
else:
self.current_command = self.CFG_PATH_LAYERS
self.server.runCommand(["reparseFiles"])
elif self.current_command == self.BUILD_IMAGE:
self.building = "image"
if self.generating:
self.emit("data-generated")
self.generating = False
self.server.runCommand(["buildTargets", self.build_queue, "build"])
self.build_queue = []
self.current_command = None
def handle_event(self, event, running_build, pbar):
if not event:
return
# If we're running a build, use the RunningBuild event handler
if self.building:
self.current_phase = "building"
running_build.handle_event(event)
elif isinstance(event, bb.event.TargetsTreeGenerated):
self.current_phase = "data generation"
if event._model:
self.model.populate(event._model)
elif isinstance(event, bb.event.ConfigFilesFound):
self.current_phase = "configuration lookup"
var = event._variable
if var == "distro":
distros = event._values
distros.sort()
self.emit("distros-updated", distros)
elif var == "machine":
machines = event._values
machines.sort()
self.emit("machines-updated", machines)
elif var == "machine-sdk":
sdk_machines = event._values
sdk_machines.sort()
self.emit("sdk-machines-updated", sdk_machines)
elif isinstance(event, bb.event.ConfigFilePathFound):
self.current_phase = "configuration lookup"
path = event._path
self.emit("config-found", path)
elif isinstance(event, bb.event.FilesMatchingFound):
self.current_phase = "configuration lookup"
# FIXME: hard coding, should at least be a variable shared between
# here and the caller
if event._pattern == "rootfs_":
formats = []
for match in event._matches:
classname, sep, cls = match.rpartition(".")
fs, sep, format = classname.rpartition("_")
formats.append(format)
formats.sort()
self.emit("package-formats-found", formats)
elif isinstance(event, bb.command.CommandCompleted):
self.current_phase = None
self.run_next_command()
elif isinstance(event, bb.command.CommandFailed):
elif isinstance(event, bb.event.CacheLoadStarted):
self.current_phase = "cache loading"
bb.ui.crumbs.hobeventhandler.progress_total = event.total
pbar.set_text("Loading cache: %s/%s" % (0, bb.ui.crumbs.hobeventhandler.progress_total))
elif isinstance(event, bb.event.CacheLoadProgress):
self.current_phase = "cache loading"
pbar.set_text("Loading cache: %s/%s" % (event.current, bb.ui.crumbs.hobeventhandler.progress_total))
elif isinstance(event, bb.event.CacheLoadCompleted):
self.current_phase = None
pbar.set_text("Loading cache: %s/%s" % (bb.ui.crumbs.hobeventhandler.progress_total, bb.ui.crumbs.hobeventhandler.progress_total))
elif isinstance(event, bb.event.ParseStarted):
self.current_phase = "recipe parsing"
if event.total == 0:
return
bb.ui.crumbs.hobeventhandler.progress_total = event.total
pbar.set_text("Processing recipes: %s/%s" % (0, bb.ui.crumbs.hobeventhandler.progress_total))
elif isinstance(event, bb.event.ParseProgress):
self.current_phase = "recipe parsing"
pbar.set_text("Processing recipes: %s/%s" % (event.current, bb.ui.crumbs.hobeventhandler.progress_total))
elif isinstance(event, bb.event.ParseCompleted):
self.current_phase = None
pbar.set_fraction(1.0)
elif isinstance(event, logging.LogRecord):
format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
if event.levelno >= format.CRITICAL:
self.emit("fatal-error", event.getMessage(), self.current_phase)
return
def event_handle_idle_func (self, eventHandler, running_build, pbar):
# Consume as many messages as we can in the time available to us
event = eventHandler.getEvent()
while event:
self.handle_event(event, running_build, pbar)
event = eventHandler.getEvent()
return True
def set_machine(self, machine):
self.server.runCommand(["setVariable", "MACHINE", machine])
def set_sdk_machine(self, sdk_machine):
self.server.runCommand(["setVariable", "SDKMACHINE", sdk_machine])
def set_distro(self, distro):
self.server.runCommand(["setVariable", "DISTRO", distro])
def set_package_format(self, format):
self.server.runCommand(["setVariable", "PACKAGE_CLASSES", "package_%s" % format])
def reload_data(self, config=None):
img = self.model.selected_image
selected_packages, _ = self.model.get_selected_packages()
self.emit("reload-triggered", img, " ".join(selected_packages))
self.current_command = self.REPARSE_FILES
self.run_next_command()
def set_bbthreads(self, threads):
self.server.runCommand(["setVariable", "BB_NUMBER_THREADS", threads])
def set_pmake(self, threads):
pmake = "-j %s" % threads
self.server.runCommand(["setVariable", "BB_NUMBER_THREADS", pmake])
def build_image(self, image, image_path, configurator):
targets = []
targets.append(image)
if self.build_toolchain and self.build_toolchain_headers:
targets.append("meta-toolchain-sdk")
elif self.build_toolchain:
targets.append("meta-toolchain")
self.build_queue = targets
bbpath_ok = False
bbpath = self.server.runCommand(["getVariable", "BBPATH"])
if image_path in bbpath.split(":"):
bbpath_ok = True
bbfiles_ok = False
bbfiles = self.server.runCommand(["getVariable", "BBFILES"]).split(" ")
for files in bbfiles:
import re
pattern = "%s/\*.bb" % image_path
if re.match(pattern, files):
bbfiles_ok = True
if not bbpath_ok:
nbbp = image_path
else:
nbbp = None
if not bbfiles_ok:
nbbf = "%s/*.bb" % image_path
else:
nbbf = None
if not bbfiles_ok or not bbpath_ok:
configurator.insertTempBBPath(nbbp, nbbf)
self.current_command = self.REPARSE_FILES
self.run_next_command()
def build_packages(self, pkgs):
self.building = "packages"
self.server.runCommand(["buildTargets", pkgs, "build"])
def cancel_build(self, force=False):
if force:
# Force the cooker to stop as quickly as possible
self.server.runCommand(["stateStop"])
else:
# Wait for tasks to complete before shutting down, this helps
# leave the workdir in a usable state
self.server.runCommand(["stateShutdown"])
def set_incompatible_license(self, incompatible):
self.server.runCommand(["setVariable", "INCOMPATIBLE_LICENSE", incompatible])
def toggle_toolchain(self, enabled):
if self.build_toolchain != enabled:
self.build_toolchain = enabled
def toggle_toolchain_headers(self, enabled):
if self.build_toolchain_headers != enabled:
self.build_toolchain_headers = enabled
def set_fstypes(self, fstypes):
self.server.runCommand(["setVariable", "IMAGE_FSTYPES", fstypes])
def add_image_output_type(self, output_type):
if output_type not in self.image_output_types:
self.image_output_types.append(output_type)
fstypes = " ".join(self.image_output_types)
self.set_fstypes(fstypes)
return fstypes
def remove_image_output_type(self, output_type):
if output_type in self.image_output_types:
ind = self.image_output_types.index(output_type)
self.image_output_types.pop(ind)
fstypes = " ".join(self.image_output_types)
self.set_fstypes(fstypes)
return fstypes
def get_image_deploy_dir(self):
return self.server.runCommand(["getVariable", "DEPLOY_DIR_IMAGE"])
|