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