diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2011-11-30 16:48:47 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-12-01 16:54:07 +0000 |
commit | 1dcb2d8eeb034ce7cca035830889e23bcae0722c (patch) | |
tree | 17f59c28e13bbf413f02cbc9559033dd5661e680 /meta/classes/buildhistory.bbclass | |
parent | 8e2c57876764a498760cc310187f96e9126e3428 (diff) | |
download | poky-1dcb2d8eeb034ce7cca035830889e23bcae0722c.tar.gz |
classes/buildhistory: add new output history collection class
Create a new build output history reporting class, using testlab.bbclass
from meta-oe and packagehistory.bbclass as a base. This records information
from packages and images output from the build process in text files
structured suitably for tracking within a git repository, thus enabling
monitoring of changes over time.
Build history collection can be enabled simply by adding the following
to your local.conf:
INHERIT += "buildhistory"
The output after a build can then be found in BUILDHISTORY_DIR (defaults to
TMPDIR/buildhistory). If you set up this directory as a git repository and
set BUILDHISTORY_COMMIT to "1" in local.conf, the build history data will
be committed on every build.
(From OE-Core rev: 508ff624fea705eb93cf2cc1e0c9c42cb817acf8)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/buildhistory.bbclass')
-rw-r--r-- | meta/classes/buildhistory.bbclass | 350 |
1 files changed, 350 insertions, 0 deletions
diff --git a/meta/classes/buildhistory.bbclass b/meta/classes/buildhistory.bbclass new file mode 100644 index 0000000000..89b2cb1462 --- /dev/null +++ b/meta/classes/buildhistory.bbclass | |||
@@ -0,0 +1,350 @@ | |||
1 | # | ||
2 | # Records history of build output in order to detect regressions | ||
3 | # | ||
4 | # Based in part on testlab.bbclass and packagehistory.bbclass | ||
5 | # | ||
6 | # Copyright (C) 2011 Intel Corporation | ||
7 | # Copyright (C) 2007, 2008 Koen Kooi <koen@openembedded.org> | ||
8 | # | ||
9 | |||
10 | BUILDHISTORY_DIR ?= "${TMPDIR}/buildhistory" | ||
11 | BUILDHISTORY_DIR_IMAGE = "${BUILDHISTORY_DIR}/images/${MACHINE_ARCH}/${TCLIBC}/${IMAGE_BASENAME}" | ||
12 | BUILDHISTORY_DIR_PACKAGE = "${BUILDHISTORY_DIR}/packages/${MULTIMACH_TARGET_SYS}/${PN}" | ||
13 | BUILDHISTORY_COMMIT ?= "0" | ||
14 | BUILDHISTORY_COMMIT_AUTHOR ?= "buildhistory <buildhistory@${DISTRO}>" | ||
15 | |||
16 | # Must inherit package first before changing PACKAGEFUNCS | ||
17 | inherit package | ||
18 | PACKAGEFUNCS += "buildhistory_emit_pkghistory" | ||
19 | |||
20 | # | ||
21 | # Called during do_package to write out metadata about this package | ||
22 | # for comparision when writing future packages | ||
23 | # | ||
24 | python buildhistory_emit_pkghistory() { | ||
25 | import re | ||
26 | |||
27 | pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True) | ||
28 | |||
29 | class RecipeInfo: | ||
30 | def __init__(self, name): | ||
31 | self.name = name | ||
32 | self.pe = "0" | ||
33 | self.pv = "0" | ||
34 | self.pr = "r0" | ||
35 | self.depends = "" | ||
36 | self.packages = "" | ||
37 | |||
38 | class PackageInfo: | ||
39 | def __init__(self, name): | ||
40 | self.name = name | ||
41 | self.pe = "0" | ||
42 | self.pv = "0" | ||
43 | self.pr = "r0" | ||
44 | self.size = 0 | ||
45 | self.depends = "" | ||
46 | self.rdepends = "" | ||
47 | self.rrecommends = "" | ||
48 | self.files = "" | ||
49 | self.filelist = "" | ||
50 | |||
51 | # Should check PACKAGES here to see if anything removed | ||
52 | |||
53 | def getpkgvar(pkg, var): | ||
54 | val = bb.data.getVar('%s_%s' % (var, pkg), d, 1) | ||
55 | if val: | ||
56 | return val | ||
57 | val = bb.data.getVar('%s' % (var), d, 1) | ||
58 | |||
59 | return val | ||
60 | |||
61 | def readRecipeInfo(pn, histfile): | ||
62 | rcpinfo = RecipeInfo(pn) | ||
63 | f = open(histfile, "r") | ||
64 | try: | ||
65 | for line in f: | ||
66 | lns = line.split('=') | ||
67 | name = lns[0].strip() | ||
68 | value = lns[1].strip(" \t\r\n").strip('"') | ||
69 | if name == "PE": | ||
70 | rcpinfo.pe = value | ||
71 | elif name == "PV": | ||
72 | rcpinfo.pv = value | ||
73 | elif name == "PR": | ||
74 | rcpinfo.pr = value | ||
75 | elif name == "DEPENDS": | ||
76 | rcpinfo.depends = value | ||
77 | elif name == "PACKAGES": | ||
78 | rcpinfo.packages = value | ||
79 | finally: | ||
80 | f.close() | ||
81 | return rcpinfo | ||
82 | |||
83 | def readPackageInfo(pkg, histfile): | ||
84 | pkginfo = PackageInfo(pkg) | ||
85 | f = open(histfile, "r") | ||
86 | try: | ||
87 | for line in f: | ||
88 | lns = line.split('=') | ||
89 | name = lns[0].strip() | ||
90 | value = lns[1].strip(" \t\r\n").strip('"') | ||
91 | if name == "PE": | ||
92 | pkginfo.pe = value | ||
93 | elif name == "PV": | ||
94 | pkginfo.pv = value | ||
95 | elif name == "PR": | ||
96 | pkginfo.pr = value | ||
97 | elif name == "RDEPENDS": | ||
98 | pkginfo.rdepends = value | ||
99 | elif name == "RRECOMMENDS": | ||
100 | pkginfo.rrecommends = value | ||
101 | elif name == "PKGSIZE": | ||
102 | pkginfo.size = long(value) | ||
103 | elif name == "FILES": | ||
104 | pkginfo.files = value | ||
105 | elif name == "FILELIST": | ||
106 | pkginfo.filelist = value | ||
107 | finally: | ||
108 | f.close() | ||
109 | return pkginfo | ||
110 | |||
111 | def getlastrecipeversion(pn): | ||
112 | try: | ||
113 | histfile = os.path.join(pkghistdir, "latest") | ||
114 | return readRecipeInfo(pn, histfile) | ||
115 | except EnvironmentError: | ||
116 | return None | ||
117 | |||
118 | def getlastpkgversion(pkg): | ||
119 | try: | ||
120 | histfile = os.path.join(pkghistdir, pkg, "latest") | ||
121 | return readPackageInfo(pkg, histfile) | ||
122 | except EnvironmentError: | ||
123 | return None | ||
124 | |||
125 | def squashspaces(string): | ||
126 | return re.sub("\s+", " ", string) | ||
127 | |||
128 | pn = d.getVar('PN', True) | ||
129 | pe = d.getVar('PE', True) or "0" | ||
130 | pv = d.getVar('PV', True) | ||
131 | pr = d.getVar('PR', True) | ||
132 | packages = squashspaces(d.getVar('PACKAGES', True)) | ||
133 | |||
134 | rcpinfo = RecipeInfo(pn) | ||
135 | rcpinfo.pe = pe | ||
136 | rcpinfo.pv = pv | ||
137 | rcpinfo.pr = pr | ||
138 | rcpinfo.depends = squashspaces(d.getVar('DEPENDS', True) or "") | ||
139 | rcpinfo.packages = packages | ||
140 | write_recipehistory(rcpinfo, d) | ||
141 | write_latestlink(None, pe, pv, pr, d) | ||
142 | |||
143 | # Apparently the version can be different on a per-package basis (see Python) | ||
144 | pkgdest = d.getVar('PKGDEST', True) | ||
145 | for pkg in packages.split(): | ||
146 | pe = getpkgvar(pkg, 'PE') or "0" | ||
147 | pv = getpkgvar(pkg, 'PV') | ||
148 | pr = getpkgvar(pkg, 'PR') | ||
149 | # | ||
150 | # Find out what the last version was | ||
151 | # Make sure the version did not decrease | ||
152 | # | ||
153 | lastversion = getlastpkgversion(pkg) | ||
154 | if lastversion: | ||
155 | last_pe = lastversion.pe | ||
156 | last_pv = lastversion.pv | ||
157 | last_pr = lastversion.pr | ||
158 | r = bb.utils.vercmp((pe, pv, pr), (last_pe, last_pv, last_pr)) | ||
159 | if r < 0: | ||
160 | bb.fatal("Package version for package %s went backwards which would break package feeds from (%s:%s-%s to %s:%s-%s)" % (pkg, last_pe, last_pv, last_pr, pe, pv, pr)) | ||
161 | |||
162 | pkginfo = PackageInfo(pkg) | ||
163 | pkginfo.pe = pe | ||
164 | pkginfo.pv = pv | ||
165 | pkginfo.pr = pr | ||
166 | pkginfo.rdepends = squashspaces(getpkgvar(pkg, 'RDEPENDS') or "") | ||
167 | pkginfo.rrecommends = squashspaces(getpkgvar(pkg, 'RRECOMMENDS') or "") | ||
168 | pkginfo.files = squashspaces(getpkgvar(pkg, 'FILES') or "") | ||
169 | |||
170 | # Gather information about packaged files | ||
171 | pkgdestpkg = os.path.join(pkgdest, pkg) | ||
172 | filelist = [] | ||
173 | pkginfo.size = 0 | ||
174 | for root, dirs, files in os.walk(pkgdestpkg): | ||
175 | relpth = os.path.relpath(root, pkgdestpkg) | ||
176 | for f in files: | ||
177 | fstat = os.lstat(os.path.join(root, f)) | ||
178 | pkginfo.size += fstat.st_size | ||
179 | filelist.append(os.sep + os.path.join(relpth, f)) | ||
180 | pkginfo.filelist = " ".join(filelist) | ||
181 | |||
182 | write_pkghistory(pkginfo, d) | ||
183 | |||
184 | if lastversion: | ||
185 | check_pkghistory(pkginfo, lastversion) | ||
186 | |||
187 | write_latestlink(pkg, pe, pv, pr, d) | ||
188 | } | ||
189 | |||
190 | |||
191 | def check_pkghistory(pkginfo, lastversion): | ||
192 | |||
193 | bb.debug(2, "Checking package history") | ||
194 | # RDEPENDS removed? | ||
195 | # PKG changed? | ||
196 | # Each file list of each package for file removals? | ||
197 | |||
198 | |||
199 | def write_recipehistory(rcpinfo, d): | ||
200 | bb.debug(2, "Writing recipe history") | ||
201 | |||
202 | pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True) | ||
203 | |||
204 | if not os.path.exists(pkghistdir): | ||
205 | os.makedirs(pkghistdir) | ||
206 | |||
207 | verfile = os.path.join(pkghistdir, "%s:%s-%s" % (rcpinfo.pe, rcpinfo.pv, rcpinfo.pr)) | ||
208 | f = open(verfile, "w") | ||
209 | try: | ||
210 | if rcpinfo.pe != "0": | ||
211 | f.write("PE = %s\n" % rcpinfo.pe) | ||
212 | f.write("PV = %s\n" % rcpinfo.pv) | ||
213 | f.write("PR = %s\n" % rcpinfo.pr) | ||
214 | f.write("DEPENDS = %s\n" % rcpinfo.depends) | ||
215 | f.write("PACKAGES = %s\n" % rcpinfo.packages) | ||
216 | finally: | ||
217 | f.close() | ||
218 | |||
219 | |||
220 | def write_pkghistory(pkginfo, d): | ||
221 | bb.debug(2, "Writing package history") | ||
222 | |||
223 | pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True) | ||
224 | |||
225 | verpath = os.path.join(pkghistdir, pkginfo.name) | ||
226 | if not os.path.exists(verpath): | ||
227 | os.makedirs(verpath) | ||
228 | |||
229 | verfile = os.path.join(verpath, "%s:%s-%s" % (pkginfo.pe, pkginfo.pv, pkginfo.pr)) | ||
230 | f = open(verfile, "w") | ||
231 | try: | ||
232 | if pkginfo.pe != "0": | ||
233 | f.write("PE = %s\n" % pkginfo.pe) | ||
234 | f.write("PV = %s\n" % pkginfo.pv) | ||
235 | f.write("PR = %s\n" % pkginfo.pr) | ||
236 | f.write("RDEPENDS = %s\n" % pkginfo.rdepends) | ||
237 | f.write("RRECOMMENDS = %s\n" % pkginfo.rrecommends) | ||
238 | f.write("PKGSIZE = %d\n" % pkginfo.size) | ||
239 | f.write("FILES = %s\n" % pkginfo.files) | ||
240 | f.write("FILELIST = %s\n" % pkginfo.filelist) | ||
241 | finally: | ||
242 | f.close() | ||
243 | |||
244 | |||
245 | def write_latestlink(pkg, pe, pv, pr, d): | ||
246 | import shutil | ||
247 | |||
248 | pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True) | ||
249 | |||
250 | def rm_link(path): | ||
251 | try: | ||
252 | os.unlink(path) | ||
253 | except OSError: | ||
254 | return | ||
255 | |||
256 | if pkg: | ||
257 | filedir = os.path.join(pkghistdir, pkg) | ||
258 | else: | ||
259 | filedir = pkghistdir | ||
260 | rm_link(os.path.join(filedir, "latest")) | ||
261 | shutil.copy(os.path.join(filedir, "%s:%s-%s" % (pe, pv, pr)), os.path.join(filedir, "latest")) | ||
262 | |||
263 | |||
264 | buildhistory_get_image_installed() { | ||
265 | # Anything requiring the use of the packaging system should be done in here | ||
266 | # in case the packaging files are going to be removed for this image | ||
267 | |||
268 | mkdir -p ${BUILDHISTORY_DIR_IMAGE} | ||
269 | |||
270 | # Get list of installed packages | ||
271 | list_installed_packages | sort > ${BUILDHISTORY_DIR_IMAGE}/installed-package-names.txt | ||
272 | INSTALLED_PKGS=`cat ${BUILDHISTORY_DIR_IMAGE}/installed-package-names.txt` | ||
273 | |||
274 | # Produce installed package file and size lists and dependency graph | ||
275 | echo -n > ${BUILDHISTORY_DIR_IMAGE}/installed-packages.txt | ||
276 | echo -n > ${BUILDHISTORY_DIR_IMAGE}/installed-package-sizes.tmp | ||
277 | echo -e "digraph depends {\n node [shape=plaintext]" > ${BUILDHISTORY_DIR_IMAGE}/depends.dot | ||
278 | for pkg in $INSTALLED_PKGS; do | ||
279 | pkgfile=`get_package_filename $pkg` | ||
280 | echo `basename $pkgfile` >> ${BUILDHISTORY_DIR_IMAGE}/installed-packages.txt | ||
281 | if [ -f $pkgfile ] ; then | ||
282 | pkgsize=`du -k $pkgfile | head -n1 | awk '{ print $1 }'` | ||
283 | echo $pkgsize $pkg >> ${BUILDHISTORY_DIR_IMAGE}/installed-package-sizes.tmp | ||
284 | fi | ||
285 | |||
286 | deps=`list_package_depends $pkg` | ||
287 | for dep in $deps ; do | ||
288 | echo "$pkg OPP $dep;" | sed -e 's:-:_:g' -e 's:\.:_:g' -e 's:+::g' | sed 's:OPP:->:g' >> ${BUILDHISTORY_DIR_IMAGE}/depends.dot | ||
289 | done | ||
290 | |||
291 | recs=`list_package_recommends $pkg` | ||
292 | for rec in $recs ; do | ||
293 | echo "$pkg OPP $rec [style=dotted];" | sed -e 's:-:_:g' -e 's:\.:_:g' -e 's:+::g' | sed 's:OPP:->:g' >> ${BUILDHISTORY_DIR_IMAGE}/depends.dot | ||
294 | done | ||
295 | done | ||
296 | echo "}" >> ${BUILDHISTORY_DIR_IMAGE}/depends.dot | ||
297 | |||
298 | cat ${BUILDHISTORY_DIR_IMAGE}/installed-package-sizes.tmp | sort -n -r | awk '{print $1 "\tKiB " $2}' > ${BUILDHISTORY_DIR_IMAGE}/installed-package-sizes.txt | ||
299 | rm ${BUILDHISTORY_DIR_IMAGE}/installed-package-sizes.tmp | ||
300 | |||
301 | # Produce some cut-down graphs (for readability) | ||
302 | grep -v kernel_image ${BUILDHISTORY_DIR_IMAGE}/depends.dot | grep -v kernel_2 | grep -v kernel_3 > ${BUILDHISTORY_DIR_IMAGE}/depends-nokernel.dot | ||
303 | grep -v libc6 ${BUILDHISTORY_DIR_IMAGE}/depends-nokernel.dot | grep -v libgcc > ${BUILDHISTORY_DIR_IMAGE}/depends-nokernel-nolibc.dot | ||
304 | grep -v update_ ${BUILDHISTORY_DIR_IMAGE}/depends-nokernel-nolibc.dot > ${BUILDHISTORY_DIR_IMAGE}/depends-nokernel-nolibc-noupdate.dot | ||
305 | grep -v kernel_module ${BUILDHISTORY_DIR_IMAGE}/depends-nokernel-nolibc-noupdate.dot > ${BUILDHISTORY_DIR_IMAGE}/depends-nokernel-nolibc-noupdate-nomodules.dot | ||
306 | |||
307 | # Workaround for broken shell function dependencies | ||
308 | if false ; then | ||
309 | get_package_filename | ||
310 | list_package_depends | ||
311 | list_package_recommends | ||
312 | fi | ||
313 | } | ||
314 | |||
315 | buildhistory_get_imageinfo() { | ||
316 | # List the files in the image, but exclude date/time etc. | ||
317 | # This awk script is somewhat messy, but handles where the size is not printed for device files under pseudo | ||
318 | find ${IMAGE_ROOTFS} -ls | awk '{ if ( $7 ~ /[0-9]/ ) printf "%s %10-s %10-s %10s %s %s %s\n", $3, $5, $6, $7, $11, $12, $13 ; else printf "%s %10-s %10-s %10s %s %s %s\n", $3, $5, $6, 0, $10, $11, $12 }' > ${BUILDHISTORY_DIR_IMAGE}/files-in-image.txt | ||
319 | |||
320 | # Add some configuration information | ||
321 | echo "${MACHINE}: ${IMAGE_BASENAME} configured for ${DISTRO} ${DISTRO_VERSION}" > ${BUILDHISTORY_DIR_IMAGE}/build-id | ||
322 | echo "${@buildhistory_get_layers(d)}" >> ${BUILDHISTORY_DIR_IMAGE}/build-id | ||
323 | } | ||
324 | |||
325 | # By prepending we get in before the removal of packaging files | ||
326 | ROOTFS_POSTPROCESS_COMMAND =+ "buildhistory_get_image_installed ; " | ||
327 | |||
328 | IMAGE_POSTPROCESS_COMMAND += " buildhistory_get_imageinfo ; " | ||
329 | |||
330 | def buildhistory_get_layers(d): | ||
331 | layertext = "Configured metadata layers:\n%s\n" % '\n'.join(get_layers_branch_rev(d)) | ||
332 | return layertext | ||
333 | |||
334 | |||
335 | buildhistory_commit() { | ||
336 | ( cd ${BUILDHISTORY_DIR}/ | ||
337 | git add ${BUILDHISTORY_DIR}/* | ||
338 | git commit ${BUILDHISTORY_DIR}/ -m "Build ${BUILDNAME} for machine ${MACHINE} configured for ${DISTRO} ${DISTRO_VERSION}" --author "${BUILDHISTORY_COMMIT_AUTHOR}" > /dev/null || true) | ||
339 | } | ||
340 | |||
341 | python buildhistory_eventhandler() { | ||
342 | import bb.build | ||
343 | import bb.event | ||
344 | |||
345 | if isinstance(e, bb.event.BuildCompleted): | ||
346 | if e.data.getVar("BUILDHISTORY_COMMIT", True) == "1": | ||
347 | bb.build.exec_func("buildhistory_commit", e.data) | ||
348 | } | ||
349 | |||
350 | addhandler buildhistory_eventhandler | ||