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