blob: 3823c664ab7c119003706d637a184138ad0e50a9 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#
2# Records history of build output in order to detect regressions
3#
4# Based in part on testlab.bbclass and packagehistory.bbclass
5#
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006# Copyright (C) 2011-2016 Intel Corporation
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007# Copyright (C) 2007-2011 Koen Kooi <koen@openembedded.org>
8#
9
10BUILDHISTORY_FEATURES ?= "image package sdk"
11BUILDHISTORY_DIR ?= "${TOPDIR}/buildhistory"
12BUILDHISTORY_DIR_IMAGE = "${BUILDHISTORY_DIR}/images/${MACHINE_ARCH}/${TCLIBC}/${IMAGE_BASENAME}"
13BUILDHISTORY_DIR_PACKAGE = "${BUILDHISTORY_DIR}/packages/${MULTIMACH_TARGET_SYS}/${PN}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050014
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
33BUILDHISTORY_RESET ?= ""
34
35BUILDHISTORY_OLD_DIR = "${BUILDHISTORY_DIR}/${@ "old" if "${BUILDHISTORY_RESET}" else ""}"
36BUILDHISTORY_OLD_DIR_PACKAGE = "${BUILDHISTORY_OLD_DIR}/packages/${MULTIMACH_TARGET_SYS}/${PN}"
37BUILDHISTORY_DIR_SDK = "${BUILDHISTORY_DIR}/sdk/${SDK_NAME}${SDK_EXT}/${IMAGE_BASENAME}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038BUILDHISTORY_IMAGE_FILES ?= "/etc/passwd /etc/group"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050039BUILDHISTORY_SDK_FILES ?= "conf/local.conf conf/bblayers.conf conf/auto.conf conf/locked-sigs.inc conf/devtool.conf"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040BUILDHISTORY_COMMIT ?= "0"
41BUILDHISTORY_COMMIT_AUTHOR ?= "buildhistory <buildhistory@${DISTRO}>"
42BUILDHISTORY_PUSH_REPO ?= ""
43
44SSTATEPOSTINSTFUNCS_append = " buildhistory_emit_pkghistory"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050045# We want to avoid influencing the signatures of sstate tasks - first the function itself:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046sstate_install[vardepsexclude] += "buildhistory_emit_pkghistory"
47# then the value added to SSTATEPOSTINSTFUNCS:
48SSTATEPOSTINSTFUNCS[vardepvalueexclude] .= "| buildhistory_emit_pkghistory"
49
Brad Bishop6e60e8b2018-02-01 10:27:11 -050050# Similarly for our function that gets the output signatures
51SSTATEPOSTUNPACKFUNCS_append = " buildhistory_emit_outputsigs"
52sstate_installpkgdir[vardepsexclude] += "buildhistory_emit_outputsigs"
53SSTATEPOSTUNPACKFUNCS[vardepvalueexclude] .= "| buildhistory_emit_outputsigs"
54
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050055# 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 Williamsc124f4f2015-09-15 14:41:29 -050059#
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050060# 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.
63BUILDHISTORY_PRESERVE = "latest latest_srcrev"
64
Patrick Williamsc0f7c042017-02-23 20:41:17 -060065PATCH_GIT_USER_EMAIL ?= "buildhistory@oe"
66PATCH_GIT_USER_NAME ?= "OpenEmbedded"
67
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050068#
69# Write out metadata about this package for comparison when writing future packages
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070#
71python buildhistory_emit_pkghistory() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050072 if not d.getVar('BB_CURRENTTASK') in ['packagedata', 'packagedata_setscene']:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073 return 0
74
Brad Bishop6e60e8b2018-02-01 10:27:11 -050075 if not "package" in (d.getVar('BUILDHISTORY_FEATURES') or "").split():
Patrick Williamsc124f4f2015-09-15 14:41:29 -050076 return 0
77
78 import re
79 import json
80 import errno
81
Brad Bishop6e60e8b2018-02-01 10:27:11 -050082 pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE')
83 oldpkghistdir = d.getVar('BUILDHISTORY_OLD_DIR_PACKAGE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084
85 class RecipeInfo:
86 def __init__(self, name):
87 self.name = name
88 self.pe = "0"
89 self.pv = "0"
90 self.pr = "r0"
91 self.depends = ""
92 self.packages = ""
93 self.srcrev = ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050094 self.layer = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095
96
97 class PackageInfo:
98 def __init__(self, name):
99 self.name = name
100 self.pe = "0"
101 self.pv = "0"
102 self.pr = "r0"
103 # pkg/pkge/pkgv/pkgr should be empty because we want to be able to default them
104 self.pkg = ""
105 self.pkge = ""
106 self.pkgv = ""
107 self.pkgr = ""
108 self.size = 0
109 self.depends = ""
110 self.rprovides = ""
111 self.rdepends = ""
112 self.rrecommends = ""
113 self.rsuggests = ""
114 self.rreplaces = ""
115 self.rconflicts = ""
116 self.files = ""
117 self.filelist = ""
118 # Variables that need to be written to their own separate file
119 self.filevars = dict.fromkeys(['pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm'])
120
121 # Should check PACKAGES here to see if anything removed
122
123 def readPackageInfo(pkg, histfile):
124 pkginfo = PackageInfo(pkg)
125 with open(histfile, "r") as f:
126 for line in f:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500127 lns = line.split('=', 1)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500128 name = lns[0].strip()
129 value = lns[1].strip(" \t\r\n").strip('"')
130 if name == "PE":
131 pkginfo.pe = value
132 elif name == "PV":
133 pkginfo.pv = value
134 elif name == "PR":
135 pkginfo.pr = value
136 elif name == "PKG":
137 pkginfo.pkg = value
138 elif name == "PKGE":
139 pkginfo.pkge = value
140 elif name == "PKGV":
141 pkginfo.pkgv = value
142 elif name == "PKGR":
143 pkginfo.pkgr = value
144 elif name == "RPROVIDES":
145 pkginfo.rprovides = value
146 elif name == "RDEPENDS":
147 pkginfo.rdepends = value
148 elif name == "RRECOMMENDS":
149 pkginfo.rrecommends = value
150 elif name == "RSUGGESTS":
151 pkginfo.rsuggests = value
152 elif name == "RREPLACES":
153 pkginfo.rreplaces = value
154 elif name == "RCONFLICTS":
155 pkginfo.rconflicts = value
156 elif name == "PKGSIZE":
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600157 pkginfo.size = int(value)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500158 elif name == "FILES":
159 pkginfo.files = value
160 elif name == "FILELIST":
161 pkginfo.filelist = value
162 # Apply defaults
163 if not pkginfo.pkg:
164 pkginfo.pkg = pkginfo.name
165 if not pkginfo.pkge:
166 pkginfo.pkge = pkginfo.pe
167 if not pkginfo.pkgv:
168 pkginfo.pkgv = pkginfo.pv
169 if not pkginfo.pkgr:
170 pkginfo.pkgr = pkginfo.pr
171 return pkginfo
172
173 def getlastpkgversion(pkg):
174 try:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500175 histfile = os.path.join(oldpkghistdir, pkg, "latest")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500176 return readPackageInfo(pkg, histfile)
177 except EnvironmentError:
178 return None
179
180 def sortpkglist(string):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500181 pkgiter = re.finditer(r'[a-zA-Z0-9.+-]+( \([><=]+[^)]+\))?', string, 0)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500182 pkglist = [p.group(0) for p in pkgiter]
183 pkglist.sort()
184 return ' '.join(pkglist)
185
186 def sortlist(string):
187 items = string.split(' ')
188 items.sort()
189 return ' '.join(items)
190
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500191 pn = d.getVar('PN')
192 pe = d.getVar('PE') or "0"
193 pv = d.getVar('PV')
194 pr = d.getVar('PR')
195 layer = bb.utils.get_file_layer(d.getVar('FILE', True), d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500196
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500197 pkgdata_dir = d.getVar('PKGDATA_DIR')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500198 packages = ""
199 try:
200 with open(os.path.join(pkgdata_dir, pn)) as f:
201 for line in f.readlines():
202 if line.startswith('PACKAGES: '):
203 packages = oe.utils.squashspaces(line.split(': ', 1)[1])
204 break
205 except IOError as e:
206 if e.errno == errno.ENOENT:
207 # Probably a -cross recipe, just ignore
208 return 0
209 else:
210 raise
211
212 packagelist = packages.split()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500213 preserve = d.getVar('BUILDHISTORY_PRESERVE').split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500214 if not os.path.exists(pkghistdir):
215 bb.utils.mkdirhier(pkghistdir)
216 else:
217 # Remove files for packages that no longer exist
218 for item in os.listdir(pkghistdir):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500219 if item not in preserve:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500220 if item not in packagelist:
221 itempath = os.path.join(pkghistdir, item)
222 if os.path.isdir(itempath):
223 for subfile in os.listdir(itempath):
224 os.unlink(os.path.join(itempath, subfile))
225 os.rmdir(itempath)
226 else:
227 os.unlink(itempath)
228
229 rcpinfo = RecipeInfo(pn)
230 rcpinfo.pe = pe
231 rcpinfo.pv = pv
232 rcpinfo.pr = pr
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500233 rcpinfo.depends = sortlist(oe.utils.squashspaces(d.getVar('DEPENDS') or ""))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500234 rcpinfo.packages = packages
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500235 rcpinfo.layer = layer
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500236 write_recipehistory(rcpinfo, d)
237
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500238 pkgdest = d.getVar('PKGDEST')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500239 for pkg in packagelist:
240 pkgdata = {}
241 with open(os.path.join(pkgdata_dir, 'runtime', pkg)) as f:
242 for line in f.readlines():
243 item = line.rstrip('\n').split(': ', 1)
244 key = item[0]
245 if key.endswith('_' + pkg):
246 key = key[:-len(pkg)-1]
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600247 pkgdata[key] = item[1]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500248
249 pkge = pkgdata.get('PKGE', '0')
250 pkgv = pkgdata['PKGV']
251 pkgr = pkgdata['PKGR']
252 #
253 # Find out what the last version was
254 # Make sure the version did not decrease
255 #
256 lastversion = getlastpkgversion(pkg)
257 if lastversion:
258 last_pkge = lastversion.pkge
259 last_pkgv = lastversion.pkgv
260 last_pkgr = lastversion.pkgr
261 r = bb.utils.vercmp((pkge, pkgv, pkgr), (last_pkge, last_pkgv, last_pkgr))
262 if r < 0:
263 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)
264 package_qa_handle_error("version-going-backwards", msg, d)
265
266 pkginfo = PackageInfo(pkg)
267 # Apparently the version can be different on a per-package basis (see Python)
268 pkginfo.pe = pkgdata.get('PE', '0')
269 pkginfo.pv = pkgdata['PV']
270 pkginfo.pr = pkgdata['PR']
271 pkginfo.pkg = pkgdata['PKG']
272 pkginfo.pkge = pkge
273 pkginfo.pkgv = pkgv
274 pkginfo.pkgr = pkgr
275 pkginfo.rprovides = sortpkglist(oe.utils.squashspaces(pkgdata.get('RPROVIDES', "")))
276 pkginfo.rdepends = sortpkglist(oe.utils.squashspaces(pkgdata.get('RDEPENDS', "")))
277 pkginfo.rrecommends = sortpkglist(oe.utils.squashspaces(pkgdata.get('RRECOMMENDS', "")))
278 pkginfo.rsuggests = sortpkglist(oe.utils.squashspaces(pkgdata.get('RSUGGESTS', "")))
279 pkginfo.rreplaces = sortpkglist(oe.utils.squashspaces(pkgdata.get('RREPLACES', "")))
280 pkginfo.rconflicts = sortpkglist(oe.utils.squashspaces(pkgdata.get('RCONFLICTS', "")))
281 pkginfo.files = oe.utils.squashspaces(pkgdata.get('FILES', ""))
282 for filevar in pkginfo.filevars:
283 pkginfo.filevars[filevar] = pkgdata.get(filevar, "")
284
285 # Gather information about packaged files
286 val = pkgdata.get('FILES_INFO', '')
287 dictval = json.loads(val)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600288 filelist = list(dictval.keys())
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500289 filelist.sort()
290 pkginfo.filelist = " ".join(filelist)
291
292 pkginfo.size = int(pkgdata['PKGSIZE'])
293
294 write_pkghistory(pkginfo, d)
295
296 # Create files-in-<package-name>.txt files containing a list of files of each recipe's package
297 bb.build.exec_func("buildhistory_list_pkg_files", d)
298}
299
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500300python buildhistory_emit_outputsigs() {
301 if not "task" in (d.getVar('BUILDHISTORY_FEATURES') or "").split():
302 return
303
304 import hashlib
305
306 taskoutdir = os.path.join(d.getVar('BUILDHISTORY_DIR'), 'task', 'output')
307 bb.utils.mkdirhier(taskoutdir)
308 currenttask = d.getVar('BB_CURRENTTASK')
309 pn = d.getVar('PN')
310 taskfile = os.path.join(taskoutdir, '%s.%s' % (pn, currenttask))
311
312 cwd = os.getcwd()
313 filesigs = {}
314 for root, _, files in os.walk(cwd):
315 for fname in files:
316 if fname == 'fixmepath':
317 continue
318 fullpath = os.path.join(root, fname)
319 try:
320 if os.path.islink(fullpath):
321 sha256 = hashlib.sha256(os.readlink(fullpath).encode('utf-8')).hexdigest()
322 elif os.path.isfile(fullpath):
323 sha256 = bb.utils.sha256_file(fullpath)
324 else:
325 continue
326 except OSError:
327 bb.warn('buildhistory: unable to read %s to get output signature' % fullpath)
328 continue
329 filesigs[os.path.relpath(fullpath, cwd)] = sha256
330 with open(taskfile, 'w') as f:
331 for fpath, fsig in sorted(filesigs.items(), key=lambda item: item[0]):
332 f.write('%s %s\n' % (fpath, fsig))
333}
334
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500335
336def write_recipehistory(rcpinfo, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500337 bb.debug(2, "Writing recipe history")
338
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500339 pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500340
341 infofile = os.path.join(pkghistdir, "latest")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600342 with open(infofile, "w") as f:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500343 if rcpinfo.pe != "0":
344 f.write(u"PE = %s\n" % rcpinfo.pe)
345 f.write(u"PV = %s\n" % rcpinfo.pv)
346 f.write(u"PR = %s\n" % rcpinfo.pr)
347 f.write(u"DEPENDS = %s\n" % rcpinfo.depends)
348 f.write(u"PACKAGES = %s\n" % rcpinfo.packages)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500349 f.write(u"LAYER = %s\n" % rcpinfo.layer)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500350
351
352def write_pkghistory(pkginfo, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500353 bb.debug(2, "Writing package history for package %s" % pkginfo.name)
354
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500355 pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500356
357 pkgpath = os.path.join(pkghistdir, pkginfo.name)
358 if not os.path.exists(pkgpath):
359 bb.utils.mkdirhier(pkgpath)
360
361 infofile = os.path.join(pkgpath, "latest")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600362 with open(infofile, "w") as f:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500363 if pkginfo.pe != "0":
364 f.write(u"PE = %s\n" % pkginfo.pe)
365 f.write(u"PV = %s\n" % pkginfo.pv)
366 f.write(u"PR = %s\n" % pkginfo.pr)
367
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600368 if pkginfo.pkg != pkginfo.name:
369 f.write(u"PKG = %s\n" % pkginfo.pkg)
370 if pkginfo.pkge != pkginfo.pe:
371 f.write(u"PKGE = %s\n" % pkginfo.pkge)
372 if pkginfo.pkgv != pkginfo.pv:
373 f.write(u"PKGV = %s\n" % pkginfo.pkgv)
374 if pkginfo.pkgr != pkginfo.pr:
375 f.write(u"PKGR = %s\n" % pkginfo.pkgr)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500376 f.write(u"RPROVIDES = %s\n" % pkginfo.rprovides)
377 f.write(u"RDEPENDS = %s\n" % pkginfo.rdepends)
378 f.write(u"RRECOMMENDS = %s\n" % pkginfo.rrecommends)
379 if pkginfo.rsuggests:
380 f.write(u"RSUGGESTS = %s\n" % pkginfo.rsuggests)
381 if pkginfo.rreplaces:
382 f.write(u"RREPLACES = %s\n" % pkginfo.rreplaces)
383 if pkginfo.rconflicts:
384 f.write(u"RCONFLICTS = %s\n" % pkginfo.rconflicts)
385 f.write(u"PKGSIZE = %d\n" % pkginfo.size)
386 f.write(u"FILES = %s\n" % pkginfo.files)
387 f.write(u"FILELIST = %s\n" % pkginfo.filelist)
388
389 for filevar in pkginfo.filevars:
390 filevarpath = os.path.join(pkgpath, "latest.%s" % filevar)
391 val = pkginfo.filevars[filevar]
392 if val:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600393 with open(filevarpath, "w") as f:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500394 f.write(val)
395 else:
396 if os.path.exists(filevarpath):
397 os.unlink(filevarpath)
398
399#
400# rootfs_type can be: image, sdk_target, sdk_host
401#
402def buildhistory_list_installed(d, rootfs_type="image"):
403 from oe.rootfs import image_list_installed_packages
404 from oe.sdk import sdk_list_installed_packages
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500405 from oe.utils import format_pkg_list
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500406
407 process_list = [('file', 'bh_installed_pkgs.txt'),\
408 ('deps', 'bh_installed_pkgs_deps.txt')]
409
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500410 if rootfs_type == "image":
411 pkgs = image_list_installed_packages(d)
412 else:
413 pkgs = sdk_list_installed_packages(d, rootfs_type == "sdk_target")
414
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500415 for output_type, output_file in process_list:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500416 output_file_full = os.path.join(d.getVar('WORKDIR'), output_file)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500417
418 with open(output_file_full, 'w') as output:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500419 output.write(format_pkg_list(pkgs, output_type))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500420
421python buildhistory_list_installed_image() {
422 buildhistory_list_installed(d)
423}
424
425python buildhistory_list_installed_sdk_target() {
426 buildhistory_list_installed(d, "sdk_target")
427}
428
429python buildhistory_list_installed_sdk_host() {
430 buildhistory_list_installed(d, "sdk_host")
431}
432
433buildhistory_get_installed() {
434 mkdir -p $1
435
436 # Get list of installed packages
437 pkgcache="$1/installed-packages.tmp"
438 cat ${WORKDIR}/bh_installed_pkgs.txt | sort > $pkgcache && rm ${WORKDIR}/bh_installed_pkgs.txt
439
440 cat $pkgcache | awk '{ print $1 }' > $1/installed-package-names.txt
441 if [ -s $pkgcache ] ; then
442 cat $pkgcache | awk '{ print $2 }' | xargs -n1 basename > $1/installed-packages.txt
443 else
444 printf "" > $1/installed-packages.txt
445 fi
446
447 # Produce dependency graph
448 # First, quote each name to handle characters that cause issues for dot
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500449 sed 's:\([^| ]*\):"\1":g' ${WORKDIR}/bh_installed_pkgs_deps.txt > $1/depends.tmp &&
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500450 rm ${WORKDIR}/bh_installed_pkgs_deps.txt
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500451 # Remove lines with rpmlib(...) and config(...) dependencies, change the
452 # delimiter from pipe to "->", set the style for recommend lines and
453 # turn versioned dependencies into edge labels.
454 sed -i -e '/rpmlib(/d' \
455 -e '/config(/d' \
456 -e 's:|: -> :' \
457 -e 's:"\[REC\]":[style=dotted]:' \
458 -e 's:"\([<>=]\+\)" "\([^"]*\)":[label="\1 \2"]:' \
459 $1/depends.tmp
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500460 # Add header, sorted and de-duped contents and footer and then delete the temp file
461 printf "digraph depends {\n node [shape=plaintext]\n" > $1/depends.dot
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500462 cat $1/depends.tmp | sort -u >> $1/depends.dot
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500463 echo "}" >> $1/depends.dot
464 rm $1/depends.tmp
465
466 # Produce installed package sizes list
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500467 oe-pkgdata-util -p ${PKGDATA_DIR} read-value "PKGSIZE" -n -f $pkgcache > $1/installed-package-sizes.tmp
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500468 cat $1/installed-package-sizes.tmp | awk '{print $2 "\tKiB\t" $1}' | sort -n -r > $1/installed-package-sizes.txt
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500469 rm $1/installed-package-sizes.tmp
470
471 # We're now done with the cache, delete it
472 rm $pkgcache
473
474 if [ "$2" != "sdk" ] ; then
475 # Produce some cut-down graphs (for readability)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500476 grep -v kernel-image $1/depends.dot | grep -v kernel-3 | grep -v kernel-4 > $1/depends-nokernel.dot
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500477 grep -v libc6 $1/depends-nokernel.dot | grep -v libgcc > $1/depends-nokernel-nolibc.dot
478 grep -v update- $1/depends-nokernel-nolibc.dot > $1/depends-nokernel-nolibc-noupdate.dot
479 grep -v kernel-module $1/depends-nokernel-nolibc-noupdate.dot > $1/depends-nokernel-nolibc-noupdate-nomodules.dot
480 fi
481
482 # add complementary package information
483 if [ -e ${WORKDIR}/complementary_pkgs.txt ]; then
484 cp ${WORKDIR}/complementary_pkgs.txt $1
485 fi
486}
487
488buildhistory_get_image_installed() {
489 # Anything requiring the use of the packaging system should be done in here
490 # in case the packaging files are going to be removed for this image
491
492 if [ "${@bb.utils.contains('BUILDHISTORY_FEATURES', 'image', '1', '0', d)}" = "0" ] ; then
493 return
494 fi
495
496 buildhistory_get_installed ${BUILDHISTORY_DIR_IMAGE}
497}
498
499buildhistory_get_sdk_installed() {
500 # Anything requiring the use of the packaging system should be done in here
501 # in case the packaging files are going to be removed for this SDK
502
503 if [ "${@bb.utils.contains('BUILDHISTORY_FEATURES', 'sdk', '1', '0', d)}" = "0" ] ; then
504 return
505 fi
506
507 buildhistory_get_installed ${BUILDHISTORY_DIR_SDK}/$1 sdk
508}
509
510buildhistory_get_sdk_installed_host() {
511 buildhistory_get_sdk_installed host
512}
513
514buildhistory_get_sdk_installed_target() {
515 buildhistory_get_sdk_installed target
516}
517
518buildhistory_list_files() {
519 # List the files in the specified directory, but exclude date/time etc.
520 # This awk script is somewhat messy, but handles where the size is not printed for device files under pseudo
521 if [ "$3" = "fakeroot" ] ; then
522 ( cd $1 && ${FAKEROOTENV} ${FAKEROOTCMD} find . ! -path . -printf "%M %-10u %-10g %10s %p -> %l\n" | sort -k5 | sed 's/ * -> $//' > $2 )
523 else
524 ( cd $1 && find . ! -path . -printf "%M %-10u %-10g %10s %p -> %l\n" | sort -k5 | sed 's/ * -> $//' > $2 )
525 fi
526}
527
528buildhistory_list_pkg_files() {
529 # Create individual files-in-package for each recipe's package
530 for pkgdir in $(find ${PKGDEST}/* -maxdepth 0 -type d); do
531 pkgname=$(basename $pkgdir)
532 outfolder="${BUILDHISTORY_DIR_PACKAGE}/$pkgname"
533 outfile="$outfolder/files-in-package.txt"
534 # Make sure the output folder exists so we can create the file
535 if [ ! -d $outfolder ] ; then
536 bbdebug 2 "Folder $outfolder does not exist, file $outfile not created"
537 continue
538 fi
539 buildhistory_list_files $pkgdir $outfile fakeroot
540 done
541}
542
543buildhistory_get_imageinfo() {
544 if [ "${@bb.utils.contains('BUILDHISTORY_FEATURES', 'image', '1', '0', d)}" = "0" ] ; then
545 return
546 fi
547
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500548 mkdir -p ${BUILDHISTORY_DIR_IMAGE}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500549 buildhistory_list_files ${IMAGE_ROOTFS} ${BUILDHISTORY_DIR_IMAGE}/files-in-image.txt
550
551 # Collect files requested in BUILDHISTORY_IMAGE_FILES
552 rm -rf ${BUILDHISTORY_DIR_IMAGE}/image-files
553 for f in ${BUILDHISTORY_IMAGE_FILES}; do
554 if [ -f ${IMAGE_ROOTFS}/$f ] ; then
555 mkdir -p ${BUILDHISTORY_DIR_IMAGE}/image-files/`dirname $f`
556 cp ${IMAGE_ROOTFS}/$f ${BUILDHISTORY_DIR_IMAGE}/image-files/$f
557 fi
558 done
559
560 # Record some machine-readable meta-information about the image
561 printf "" > ${BUILDHISTORY_DIR_IMAGE}/image-info.txt
562 cat >> ${BUILDHISTORY_DIR_IMAGE}/image-info.txt <<END
563${@buildhistory_get_imagevars(d)}
564END
565 imagesize=`du -ks ${IMAGE_ROOTFS} | awk '{ print $1 }'`
566 echo "IMAGESIZE = $imagesize" >> ${BUILDHISTORY_DIR_IMAGE}/image-info.txt
567
568 # Add some configuration information
569 echo "${MACHINE}: ${IMAGE_BASENAME} configured for ${DISTRO} ${DISTRO_VERSION}" > ${BUILDHISTORY_DIR_IMAGE}/build-id.txt
570
571 cat >> ${BUILDHISTORY_DIR_IMAGE}/build-id.txt <<END
572${@buildhistory_get_build_id(d)}
573END
574}
575
576buildhistory_get_sdkinfo() {
577 if [ "${@bb.utils.contains('BUILDHISTORY_FEATURES', 'sdk', '1', '0', d)}" = "0" ] ; then
578 return
579 fi
580
581 buildhistory_list_files ${SDK_OUTPUT} ${BUILDHISTORY_DIR_SDK}/files-in-sdk.txt
582
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500583 # Collect files requested in BUILDHISTORY_SDK_FILES
584 rm -rf ${BUILDHISTORY_DIR_SDK}/sdk-files
585 for f in ${BUILDHISTORY_SDK_FILES}; do
586 if [ -f ${SDK_OUTPUT}/${SDKPATH}/$f ] ; then
587 mkdir -p ${BUILDHISTORY_DIR_SDK}/sdk-files/`dirname $f`
588 cp ${SDK_OUTPUT}/${SDKPATH}/$f ${BUILDHISTORY_DIR_SDK}/sdk-files/$f
589 fi
590 done
591
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500592 # Record some machine-readable meta-information about the SDK
593 printf "" > ${BUILDHISTORY_DIR_SDK}/sdk-info.txt
594 cat >> ${BUILDHISTORY_DIR_SDK}/sdk-info.txt <<END
595${@buildhistory_get_sdkvars(d)}
596END
597 sdksize=`du -ks ${SDK_OUTPUT} | awk '{ print $1 }'`
598 echo "SDKSIZE = $sdksize" >> ${BUILDHISTORY_DIR_SDK}/sdk-info.txt
599}
600
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500601python buildhistory_get_extra_sdkinfo() {
602 import operator
603 import math
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500604
605 if d.getVar('BB_CURRENTTASK') == 'populate_sdk_ext' and \
606 "sdk" in (d.getVar('BUILDHISTORY_FEATURES') or "").split():
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500607 tasksizes = {}
608 filesizes = {}
609 for root, _, files in os.walk(d.expand('${SDK_OUTPUT}/${SDKPATH}/sstate-cache')):
610 for fn in files:
611 if fn.endswith('.tgz'):
612 fsize = int(math.ceil(float(os.path.getsize(os.path.join(root, fn))) / 1024))
613 task = fn.rsplit(':', 1)[1].split('_', 1)[1].split('.')[0]
614 origtotal = tasksizes.get(task, 0)
615 tasksizes[task] = origtotal + fsize
616 filesizes[fn] = fsize
617 with open(d.expand('${BUILDHISTORY_DIR_SDK}/sstate-package-sizes.txt'), 'w') as f:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600618 filesizes_sorted = sorted(filesizes.items(), key=operator.itemgetter(1, 0), reverse=True)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500619 for fn, size in filesizes_sorted:
620 f.write('%10d KiB %s\n' % (size, fn))
621 with open(d.expand('${BUILDHISTORY_DIR_SDK}/sstate-task-sizes.txt'), 'w') as f:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600622 tasksizes_sorted = sorted(tasksizes.items(), key=operator.itemgetter(1, 0), reverse=True)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500623 for task, size in tasksizes_sorted:
624 f.write('%10d KiB %s\n' % (size, task))
625}
626
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500627# By using ROOTFS_POSTUNINSTALL_COMMAND we get in after uninstallation of
628# unneeded packages but before the removal of packaging files
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500629ROOTFS_POSTUNINSTALL_COMMAND += "buildhistory_list_installed_image ;"
630ROOTFS_POSTUNINSTALL_COMMAND += "buildhistory_get_image_installed ;"
631ROOTFS_POSTUNINSTALL_COMMAND[vardepvalueexclude] .= "| buildhistory_list_installed_image ;| buildhistory_get_image_installed ;"
632ROOTFS_POSTUNINSTALL_COMMAND[vardepsexclude] += "buildhistory_list_installed_image buildhistory_get_image_installed"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500633
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500634IMAGE_POSTPROCESS_COMMAND += "buildhistory_get_imageinfo ;"
635IMAGE_POSTPROCESS_COMMAND[vardepvalueexclude] .= "| buildhistory_get_imageinfo ;"
636IMAGE_POSTPROCESS_COMMAND[vardepsexclude] += "buildhistory_get_imageinfo"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500637
638# We want these to be the last run so that we get called after complementary package installation
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500639POPULATE_SDK_POST_TARGET_COMMAND_append = " buildhistory_list_installed_sdk_target;"
640POPULATE_SDK_POST_TARGET_COMMAND_append = " buildhistory_get_sdk_installed_target;"
641POPULATE_SDK_POST_TARGET_COMMAND[vardepvalueexclude] .= "| buildhistory_list_installed_sdk_target;| buildhistory_get_sdk_installed_target;"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500642
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500643POPULATE_SDK_POST_HOST_COMMAND_append = " buildhistory_list_installed_sdk_host;"
644POPULATE_SDK_POST_HOST_COMMAND_append = " buildhistory_get_sdk_installed_host;"
645POPULATE_SDK_POST_HOST_COMMAND[vardepvalueexclude] .= "| buildhistory_list_installed_sdk_host;| buildhistory_get_sdk_installed_host;"
646
647SDK_POSTPROCESS_COMMAND_append = " buildhistory_get_sdkinfo ; buildhistory_get_extra_sdkinfo; "
648SDK_POSTPROCESS_COMMAND[vardepvalueexclude] .= "| buildhistory_get_sdkinfo ; buildhistory_get_extra_sdkinfo; "
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500649
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500650python buildhistory_write_sigs() {
651 if not "task" in (d.getVar('BUILDHISTORY_FEATURES') or "").split():
652 return
653
654 # Create sigs file
655 if hasattr(bb.parse.siggen, 'dump_siglist'):
656 taskoutdir = os.path.join(d.getVar('BUILDHISTORY_DIR'), 'task')
657 bb.utils.mkdirhier(taskoutdir)
658 bb.parse.siggen.dump_siglist(os.path.join(taskoutdir, 'tasksigs.txt'))
659}
660
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500661def buildhistory_get_build_id(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500662 if d.getVar('BB_WORKERCONTEXT') != '1':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500663 return ""
664 localdata = bb.data.createCopy(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500665 statuslines = []
666 for func in oe.data.typed_value('BUILDCFG_FUNCS', localdata):
667 g = globals()
668 if func not in g:
669 bb.warn("Build configuration function '%s' does not exist" % func)
670 else:
671 flines = g[func](localdata)
672 if flines:
673 statuslines.extend(flines)
674
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500675 statusheader = d.getVar('BUILDCFG_HEADER')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500676 return('\n%s\n%s\n' % (statusheader, '\n'.join(statuslines)))
677
678def buildhistory_get_metadata_revs(d):
679 # We want an easily machine-readable format here, so get_layers_branch_rev isn't quite what we want
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500680 layers = (d.getVar("BBLAYERS") or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500681 medadata_revs = ["%-17s = %s:%s" % (os.path.basename(i), \
682 base_get_metadata_git_branch(i, None).strip(), \
683 base_get_metadata_git_revision(i, None)) \
684 for i in layers]
685 return '\n'.join(medadata_revs)
686
687def outputvars(vars, listvars, d):
688 vars = vars.split()
689 listvars = listvars.split()
690 ret = ""
691 for var in vars:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500692 value = d.getVar(var) or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500693 if var in listvars:
694 # Squash out spaces
695 value = oe.utils.squashspaces(value)
696 ret += "%s = %s\n" % (var, value)
697 return ret.rstrip('\n')
698
699def buildhistory_get_imagevars(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500700 if d.getVar('BB_WORKERCONTEXT') != '1':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500701 return ""
702 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"
703 listvars = "USER_CLASSES IMAGE_CLASSES IMAGE_FEATURES IMAGE_LINGUAS IMAGE_INSTALL BAD_RECOMMENDATIONS PACKAGE_EXCLUDE"
704 return outputvars(imagevars, listvars, d)
705
706def buildhistory_get_sdkvars(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500707 if d.getVar('BB_WORKERCONTEXT') != '1':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500708 return ""
709 sdkvars = "DISTRO DISTRO_VERSION SDK_NAME SDK_VERSION SDKMACHINE SDKIMAGE_FEATURES BAD_RECOMMENDATIONS NO_RECOMMENDATIONS PACKAGE_EXCLUDE"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500710 if d.getVar('BB_CURRENTTASK') == 'populate_sdk_ext':
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500711 # Extensible SDK uses some additional variables
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600712 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 Williamsd8c66bc2016-06-20 12:57:21 -0500713 listvars = "SDKIMAGE_FEATURES BAD_RECOMMENDATIONS PACKAGE_EXCLUDE SDK_LOCAL_CONF_WHITELIST SDK_LOCAL_CONF_BLACKLIST SDK_INHERIT_BLACKLIST"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500714 return outputvars(sdkvars, listvars, d)
715
716
717def buildhistory_get_cmdline(d):
718 if sys.argv[0].endswith('bin/bitbake'):
719 bincmd = 'bitbake'
720 else:
721 bincmd = sys.argv[0]
722 return '%s %s' % (bincmd, ' '.join(sys.argv[1:]))
723
724
725buildhistory_single_commit() {
726 if [ "$3" = "" ] ; then
727 commitopts="${BUILDHISTORY_DIR}/ --allow-empty"
728 item="No changes"
729 else
730 commitopts="$3 metadata-revs"
731 item="$3"
732 fi
733 if [ "${BUILDHISTORY_BUILD_FAILURES}" = "0" ] ; then
734 result="succeeded"
735 else
736 result="failed"
737 fi
738 case ${BUILDHISTORY_BUILD_INTERRUPTED} in
739 1)
740 result="$result (interrupted)"
741 ;;
742 2)
743 result="$result (force interrupted)"
744 ;;
745 esac
746 commitmsgfile=`mktemp`
747 cat > $commitmsgfile << END
748$item: Build ${BUILDNAME} of ${DISTRO} ${DISTRO_VERSION} for machine ${MACHINE} on $2
749
750cmd: $1
751
752result: $result
753
754metadata revisions:
755END
756 cat ${BUILDHISTORY_DIR}/metadata-revs >> $commitmsgfile
757 git commit $commitopts -F $commitmsgfile --author "${BUILDHISTORY_COMMIT_AUTHOR}" > /dev/null
758 rm $commitmsgfile
759}
760
761buildhistory_commit() {
762 if [ ! -d ${BUILDHISTORY_DIR} ] ; then
763 # Code above that creates this dir never executed, so there can't be anything to commit
764 return
765 fi
766
767 # Create a machine-readable list of metadata revisions for each layer
768 cat > ${BUILDHISTORY_DIR}/metadata-revs <<END
769${@buildhistory_get_metadata_revs(d)}
770END
771
772 ( cd ${BUILDHISTORY_DIR}/
773 # Initialise the repo if necessary
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500774 if [ ! -e .git ] ; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500775 git init -q
776 else
777 git tag -f build-minus-3 build-minus-2 > /dev/null 2>&1 || true
778 git tag -f build-minus-2 build-minus-1 > /dev/null 2>&1 || true
779 git tag -f build-minus-1 > /dev/null 2>&1 || true
780 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600781
782 check_git_config
783
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500784 # Check if there are new/changed files to commit (other than metadata-revs)
785 repostatus=`git status --porcelain | grep -v " metadata-revs$"`
786 HOSTNAME=`hostname 2>/dev/null || echo unknown`
787 CMDLINE="${@buildhistory_get_cmdline(d)}"
788 if [ "$repostatus" != "" ] ; then
789 git add -A .
790 # porcelain output looks like "?? packages/foo/bar"
791 # Ensure we commit metadata-revs with the first commit
792 for entry in `echo "$repostatus" | awk '{print $2}' | awk -F/ '{print $1}' | sort | uniq` ; do
793 buildhistory_single_commit "$CMDLINE" "$HOSTNAME" "$entry"
794 done
795 git gc --auto --quiet
796 else
797 buildhistory_single_commit "$CMDLINE" "$HOSTNAME"
798 fi
799 if [ "${BUILDHISTORY_PUSH_REPO}" != "" ] ; then
800 git push -q ${BUILDHISTORY_PUSH_REPO}
801 fi) || true
802}
803
804python buildhistory_eventhandler() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500805 if e.data.getVar('BUILDHISTORY_FEATURES').strip():
806 reset = e.data.getVar("BUILDHISTORY_RESET")
807 olddir = e.data.getVar("BUILDHISTORY_OLD_DIR")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500808 if isinstance(e, bb.event.BuildStarted):
809 if reset:
810 import shutil
811 # Clean up after potentially interrupted build.
812 if os.path.isdir(olddir):
813 shutil.rmtree(olddir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500814 rootdir = e.data.getVar("BUILDHISTORY_DIR")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500815 entries = [ x for x in os.listdir(rootdir) if not x.startswith('.') ]
816 bb.utils.mkdirhier(olddir)
817 for entry in entries:
818 os.rename(os.path.join(rootdir, entry),
819 os.path.join(olddir, entry))
820 elif isinstance(e, bb.event.BuildCompleted):
821 if reset:
822 import shutil
823 shutil.rmtree(olddir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500824 if e.data.getVar("BUILDHISTORY_COMMIT") == "1":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500825 bb.note("Writing buildhistory")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500826 bb.build.exec_func("buildhistory_write_sigs", d)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500827 localdata = bb.data.createCopy(e.data)
828 localdata.setVar('BUILDHISTORY_BUILD_FAILURES', str(e._failures))
829 interrupted = getattr(e, '_interrupted', 0)
830 localdata.setVar('BUILDHISTORY_BUILD_INTERRUPTED', str(interrupted))
831 bb.build.exec_func("buildhistory_commit", localdata)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500832}
833
834addhandler buildhistory_eventhandler
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500835buildhistory_eventhandler[eventmask] = "bb.event.BuildCompleted bb.event.BuildStarted"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500836
837
838# FIXME this ought to be moved into the fetcher
839def _get_srcrev_values(d):
840 """
841 Return the version strings for the current recipe
842 """
843
844 scms = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500845 fetcher = bb.fetch.Fetch(d.getVar('SRC_URI').split(), d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500846 urldata = fetcher.ud
847 for u in urldata:
848 if urldata[u].method.supports_srcrev():
849 scms.append(u)
850
851 autoinc_templ = 'AUTOINC+'
852 dict_srcrevs = {}
853 dict_tag_srcrevs = {}
854 for scm in scms:
855 ud = urldata[scm]
856 for name in ud.names:
857 try:
858 rev = ud.method.sortable_revision(ud, d, name)
859 except TypeError:
860 # support old bitbake versions
861 rev = ud.method.sortable_revision(scm, ud, d, name)
862 # Clean this up when we next bump bitbake version
863 if type(rev) != str:
864 autoinc, rev = rev
865 elif rev.startswith(autoinc_templ):
866 rev = rev[len(autoinc_templ):]
867 dict_srcrevs[name] = rev
868 if 'tag' in ud.parm:
869 tag = ud.parm['tag'];
870 key = name+'_'+tag
871 dict_tag_srcrevs[key] = rev
872 return (dict_srcrevs, dict_tag_srcrevs)
873
874do_fetch[postfuncs] += "write_srcrev"
875do_fetch[vardepsexclude] += "write_srcrev"
876python write_srcrev() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500877 pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500878 srcrevfile = os.path.join(pkghistdir, 'latest_srcrev')
879
880 srcrevs, tag_srcrevs = _get_srcrev_values(d)
881 if srcrevs:
882 if not os.path.exists(pkghistdir):
883 bb.utils.mkdirhier(pkghistdir)
884 old_tag_srcrevs = {}
885 if os.path.exists(srcrevfile):
886 with open(srcrevfile) as f:
887 for line in f:
888 if line.startswith('# tag_'):
889 key, value = line.split("=", 1)
890 key = key.replace('# tag_', '').strip()
891 value = value.replace('"', '').strip()
892 old_tag_srcrevs[key] = value
893 with open(srcrevfile, 'w') as f:
894 orig_srcrev = d.getVar('SRCREV', False) or 'INVALID'
895 if orig_srcrev != 'INVALID':
896 f.write('# SRCREV = "%s"\n' % orig_srcrev)
897 if len(srcrevs) > 1:
898 for name, srcrev in srcrevs.items():
899 orig_srcrev = d.getVar('SRCREV_%s' % name, False)
900 if orig_srcrev:
901 f.write('# SRCREV_%s = "%s"\n' % (name, orig_srcrev))
902 f.write('SRCREV_%s = "%s"\n' % (name, srcrev))
903 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500904 f.write('SRCREV = "%s"\n' % next(iter(srcrevs.values())))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500905 if len(tag_srcrevs) > 0:
906 for name, srcrev in tag_srcrevs.items():
907 f.write('# tag_%s = "%s"\n' % (name, srcrev))
908 if name in old_tag_srcrevs and old_tag_srcrevs[name] != srcrev:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500909 pkg = d.getVar('PN')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500910 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))
911
912 else:
913 if os.path.exists(srcrevfile):
914 os.remove(srcrevfile)
915}