buildhistory.bbclass 39 KB

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