diff options
author | Alexandru DAMIAN <alexandru.damian@intel.com> | 2013-11-28 19:54:01 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-12-10 11:16:11 +0000 |
commit | 340c35e9d1f8fcaa39d708c3d5e432e0856af34c (patch) | |
tree | 6ade69b873fb465af9604e3ccb2db103321c48b0 /meta/classes/toaster.bbclass | |
parent | 5145b5a6c1a50df10006bb0100fbd0e890af15d9 (diff) | |
download | poky-340c35e9d1f8fcaa39d708c3d5e432e0856af34c.tar.gz |
toaster.bbclass: read package and image information
In the process of removing the local system accesses
from toaster UI (which must be able to run remotely),
the code to read package information is moved
from Bitbake Toaster UI to the server-side
toaster.bbclass
[YOCTO #5604]
(From OE-Core rev: 380d48da4b476f43554e38e464e7e25c930f88b6)
Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/toaster.bbclass')
-rw-r--r-- | meta/classes/toaster.bbclass | 91 |
1 files changed, 74 insertions, 17 deletions
diff --git a/meta/classes/toaster.bbclass b/meta/classes/toaster.bbclass index 59c61c5cec..e1a93b5702 100644 --- a/meta/classes/toaster.bbclass +++ b/meta/classes/toaster.bbclass | |||
@@ -92,6 +92,23 @@ python toaster_layerinfo_dumpdata() { | |||
92 | 92 | ||
93 | # Dump package file info data | 93 | # Dump package file info data |
94 | 94 | ||
95 | def _toaster_load_pkgdatafile(dirpath, filepath): | ||
96 | import json | ||
97 | pkgdata = {} | ||
98 | with open(os.path.join(dirpath, filepath), "r") as fin: | ||
99 | for line in fin: | ||
100 | try: | ||
101 | kn, kv = line.strip().split(": ", 1) | ||
102 | kn = "_".join([x for x in kn.split("_") if x.isupper()]) | ||
103 | pkgdata[kn] = kv.strip() | ||
104 | if kn == 'FILES_INFO': | ||
105 | pkgdata[kn] = json.loads(kv) | ||
106 | |||
107 | except ValueError: | ||
108 | pass # ignore lines without valid key: value pairs | ||
109 | return pkgdata | ||
110 | |||
111 | |||
95 | python toaster_package_dumpdata() { | 112 | python toaster_package_dumpdata() { |
96 | """ | 113 | """ |
97 | Dumps the data created by emit_pkgdata | 114 | Dumps the data created by emit_pkgdata |
@@ -103,27 +120,12 @@ python toaster_package_dumpdata() { | |||
103 | 120 | ||
104 | pkgdatadir = d.getVar('PKGDESTWORK', True) | 121 | pkgdatadir = d.getVar('PKGDESTWORK', True) |
105 | 122 | ||
106 | |||
107 | # scan and send data for each package | 123 | # scan and send data for each package |
108 | import json | ||
109 | 124 | ||
110 | lpkgdata = {} | 125 | lpkgdata = {} |
111 | for pkg in packages.split(): | 126 | for pkg in packages.split(): |
112 | 127 | ||
113 | subdata_file = pkgdatadir + "/runtime/%s" % pkg | 128 | lpkgdata = _toaster_load_pkgdatafile(pkgdatadir + "/runtime/", pkg) |
114 | lpkgdata = {} | ||
115 | |||
116 | sf = open(subdata_file, "r") | ||
117 | line = sf.readline() | ||
118 | while line: | ||
119 | (n, v) = line.rstrip().split(":", 1) | ||
120 | if pkg in n: | ||
121 | n = n.replace("_" + pkg, "") | ||
122 | if n == 'FILES_INFO': | ||
123 | lpkgdata[n] = json.loads(v) | ||
124 | else: | ||
125 | lpkgdata[n] = v.strip() | ||
126 | line = sf.readline() | ||
127 | 129 | ||
128 | # Fire an event containing the pkg data | 130 | # Fire an event containing the pkg data |
129 | bb.event.fire(bb.event.MetadataEvent("SinglePackageInfo", lpkgdata), d) | 131 | bb.event.fire(bb.event.MetadataEvent("SinglePackageInfo", lpkgdata), d) |
@@ -209,7 +211,7 @@ python toaster_collect_task_stats() { | |||
209 | pass | 211 | pass |
210 | 212 | ||
211 | 213 | ||
212 | if isinstance(e, bb.event.BuildCompleted): | 214 | if isinstance(e, bb.event.BuildCompleted) and os.path.exists(os.path.join(e.data.getVar('BUILDSTATS_BASE', True), "toasterstatlist")): |
213 | events = [] | 215 | events = [] |
214 | with open(os.path.join(e.data.getVar('BUILDSTATS_BASE', True), "toasterstatlist"), "r") as fin: | 216 | with open(os.path.join(e.data.getVar('BUILDSTATS_BASE', True), "toasterstatlist"), "r") as fin: |
215 | for line in fin: | 217 | for line in fin: |
@@ -219,6 +221,58 @@ python toaster_collect_task_stats() { | |||
219 | os.unlink(os.path.join(e.data.getVar('BUILDSTATS_BASE', True), "toasterstatlist")) | 221 | os.unlink(os.path.join(e.data.getVar('BUILDSTATS_BASE', True), "toasterstatlist")) |
220 | } | 222 | } |
221 | 223 | ||
224 | # dump relevant build history data as an event when the build is completed | ||
225 | |||
226 | python toaster_buildhistory_dump() { | ||
227 | import re | ||
228 | BUILDHISTORY_DIR = e.data.expand("${TOPDIR}/buildhistory") | ||
229 | BUILDHISTORY_DIR_IMAGE_BASE = e.data.expand("%s/images/${MACHINE_ARCH}/${TCLIBC}/"% BUILDHISTORY_DIR) | ||
230 | pkgdata_dir = e.data.getVar("PKGDATA_DIR", True) | ||
231 | |||
232 | |||
233 | # scan the build targets for this build | ||
234 | images = {} | ||
235 | allpkgs = {} | ||
236 | for target in e._pkgs: | ||
237 | installed_img_path = e.data.expand(os.path.join(BUILDHISTORY_DIR_IMAGE_BASE, target)) | ||
238 | if os.path.exists(installed_img_path): | ||
239 | images[target] = {} | ||
240 | with open("%s/installed-package-sizes.txt" % installed_img_path, "r") as fin: | ||
241 | for line in fin: | ||
242 | line = line.rstrip(";") | ||
243 | psize, px = line.split("\t") | ||
244 | punit, pname = px.split(" ") | ||
245 | # this size is "installed-size" as it measures how much space it takes on disk | ||
246 | images[target][pname.strip()] = {'size':int(psize)*1024, 'depends' : []} | ||
247 | |||
248 | with open("%s/depends.dot" % installed_img_path, "r") as fin: | ||
249 | p = re.compile(r' -> ') | ||
250 | dot = re.compile(r'.*style=dotted') | ||
251 | for line in fin: | ||
252 | line = line.rstrip(';') | ||
253 | linesplit = p.split(line) | ||
254 | if len(linesplit) == 2: | ||
255 | pname = linesplit[0].rstrip('"').strip('"') | ||
256 | dependsname = linesplit[1].split(" ")[0].strip().strip(";").strip('"').rstrip('"') | ||
257 | deptype = "depends" | ||
258 | if dot.match(line): | ||
259 | deptype = "recommends" | ||
260 | if not pname in images[target]: | ||
261 | images[target][pname] = {'size': 0, 'depends' : []} | ||
262 | if not dependsname in images[target]: | ||
263 | images[target][dependsname] = {'size': 0, 'depends' : []} | ||
264 | images[target][pname]['depends'].append((dependsname, deptype)) | ||
265 | |||
266 | for pname in images[target]: | ||
267 | if not pname in allpkgs: | ||
268 | allpkgs[pname] = _toaster_load_pkgdatafile("%s/runtime-reverse/" % pkgdata_dir, pname) | ||
269 | |||
270 | |||
271 | data = { 'pkgdata' : allpkgs, 'imgdata' : images } | ||
272 | |||
273 | bb.event.fire(bb.event.MetadataEvent("ImagePkgList", data), e.data) | ||
274 | |||
275 | } | ||
222 | 276 | ||
223 | # set event handlers | 277 | # set event handlers |
224 | addhandler toaster_layerinfo_dumpdata | 278 | addhandler toaster_layerinfo_dumpdata |
@@ -226,6 +280,9 @@ toaster_layerinfo_dumpdata[eventmask] = "bb.event.TreeDataPreparationCompleted" | |||
226 | 280 | ||
227 | addhandler toaster_collect_task_stats | 281 | addhandler toaster_collect_task_stats |
228 | toaster_collect_task_stats[eventmask] = "bb.event.BuildCompleted bb.build.TaskSucceeded bb.build.TaskFailed" | 282 | toaster_collect_task_stats[eventmask] = "bb.event.BuildCompleted bb.build.TaskSucceeded bb.build.TaskFailed" |
283 | |||
284 | addhandler toaster_buildhistory_dump | ||
285 | toaster_buildhistory_dump[eventmask] = "bb.event.BuildCompleted" | ||
229 | do_package[postfuncs] += "toaster_package_dumpdata " | 286 | do_package[postfuncs] += "toaster_package_dumpdata " |
230 | 287 | ||
231 | do_rootfs[postfuncs] += "toaster_image_dumpdata " | 288 | do_rootfs[postfuncs] += "toaster_image_dumpdata " |