Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # Records history of build output in order to detect regressions |
| 3 | # |
| 4 | # Based in part on testlab.bbclass and packagehistory.bbclass |
| 5 | # |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 6 | # Copyright (C) 2011-2016 Intel Corporation |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | # Copyright (C) 2007-2011 Koen Kooi <koen@openembedded.org> |
| 8 | # |
| 9 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 10 | inherit image-artifact-names |
| 11 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | BUILDHISTORY_FEATURES ?= "image package sdk" |
| 13 | BUILDHISTORY_DIR ?= "${TOPDIR}/buildhistory" |
| 14 | BUILDHISTORY_DIR_IMAGE = "${BUILDHISTORY_DIR}/images/${MACHINE_ARCH}/${TCLIBC}/${IMAGE_BASENAME}" |
| 15 | BUILDHISTORY_DIR_PACKAGE = "${BUILDHISTORY_DIR}/packages/${MULTIMACH_TARGET_SYS}/${PN}" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 16 | |
| 17 | # Setting this to non-empty will remove the old content of the buildhistory as part of |
| 18 | # the current bitbake invocation and replace it with information about what was built |
| 19 | # during the build. |
| 20 | # |
| 21 | # This is meant to be used in continuous integration (CI) systems when invoking bitbake |
| 22 | # for full world builds. The effect in that case is that information about packages |
| 23 | # that no longer get build also gets removed from the buildhistory, which is not |
| 24 | # the case otherwise. |
| 25 | # |
| 26 | # The advantage over manually cleaning the buildhistory outside of bitbake is that |
| 27 | # the "version-going-backwards" check still works. When relying on that, be careful |
| 28 | # about failed world builds: they will lead to incomplete information in the |
| 29 | # buildhistory because information about packages that could not be built will |
| 30 | # also get removed. A CI system should handle that by discarding the buildhistory |
| 31 | # of failed builds. |
| 32 | # |
| 33 | # The expected usage is via auto.conf, but passing via the command line also works |
| 34 | # with: BB_ENV_EXTRAWHITE=BUILDHISTORY_RESET BUILDHISTORY_RESET=1 |
| 35 | BUILDHISTORY_RESET ?= "" |
| 36 | |
| 37 | BUILDHISTORY_OLD_DIR = "${BUILDHISTORY_DIR}/${@ "old" if "${BUILDHISTORY_RESET}" else ""}" |
| 38 | BUILDHISTORY_OLD_DIR_PACKAGE = "${BUILDHISTORY_OLD_DIR}/packages/${MULTIMACH_TARGET_SYS}/${PN}" |
| 39 | BUILDHISTORY_DIR_SDK = "${BUILDHISTORY_DIR}/sdk/${SDK_NAME}${SDK_EXT}/${IMAGE_BASENAME}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | BUILDHISTORY_IMAGE_FILES ?= "/etc/passwd /etc/group" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 41 | BUILDHISTORY_SDK_FILES ?= "conf/local.conf conf/bblayers.conf conf/auto.conf conf/locked-sigs.inc conf/devtool.conf" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 42 | BUILDHISTORY_COMMIT ?= "1" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 43 | BUILDHISTORY_COMMIT_AUTHOR ?= "buildhistory <buildhistory@${DISTRO}>" |
| 44 | BUILDHISTORY_PUSH_REPO ?= "" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 45 | BUILDHISTORY_TAG ?= "build" |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 46 | BUILDHISTORY_PATH_PREFIX_STRIP ?= "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 47 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 48 | SSTATEPOSTINSTFUNCS:append = " buildhistory_emit_pkghistory" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 49 | # We want to avoid influencing the signatures of sstate tasks - first the function itself: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 50 | sstate_install[vardepsexclude] += "buildhistory_emit_pkghistory" |
| 51 | # then the value added to SSTATEPOSTINSTFUNCS: |
| 52 | SSTATEPOSTINSTFUNCS[vardepvalueexclude] .= "| buildhistory_emit_pkghistory" |
| 53 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 54 | # Similarly for our function that gets the output signatures |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 55 | SSTATEPOSTUNPACKFUNCS:append = " buildhistory_emit_outputsigs" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 56 | sstate_installpkgdir[vardepsexclude] += "buildhistory_emit_outputsigs" |
| 57 | SSTATEPOSTUNPACKFUNCS[vardepvalueexclude] .= "| buildhistory_emit_outputsigs" |
| 58 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 59 | # All items excepts those listed here will be removed from a recipe's |
| 60 | # build history directory by buildhistory_emit_pkghistory(). This is |
| 61 | # necessary because some of these items (package directories, files that |
| 62 | # we no longer emit) might be obsolete. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 63 | # |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 64 | # When extending build history, derive your class from buildhistory.bbclass |
| 65 | # and extend this list here with the additional files created by the derived |
| 66 | # class. |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 67 | BUILDHISTORY_PRESERVE = "latest latest_srcrev sysroot" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 68 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 69 | PATCH_GIT_USER_EMAIL ?= "buildhistory@oe" |
| 70 | PATCH_GIT_USER_NAME ?= "OpenEmbedded" |
| 71 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 72 | # |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 73 | # Write out the contents of the sysroot |
| 74 | # |
| 75 | buildhistory_emit_sysroot() { |
| 76 | mkdir --parents ${BUILDHISTORY_DIR_PACKAGE} |
| 77 | case ${CLASSOVERRIDE} in |
| 78 | class-native|class-cross|class-crosssdk) |
| 79 | BASE=${SYSROOT_DESTDIR}/${STAGING_DIR_NATIVE} |
| 80 | ;; |
| 81 | *) |
| 82 | BASE=${SYSROOT_DESTDIR} |
| 83 | ;; |
| 84 | esac |
| 85 | buildhistory_list_files_no_owners $BASE ${BUILDHISTORY_DIR_PACKAGE}/sysroot |
| 86 | } |
| 87 | |
| 88 | # |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 89 | # Write out metadata about this package for comparison when writing future packages |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 90 | # |
| 91 | python buildhistory_emit_pkghistory() { |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 92 | if d.getVar('BB_CURRENTTASK') in ['populate_sysroot', 'populate_sysroot_setscene']: |
| 93 | bb.build.exec_func("buildhistory_emit_sysroot", d) |
| 94 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 95 | if not d.getVar('BB_CURRENTTASK') in ['packagedata', 'packagedata_setscene']: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 96 | return 0 |
| 97 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 98 | if not "package" in (d.getVar('BUILDHISTORY_FEATURES') or "").split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 99 | return 0 |
| 100 | |
| 101 | import re |
| 102 | import json |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 103 | import shlex |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 104 | import errno |
| 105 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 106 | pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE') |
| 107 | oldpkghistdir = d.getVar('BUILDHISTORY_OLD_DIR_PACKAGE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 108 | |
| 109 | class RecipeInfo: |
| 110 | def __init__(self, name): |
| 111 | self.name = name |
| 112 | self.pe = "0" |
| 113 | self.pv = "0" |
| 114 | self.pr = "r0" |
| 115 | self.depends = "" |
| 116 | self.packages = "" |
| 117 | self.srcrev = "" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 118 | self.layer = "" |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 119 | self.license = "" |
Andrew Geissler | 4ed12e1 | 2020-06-05 18:00:41 -0500 | [diff] [blame] | 120 | self.config = "" |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 121 | self.src_uri = "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 122 | |
| 123 | |
| 124 | class PackageInfo: |
| 125 | def __init__(self, name): |
| 126 | self.name = name |
| 127 | self.pe = "0" |
| 128 | self.pv = "0" |
| 129 | self.pr = "r0" |
| 130 | # pkg/pkge/pkgv/pkgr should be empty because we want to be able to default them |
| 131 | self.pkg = "" |
| 132 | self.pkge = "" |
| 133 | self.pkgv = "" |
| 134 | self.pkgr = "" |
| 135 | self.size = 0 |
| 136 | self.depends = "" |
| 137 | self.rprovides = "" |
| 138 | self.rdepends = "" |
| 139 | self.rrecommends = "" |
| 140 | self.rsuggests = "" |
| 141 | self.rreplaces = "" |
| 142 | self.rconflicts = "" |
| 143 | self.files = "" |
| 144 | self.filelist = "" |
| 145 | # Variables that need to be written to their own separate file |
| 146 | self.filevars = dict.fromkeys(['pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm']) |
| 147 | |
| 148 | # Should check PACKAGES here to see if anything removed |
| 149 | |
| 150 | def readPackageInfo(pkg, histfile): |
| 151 | pkginfo = PackageInfo(pkg) |
| 152 | with open(histfile, "r") as f: |
| 153 | for line in f: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 154 | lns = line.split('=', 1) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 155 | name = lns[0].strip() |
| 156 | value = lns[1].strip(" \t\r\n").strip('"') |
| 157 | if name == "PE": |
| 158 | pkginfo.pe = value |
| 159 | elif name == "PV": |
| 160 | pkginfo.pv = value |
| 161 | elif name == "PR": |
| 162 | pkginfo.pr = value |
| 163 | elif name == "PKG": |
| 164 | pkginfo.pkg = value |
| 165 | elif name == "PKGE": |
| 166 | pkginfo.pkge = value |
| 167 | elif name == "PKGV": |
| 168 | pkginfo.pkgv = value |
| 169 | elif name == "PKGR": |
| 170 | pkginfo.pkgr = value |
| 171 | elif name == "RPROVIDES": |
| 172 | pkginfo.rprovides = value |
| 173 | elif name == "RDEPENDS": |
| 174 | pkginfo.rdepends = value |
| 175 | elif name == "RRECOMMENDS": |
| 176 | pkginfo.rrecommends = value |
| 177 | elif name == "RSUGGESTS": |
| 178 | pkginfo.rsuggests = value |
| 179 | elif name == "RREPLACES": |
| 180 | pkginfo.rreplaces = value |
| 181 | elif name == "RCONFLICTS": |
| 182 | pkginfo.rconflicts = value |
| 183 | elif name == "PKGSIZE": |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 184 | pkginfo.size = int(value) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 185 | elif name == "FILES": |
| 186 | pkginfo.files = value |
| 187 | elif name == "FILELIST": |
| 188 | pkginfo.filelist = value |
| 189 | # Apply defaults |
| 190 | if not pkginfo.pkg: |
| 191 | pkginfo.pkg = pkginfo.name |
| 192 | if not pkginfo.pkge: |
| 193 | pkginfo.pkge = pkginfo.pe |
| 194 | if not pkginfo.pkgv: |
| 195 | pkginfo.pkgv = pkginfo.pv |
| 196 | if not pkginfo.pkgr: |
| 197 | pkginfo.pkgr = pkginfo.pr |
| 198 | return pkginfo |
| 199 | |
| 200 | def getlastpkgversion(pkg): |
| 201 | try: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 202 | histfile = os.path.join(oldpkghistdir, pkg, "latest") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 203 | return readPackageInfo(pkg, histfile) |
| 204 | except EnvironmentError: |
| 205 | return None |
| 206 | |
| 207 | def sortpkglist(string): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 208 | pkgiter = re.finditer(r'[a-zA-Z0-9.+-]+( \([><=]+[^)]+\))?', string, 0) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 209 | pkglist = [p.group(0) for p in pkgiter] |
| 210 | pkglist.sort() |
| 211 | return ' '.join(pkglist) |
| 212 | |
| 213 | def sortlist(string): |
| 214 | items = string.split(' ') |
| 215 | items.sort() |
| 216 | return ' '.join(items) |
| 217 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 218 | pn = d.getVar('PN') |
| 219 | pe = d.getVar('PE') or "0" |
| 220 | pv = d.getVar('PV') |
| 221 | pr = d.getVar('PR') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 222 | layer = bb.utils.get_file_layer(d.getVar('FILE'), d) |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 223 | license = d.getVar('LICENSE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 224 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 225 | pkgdata_dir = d.getVar('PKGDATA_DIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 226 | packages = "" |
| 227 | try: |
| 228 | with open(os.path.join(pkgdata_dir, pn)) as f: |
| 229 | for line in f.readlines(): |
| 230 | if line.startswith('PACKAGES: '): |
| 231 | packages = oe.utils.squashspaces(line.split(': ', 1)[1]) |
| 232 | break |
| 233 | except IOError as e: |
| 234 | if e.errno == errno.ENOENT: |
| 235 | # Probably a -cross recipe, just ignore |
| 236 | return 0 |
| 237 | else: |
| 238 | raise |
| 239 | |
| 240 | packagelist = packages.split() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 241 | preserve = d.getVar('BUILDHISTORY_PRESERVE').split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 242 | if not os.path.exists(pkghistdir): |
| 243 | bb.utils.mkdirhier(pkghistdir) |
| 244 | else: |
| 245 | # Remove files for packages that no longer exist |
| 246 | for item in os.listdir(pkghistdir): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 247 | if item not in preserve: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 248 | if item not in packagelist: |
| 249 | itempath = os.path.join(pkghistdir, item) |
| 250 | if os.path.isdir(itempath): |
| 251 | for subfile in os.listdir(itempath): |
| 252 | os.unlink(os.path.join(itempath, subfile)) |
| 253 | os.rmdir(itempath) |
| 254 | else: |
| 255 | os.unlink(itempath) |
| 256 | |
| 257 | rcpinfo = RecipeInfo(pn) |
| 258 | rcpinfo.pe = pe |
| 259 | rcpinfo.pv = pv |
| 260 | rcpinfo.pr = pr |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 261 | rcpinfo.depends = sortlist(oe.utils.squashspaces(d.getVar('DEPENDS') or "")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 262 | rcpinfo.packages = packages |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 263 | rcpinfo.layer = layer |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 264 | rcpinfo.license = license |
Andrew Geissler | 4ed12e1 | 2020-06-05 18:00:41 -0500 | [diff] [blame] | 265 | rcpinfo.config = sortlist(oe.utils.squashspaces(d.getVar('PACKAGECONFIG') or "")) |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 266 | rcpinfo.src_uri = oe.utils.squashspaces(d.getVar('SRC_URI') or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 267 | write_recipehistory(rcpinfo, d) |
| 268 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 269 | bb.build.exec_func("read_subpackage_metadata", d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 270 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 271 | for pkg in packagelist: |
| 272 | localdata = d.createCopy() |
| 273 | localdata.setVar('OVERRIDES', d.getVar("OVERRIDES", False) + ":" + pkg) |
| 274 | |
| 275 | pkge = localdata.getVar("PKGE") or '0' |
| 276 | pkgv = localdata.getVar("PKGV") |
| 277 | pkgr = localdata.getVar("PKGR") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 278 | # |
| 279 | # Find out what the last version was |
| 280 | # Make sure the version did not decrease |
| 281 | # |
| 282 | lastversion = getlastpkgversion(pkg) |
| 283 | if lastversion: |
| 284 | last_pkge = lastversion.pkge |
| 285 | last_pkgv = lastversion.pkgv |
| 286 | last_pkgr = lastversion.pkgr |
| 287 | r = bb.utils.vercmp((pkge, pkgv, pkgr), (last_pkge, last_pkgv, last_pkgr)) |
| 288 | if r < 0: |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 289 | msg = "Package version for package %s went backwards which would break package feeds (from %s:%s-%s to %s:%s-%s)" % (pkg, last_pkge, last_pkgv, last_pkgr, pkge, pkgv, pkgr) |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 290 | oe.qa.handle_error("version-going-backwards", msg, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 291 | |
| 292 | pkginfo = PackageInfo(pkg) |
| 293 | # Apparently the version can be different on a per-package basis (see Python) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 294 | pkginfo.pe = localdata.getVar("PE") or '0' |
| 295 | pkginfo.pv = localdata.getVar("PV") |
| 296 | pkginfo.pr = localdata.getVar("PR") |
| 297 | pkginfo.pkg = localdata.getVar("PKG") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 298 | pkginfo.pkge = pkge |
| 299 | pkginfo.pkgv = pkgv |
| 300 | pkginfo.pkgr = pkgr |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 301 | pkginfo.rprovides = sortpkglist(oe.utils.squashspaces(localdata.getVar("RPROVIDES") or "")) |
| 302 | pkginfo.rdepends = sortpkglist(oe.utils.squashspaces(localdata.getVar("RDEPENDS") or "")) |
| 303 | pkginfo.rrecommends = sortpkglist(oe.utils.squashspaces(localdata.getVar("RRECOMMENDS") or "")) |
| 304 | pkginfo.rsuggests = sortpkglist(oe.utils.squashspaces(localdata.getVar("RSUGGESTS") or "")) |
| 305 | pkginfo.replaces = sortpkglist(oe.utils.squashspaces(localdata.getVar("RREPLACES") or "")) |
| 306 | pkginfo.rconflicts = sortpkglist(oe.utils.squashspaces(localdata.getVar("RCONFLICTS") or "")) |
| 307 | pkginfo.files = oe.utils.squashspaces(localdata.getVar("FILES") or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 308 | for filevar in pkginfo.filevars: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 309 | pkginfo.filevars[filevar] = localdata.getVar(filevar) or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 310 | |
| 311 | # Gather information about packaged files |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 312 | val = localdata.getVar('FILES_INFO') or '' |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 313 | dictval = json.loads(val) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 314 | filelist = list(dictval.keys()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 315 | filelist.sort() |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 316 | pkginfo.filelist = " ".join([shlex.quote(x) for x in filelist]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 317 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 318 | pkginfo.size = int(localdata.getVar('PKGSIZE') or '0') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 319 | |
| 320 | write_pkghistory(pkginfo, d) |
| 321 | |
| 322 | # Create files-in-<package-name>.txt files containing a list of files of each recipe's package |
| 323 | bb.build.exec_func("buildhistory_list_pkg_files", d) |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 324 | oe.qa.exit_if_errors(d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 325 | } |
| 326 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 327 | python buildhistory_emit_outputsigs() { |
| 328 | if not "task" in (d.getVar('BUILDHISTORY_FEATURES') or "").split(): |
| 329 | return |
| 330 | |
| 331 | import hashlib |
| 332 | |
| 333 | taskoutdir = os.path.join(d.getVar('BUILDHISTORY_DIR'), 'task', 'output') |
| 334 | bb.utils.mkdirhier(taskoutdir) |
| 335 | currenttask = d.getVar('BB_CURRENTTASK') |
| 336 | pn = d.getVar('PN') |
| 337 | taskfile = os.path.join(taskoutdir, '%s.%s' % (pn, currenttask)) |
| 338 | |
| 339 | cwd = os.getcwd() |
| 340 | filesigs = {} |
| 341 | for root, _, files in os.walk(cwd): |
| 342 | for fname in files: |
| 343 | if fname == 'fixmepath': |
| 344 | continue |
| 345 | fullpath = os.path.join(root, fname) |
| 346 | try: |
| 347 | if os.path.islink(fullpath): |
| 348 | sha256 = hashlib.sha256(os.readlink(fullpath).encode('utf-8')).hexdigest() |
| 349 | elif os.path.isfile(fullpath): |
| 350 | sha256 = bb.utils.sha256_file(fullpath) |
| 351 | else: |
| 352 | continue |
| 353 | except OSError: |
| 354 | bb.warn('buildhistory: unable to read %s to get output signature' % fullpath) |
| 355 | continue |
| 356 | filesigs[os.path.relpath(fullpath, cwd)] = sha256 |
| 357 | with open(taskfile, 'w') as f: |
| 358 | for fpath, fsig in sorted(filesigs.items(), key=lambda item: item[0]): |
| 359 | f.write('%s %s\n' % (fpath, fsig)) |
| 360 | } |
| 361 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 362 | |
| 363 | def write_recipehistory(rcpinfo, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 364 | bb.debug(2, "Writing recipe history") |
| 365 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 366 | pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 367 | |
| 368 | infofile = os.path.join(pkghistdir, "latest") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 369 | with open(infofile, "w") as f: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 370 | if rcpinfo.pe != "0": |
| 371 | f.write(u"PE = %s\n" % rcpinfo.pe) |
| 372 | f.write(u"PV = %s\n" % rcpinfo.pv) |
| 373 | f.write(u"PR = %s\n" % rcpinfo.pr) |
| 374 | f.write(u"DEPENDS = %s\n" % rcpinfo.depends) |
| 375 | f.write(u"PACKAGES = %s\n" % rcpinfo.packages) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 376 | f.write(u"LAYER = %s\n" % rcpinfo.layer) |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 377 | f.write(u"LICENSE = %s\n" % rcpinfo.license) |
Andrew Geissler | 4ed12e1 | 2020-06-05 18:00:41 -0500 | [diff] [blame] | 378 | f.write(u"CONFIG = %s\n" % rcpinfo.config) |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 379 | f.write(u"SRC_URI = %s\n" % rcpinfo.src_uri) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 380 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 381 | write_latest_srcrev(d, pkghistdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 382 | |
| 383 | def write_pkghistory(pkginfo, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 384 | bb.debug(2, "Writing package history for package %s" % pkginfo.name) |
| 385 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 386 | pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 387 | |
| 388 | pkgpath = os.path.join(pkghistdir, pkginfo.name) |
| 389 | if not os.path.exists(pkgpath): |
| 390 | bb.utils.mkdirhier(pkgpath) |
| 391 | |
| 392 | infofile = os.path.join(pkgpath, "latest") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 393 | with open(infofile, "w") as f: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 394 | if pkginfo.pe != "0": |
| 395 | f.write(u"PE = %s\n" % pkginfo.pe) |
| 396 | f.write(u"PV = %s\n" % pkginfo.pv) |
| 397 | f.write(u"PR = %s\n" % pkginfo.pr) |
| 398 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 399 | if pkginfo.pkg != pkginfo.name: |
| 400 | f.write(u"PKG = %s\n" % pkginfo.pkg) |
| 401 | if pkginfo.pkge != pkginfo.pe: |
| 402 | f.write(u"PKGE = %s\n" % pkginfo.pkge) |
| 403 | if pkginfo.pkgv != pkginfo.pv: |
| 404 | f.write(u"PKGV = %s\n" % pkginfo.pkgv) |
| 405 | if pkginfo.pkgr != pkginfo.pr: |
| 406 | f.write(u"PKGR = %s\n" % pkginfo.pkgr) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 407 | f.write(u"RPROVIDES = %s\n" % pkginfo.rprovides) |
| 408 | f.write(u"RDEPENDS = %s\n" % pkginfo.rdepends) |
| 409 | f.write(u"RRECOMMENDS = %s\n" % pkginfo.rrecommends) |
| 410 | if pkginfo.rsuggests: |
| 411 | f.write(u"RSUGGESTS = %s\n" % pkginfo.rsuggests) |
| 412 | if pkginfo.rreplaces: |
| 413 | f.write(u"RREPLACES = %s\n" % pkginfo.rreplaces) |
| 414 | if pkginfo.rconflicts: |
| 415 | f.write(u"RCONFLICTS = %s\n" % pkginfo.rconflicts) |
| 416 | f.write(u"PKGSIZE = %d\n" % pkginfo.size) |
| 417 | f.write(u"FILES = %s\n" % pkginfo.files) |
| 418 | f.write(u"FILELIST = %s\n" % pkginfo.filelist) |
| 419 | |
| 420 | for filevar in pkginfo.filevars: |
| 421 | filevarpath = os.path.join(pkgpath, "latest.%s" % filevar) |
| 422 | val = pkginfo.filevars[filevar] |
| 423 | if val: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 424 | with open(filevarpath, "w") as f: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 425 | f.write(val) |
| 426 | else: |
| 427 | if os.path.exists(filevarpath): |
| 428 | os.unlink(filevarpath) |
| 429 | |
| 430 | # |
| 431 | # rootfs_type can be: image, sdk_target, sdk_host |
| 432 | # |
| 433 | def buildhistory_list_installed(d, rootfs_type="image"): |
| 434 | from oe.rootfs import image_list_installed_packages |
| 435 | from oe.sdk import sdk_list_installed_packages |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 436 | from oe.utils import format_pkg_list |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 437 | |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 438 | process_list = [('file', 'bh_installed_pkgs_%s.txt' % os.getpid()),\ |
| 439 | ('deps', 'bh_installed_pkgs_deps_%s.txt' % os.getpid())] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 440 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 441 | if rootfs_type == "image": |
| 442 | pkgs = image_list_installed_packages(d) |
| 443 | else: |
| 444 | pkgs = sdk_list_installed_packages(d, rootfs_type == "sdk_target") |
| 445 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 446 | if rootfs_type == "sdk_host": |
| 447 | pkgdata_dir = d.getVar('PKGDATA_DIR_SDK') |
| 448 | else: |
| 449 | pkgdata_dir = d.getVar('PKGDATA_DIR') |
| 450 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 451 | for output_type, output_file in process_list: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 452 | output_file_full = os.path.join(d.getVar('WORKDIR'), output_file) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 453 | |
| 454 | with open(output_file_full, 'w') as output: |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 455 | output.write(format_pkg_list(pkgs, output_type, pkgdata_dir)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 456 | |
| 457 | python buildhistory_list_installed_image() { |
| 458 | buildhistory_list_installed(d) |
| 459 | } |
| 460 | |
| 461 | python buildhistory_list_installed_sdk_target() { |
| 462 | buildhistory_list_installed(d, "sdk_target") |
| 463 | } |
| 464 | |
| 465 | python buildhistory_list_installed_sdk_host() { |
| 466 | buildhistory_list_installed(d, "sdk_host") |
| 467 | } |
| 468 | |
| 469 | buildhistory_get_installed() { |
| 470 | mkdir -p $1 |
| 471 | |
| 472 | # Get list of installed packages |
| 473 | pkgcache="$1/installed-packages.tmp" |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 474 | cat ${WORKDIR}/bh_installed_pkgs_${PID}.txt | sort > $pkgcache && rm ${WORKDIR}/bh_installed_pkgs_${PID}.txt |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 475 | |
| 476 | cat $pkgcache | awk '{ print $1 }' > $1/installed-package-names.txt |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 477 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 478 | if [ -s $pkgcache ] ; then |
| 479 | cat $pkgcache | awk '{ print $2 }' | xargs -n1 basename > $1/installed-packages.txt |
| 480 | else |
| 481 | printf "" > $1/installed-packages.txt |
| 482 | fi |
| 483 | |
| 484 | # Produce dependency graph |
| 485 | # First, quote each name to handle characters that cause issues for dot |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 486 | sed 's:\([^| ]*\):"\1":g' ${WORKDIR}/bh_installed_pkgs_deps_${PID}.txt > $1/depends.tmp && |
| 487 | rm ${WORKDIR}/bh_installed_pkgs_deps_${PID}.txt |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 488 | # Remove lines with rpmlib(...) and config(...) dependencies, change the |
| 489 | # delimiter from pipe to "->", set the style for recommend lines and |
| 490 | # turn versioned dependencies into edge labels. |
| 491 | sed -i -e '/rpmlib(/d' \ |
| 492 | -e '/config(/d' \ |
| 493 | -e 's:|: -> :' \ |
| 494 | -e 's:"\[REC\]":[style=dotted]:' \ |
| 495 | -e 's:"\([<>=]\+\)" "\([^"]*\)":[label="\1 \2"]:' \ |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 496 | -e 's:"\([*]\+\)" "\([^"]*\)":[label="\2"]:' \ |
| 497 | -e 's:"\[RPROVIDES\]":[style=dashed]:' \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 498 | $1/depends.tmp |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 499 | # Add header, sorted and de-duped contents and footer and then delete the temp file |
| 500 | printf "digraph depends {\n node [shape=plaintext]\n" > $1/depends.dot |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 501 | cat $1/depends.tmp | sort -u >> $1/depends.dot |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 502 | echo "}" >> $1/depends.dot |
| 503 | rm $1/depends.tmp |
| 504 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 505 | # Set correct pkgdatadir |
| 506 | pkgdatadir=${PKGDATA_DIR} |
| 507 | if [ "$2" == "sdk" ] && [ "$3" == "host" ]; then |
| 508 | pkgdatadir="${PKGDATA_DIR_SDK}" |
| 509 | fi |
| 510 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 511 | # Produce installed package sizes list |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 512 | oe-pkgdata-util -p $pkgdatadir read-value "PKGSIZE" -n -f $pkgcache > $1/installed-package-sizes.tmp |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 513 | cat $1/installed-package-sizes.tmp | awk '{print $2 "\tKiB\t" $1}' | sort -n -r > $1/installed-package-sizes.txt |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 514 | rm $1/installed-package-sizes.tmp |
| 515 | |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 516 | # Produce package info: runtime_name, buildtime_name, recipe, version, size |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 517 | oe-pkgdata-util -p $pkgdatadir read-value "PACKAGE,PN,PV,PKGSIZE" -n -f $pkgcache > $1/installed-package-info.tmp |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 518 | cat $1/installed-package-info.tmp | sort -n -r -k 5 > $1/installed-package-info.txt |
| 519 | rm $1/installed-package-info.tmp |
| 520 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 521 | # We're now done with the cache, delete it |
| 522 | rm $pkgcache |
| 523 | |
| 524 | if [ "$2" != "sdk" ] ; then |
| 525 | # Produce some cut-down graphs (for readability) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 526 | grep -v kernel-image $1/depends.dot | grep -v kernel-3 | grep -v kernel-4 > $1/depends-nokernel.dot |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 527 | grep -v libc6 $1/depends-nokernel.dot | grep -v libgcc > $1/depends-nokernel-nolibc.dot |
| 528 | grep -v update- $1/depends-nokernel-nolibc.dot > $1/depends-nokernel-nolibc-noupdate.dot |
| 529 | grep -v kernel-module $1/depends-nokernel-nolibc-noupdate.dot > $1/depends-nokernel-nolibc-noupdate-nomodules.dot |
| 530 | fi |
| 531 | |
| 532 | # add complementary package information |
| 533 | if [ -e ${WORKDIR}/complementary_pkgs.txt ]; then |
| 534 | cp ${WORKDIR}/complementary_pkgs.txt $1 |
| 535 | fi |
| 536 | } |
| 537 | |
| 538 | buildhistory_get_image_installed() { |
| 539 | # Anything requiring the use of the packaging system should be done in here |
| 540 | # in case the packaging files are going to be removed for this image |
| 541 | |
| 542 | if [ "${@bb.utils.contains('BUILDHISTORY_FEATURES', 'image', '1', '0', d)}" = "0" ] ; then |
| 543 | return |
| 544 | fi |
| 545 | |
| 546 | buildhistory_get_installed ${BUILDHISTORY_DIR_IMAGE} |
| 547 | } |
| 548 | |
| 549 | buildhistory_get_sdk_installed() { |
| 550 | # Anything requiring the use of the packaging system should be done in here |
| 551 | # in case the packaging files are going to be removed for this SDK |
| 552 | |
| 553 | if [ "${@bb.utils.contains('BUILDHISTORY_FEATURES', 'sdk', '1', '0', d)}" = "0" ] ; then |
| 554 | return |
| 555 | fi |
| 556 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 557 | buildhistory_get_installed ${BUILDHISTORY_DIR_SDK}/$1 sdk $1 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | buildhistory_get_sdk_installed_host() { |
| 561 | buildhistory_get_sdk_installed host |
| 562 | } |
| 563 | |
| 564 | buildhistory_get_sdk_installed_target() { |
| 565 | buildhistory_get_sdk_installed target |
| 566 | } |
| 567 | |
| 568 | buildhistory_list_files() { |
| 569 | # List the files in the specified directory, but exclude date/time etc. |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 570 | # This is somewhat messy, but handles where the size is not printed for device files under pseudo |
| 571 | ( cd $1 |
| 572 | find_cmd='find . ! -path . -printf "%M %-10u %-10g %10s %p -> %l\n"' |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 573 | if [ "$3" = "fakeroot" ] ; then |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 574 | eval ${FAKEROOTENV} ${FAKEROOTCMD} $find_cmd |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 575 | else |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 576 | eval $find_cmd |
| 577 | fi | sort -k5 | sed 's/ * -> $//' > $2 ) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 578 | } |
| 579 | |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 580 | buildhistory_list_files_no_owners() { |
| 581 | # List the files in the specified directory, but exclude date/time etc. |
| 582 | # Also don't output the ownership data, but instead output just - - so |
| 583 | # that the same parsing code as for _list_files works. |
| 584 | # This is somewhat messy, but handles where the size is not printed for device files under pseudo |
| 585 | ( cd $1 |
| 586 | find_cmd='find . ! -path . -printf "%M - - %10s %p -> %l\n"' |
| 587 | if [ "$3" = "fakeroot" ] ; then |
| 588 | eval ${FAKEROOTENV} ${FAKEROOTCMD} "$find_cmd" |
| 589 | else |
| 590 | eval "$find_cmd" |
| 591 | fi | sort -k5 | sed 's/ * -> $//' > $2 ) |
| 592 | } |
| 593 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 594 | buildhistory_list_pkg_files() { |
| 595 | # Create individual files-in-package for each recipe's package |
| 596 | for pkgdir in $(find ${PKGDEST}/* -maxdepth 0 -type d); do |
| 597 | pkgname=$(basename $pkgdir) |
| 598 | outfolder="${BUILDHISTORY_DIR_PACKAGE}/$pkgname" |
| 599 | outfile="$outfolder/files-in-package.txt" |
| 600 | # Make sure the output folder exists so we can create the file |
| 601 | if [ ! -d $outfolder ] ; then |
| 602 | bbdebug 2 "Folder $outfolder does not exist, file $outfile not created" |
| 603 | continue |
| 604 | fi |
| 605 | buildhistory_list_files $pkgdir $outfile fakeroot |
| 606 | done |
| 607 | } |
| 608 | |
| 609 | buildhistory_get_imageinfo() { |
| 610 | if [ "${@bb.utils.contains('BUILDHISTORY_FEATURES', 'image', '1', '0', d)}" = "0" ] ; then |
| 611 | return |
| 612 | fi |
| 613 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 614 | mkdir -p ${BUILDHISTORY_DIR_IMAGE} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 615 | buildhistory_list_files ${IMAGE_ROOTFS} ${BUILDHISTORY_DIR_IMAGE}/files-in-image.txt |
| 616 | |
| 617 | # Collect files requested in BUILDHISTORY_IMAGE_FILES |
| 618 | rm -rf ${BUILDHISTORY_DIR_IMAGE}/image-files |
| 619 | for f in ${BUILDHISTORY_IMAGE_FILES}; do |
| 620 | if [ -f ${IMAGE_ROOTFS}/$f ] ; then |
| 621 | mkdir -p ${BUILDHISTORY_DIR_IMAGE}/image-files/`dirname $f` |
| 622 | cp ${IMAGE_ROOTFS}/$f ${BUILDHISTORY_DIR_IMAGE}/image-files/$f |
| 623 | fi |
| 624 | done |
| 625 | |
| 626 | # Record some machine-readable meta-information about the image |
| 627 | printf "" > ${BUILDHISTORY_DIR_IMAGE}/image-info.txt |
| 628 | cat >> ${BUILDHISTORY_DIR_IMAGE}/image-info.txt <<END |
| 629 | ${@buildhistory_get_imagevars(d)} |
| 630 | END |
| 631 | imagesize=`du -ks ${IMAGE_ROOTFS} | awk '{ print $1 }'` |
| 632 | echo "IMAGESIZE = $imagesize" >> ${BUILDHISTORY_DIR_IMAGE}/image-info.txt |
| 633 | |
| 634 | # Add some configuration information |
| 635 | echo "${MACHINE}: ${IMAGE_BASENAME} configured for ${DISTRO} ${DISTRO_VERSION}" > ${BUILDHISTORY_DIR_IMAGE}/build-id.txt |
| 636 | |
| 637 | cat >> ${BUILDHISTORY_DIR_IMAGE}/build-id.txt <<END |
| 638 | ${@buildhistory_get_build_id(d)} |
| 639 | END |
| 640 | } |
| 641 | |
| 642 | buildhistory_get_sdkinfo() { |
| 643 | if [ "${@bb.utils.contains('BUILDHISTORY_FEATURES', 'sdk', '1', '0', d)}" = "0" ] ; then |
| 644 | return |
| 645 | fi |
| 646 | |
| 647 | buildhistory_list_files ${SDK_OUTPUT} ${BUILDHISTORY_DIR_SDK}/files-in-sdk.txt |
| 648 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 649 | # Collect files requested in BUILDHISTORY_SDK_FILES |
| 650 | rm -rf ${BUILDHISTORY_DIR_SDK}/sdk-files |
| 651 | for f in ${BUILDHISTORY_SDK_FILES}; do |
| 652 | if [ -f ${SDK_OUTPUT}/${SDKPATH}/$f ] ; then |
| 653 | mkdir -p ${BUILDHISTORY_DIR_SDK}/sdk-files/`dirname $f` |
| 654 | cp ${SDK_OUTPUT}/${SDKPATH}/$f ${BUILDHISTORY_DIR_SDK}/sdk-files/$f |
| 655 | fi |
| 656 | done |
| 657 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 658 | # Record some machine-readable meta-information about the SDK |
| 659 | printf "" > ${BUILDHISTORY_DIR_SDK}/sdk-info.txt |
| 660 | cat >> ${BUILDHISTORY_DIR_SDK}/sdk-info.txt <<END |
| 661 | ${@buildhistory_get_sdkvars(d)} |
| 662 | END |
| 663 | sdksize=`du -ks ${SDK_OUTPUT} | awk '{ print $1 }'` |
| 664 | echo "SDKSIZE = $sdksize" >> ${BUILDHISTORY_DIR_SDK}/sdk-info.txt |
| 665 | } |
| 666 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 667 | python buildhistory_get_extra_sdkinfo() { |
| 668 | import operator |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 669 | from oe.sdk import get_extra_sdkinfo |
| 670 | |
| 671 | sstate_dir = d.expand('${SDK_OUTPUT}/${SDKPATH}/sstate-cache') |
| 672 | extra_info = get_extra_sdkinfo(sstate_dir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 673 | |
| 674 | if d.getVar('BB_CURRENTTASK') == 'populate_sdk_ext' and \ |
| 675 | "sdk" in (d.getVar('BUILDHISTORY_FEATURES') or "").split(): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 676 | with open(d.expand('${BUILDHISTORY_DIR_SDK}/sstate-package-sizes.txt'), 'w') as f: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 677 | filesizes_sorted = sorted(extra_info['filesizes'].items(), key=operator.itemgetter(1, 0), reverse=True) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 678 | for fn, size in filesizes_sorted: |
| 679 | f.write('%10d KiB %s\n' % (size, fn)) |
| 680 | with open(d.expand('${BUILDHISTORY_DIR_SDK}/sstate-task-sizes.txt'), 'w') as f: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 681 | tasksizes_sorted = sorted(extra_info['tasksizes'].items(), key=operator.itemgetter(1, 0), reverse=True) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 682 | for task, size in tasksizes_sorted: |
| 683 | f.write('%10d KiB %s\n' % (size, task)) |
| 684 | } |
| 685 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 686 | # By using ROOTFS_POSTUNINSTALL_COMMAND we get in after uninstallation of |
| 687 | # unneeded packages but before the removal of packaging files |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 688 | ROOTFS_POSTUNINSTALL_COMMAND += "buildhistory_list_installed_image ;" |
| 689 | ROOTFS_POSTUNINSTALL_COMMAND += "buildhistory_get_image_installed ;" |
| 690 | ROOTFS_POSTUNINSTALL_COMMAND[vardepvalueexclude] .= "| buildhistory_list_installed_image ;| buildhistory_get_image_installed ;" |
| 691 | ROOTFS_POSTUNINSTALL_COMMAND[vardepsexclude] += "buildhistory_list_installed_image buildhistory_get_image_installed" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 692 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 693 | IMAGE_POSTPROCESS_COMMAND += "buildhistory_get_imageinfo ;" |
| 694 | IMAGE_POSTPROCESS_COMMAND[vardepvalueexclude] .= "| buildhistory_get_imageinfo ;" |
| 695 | IMAGE_POSTPROCESS_COMMAND[vardepsexclude] += "buildhistory_get_imageinfo" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 696 | |
| 697 | # We want these to be the last run so that we get called after complementary package installation |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 698 | POPULATE_SDK_POST_TARGET_COMMAND:append = " buildhistory_list_installed_sdk_target;" |
| 699 | POPULATE_SDK_POST_TARGET_COMMAND:append = " buildhistory_get_sdk_installed_target;" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 700 | POPULATE_SDK_POST_TARGET_COMMAND[vardepvalueexclude] .= "| buildhistory_list_installed_sdk_target;| buildhistory_get_sdk_installed_target;" |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 701 | POPULATE_SDK_POST_TARGET_COMMAND[vardepsexclude] += "buildhistory_list_installed_sdk_target buildhistory_get_sdk_installed_target" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 702 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 703 | POPULATE_SDK_POST_HOST_COMMAND:append = " buildhistory_list_installed_sdk_host;" |
| 704 | POPULATE_SDK_POST_HOST_COMMAND:append = " buildhistory_get_sdk_installed_host;" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 705 | POPULATE_SDK_POST_HOST_COMMAND[vardepvalueexclude] .= "| buildhistory_list_installed_sdk_host;| buildhistory_get_sdk_installed_host;" |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 706 | POPULATE_SDK_POST_HOST_COMMAND[vardepsexclude] += "buildhistory_list_installed_sdk_host buildhistory_get_sdk_installed_host" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 707 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 708 | SDK_POSTPROCESS_COMMAND:append = " buildhistory_get_sdkinfo ; buildhistory_get_extra_sdkinfo; " |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 709 | SDK_POSTPROCESS_COMMAND[vardepvalueexclude] .= "| buildhistory_get_sdkinfo ; buildhistory_get_extra_sdkinfo; " |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 710 | SDK_POSTPROCESS_COMMAND[vardepsexclude] += "buildhistory_get_sdkinfo buildhistory_get_extra_sdkinfo" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 711 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 712 | python buildhistory_write_sigs() { |
| 713 | if not "task" in (d.getVar('BUILDHISTORY_FEATURES') or "").split(): |
| 714 | return |
| 715 | |
| 716 | # Create sigs file |
| 717 | if hasattr(bb.parse.siggen, 'dump_siglist'): |
| 718 | taskoutdir = os.path.join(d.getVar('BUILDHISTORY_DIR'), 'task') |
| 719 | bb.utils.mkdirhier(taskoutdir) |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 720 | bb.parse.siggen.dump_siglist(os.path.join(taskoutdir, 'tasksigs.txt'), d.getVar("BUILDHISTORY_PATH_PREFIX_STRIP")) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 721 | } |
| 722 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 723 | def buildhistory_get_build_id(d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 724 | if d.getVar('BB_WORKERCONTEXT') != '1': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 725 | return "" |
| 726 | localdata = bb.data.createCopy(d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 727 | statuslines = [] |
| 728 | for func in oe.data.typed_value('BUILDCFG_FUNCS', localdata): |
| 729 | g = globals() |
| 730 | if func not in g: |
| 731 | bb.warn("Build configuration function '%s' does not exist" % func) |
| 732 | else: |
| 733 | flines = g[func](localdata) |
| 734 | if flines: |
| 735 | statuslines.extend(flines) |
| 736 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 737 | statusheader = d.getVar('BUILDCFG_HEADER') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 738 | return('\n%s\n%s\n' % (statusheader, '\n'.join(statuslines))) |
| 739 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 740 | def buildhistory_get_modified(path): |
| 741 | # copied from get_layer_git_status() in image-buildinfo.bbclass |
| 742 | import subprocess |
| 743 | try: |
| 744 | subprocess.check_output("""cd %s; export PSEUDO_UNLOAD=1; set -e; |
| 745 | git diff --quiet --no-ext-diff |
| 746 | git diff --quiet --no-ext-diff --cached""" % path, |
| 747 | shell=True, |
| 748 | stderr=subprocess.STDOUT) |
| 749 | return "" |
| 750 | except subprocess.CalledProcessError as ex: |
| 751 | # Silently treat errors as "modified", without checking for the |
| 752 | # (expected) return code 1 in a modified git repo. For example, we get |
| 753 | # output and a 129 return code when a layer isn't a git repo at all. |
| 754 | return " -- modified" |
| 755 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 756 | def buildhistory_get_metadata_revs(d): |
| 757 | # We want an easily machine-readable format here, so get_layers_branch_rev isn't quite what we want |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 758 | layers = (d.getVar("BBLAYERS") or "").split() |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 759 | medadata_revs = ["%-17s = %s:%s%s" % (os.path.basename(i), \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 760 | base_get_metadata_git_branch(i, None).strip(), \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 761 | base_get_metadata_git_revision(i, None), \ |
| 762 | buildhistory_get_modified(i)) \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 763 | for i in layers] |
| 764 | return '\n'.join(medadata_revs) |
| 765 | |
| 766 | def outputvars(vars, listvars, d): |
| 767 | vars = vars.split() |
| 768 | listvars = listvars.split() |
| 769 | ret = "" |
| 770 | for var in vars: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 771 | value = d.getVar(var) or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 772 | if var in listvars: |
| 773 | # Squash out spaces |
| 774 | value = oe.utils.squashspaces(value) |
| 775 | ret += "%s = %s\n" % (var, value) |
| 776 | return ret.rstrip('\n') |
| 777 | |
| 778 | def buildhistory_get_imagevars(d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 779 | if d.getVar('BB_WORKERCONTEXT') != '1': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 780 | return "" |
| 781 | imagevars = "DISTRO DISTRO_VERSION USER_CLASSES IMAGE_CLASSES IMAGE_FEATURES IMAGE_LINGUAS IMAGE_INSTALL BAD_RECOMMENDATIONS NO_RECOMMENDATIONS PACKAGE_EXCLUDE ROOTFS_POSTPROCESS_COMMAND IMAGE_POSTPROCESS_COMMAND" |
| 782 | listvars = "USER_CLASSES IMAGE_CLASSES IMAGE_FEATURES IMAGE_LINGUAS IMAGE_INSTALL BAD_RECOMMENDATIONS PACKAGE_EXCLUDE" |
| 783 | return outputvars(imagevars, listvars, d) |
| 784 | |
| 785 | def buildhistory_get_sdkvars(d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 786 | if d.getVar('BB_WORKERCONTEXT') != '1': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 787 | return "" |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 788 | sdkvars = "DISTRO DISTRO_VERSION SDK_NAME SDK_VERSION SDKMACHINE SDKIMAGE_FEATURES TOOLCHAIN_HOST_TASK TOOLCHAIN_TARGET_TASK BAD_RECOMMENDATIONS NO_RECOMMENDATIONS PACKAGE_EXCLUDE" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 789 | if d.getVar('BB_CURRENTTASK') == 'populate_sdk_ext': |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 790 | # Extensible SDK uses some additional variables |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 791 | sdkvars += " SDK_LOCAL_CONF_WHITELIST SDK_LOCAL_CONF_BLACKLIST SDK_INHERIT_BLACKLIST SDK_UPDATE_URL SDK_EXT_TYPE SDK_RECRDEP_TASKS SDK_INCLUDE_PKGDATA SDK_INCLUDE_TOOLCHAIN" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 792 | listvars = "SDKIMAGE_FEATURES BAD_RECOMMENDATIONS PACKAGE_EXCLUDE SDK_LOCAL_CONF_WHITELIST SDK_LOCAL_CONF_BLACKLIST SDK_INHERIT_BLACKLIST" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 793 | return outputvars(sdkvars, listvars, d) |
| 794 | |
| 795 | |
| 796 | def buildhistory_get_cmdline(d): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 797 | argv = d.getVar('BB_CMDLINE', False) |
| 798 | if argv: |
| 799 | if argv[0].endswith('bin/bitbake'): |
| 800 | bincmd = 'bitbake' |
| 801 | else: |
| 802 | bincmd = argv[0] |
| 803 | return '%s %s' % (bincmd, ' '.join(argv[1:])) |
| 804 | return '' |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 805 | |
| 806 | |
| 807 | buildhistory_single_commit() { |
| 808 | if [ "$3" = "" ] ; then |
| 809 | commitopts="${BUILDHISTORY_DIR}/ --allow-empty" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 810 | shortlogprefix="No changes: " |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 811 | else |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 812 | commitopts="" |
| 813 | shortlogprefix="" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 814 | fi |
| 815 | if [ "${BUILDHISTORY_BUILD_FAILURES}" = "0" ] ; then |
| 816 | result="succeeded" |
| 817 | else |
| 818 | result="failed" |
| 819 | fi |
| 820 | case ${BUILDHISTORY_BUILD_INTERRUPTED} in |
| 821 | 1) |
| 822 | result="$result (interrupted)" |
| 823 | ;; |
| 824 | 2) |
| 825 | result="$result (force interrupted)" |
| 826 | ;; |
| 827 | esac |
| 828 | commitmsgfile=`mktemp` |
| 829 | cat > $commitmsgfile << END |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 830 | ${shortlogprefix}Build ${BUILDNAME} of ${DISTRO} ${DISTRO_VERSION} for machine ${MACHINE} on $2 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 831 | |
| 832 | cmd: $1 |
| 833 | |
| 834 | result: $result |
| 835 | |
| 836 | metadata revisions: |
| 837 | END |
| 838 | cat ${BUILDHISTORY_DIR}/metadata-revs >> $commitmsgfile |
| 839 | git commit $commitopts -F $commitmsgfile --author "${BUILDHISTORY_COMMIT_AUTHOR}" > /dev/null |
| 840 | rm $commitmsgfile |
| 841 | } |
| 842 | |
| 843 | buildhistory_commit() { |
| 844 | if [ ! -d ${BUILDHISTORY_DIR} ] ; then |
| 845 | # Code above that creates this dir never executed, so there can't be anything to commit |
| 846 | return |
| 847 | fi |
| 848 | |
| 849 | # Create a machine-readable list of metadata revisions for each layer |
| 850 | cat > ${BUILDHISTORY_DIR}/metadata-revs <<END |
| 851 | ${@buildhistory_get_metadata_revs(d)} |
| 852 | END |
| 853 | |
| 854 | ( cd ${BUILDHISTORY_DIR}/ |
| 855 | # Initialise the repo if necessary |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 856 | if [ ! -e .git ] ; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 857 | git init -q |
| 858 | else |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 859 | git tag -f ${BUILDHISTORY_TAG}-minus-3 ${BUILDHISTORY_TAG}-minus-2 > /dev/null 2>&1 || true |
| 860 | git tag -f ${BUILDHISTORY_TAG}-minus-2 ${BUILDHISTORY_TAG}-minus-1 > /dev/null 2>&1 || true |
| 861 | git tag -f ${BUILDHISTORY_TAG}-minus-1 > /dev/null 2>&1 || true |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 862 | fi |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 863 | |
| 864 | check_git_config |
| 865 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 866 | # Check if there are new/changed files to commit (other than metadata-revs) |
| 867 | repostatus=`git status --porcelain | grep -v " metadata-revs$"` |
| 868 | HOSTNAME=`hostname 2>/dev/null || echo unknown` |
| 869 | CMDLINE="${@buildhistory_get_cmdline(d)}" |
| 870 | if [ "$repostatus" != "" ] ; then |
| 871 | git add -A . |
| 872 | # porcelain output looks like "?? packages/foo/bar" |
| 873 | # Ensure we commit metadata-revs with the first commit |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 874 | buildhistory_single_commit "$CMDLINE" "$HOSTNAME" dummy |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 875 | git gc --auto --quiet |
| 876 | else |
| 877 | buildhistory_single_commit "$CMDLINE" "$HOSTNAME" |
| 878 | fi |
| 879 | if [ "${BUILDHISTORY_PUSH_REPO}" != "" ] ; then |
| 880 | git push -q ${BUILDHISTORY_PUSH_REPO} |
| 881 | fi) || true |
| 882 | } |
| 883 | |
| 884 | python buildhistory_eventhandler() { |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 885 | if (e.data.getVar('BUILDHISTORY_FEATURES') or "").strip(): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 886 | reset = e.data.getVar("BUILDHISTORY_RESET") |
| 887 | olddir = e.data.getVar("BUILDHISTORY_OLD_DIR") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 888 | if isinstance(e, bb.event.BuildStarted): |
| 889 | if reset: |
| 890 | import shutil |
| 891 | # Clean up after potentially interrupted build. |
| 892 | if os.path.isdir(olddir): |
| 893 | shutil.rmtree(olddir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 894 | rootdir = e.data.getVar("BUILDHISTORY_DIR") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 895 | entries = [ x for x in os.listdir(rootdir) if not x.startswith('.') ] |
| 896 | bb.utils.mkdirhier(olddir) |
| 897 | for entry in entries: |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 898 | bb.utils.rename(os.path.join(rootdir, entry), |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 899 | os.path.join(olddir, entry)) |
| 900 | elif isinstance(e, bb.event.BuildCompleted): |
| 901 | if reset: |
| 902 | import shutil |
| 903 | shutil.rmtree(olddir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 904 | if e.data.getVar("BUILDHISTORY_COMMIT") == "1": |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 905 | bb.note("Writing buildhistory") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 906 | bb.build.exec_func("buildhistory_write_sigs", d) |
Brad Bishop | f3fd288 | 2019-06-21 08:06:37 -0400 | [diff] [blame] | 907 | import time |
| 908 | start=time.time() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 909 | localdata = bb.data.createCopy(e.data) |
| 910 | localdata.setVar('BUILDHISTORY_BUILD_FAILURES', str(e._failures)) |
| 911 | interrupted = getattr(e, '_interrupted', 0) |
| 912 | localdata.setVar('BUILDHISTORY_BUILD_INTERRUPTED', str(interrupted)) |
| 913 | bb.build.exec_func("buildhistory_commit", localdata) |
Brad Bishop | f3fd288 | 2019-06-21 08:06:37 -0400 | [diff] [blame] | 914 | stop=time.time() |
| 915 | bb.note("Writing buildhistory took: %s seconds" % round(stop-start)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 916 | else: |
| 917 | bb.note("No commit since BUILDHISTORY_COMMIT != '1'") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | addhandler buildhistory_eventhandler |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 921 | buildhistory_eventhandler[eventmask] = "bb.event.BuildCompleted bb.event.BuildStarted" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 922 | |
| 923 | |
| 924 | # FIXME this ought to be moved into the fetcher |
| 925 | def _get_srcrev_values(d): |
| 926 | """ |
| 927 | Return the version strings for the current recipe |
| 928 | """ |
| 929 | |
| 930 | scms = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 931 | fetcher = bb.fetch.Fetch(d.getVar('SRC_URI').split(), d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 932 | urldata = fetcher.ud |
| 933 | for u in urldata: |
| 934 | if urldata[u].method.supports_srcrev(): |
| 935 | scms.append(u) |
| 936 | |
| 937 | autoinc_templ = 'AUTOINC+' |
| 938 | dict_srcrevs = {} |
| 939 | dict_tag_srcrevs = {} |
| 940 | for scm in scms: |
| 941 | ud = urldata[scm] |
| 942 | for name in ud.names: |
| 943 | try: |
| 944 | rev = ud.method.sortable_revision(ud, d, name) |
| 945 | except TypeError: |
| 946 | # support old bitbake versions |
| 947 | rev = ud.method.sortable_revision(scm, ud, d, name) |
| 948 | # Clean this up when we next bump bitbake version |
| 949 | if type(rev) != str: |
| 950 | autoinc, rev = rev |
| 951 | elif rev.startswith(autoinc_templ): |
| 952 | rev = rev[len(autoinc_templ):] |
| 953 | dict_srcrevs[name] = rev |
| 954 | if 'tag' in ud.parm: |
| 955 | tag = ud.parm['tag']; |
| 956 | key = name+'_'+tag |
| 957 | dict_tag_srcrevs[key] = rev |
| 958 | return (dict_srcrevs, dict_tag_srcrevs) |
| 959 | |
| 960 | do_fetch[postfuncs] += "write_srcrev" |
| 961 | do_fetch[vardepsexclude] += "write_srcrev" |
| 962 | python write_srcrev() { |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 963 | write_latest_srcrev(d, d.getVar('BUILDHISTORY_DIR_PACKAGE')) |
| 964 | } |
| 965 | |
| 966 | def write_latest_srcrev(d, pkghistdir): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 967 | srcrevfile = os.path.join(pkghistdir, 'latest_srcrev') |
| 968 | |
| 969 | srcrevs, tag_srcrevs = _get_srcrev_values(d) |
| 970 | if srcrevs: |
| 971 | if not os.path.exists(pkghistdir): |
| 972 | bb.utils.mkdirhier(pkghistdir) |
| 973 | old_tag_srcrevs = {} |
| 974 | if os.path.exists(srcrevfile): |
| 975 | with open(srcrevfile) as f: |
| 976 | for line in f: |
| 977 | if line.startswith('# tag_'): |
| 978 | key, value = line.split("=", 1) |
| 979 | key = key.replace('# tag_', '').strip() |
| 980 | value = value.replace('"', '').strip() |
| 981 | old_tag_srcrevs[key] = value |
| 982 | with open(srcrevfile, 'w') as f: |
| 983 | orig_srcrev = d.getVar('SRCREV', False) or 'INVALID' |
| 984 | if orig_srcrev != 'INVALID': |
| 985 | f.write('# SRCREV = "%s"\n' % orig_srcrev) |
| 986 | if len(srcrevs) > 1: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 987 | for name, srcrev in sorted(srcrevs.items()): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 988 | orig_srcrev = d.getVar('SRCREV_%s' % name, False) |
| 989 | if orig_srcrev: |
| 990 | f.write('# SRCREV_%s = "%s"\n' % (name, orig_srcrev)) |
| 991 | f.write('SRCREV_%s = "%s"\n' % (name, srcrev)) |
| 992 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 993 | f.write('SRCREV = "%s"\n' % next(iter(srcrevs.values()))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 994 | if len(tag_srcrevs) > 0: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 995 | for name, srcrev in sorted(tag_srcrevs.items()): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 996 | f.write('# tag_%s = "%s"\n' % (name, srcrev)) |
| 997 | if name in old_tag_srcrevs and old_tag_srcrevs[name] != srcrev: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 998 | pkg = d.getVar('PN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 999 | bb.warn("Revision for tag %s in package %s was changed since last build (from %s to %s)" % (name, pkg, old_tag_srcrevs[name], srcrev)) |
| 1000 | |
| 1001 | else: |
| 1002 | if os.path.exists(srcrevfile): |
| 1003 | os.remove(srcrevfile) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1004 | |
| 1005 | do_testimage[postfuncs] += "write_ptest_result" |
| 1006 | do_testimage[vardepsexclude] += "write_ptest_result" |
| 1007 | |
| 1008 | python write_ptest_result() { |
| 1009 | write_latest_ptest_result(d, d.getVar('BUILDHISTORY_DIR')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1010 | } |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1011 | |
| 1012 | def write_latest_ptest_result(d, histdir): |
| 1013 | import glob |
| 1014 | import subprocess |
| 1015 | test_log_dir = d.getVar('TEST_LOG_DIR') |
| 1016 | input_ptest = os.path.join(test_log_dir, 'ptest_log') |
| 1017 | output_ptest = os.path.join(histdir, 'ptest') |
| 1018 | if os.path.exists(input_ptest): |
| 1019 | try: |
| 1020 | # Lock it avoid race issue |
| 1021 | lock = bb.utils.lockfile(output_ptest + "/ptest.lock") |
| 1022 | bb.utils.mkdirhier(output_ptest) |
| 1023 | oe.path.copytree(input_ptest, output_ptest) |
| 1024 | # Sort test result |
| 1025 | for result in glob.glob('%s/pass.fail.*' % output_ptest): |
| 1026 | bb.debug(1, 'Processing %s' % result) |
| 1027 | cmd = ['sort', result, '-o', result] |
| 1028 | bb.debug(1, 'Running %s' % cmd) |
| 1029 | ret = subprocess.call(cmd) |
| 1030 | if ret != 0: |
| 1031 | bb.error('Failed to run %s!' % cmd) |
| 1032 | finally: |
| 1033 | bb.utils.unlockfile(lock) |