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