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