buildhistory.bbclass 38 KB

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