diff options
Diffstat (limited to 'meta/classes/buildhistory.bbclass')
| -rw-r--r-- | meta/classes/buildhistory.bbclass | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/meta/classes/buildhistory.bbclass b/meta/classes/buildhistory.bbclass new file mode 100644 index 0000000000..21f8493ce5 --- /dev/null +++ b/meta/classes/buildhistory.bbclass | |||
| @@ -0,0 +1,105 @@ | |||
| 1 | # | ||
| 2 | # Records history of build output in order to detect regressions | ||
| 3 | # | ||
| 4 | # Based in part on testlab.bbclass | ||
| 5 | # | ||
| 6 | # Copyright (C) 2011 Intel Corporation | ||
| 7 | # Copyright (C) 2007-2011 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_COMMIT ?= "0" | ||
| 13 | BUILDHISTORY_COMMIT_AUTHOR ?= "buildhistory <buildhistory@${DISTRO}>" | ||
| 14 | BUILDHISTORY_PUSH_REPO ?= "" | ||
| 15 | |||
| 16 | buildhistory_get_image_installed() { | ||
| 17 | # Anything requiring the use of the packaging system should be done in here | ||
| 18 | # in case the packaging files are going to be removed for this image | ||
| 19 | |||
| 20 | mkdir -p ${BUILDHISTORY_DIR_IMAGE} | ||
| 21 | |||
| 22 | # Get list of installed packages | ||
| 23 | list_installed_packages | sort > ${BUILDHISTORY_DIR_IMAGE}/installed-package-names.txt | ||
| 24 | INSTALLED_PKGS=`cat ${BUILDHISTORY_DIR_IMAGE}/installed-package-names.txt` | ||
| 25 | |||
| 26 | # Produce installed package file and size lists and dependency graph | ||
| 27 | echo -n > ${BUILDHISTORY_DIR_IMAGE}/installed-packages.txt | ||
| 28 | echo -n > ${BUILDHISTORY_DIR_IMAGE}/installed-package-sizes.tmp | ||
| 29 | echo -e "digraph depends {\n node [shape=plaintext]" > ${BUILDHISTORY_DIR_IMAGE}/depends.dot | ||
| 30 | for pkg in $INSTALLED_PKGS; do | ||
| 31 | pkgfile=`get_package_filename $pkg` | ||
| 32 | echo `basename $pkgfile` >> ${BUILDHISTORY_DIR_IMAGE}/installed-packages.txt | ||
| 33 | if [ -f $pkgfile ] ; then | ||
| 34 | pkgsize=`du -k $pkgfile | head -n1 | awk '{ print $1 }'` | ||
| 35 | echo $pkgsize $pkg >> ${BUILDHISTORY_DIR_IMAGE}/installed-package-sizes.tmp | ||
| 36 | fi | ||
| 37 | |||
| 38 | deps=`list_package_depends $pkg` | ||
| 39 | for dep in $deps ; do | ||
| 40 | echo "$pkg OPP $dep;" | sed -e 's:-:_:g' -e 's:\.:_:g' -e 's:+::g' | sed 's:OPP:->:g' >> ${BUILDHISTORY_DIR_IMAGE}/depends.dot | ||
| 41 | done | ||
| 42 | |||
| 43 | recs=`list_package_recommends $pkg` | ||
| 44 | for rec in $recs ; do | ||
| 45 | 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 | ||
| 46 | done | ||
| 47 | done | ||
| 48 | echo "}" >> ${BUILDHISTORY_DIR_IMAGE}/depends.dot | ||
| 49 | |||
| 50 | cat ${BUILDHISTORY_DIR_IMAGE}/installed-package-sizes.tmp | sort -n -r | awk '{print $1 "\tKiB " $2}' > ${BUILDHISTORY_DIR_IMAGE}/installed-package-sizes.txt | ||
| 51 | rm ${BUILDHISTORY_DIR_IMAGE}/installed-package-sizes.tmp | ||
| 52 | |||
| 53 | # Produce some cut-down graphs (for readability) | ||
| 54 | grep -v kernel_image ${BUILDHISTORY_DIR_IMAGE}/depends.dot | grep -v kernel_2 | grep -v kernel_3 > ${BUILDHISTORY_DIR_IMAGE}/depends-nokernel.dot | ||
| 55 | grep -v libc6 ${BUILDHISTORY_DIR_IMAGE}/depends-nokernel.dot | grep -v libgcc > ${BUILDHISTORY_DIR_IMAGE}/depends-nokernel-nolibc.dot | ||
| 56 | grep -v update_ ${BUILDHISTORY_DIR_IMAGE}/depends-nokernel-nolibc.dot > ${BUILDHISTORY_DIR_IMAGE}/depends-nokernel-nolibc-noupdate.dot | ||
| 57 | grep -v kernel_module ${BUILDHISTORY_DIR_IMAGE}/depends-nokernel-nolibc-noupdate.dot > ${BUILDHISTORY_DIR_IMAGE}/depends-nokernel-nolibc-noupdate-nomodules.dot | ||
| 58 | |||
| 59 | # Workaround for broken shell function dependencies | ||
| 60 | if false ; then | ||
| 61 | get_package_filename | ||
| 62 | list_package_depends | ||
| 63 | list_package_recommends | ||
| 64 | fi | ||
| 65 | } | ||
| 66 | |||
| 67 | buildhistory_get_imageinfo() { | ||
| 68 | # List the files in the image, but exclude date/time etc. | ||
| 69 | # This awk script is somewhat messy, but handles where the size is not printed for device files under pseudo | ||
| 70 | 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 | ||
| 71 | |||
| 72 | # Add some configuration information | ||
| 73 | echo "${MACHINE}: ${IMAGE_BASENAME} configured for ${DISTRO} ${DISTRO_VERSION}" > ${BUILDHISTORY_DIR_IMAGE}/build-id | ||
| 74 | echo "${@buildhistory_get_layers(d)}" >> ${BUILDHISTORY_DIR_IMAGE}/build-id | ||
| 75 | } | ||
| 76 | |||
| 77 | # By prepending we get in before the removal of packaging files | ||
| 78 | ROOTFS_POSTPROCESS_COMMAND =+ "buildhistory_get_image_installed ; " | ||
| 79 | |||
| 80 | IMAGE_POSTPROCESS_COMMAND += " buildhistory_get_imageinfo ; " | ||
| 81 | |||
| 82 | def buildhistory_get_layers(d): | ||
| 83 | layertext = "Configured metadata layers:\n%s\n" % '\n'.join(get_layers_branch_rev(d)) | ||
| 84 | return layertext | ||
| 85 | |||
| 86 | |||
| 87 | buildhistory_commit() { | ||
| 88 | ( cd ${BUILDHISTORY_DIR}/ | ||
| 89 | git add ${BUILDHISTORY_DIR}/* | ||
| 90 | git commit ${BUILDHISTORY_DIR}/ -m "Build ${BUILDNAME} for machine ${MACHINE} configured for ${DISTRO} ${DISTRO_VERSION}" --author "${BUILDHISTORY_COMMIT_AUTHOR}" > /dev/null | ||
| 91 | if [ "${BUILDHISTORY_PUSH_REPO}" != "" ] ; then | ||
| 92 | git push -q ${BUILDHISTORY_PUSH_REPO} | ||
| 93 | fi) || true | ||
| 94 | } | ||
| 95 | |||
| 96 | python buildhistory_eventhandler() { | ||
| 97 | import bb.build | ||
| 98 | import bb.event | ||
| 99 | |||
| 100 | if isinstance(e, bb.event.BuildCompleted): | ||
| 101 | if e.data.getVar("BUILDHISTORY_COMMIT", True) == "1": | ||
| 102 | bb.build.exec_func("buildhistory_commit", e.data) | ||
| 103 | } | ||
| 104 | |||
| 105 | addhandler buildhistory_eventhandler | ||
