blob: 0f26c3c07b3cd2cebdbabc42e78a45f831dddac1 [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
Andrew Geisslerc9f78652020-09-18 14:11:35 -050010inherit image-artifact-names
11
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012BUILDHISTORY_FEATURES ?= "image package sdk"
13BUILDHISTORY_DIR ?= "${TOPDIR}/buildhistory"
14BUILDHISTORY_DIR_IMAGE = "${BUILDHISTORY_DIR}/images/${MACHINE_ARCH}/${TCLIBC}/${IMAGE_BASENAME}"
15BUILDHISTORY_DIR_PACKAGE = "${BUILDHISTORY_DIR}/packages/${MULTIMACH_TARGET_SYS}/${PN}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050016
17# Setting this to non-empty will remove the old content of the buildhistory as part of
18# the current bitbake invocation and replace it with information about what was built
19# during the build.
20#
21# This is meant to be used in continuous integration (CI) systems when invoking bitbake
22# for full world builds. The effect in that case is that information about packages
23# that no longer get build also gets removed from the buildhistory, which is not
24# the case otherwise.
25#
26# The advantage over manually cleaning the buildhistory outside of bitbake is that
27# the "version-going-backwards" check still works. When relying on that, be careful
28# about failed world builds: they will lead to incomplete information in the
29# buildhistory because information about packages that could not be built will
30# also get removed. A CI system should handle that by discarding the buildhistory
31# of failed builds.
32#
33# The expected usage is via auto.conf, but passing via the command line also works
34# with: BB_ENV_EXTRAWHITE=BUILDHISTORY_RESET BUILDHISTORY_RESET=1
35BUILDHISTORY_RESET ?= ""
36
37BUILDHISTORY_OLD_DIR = "${BUILDHISTORY_DIR}/${@ "old" if "${BUILDHISTORY_RESET}" else ""}"
38BUILDHISTORY_OLD_DIR_PACKAGE = "${BUILDHISTORY_OLD_DIR}/packages/${MULTIMACH_TARGET_SYS}/${PN}"
39BUILDHISTORY_DIR_SDK = "${BUILDHISTORY_DIR}/sdk/${SDK_NAME}${SDK_EXT}/${IMAGE_BASENAME}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040BUILDHISTORY_IMAGE_FILES ?= "/etc/passwd /etc/group"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050041BUILDHISTORY_SDK_FILES ?= "conf/local.conf conf/bblayers.conf conf/auto.conf conf/locked-sigs.inc conf/devtool.conf"
Brad Bishop316dfdd2018-06-25 12:45:53 -040042BUILDHISTORY_COMMIT ?= "1"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043BUILDHISTORY_COMMIT_AUTHOR ?= "buildhistory <buildhistory@${DISTRO}>"
44BUILDHISTORY_PUSH_REPO ?= ""
Andrew Geissler82c905d2020-04-13 13:39:40 -050045BUILDHISTORY_TAG ?= "build"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046
47SSTATEPOSTINSTFUNCS_append = " buildhistory_emit_pkghistory"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050048# We want to avoid influencing the signatures of sstate tasks - first the function itself:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050049sstate_install[vardepsexclude] += "buildhistory_emit_pkghistory"
50# then the value added to SSTATEPOSTINSTFUNCS:
51SSTATEPOSTINSTFUNCS[vardepvalueexclude] .= "| buildhistory_emit_pkghistory"
52
Brad Bishop6e60e8b2018-02-01 10:27:11 -050053# Similarly for our function that gets the output signatures
54SSTATEPOSTUNPACKFUNCS_append = " buildhistory_emit_outputsigs"
55sstate_installpkgdir[vardepsexclude] += "buildhistory_emit_outputsigs"
56SSTATEPOSTUNPACKFUNCS[vardepvalueexclude] .= "| buildhistory_emit_outputsigs"
57
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050058# All items excepts those listed here will be removed from a recipe's
59# build history directory by buildhistory_emit_pkghistory(). This is
60# necessary because some of these items (package directories, files that
61# we no longer emit) might be obsolete.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050062#
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050063# When extending build history, derive your class from buildhistory.bbclass
64# and extend this list here with the additional files created by the derived
65# class.
Brad Bishop96ff1982019-08-19 13:50:42 -040066BUILDHISTORY_PRESERVE = "latest latest_srcrev sysroot"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050067
Patrick Williamsc0f7c042017-02-23 20:41:17 -060068PATCH_GIT_USER_EMAIL ?= "buildhistory@oe"
69PATCH_GIT_USER_NAME ?= "OpenEmbedded"
70
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050071#
Brad Bishop96ff1982019-08-19 13:50:42 -040072# Write out the contents of the sysroot
73#
74buildhistory_emit_sysroot() {
75 mkdir --parents ${BUILDHISTORY_DIR_PACKAGE}
76 case ${CLASSOVERRIDE} in
77 class-native|class-cross|class-crosssdk)
78 BASE=${SYSROOT_DESTDIR}/${STAGING_DIR_NATIVE}
79 ;;
80 *)
81 BASE=${SYSROOT_DESTDIR}
82 ;;
83 esac
84 buildhistory_list_files_no_owners $BASE ${BUILDHISTORY_DIR_PACKAGE}/sysroot
85}
86
87#
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050088# Write out metadata about this package for comparison when writing future packages
Patrick Williamsc124f4f2015-09-15 14:41:29 -050089#
90python buildhistory_emit_pkghistory() {
Brad Bishop96ff1982019-08-19 13:50:42 -040091 if d.getVar('BB_CURRENTTASK') in ['populate_sysroot', 'populate_sysroot_setscene']:
92 bb.build.exec_func("buildhistory_emit_sysroot", d)
93
Brad Bishop6e60e8b2018-02-01 10:27:11 -050094 if not d.getVar('BB_CURRENTTASK') in ['packagedata', 'packagedata_setscene']:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095 return 0
96
Brad Bishop6e60e8b2018-02-01 10:27:11 -050097 if not "package" in (d.getVar('BUILDHISTORY_FEATURES') or "").split():
Patrick Williamsc124f4f2015-09-15 14:41:29 -050098 return 0
99
100 import re
101 import json
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800102 import shlex
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500103 import errno
104
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500105 pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE')
106 oldpkghistdir = d.getVar('BUILDHISTORY_OLD_DIR_PACKAGE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107
108 class RecipeInfo:
109 def __init__(self, name):
110 self.name = name
111 self.pe = "0"
112 self.pv = "0"
113 self.pr = "r0"
114 self.depends = ""
115 self.packages = ""
116 self.srcrev = ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500117 self.layer = ""
Andrew Geissler4ed12e12020-06-05 18:00:41 -0500118 self.config = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500119
120
121 class PackageInfo:
122 def __init__(self, name):
123 self.name = name
124 self.pe = "0"
125 self.pv = "0"
126 self.pr = "r0"
127 # pkg/pkge/pkgv/pkgr should be empty because we want to be able to default them
128 self.pkg = ""
129 self.pkge = ""
130 self.pkgv = ""
131 self.pkgr = ""
132 self.size = 0
133 self.depends = ""
134 self.rprovides = ""
135 self.rdepends = ""
136 self.rrecommends = ""
137 self.rsuggests = ""
138 self.rreplaces = ""
139 self.rconflicts = ""
140 self.files = ""
141 self.filelist = ""
142 # Variables that need to be written to their own separate file
143 self.filevars = dict.fromkeys(['pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm'])
144
145 # Should check PACKAGES here to see if anything removed
146
147 def readPackageInfo(pkg, histfile):
148 pkginfo = PackageInfo(pkg)
149 with open(histfile, "r") as f:
150 for line in f:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500151 lns = line.split('=', 1)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500152 name = lns[0].strip()
153 value = lns[1].strip(" \t\r\n").strip('"')
154 if name == "PE":
155 pkginfo.pe = value
156 elif name == "PV":
157 pkginfo.pv = value
158 elif name == "PR":
159 pkginfo.pr = value
160 elif name == "PKG":
161 pkginfo.pkg = value
162 elif name == "PKGE":
163 pkginfo.pkge = value
164 elif name == "PKGV":
165 pkginfo.pkgv = value
166 elif name == "PKGR":
167 pkginfo.pkgr = value
168 elif name == "RPROVIDES":
169 pkginfo.rprovides = value
170 elif name == "RDEPENDS":
171 pkginfo.rdepends = value
172 elif name == "RRECOMMENDS":
173 pkginfo.rrecommends = value
174 elif name == "RSUGGESTS":
175 pkginfo.rsuggests = value
176 elif name == "RREPLACES":
177 pkginfo.rreplaces = value
178 elif name == "RCONFLICTS":
179 pkginfo.rconflicts = value
180 elif name == "PKGSIZE":
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600181 pkginfo.size = int(value)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500182 elif name == "FILES":
183 pkginfo.files = value
184 elif name == "FILELIST":
185 pkginfo.filelist = value
186 # Apply defaults
187 if not pkginfo.pkg:
188 pkginfo.pkg = pkginfo.name
189 if not pkginfo.pkge:
190 pkginfo.pkge = pkginfo.pe
191 if not pkginfo.pkgv:
192 pkginfo.pkgv = pkginfo.pv
193 if not pkginfo.pkgr:
194 pkginfo.pkgr = pkginfo.pr
195 return pkginfo
196
197 def getlastpkgversion(pkg):
198 try:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500199 histfile = os.path.join(oldpkghistdir, pkg, "latest")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500200 return readPackageInfo(pkg, histfile)
201 except EnvironmentError:
202 return None
203
204 def sortpkglist(string):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500205 pkgiter = re.finditer(r'[a-zA-Z0-9.+-]+( \([><=]+[^)]+\))?', string, 0)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500206 pkglist = [p.group(0) for p in pkgiter]
207 pkglist.sort()
208 return ' '.join(pkglist)
209
210 def sortlist(string):
211 items = string.split(' ')
212 items.sort()
213 return ' '.join(items)
214
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500215 pn = d.getVar('PN')
216 pe = d.getVar('PE') or "0"
217 pv = d.getVar('PV')
218 pr = d.getVar('PR')
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500219 layer = bb.utils.get_file_layer(d.getVar('FILE'), d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500220
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500221 pkgdata_dir = d.getVar('PKGDATA_DIR')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500222 packages = ""
223 try:
224 with open(os.path.join(pkgdata_dir, pn)) as f:
225 for line in f.readlines():
226 if line.startswith('PACKAGES: '):
227 packages = oe.utils.squashspaces(line.split(': ', 1)[1])
228 break
229 except IOError as e:
230 if e.errno == errno.ENOENT:
231 # Probably a -cross recipe, just ignore
232 return 0
233 else:
234 raise
235
236 packagelist = packages.split()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500237 preserve = d.getVar('BUILDHISTORY_PRESERVE').split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500238 if not os.path.exists(pkghistdir):
239 bb.utils.mkdirhier(pkghistdir)
240 else:
241 # Remove files for packages that no longer exist
242 for item in os.listdir(pkghistdir):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500243 if item not in preserve:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500244 if item not in packagelist:
245 itempath = os.path.join(pkghistdir, item)
246 if os.path.isdir(itempath):
247 for subfile in os.listdir(itempath):
248 os.unlink(os.path.join(itempath, subfile))
249 os.rmdir(itempath)
250 else:
251 os.unlink(itempath)
252
253 rcpinfo = RecipeInfo(pn)
254 rcpinfo.pe = pe
255 rcpinfo.pv = pv
256 rcpinfo.pr = pr
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500257 rcpinfo.depends = sortlist(oe.utils.squashspaces(d.getVar('DEPENDS') or ""))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500258 rcpinfo.packages = packages
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500259 rcpinfo.layer = layer
Andrew Geissler4ed12e12020-06-05 18:00:41 -0500260 rcpinfo.config = sortlist(oe.utils.squashspaces(d.getVar('PACKAGECONFIG') or ""))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500261 write_recipehistory(rcpinfo, d)
262
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500263 bb.build.exec_func("read_subpackage_metadata", d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500264
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500265 for pkg in packagelist:
266 localdata = d.createCopy()
267 localdata.setVar('OVERRIDES', d.getVar("OVERRIDES", False) + ":" + pkg)
268
269 pkge = localdata.getVar("PKGE") or '0'
270 pkgv = localdata.getVar("PKGV")
271 pkgr = localdata.getVar("PKGR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500272 #
273 # Find out what the last version was
274 # Make sure the version did not decrease
275 #
276 lastversion = getlastpkgversion(pkg)
277 if lastversion:
278 last_pkge = lastversion.pkge
279 last_pkgv = lastversion.pkgv
280 last_pkgr = lastversion.pkgr
281 r = bb.utils.vercmp((pkge, pkgv, pkgr), (last_pkge, last_pkgv, last_pkgr))
282 if r < 0:
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500283 msg = "Package version for package %s went backwards which would break package feeds (from %s:%s-%s to %s:%s-%s)" % (pkg, last_pkge, last_pkgv, last_pkgr, pkge, pkgv, pkgr)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500284 package_qa_handle_error("version-going-backwards", msg, d)
285
286 pkginfo = PackageInfo(pkg)
287 # Apparently the version can be different on a per-package basis (see Python)
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500288 pkginfo.pe = localdata.getVar("PE") or '0'
289 pkginfo.pv = localdata.getVar("PV")
290 pkginfo.pr = localdata.getVar("PR")
291 pkginfo.pkg = localdata.getVar("PKG")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500292 pkginfo.pkge = pkge
293 pkginfo.pkgv = pkgv
294 pkginfo.pkgr = pkgr
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500295 pkginfo.rprovides = sortpkglist(oe.utils.squashspaces(localdata.getVar("RPROVIDES") or ""))
296 pkginfo.rdepends = sortpkglist(oe.utils.squashspaces(localdata.getVar("RDEPENDS") or ""))
297 pkginfo.rrecommends = sortpkglist(oe.utils.squashspaces(localdata.getVar("RRECOMMENDS") or ""))
298 pkginfo.rsuggests = sortpkglist(oe.utils.squashspaces(localdata.getVar("RSUGGESTS") or ""))
299 pkginfo.replaces = sortpkglist(oe.utils.squashspaces(localdata.getVar("RREPLACES") or ""))
300 pkginfo.rconflicts = sortpkglist(oe.utils.squashspaces(localdata.getVar("RCONFLICTS") or ""))
301 pkginfo.files = oe.utils.squashspaces(localdata.getVar("FILES") or "")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500302 for filevar in pkginfo.filevars:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500303 pkginfo.filevars[filevar] = localdata.getVar(filevar) or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500304
305 # Gather information about packaged files
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500306 val = localdata.getVar('FILES_INFO') or ''
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500307 dictval = json.loads(val)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600308 filelist = list(dictval.keys())
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500309 filelist.sort()
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800310 pkginfo.filelist = " ".join([shlex.quote(x) for x in filelist])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500311
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500312 pkginfo.size = int(localdata.getVar('PKGSIZE') or '0')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500313
314 write_pkghistory(pkginfo, d)
315
316 # Create files-in-<package-name>.txt files containing a list of files of each recipe's package
317 bb.build.exec_func("buildhistory_list_pkg_files", d)
318}
319
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500320python buildhistory_emit_outputsigs() {
321 if not "task" in (d.getVar('BUILDHISTORY_FEATURES') or "").split():
322 return
323
324 import hashlib
325
326 taskoutdir = os.path.join(d.getVar('BUILDHISTORY_DIR'), 'task', 'output')
327 bb.utils.mkdirhier(taskoutdir)
328 currenttask = d.getVar('BB_CURRENTTASK')
329 pn = d.getVar('PN')
330 taskfile = os.path.join(taskoutdir, '%s.%s' % (pn, currenttask))
331
332 cwd = os.getcwd()
333 filesigs = {}
334 for root, _, files in os.walk(cwd):
335 for fname in files:
336 if fname == 'fixmepath':
337 continue
338 fullpath = os.path.join(root, fname)
339 try:
340 if os.path.islink(fullpath):
341 sha256 = hashlib.sha256(os.readlink(fullpath).encode('utf-8')).hexdigest()
342 elif os.path.isfile(fullpath):
343 sha256 = bb.utils.sha256_file(fullpath)
344 else:
345 continue
346 except OSError:
347 bb.warn('buildhistory: unable to read %s to get output signature' % fullpath)
348 continue
349 filesigs[os.path.relpath(fullpath, cwd)] = sha256
350 with open(taskfile, 'w') as f:
351 for fpath, fsig in sorted(filesigs.items(), key=lambda item: item[0]):
352 f.write('%s %s\n' % (fpath, fsig))
353}
354
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500355
356def write_recipehistory(rcpinfo, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500357 bb.debug(2, "Writing recipe history")
358
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500359 pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500360
361 infofile = os.path.join(pkghistdir, "latest")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600362 with open(infofile, "w") as f:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500363 if rcpinfo.pe != "0":
364 f.write(u"PE = %s\n" % rcpinfo.pe)
365 f.write(u"PV = %s\n" % rcpinfo.pv)
366 f.write(u"PR = %s\n" % rcpinfo.pr)
367 f.write(u"DEPENDS = %s\n" % rcpinfo.depends)
368 f.write(u"PACKAGES = %s\n" % rcpinfo.packages)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500369 f.write(u"LAYER = %s\n" % rcpinfo.layer)
Andrew Geissler4ed12e12020-06-05 18:00:41 -0500370 f.write(u"CONFIG = %s\n" % rcpinfo.config)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500371
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500372 write_latest_srcrev(d, pkghistdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500373
374def write_pkghistory(pkginfo, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500375 bb.debug(2, "Writing package history for package %s" % pkginfo.name)
376
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500377 pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500378
379 pkgpath = os.path.join(pkghistdir, pkginfo.name)
380 if not os.path.exists(pkgpath):
381 bb.utils.mkdirhier(pkgpath)
382
383 infofile = os.path.join(pkgpath, "latest")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600384 with open(infofile, "w") as f:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500385 if pkginfo.pe != "0":
386 f.write(u"PE = %s\n" % pkginfo.pe)
387 f.write(u"PV = %s\n" % pkginfo.pv)
388 f.write(u"PR = %s\n" % pkginfo.pr)
389
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600390 if pkginfo.pkg != pkginfo.name:
391 f.write(u"PKG = %s\n" % pkginfo.pkg)
392 if pkginfo.pkge != pkginfo.pe:
393 f.write(u"PKGE = %s\n" % pkginfo.pkge)
394 if pkginfo.pkgv != pkginfo.pv:
395 f.write(u"PKGV = %s\n" % pkginfo.pkgv)
396 if pkginfo.pkgr != pkginfo.pr:
397 f.write(u"PKGR = %s\n" % pkginfo.pkgr)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500398 f.write(u"RPROVIDES = %s\n" % pkginfo.rprovides)
399 f.write(u"RDEPENDS = %s\n" % pkginfo.rdepends)
400 f.write(u"RRECOMMENDS = %s\n" % pkginfo.rrecommends)
401 if pkginfo.rsuggests:
402 f.write(u"RSUGGESTS = %s\n" % pkginfo.rsuggests)
403 if pkginfo.rreplaces:
404 f.write(u"RREPLACES = %s\n" % pkginfo.rreplaces)
405 if pkginfo.rconflicts:
406 f.write(u"RCONFLICTS = %s\n" % pkginfo.rconflicts)
407 f.write(u"PKGSIZE = %d\n" % pkginfo.size)
408 f.write(u"FILES = %s\n" % pkginfo.files)
409 f.write(u"FILELIST = %s\n" % pkginfo.filelist)
410
411 for filevar in pkginfo.filevars:
412 filevarpath = os.path.join(pkgpath, "latest.%s" % filevar)
413 val = pkginfo.filevars[filevar]
414 if val:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600415 with open(filevarpath, "w") as f:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500416 f.write(val)
417 else:
418 if os.path.exists(filevarpath):
419 os.unlink(filevarpath)
420
421#
422# rootfs_type can be: image, sdk_target, sdk_host
423#
424def buildhistory_list_installed(d, rootfs_type="image"):
425 from oe.rootfs import image_list_installed_packages
426 from oe.sdk import sdk_list_installed_packages
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500427 from oe.utils import format_pkg_list
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500428
Andrew Geissler635e0e42020-08-21 15:58:33 -0500429 process_list = [('file', 'bh_installed_pkgs_%s.txt' % os.getpid()),\
430 ('deps', 'bh_installed_pkgs_deps_%s.txt' % os.getpid())]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500431
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500432 if rootfs_type == "image":
433 pkgs = image_list_installed_packages(d)
434 else:
435 pkgs = sdk_list_installed_packages(d, rootfs_type == "sdk_target")
436
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500437 for output_type, output_file in process_list:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500438 output_file_full = os.path.join(d.getVar('WORKDIR'), output_file)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500439
440 with open(output_file_full, 'w') as output:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500441 output.write(format_pkg_list(pkgs, output_type))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500442
443python buildhistory_list_installed_image() {
444 buildhistory_list_installed(d)
445}
446
447python buildhistory_list_installed_sdk_target() {
448 buildhistory_list_installed(d, "sdk_target")
449}
450
451python buildhistory_list_installed_sdk_host() {
452 buildhistory_list_installed(d, "sdk_host")
453}
454
455buildhistory_get_installed() {
456 mkdir -p $1
457
458 # Get list of installed packages
459 pkgcache="$1/installed-packages.tmp"
Andrew Geissler635e0e42020-08-21 15:58:33 -0500460 cat ${WORKDIR}/bh_installed_pkgs_${PID}.txt | sort > $pkgcache && rm ${WORKDIR}/bh_installed_pkgs_${PID}.txt
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500461
462 cat $pkgcache | awk '{ print $1 }' > $1/installed-package-names.txt
Andrew Geissler635e0e42020-08-21 15:58:33 -0500463
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500464 if [ -s $pkgcache ] ; then
465 cat $pkgcache | awk '{ print $2 }' | xargs -n1 basename > $1/installed-packages.txt
466 else
467 printf "" > $1/installed-packages.txt
468 fi
469
470 # Produce dependency graph
471 # First, quote each name to handle characters that cause issues for dot
Andrew Geissler635e0e42020-08-21 15:58:33 -0500472 sed 's:\([^| ]*\):"\1":g' ${WORKDIR}/bh_installed_pkgs_deps_${PID}.txt > $1/depends.tmp &&
473 rm ${WORKDIR}/bh_installed_pkgs_deps_${PID}.txt
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500474 # Remove lines with rpmlib(...) and config(...) dependencies, change the
475 # delimiter from pipe to "->", set the style for recommend lines and
476 # turn versioned dependencies into edge labels.
477 sed -i -e '/rpmlib(/d' \
478 -e '/config(/d' \
479 -e 's:|: -> :' \
480 -e 's:"\[REC\]":[style=dotted]:' \
481 -e 's:"\([<>=]\+\)" "\([^"]*\)":[label="\1 \2"]:' \
482 $1/depends.tmp
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500483 # Add header, sorted and de-duped contents and footer and then delete the temp file
484 printf "digraph depends {\n node [shape=plaintext]\n" > $1/depends.dot
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500485 cat $1/depends.tmp | sort -u >> $1/depends.dot
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500486 echo "}" >> $1/depends.dot
487 rm $1/depends.tmp
488
489 # Produce installed package sizes list
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500490 oe-pkgdata-util -p ${PKGDATA_DIR} read-value "PKGSIZE" -n -f $pkgcache > $1/installed-package-sizes.tmp
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500491 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 -0500492 rm $1/installed-package-sizes.tmp
493
494 # We're now done with the cache, delete it
495 rm $pkgcache
496
497 if [ "$2" != "sdk" ] ; then
498 # Produce some cut-down graphs (for readability)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500499 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 -0500500 grep -v libc6 $1/depends-nokernel.dot | grep -v libgcc > $1/depends-nokernel-nolibc.dot
501 grep -v update- $1/depends-nokernel-nolibc.dot > $1/depends-nokernel-nolibc-noupdate.dot
502 grep -v kernel-module $1/depends-nokernel-nolibc-noupdate.dot > $1/depends-nokernel-nolibc-noupdate-nomodules.dot
503 fi
504
505 # add complementary package information
506 if [ -e ${WORKDIR}/complementary_pkgs.txt ]; then
507 cp ${WORKDIR}/complementary_pkgs.txt $1
508 fi
509}
510
511buildhistory_get_image_installed() {
512 # Anything requiring the use of the packaging system should be done in here
513 # in case the packaging files are going to be removed for this image
514
515 if [ "${@bb.utils.contains('BUILDHISTORY_FEATURES', 'image', '1', '0', d)}" = "0" ] ; then
516 return
517 fi
518
519 buildhistory_get_installed ${BUILDHISTORY_DIR_IMAGE}
520}
521
522buildhistory_get_sdk_installed() {
523 # Anything requiring the use of the packaging system should be done in here
524 # in case the packaging files are going to be removed for this SDK
525
526 if [ "${@bb.utils.contains('BUILDHISTORY_FEATURES', 'sdk', '1', '0', d)}" = "0" ] ; then
527 return
528 fi
529
530 buildhistory_get_installed ${BUILDHISTORY_DIR_SDK}/$1 sdk
531}
532
533buildhistory_get_sdk_installed_host() {
534 buildhistory_get_sdk_installed host
535}
536
537buildhistory_get_sdk_installed_target() {
538 buildhistory_get_sdk_installed target
539}
540
541buildhistory_list_files() {
542 # List the files in the specified directory, but exclude date/time etc.
Brad Bishop19323692019-04-05 15:28:33 -0400543 # This is somewhat messy, but handles where the size is not printed for device files under pseudo
544 ( cd $1
545 find_cmd='find . ! -path . -printf "%M %-10u %-10g %10s %p -> %l\n"'
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500546 if [ "$3" = "fakeroot" ] ; then
Brad Bishop19323692019-04-05 15:28:33 -0400547 eval ${FAKEROOTENV} ${FAKEROOTCMD} $find_cmd
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500548 else
Brad Bishop19323692019-04-05 15:28:33 -0400549 eval $find_cmd
550 fi | sort -k5 | sed 's/ * -> $//' > $2 )
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500551}
552
Brad Bishop96ff1982019-08-19 13:50:42 -0400553buildhistory_list_files_no_owners() {
554 # List the files in the specified directory, but exclude date/time etc.
555 # Also don't output the ownership data, but instead output just - - so
556 # that the same parsing code as for _list_files works.
557 # This is somewhat messy, but handles where the size is not printed for device files under pseudo
558 ( cd $1
559 find_cmd='find . ! -path . -printf "%M - - %10s %p -> %l\n"'
560 if [ "$3" = "fakeroot" ] ; then
561 eval ${FAKEROOTENV} ${FAKEROOTCMD} "$find_cmd"
562 else
563 eval "$find_cmd"
564 fi | sort -k5 | sed 's/ * -> $//' > $2 )
565}
566
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500567buildhistory_list_pkg_files() {
568 # Create individual files-in-package for each recipe's package
569 for pkgdir in $(find ${PKGDEST}/* -maxdepth 0 -type d); do
570 pkgname=$(basename $pkgdir)
571 outfolder="${BUILDHISTORY_DIR_PACKAGE}/$pkgname"
572 outfile="$outfolder/files-in-package.txt"
573 # Make sure the output folder exists so we can create the file
574 if [ ! -d $outfolder ] ; then
575 bbdebug 2 "Folder $outfolder does not exist, file $outfile not created"
576 continue
577 fi
578 buildhistory_list_files $pkgdir $outfile fakeroot
579 done
580}
581
582buildhistory_get_imageinfo() {
583 if [ "${@bb.utils.contains('BUILDHISTORY_FEATURES', 'image', '1', '0', d)}" = "0" ] ; then
584 return
585 fi
586
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500587 mkdir -p ${BUILDHISTORY_DIR_IMAGE}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500588 buildhistory_list_files ${IMAGE_ROOTFS} ${BUILDHISTORY_DIR_IMAGE}/files-in-image.txt
589
590 # Collect files requested in BUILDHISTORY_IMAGE_FILES
591 rm -rf ${BUILDHISTORY_DIR_IMAGE}/image-files
592 for f in ${BUILDHISTORY_IMAGE_FILES}; do
593 if [ -f ${IMAGE_ROOTFS}/$f ] ; then
594 mkdir -p ${BUILDHISTORY_DIR_IMAGE}/image-files/`dirname $f`
595 cp ${IMAGE_ROOTFS}/$f ${BUILDHISTORY_DIR_IMAGE}/image-files/$f
596 fi
597 done
598
599 # Record some machine-readable meta-information about the image
600 printf "" > ${BUILDHISTORY_DIR_IMAGE}/image-info.txt
601 cat >> ${BUILDHISTORY_DIR_IMAGE}/image-info.txt <<END
602${@buildhistory_get_imagevars(d)}
603END
604 imagesize=`du -ks ${IMAGE_ROOTFS} | awk '{ print $1 }'`
605 echo "IMAGESIZE = $imagesize" >> ${BUILDHISTORY_DIR_IMAGE}/image-info.txt
606
607 # Add some configuration information
608 echo "${MACHINE}: ${IMAGE_BASENAME} configured for ${DISTRO} ${DISTRO_VERSION}" > ${BUILDHISTORY_DIR_IMAGE}/build-id.txt
609
610 cat >> ${BUILDHISTORY_DIR_IMAGE}/build-id.txt <<END
611${@buildhistory_get_build_id(d)}
612END
613}
614
615buildhistory_get_sdkinfo() {
616 if [ "${@bb.utils.contains('BUILDHISTORY_FEATURES', 'sdk', '1', '0', d)}" = "0" ] ; then
617 return
618 fi
619
620 buildhistory_list_files ${SDK_OUTPUT} ${BUILDHISTORY_DIR_SDK}/files-in-sdk.txt
621
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500622 # Collect files requested in BUILDHISTORY_SDK_FILES
623 rm -rf ${BUILDHISTORY_DIR_SDK}/sdk-files
624 for f in ${BUILDHISTORY_SDK_FILES}; do
625 if [ -f ${SDK_OUTPUT}/${SDKPATH}/$f ] ; then
626 mkdir -p ${BUILDHISTORY_DIR_SDK}/sdk-files/`dirname $f`
627 cp ${SDK_OUTPUT}/${SDKPATH}/$f ${BUILDHISTORY_DIR_SDK}/sdk-files/$f
628 fi
629 done
630
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500631 # Record some machine-readable meta-information about the SDK
632 printf "" > ${BUILDHISTORY_DIR_SDK}/sdk-info.txt
633 cat >> ${BUILDHISTORY_DIR_SDK}/sdk-info.txt <<END
634${@buildhistory_get_sdkvars(d)}
635END
636 sdksize=`du -ks ${SDK_OUTPUT} | awk '{ print $1 }'`
637 echo "SDKSIZE = $sdksize" >> ${BUILDHISTORY_DIR_SDK}/sdk-info.txt
638}
639
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500640python buildhistory_get_extra_sdkinfo() {
641 import operator
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500642 from oe.sdk import get_extra_sdkinfo
643
644 sstate_dir = d.expand('${SDK_OUTPUT}/${SDKPATH}/sstate-cache')
645 extra_info = get_extra_sdkinfo(sstate_dir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500646
647 if d.getVar('BB_CURRENTTASK') == 'populate_sdk_ext' and \
648 "sdk" in (d.getVar('BUILDHISTORY_FEATURES') or "").split():
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500649 with open(d.expand('${BUILDHISTORY_DIR_SDK}/sstate-package-sizes.txt'), 'w') as f:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500650 filesizes_sorted = sorted(extra_info['filesizes'].items(), key=operator.itemgetter(1, 0), reverse=True)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500651 for fn, size in filesizes_sorted:
652 f.write('%10d KiB %s\n' % (size, fn))
653 with open(d.expand('${BUILDHISTORY_DIR_SDK}/sstate-task-sizes.txt'), 'w') as f:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500654 tasksizes_sorted = sorted(extra_info['tasksizes'].items(), key=operator.itemgetter(1, 0), reverse=True)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500655 for task, size in tasksizes_sorted:
656 f.write('%10d KiB %s\n' % (size, task))
657}
658
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500659# By using ROOTFS_POSTUNINSTALL_COMMAND we get in after uninstallation of
660# unneeded packages but before the removal of packaging files
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500661ROOTFS_POSTUNINSTALL_COMMAND += "buildhistory_list_installed_image ;"
662ROOTFS_POSTUNINSTALL_COMMAND += "buildhistory_get_image_installed ;"
663ROOTFS_POSTUNINSTALL_COMMAND[vardepvalueexclude] .= "| buildhistory_list_installed_image ;| buildhistory_get_image_installed ;"
664ROOTFS_POSTUNINSTALL_COMMAND[vardepsexclude] += "buildhistory_list_installed_image buildhistory_get_image_installed"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500665
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500666IMAGE_POSTPROCESS_COMMAND += "buildhistory_get_imageinfo ;"
667IMAGE_POSTPROCESS_COMMAND[vardepvalueexclude] .= "| buildhistory_get_imageinfo ;"
668IMAGE_POSTPROCESS_COMMAND[vardepsexclude] += "buildhistory_get_imageinfo"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500669
670# We want these to be the last run so that we get called after complementary package installation
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500671POPULATE_SDK_POST_TARGET_COMMAND_append = " buildhistory_list_installed_sdk_target;"
672POPULATE_SDK_POST_TARGET_COMMAND_append = " buildhistory_get_sdk_installed_target;"
673POPULATE_SDK_POST_TARGET_COMMAND[vardepvalueexclude] .= "| buildhistory_list_installed_sdk_target;| buildhistory_get_sdk_installed_target;"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500674
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500675POPULATE_SDK_POST_HOST_COMMAND_append = " buildhistory_list_installed_sdk_host;"
676POPULATE_SDK_POST_HOST_COMMAND_append = " buildhistory_get_sdk_installed_host;"
677POPULATE_SDK_POST_HOST_COMMAND[vardepvalueexclude] .= "| buildhistory_list_installed_sdk_host;| buildhistory_get_sdk_installed_host;"
678
679SDK_POSTPROCESS_COMMAND_append = " buildhistory_get_sdkinfo ; buildhistory_get_extra_sdkinfo; "
680SDK_POSTPROCESS_COMMAND[vardepvalueexclude] .= "| buildhistory_get_sdkinfo ; buildhistory_get_extra_sdkinfo; "
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500681
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500682python buildhistory_write_sigs() {
683 if not "task" in (d.getVar('BUILDHISTORY_FEATURES') or "").split():
684 return
685
686 # Create sigs file
687 if hasattr(bb.parse.siggen, 'dump_siglist'):
688 taskoutdir = os.path.join(d.getVar('BUILDHISTORY_DIR'), 'task')
689 bb.utils.mkdirhier(taskoutdir)
690 bb.parse.siggen.dump_siglist(os.path.join(taskoutdir, 'tasksigs.txt'))
691}
692
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500693def buildhistory_get_build_id(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500694 if d.getVar('BB_WORKERCONTEXT') != '1':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500695 return ""
696 localdata = bb.data.createCopy(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500697 statuslines = []
698 for func in oe.data.typed_value('BUILDCFG_FUNCS', localdata):
699 g = globals()
700 if func not in g:
701 bb.warn("Build configuration function '%s' does not exist" % func)
702 else:
703 flines = g[func](localdata)
704 if flines:
705 statuslines.extend(flines)
706
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500707 statusheader = d.getVar('BUILDCFG_HEADER')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500708 return('\n%s\n%s\n' % (statusheader, '\n'.join(statuslines)))
709
Brad Bishop19323692019-04-05 15:28:33 -0400710def buildhistory_get_modified(path):
711 # copied from get_layer_git_status() in image-buildinfo.bbclass
712 import subprocess
713 try:
714 subprocess.check_output("""cd %s; export PSEUDO_UNLOAD=1; set -e;
715 git diff --quiet --no-ext-diff
716 git diff --quiet --no-ext-diff --cached""" % path,
717 shell=True,
718 stderr=subprocess.STDOUT)
719 return ""
720 except subprocess.CalledProcessError as ex:
721 # Silently treat errors as "modified", without checking for the
722 # (expected) return code 1 in a modified git repo. For example, we get
723 # output and a 129 return code when a layer isn't a git repo at all.
724 return " -- modified"
725
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500726def buildhistory_get_metadata_revs(d):
727 # 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 -0500728 layers = (d.getVar("BBLAYERS") or "").split()
Brad Bishop19323692019-04-05 15:28:33 -0400729 medadata_revs = ["%-17s = %s:%s%s" % (os.path.basename(i), \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500730 base_get_metadata_git_branch(i, None).strip(), \
Brad Bishop19323692019-04-05 15:28:33 -0400731 base_get_metadata_git_revision(i, None), \
732 buildhistory_get_modified(i)) \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500733 for i in layers]
734 return '\n'.join(medadata_revs)
735
736def outputvars(vars, listvars, d):
737 vars = vars.split()
738 listvars = listvars.split()
739 ret = ""
740 for var in vars:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500741 value = d.getVar(var) or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500742 if var in listvars:
743 # Squash out spaces
744 value = oe.utils.squashspaces(value)
745 ret += "%s = %s\n" % (var, value)
746 return ret.rstrip('\n')
747
748def buildhistory_get_imagevars(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500749 if d.getVar('BB_WORKERCONTEXT') != '1':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500750 return ""
751 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"
752 listvars = "USER_CLASSES IMAGE_CLASSES IMAGE_FEATURES IMAGE_LINGUAS IMAGE_INSTALL BAD_RECOMMENDATIONS PACKAGE_EXCLUDE"
753 return outputvars(imagevars, listvars, d)
754
755def buildhistory_get_sdkvars(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500756 if d.getVar('BB_WORKERCONTEXT') != '1':
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500757 return ""
758 sdkvars = "DISTRO DISTRO_VERSION SDK_NAME SDK_VERSION SDKMACHINE SDKIMAGE_FEATURES BAD_RECOMMENDATIONS NO_RECOMMENDATIONS PACKAGE_EXCLUDE"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500759 if d.getVar('BB_CURRENTTASK') == 'populate_sdk_ext':
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500760 # Extensible SDK uses some additional variables
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600761 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 -0500762 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 -0500763 return outputvars(sdkvars, listvars, d)
764
765
766def buildhistory_get_cmdline(d):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500767 argv = d.getVar('BB_CMDLINE', False)
768 if argv:
769 if argv[0].endswith('bin/bitbake'):
770 bincmd = 'bitbake'
771 else:
772 bincmd = argv[0]
773 return '%s %s' % (bincmd, ' '.join(argv[1:]))
774 return ''
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500775
776
777buildhistory_single_commit() {
778 if [ "$3" = "" ] ; then
779 commitopts="${BUILDHISTORY_DIR}/ --allow-empty"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500780 shortlogprefix="No changes: "
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500781 else
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500782 commitopts=""
783 shortlogprefix=""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500784 fi
785 if [ "${BUILDHISTORY_BUILD_FAILURES}" = "0" ] ; then
786 result="succeeded"
787 else
788 result="failed"
789 fi
790 case ${BUILDHISTORY_BUILD_INTERRUPTED} in
791 1)
792 result="$result (interrupted)"
793 ;;
794 2)
795 result="$result (force interrupted)"
796 ;;
797 esac
798 commitmsgfile=`mktemp`
799 cat > $commitmsgfile << END
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500800${shortlogprefix}Build ${BUILDNAME} of ${DISTRO} ${DISTRO_VERSION} for machine ${MACHINE} on $2
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500801
802cmd: $1
803
804result: $result
805
806metadata revisions:
807END
808 cat ${BUILDHISTORY_DIR}/metadata-revs >> $commitmsgfile
809 git commit $commitopts -F $commitmsgfile --author "${BUILDHISTORY_COMMIT_AUTHOR}" > /dev/null
810 rm $commitmsgfile
811}
812
813buildhistory_commit() {
814 if [ ! -d ${BUILDHISTORY_DIR} ] ; then
815 # Code above that creates this dir never executed, so there can't be anything to commit
816 return
817 fi
818
819 # Create a machine-readable list of metadata revisions for each layer
820 cat > ${BUILDHISTORY_DIR}/metadata-revs <<END
821${@buildhistory_get_metadata_revs(d)}
822END
823
824 ( cd ${BUILDHISTORY_DIR}/
825 # Initialise the repo if necessary
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500826 if [ ! -e .git ] ; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500827 git init -q
828 else
Andrew Geissler82c905d2020-04-13 13:39:40 -0500829 git tag -f ${BUILDHISTORY_TAG}-minus-3 ${BUILDHISTORY_TAG}-minus-2 > /dev/null 2>&1 || true
830 git tag -f ${BUILDHISTORY_TAG}-minus-2 ${BUILDHISTORY_TAG}-minus-1 > /dev/null 2>&1 || true
831 git tag -f ${BUILDHISTORY_TAG}-minus-1 > /dev/null 2>&1 || true
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500832 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600833
834 check_git_config
835
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500836 # Check if there are new/changed files to commit (other than metadata-revs)
837 repostatus=`git status --porcelain | grep -v " metadata-revs$"`
838 HOSTNAME=`hostname 2>/dev/null || echo unknown`
839 CMDLINE="${@buildhistory_get_cmdline(d)}"
840 if [ "$repostatus" != "" ] ; then
841 git add -A .
842 # porcelain output looks like "?? packages/foo/bar"
843 # Ensure we commit metadata-revs with the first commit
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500844 buildhistory_single_commit "$CMDLINE" "$HOSTNAME" dummy
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500845 git gc --auto --quiet
846 else
847 buildhistory_single_commit "$CMDLINE" "$HOSTNAME"
848 fi
849 if [ "${BUILDHISTORY_PUSH_REPO}" != "" ] ; then
850 git push -q ${BUILDHISTORY_PUSH_REPO}
851 fi) || true
852}
853
854python buildhistory_eventhandler() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500855 if e.data.getVar('BUILDHISTORY_FEATURES').strip():
856 reset = e.data.getVar("BUILDHISTORY_RESET")
857 olddir = e.data.getVar("BUILDHISTORY_OLD_DIR")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500858 if isinstance(e, bb.event.BuildStarted):
859 if reset:
860 import shutil
861 # Clean up after potentially interrupted build.
862 if os.path.isdir(olddir):
863 shutil.rmtree(olddir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500864 rootdir = e.data.getVar("BUILDHISTORY_DIR")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500865 entries = [ x for x in os.listdir(rootdir) if not x.startswith('.') ]
866 bb.utils.mkdirhier(olddir)
867 for entry in entries:
868 os.rename(os.path.join(rootdir, entry),
869 os.path.join(olddir, entry))
870 elif isinstance(e, bb.event.BuildCompleted):
871 if reset:
872 import shutil
873 shutil.rmtree(olddir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500874 if e.data.getVar("BUILDHISTORY_COMMIT") == "1":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500875 bb.note("Writing buildhistory")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500876 bb.build.exec_func("buildhistory_write_sigs", d)
Brad Bishopf3fd2882019-06-21 08:06:37 -0400877 import time
878 start=time.time()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500879 localdata = bb.data.createCopy(e.data)
880 localdata.setVar('BUILDHISTORY_BUILD_FAILURES', str(e._failures))
881 interrupted = getattr(e, '_interrupted', 0)
882 localdata.setVar('BUILDHISTORY_BUILD_INTERRUPTED', str(interrupted))
883 bb.build.exec_func("buildhistory_commit", localdata)
Brad Bishopf3fd2882019-06-21 08:06:37 -0400884 stop=time.time()
885 bb.note("Writing buildhistory took: %s seconds" % round(stop-start))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500886 else:
887 bb.note("No commit since BUILDHISTORY_COMMIT != '1'")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500888}
889
890addhandler buildhistory_eventhandler
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500891buildhistory_eventhandler[eventmask] = "bb.event.BuildCompleted bb.event.BuildStarted"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500892
893
894# FIXME this ought to be moved into the fetcher
895def _get_srcrev_values(d):
896 """
897 Return the version strings for the current recipe
898 """
899
900 scms = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500901 fetcher = bb.fetch.Fetch(d.getVar('SRC_URI').split(), d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500902 urldata = fetcher.ud
903 for u in urldata:
904 if urldata[u].method.supports_srcrev():
905 scms.append(u)
906
907 autoinc_templ = 'AUTOINC+'
908 dict_srcrevs = {}
909 dict_tag_srcrevs = {}
910 for scm in scms:
911 ud = urldata[scm]
912 for name in ud.names:
913 try:
914 rev = ud.method.sortable_revision(ud, d, name)
915 except TypeError:
916 # support old bitbake versions
917 rev = ud.method.sortable_revision(scm, ud, d, name)
918 # Clean this up when we next bump bitbake version
919 if type(rev) != str:
920 autoinc, rev = rev
921 elif rev.startswith(autoinc_templ):
922 rev = rev[len(autoinc_templ):]
923 dict_srcrevs[name] = rev
924 if 'tag' in ud.parm:
925 tag = ud.parm['tag'];
926 key = name+'_'+tag
927 dict_tag_srcrevs[key] = rev
928 return (dict_srcrevs, dict_tag_srcrevs)
929
930do_fetch[postfuncs] += "write_srcrev"
931do_fetch[vardepsexclude] += "write_srcrev"
932python write_srcrev() {
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500933 write_latest_srcrev(d, d.getVar('BUILDHISTORY_DIR_PACKAGE'))
934}
935
936def write_latest_srcrev(d, pkghistdir):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500937 srcrevfile = os.path.join(pkghistdir, 'latest_srcrev')
938
939 srcrevs, tag_srcrevs = _get_srcrev_values(d)
940 if srcrevs:
941 if not os.path.exists(pkghistdir):
942 bb.utils.mkdirhier(pkghistdir)
943 old_tag_srcrevs = {}
944 if os.path.exists(srcrevfile):
945 with open(srcrevfile) as f:
946 for line in f:
947 if line.startswith('# tag_'):
948 key, value = line.split("=", 1)
949 key = key.replace('# tag_', '').strip()
950 value = value.replace('"', '').strip()
951 old_tag_srcrevs[key] = value
952 with open(srcrevfile, 'w') as f:
953 orig_srcrev = d.getVar('SRCREV', False) or 'INVALID'
954 if orig_srcrev != 'INVALID':
955 f.write('# SRCREV = "%s"\n' % orig_srcrev)
956 if len(srcrevs) > 1:
Brad Bishop19323692019-04-05 15:28:33 -0400957 for name, srcrev in sorted(srcrevs.items()):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500958 orig_srcrev = d.getVar('SRCREV_%s' % name, False)
959 if orig_srcrev:
960 f.write('# SRCREV_%s = "%s"\n' % (name, orig_srcrev))
961 f.write('SRCREV_%s = "%s"\n' % (name, srcrev))
962 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500963 f.write('SRCREV = "%s"\n' % next(iter(srcrevs.values())))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500964 if len(tag_srcrevs) > 0:
Brad Bishop19323692019-04-05 15:28:33 -0400965 for name, srcrev in sorted(tag_srcrevs.items()):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500966 f.write('# tag_%s = "%s"\n' % (name, srcrev))
967 if name in old_tag_srcrevs and old_tag_srcrevs[name] != srcrev:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500968 pkg = d.getVar('PN')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500969 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))
970
971 else:
972 if os.path.exists(srcrevfile):
973 os.remove(srcrevfile)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500974
975do_testimage[postfuncs] += "write_ptest_result"
976do_testimage[vardepsexclude] += "write_ptest_result"
977
978python write_ptest_result() {
979 write_latest_ptest_result(d, d.getVar('BUILDHISTORY_DIR'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500980}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500981
982def write_latest_ptest_result(d, histdir):
983 import glob
984 import subprocess
985 test_log_dir = d.getVar('TEST_LOG_DIR')
986 input_ptest = os.path.join(test_log_dir, 'ptest_log')
987 output_ptest = os.path.join(histdir, 'ptest')
988 if os.path.exists(input_ptest):
989 try:
990 # Lock it avoid race issue
991 lock = bb.utils.lockfile(output_ptest + "/ptest.lock")
992 bb.utils.mkdirhier(output_ptest)
993 oe.path.copytree(input_ptest, output_ptest)
994 # Sort test result
995 for result in glob.glob('%s/pass.fail.*' % output_ptest):
996 bb.debug(1, 'Processing %s' % result)
997 cmd = ['sort', result, '-o', result]
998 bb.debug(1, 'Running %s' % cmd)
999 ret = subprocess.call(cmd)
1000 if ret != 0:
1001 bb.error('Failed to run %s!' % cmd)
1002 finally:
1003 bb.utils.unlockfile(lock)