buildhistory.bbclass 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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) 2013 Intel Corporation
  7. # Copyright (C) 2007-2011 Koen Kooi <koen@openembedded.org>
  8. #
  9. BUILDHISTORY_FEATURES ?= "image package sdk"
  10. BUILDHISTORY_DIR ?= "${TOPDIR}/buildhistory"
  11. BUILDHISTORY_DIR_IMAGE = "${BUILDHISTORY_DIR}/images/${MACHINE_ARCH}/${TCLIBC}/${IMAGE_BASENAME}"
  12. BUILDHISTORY_DIR_PACKAGE = "${BUILDHISTORY_DIR}/packages/${MULTIMACH_TARGET_SYS}/${PN}"
  13. BUILDHISTORY_DIR_SDK = "${BUILDHISTORY_DIR}/sdk/${SDK_NAME}/${IMAGE_BASENAME}"
  14. BUILDHISTORY_IMAGE_FILES ?= "/etc/passwd /etc/group"
  15. BUILDHISTORY_COMMIT ?= "0"
  16. BUILDHISTORY_COMMIT_AUTHOR ?= "buildhistory <buildhistory@${DISTRO}>"
  17. BUILDHISTORY_PUSH_REPO ?= ""
  18. # Must inherit package first before changing PACKAGEFUNCS
  19. inherit package
  20. PACKAGEFUNCS += "buildhistory_emit_pkghistory"
  21. # We don't want to force a rerun of do_package for everything
  22. # if the buildhistory_emit_pkghistory function or any of the
  23. # variables it refers to changes
  24. do_package[vardepsexclude] += "buildhistory_emit_pkghistory"
  25. #
  26. # Called during do_package to write out metadata about this package
  27. # for comparision when writing future packages
  28. #
  29. python buildhistory_emit_pkghistory() {
  30. import re
  31. if not "package" in (d.getVar('BUILDHISTORY_FEATURES', True) or "").split():
  32. return 0
  33. pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True)
  34. class RecipeInfo:
  35. def __init__(self, name):
  36. self.name = name
  37. self.pe = "0"
  38. self.pv = "0"
  39. self.pr = "r0"
  40. self.depends = ""
  41. self.packages = ""
  42. self.bbfile = ""
  43. self.src_uri = ""
  44. self.srcrev = ""
  45. self.srcrev_autorev = ""
  46. class PackageInfo:
  47. def __init__(self, name):
  48. self.name = name
  49. self.pe = "0"
  50. self.pv = "0"
  51. self.pr = "r0"
  52. # pkg/pkge/pkgv/pkgr should be empty because we want to be able to default them
  53. self.pkg = ""
  54. self.pkge = ""
  55. self.pkgv = ""
  56. self.pkgr = ""
  57. self.size = 0
  58. self.depends = ""
  59. self.rprovides = ""
  60. self.rdepends = ""
  61. self.rrecommends = ""
  62. self.rsuggests = ""
  63. self.rreplaces = ""
  64. self.rconflicts = ""
  65. self.files = ""
  66. self.filelist = ""
  67. # Variables that need to be written to their own separate file
  68. self.filevars = dict.fromkeys(['pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm'])
  69. # Should check PACKAGES here to see if anything removed
  70. def getpkgvar(pkg, var):
  71. val = bb.data.getVar('%s_%s' % (var, pkg), d, 1)
  72. if val:
  73. return val
  74. val = bb.data.getVar('%s' % (var), d, 1)
  75. return val
  76. def readPackageInfo(pkg, histfile):
  77. pkginfo = PackageInfo(pkg)
  78. with open(histfile, "r") as f:
  79. for line in f:
  80. lns = line.split('=')
  81. name = lns[0].strip()
  82. value = lns[1].strip(" \t\r\n").strip('"')
  83. if name == "PE":
  84. pkginfo.pe = value
  85. elif name == "PV":
  86. pkginfo.pv = value
  87. elif name == "PR":
  88. pkginfo.pr = value
  89. elif name == "PKG":
  90. pkginfo.pkg = value
  91. elif name == "PKGE":
  92. pkginfo.pkge = value
  93. elif name == "PKGV":
  94. pkginfo.pkgv = value
  95. elif name == "PKGR":
  96. pkginfo.pkgr = value
  97. elif name == "RPROVIDES":
  98. pkginfo.rprovides = value
  99. elif name == "RDEPENDS":
  100. pkginfo.rdepends = value
  101. elif name == "RRECOMMENDS":
  102. pkginfo.rrecommends = value
  103. elif name == "RSUGGESTS":
  104. pkginfo.rsuggests = value
  105. elif name == "RREPLACES":
  106. pkginfo.rreplaces = value
  107. elif name == "RCONFLICTS":
  108. pkginfo.rconflicts = value
  109. elif name == "PKGSIZE":
  110. pkginfo.size = long(value)
  111. elif name == "FILES":
  112. pkginfo.files = value
  113. elif name == "FILELIST":
  114. pkginfo.filelist = value
  115. # Apply defaults
  116. if not pkginfo.pkg:
  117. pkginfo.pkg = pkginfo.name
  118. if not pkginfo.pkge:
  119. pkginfo.pkge = pkginfo.pe
  120. if not pkginfo.pkgv:
  121. pkginfo.pkgv = pkginfo.pv
  122. if not pkginfo.pkgr:
  123. pkginfo.pkgr = pkginfo.pr
  124. return pkginfo
  125. def getlastpkgversion(pkg):
  126. try:
  127. histfile = os.path.join(pkghistdir, pkg, "latest")
  128. return readPackageInfo(pkg, histfile)
  129. except EnvironmentError:
  130. return None
  131. def sortpkglist(string):
  132. pkgiter = re.finditer(r'[a-zA-Z0-9.+-]+( \([><=]+ [^ )]+\))?', string, 0)
  133. pkglist = [p.group(0) for p in pkgiter]
  134. pkglist.sort()
  135. return ' '.join(pkglist)
  136. def sortlist(string):
  137. items = string.split(' ')
  138. items.sort()
  139. return ' '.join(items)
  140. pn = d.getVar('PN', True)
  141. pe = d.getVar('PE', True) or "0"
  142. pv = d.getVar('PV', True)
  143. pr = d.getVar('PR', True)
  144. bbfile = d.getVar('BB_FILENAME', True)
  145. src_uri = d.getVar('SRC_URI', True)
  146. srcrev = d.getVar('SRCREV', True)
  147. srcrev_autorev = 'yes' if d.getVar('SRCREV', False) == 'AUTOINC' else 'no'
  148. packages = squashspaces(d.getVar('PACKAGES', True))
  149. packagelist = packages.split()
  150. if not os.path.exists(pkghistdir):
  151. bb.utils.mkdirhier(pkghistdir)
  152. else:
  153. # Remove files for packages that no longer exist
  154. for item in os.listdir(pkghistdir):
  155. if item != "latest" and item != "latest_srcrev":
  156. if item not in packagelist:
  157. subdir = os.path.join(pkghistdir, item)
  158. for subfile in os.listdir(subdir):
  159. os.unlink(os.path.join(subdir, subfile))
  160. os.rmdir(subdir)
  161. rcpinfo = RecipeInfo(pn)
  162. rcpinfo.pe = pe
  163. rcpinfo.pv = pv
  164. rcpinfo.pr = pr
  165. rcpinfo.depends = sortlist(squashspaces(d.getVar('DEPENDS', True) or ""))
  166. rcpinfo.bbfile = bbfile
  167. rcpinfo.src_uri = src_uri
  168. rcpinfo.srcrev = srcrev
  169. rcpinfo.srcrev_autorev = srcrev_autorev
  170. rcpinfo.packages = packages
  171. write_recipehistory(rcpinfo, d)
  172. pkgdest = d.getVar('PKGDEST', True)
  173. for pkg in packagelist:
  174. pkge = getpkgvar(pkg, 'PKGE') or "0"
  175. pkgv = getpkgvar(pkg, 'PKGV')
  176. pkgr = getpkgvar(pkg, 'PKGR')
  177. #
  178. # Find out what the last version was
  179. # Make sure the version did not decrease
  180. #
  181. lastversion = getlastpkgversion(pkg)
  182. if lastversion:
  183. last_pkge = lastversion.pkge
  184. last_pkgv = lastversion.pkgv
  185. last_pkgr = lastversion.pkgr
  186. r = bb.utils.vercmp((pkge, pkgv, pkgr), (last_pkge, last_pkgv, last_pkgr))
  187. if r < 0:
  188. 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)
  189. package_qa_handle_error("version-going-backwards", msg, d)
  190. pkginfo = PackageInfo(pkg)
  191. # Apparently the version can be different on a per-package basis (see Python)
  192. pkginfo.pe = getpkgvar(pkg, 'PE') or "0"
  193. pkginfo.pv = getpkgvar(pkg, 'PV')
  194. pkginfo.pr = getpkgvar(pkg, 'PR')
  195. pkginfo.pkg = getpkgvar(pkg, 'PKG') or pkg
  196. pkginfo.pkge = pkge
  197. pkginfo.pkgv = pkgv
  198. pkginfo.pkgr = pkgr
  199. pkginfo.rprovides = sortpkglist(squashspaces(getpkgvar(pkg, 'RPROVIDES') or ""))
  200. pkginfo.rdepends = sortpkglist(squashspaces(getpkgvar(pkg, 'RDEPENDS') or ""))
  201. pkginfo.rrecommends = sortpkglist(squashspaces(getpkgvar(pkg, 'RRECOMMENDS') or ""))
  202. pkginfo.rsuggests = sortpkglist(squashspaces(getpkgvar(pkg, 'RSUGGESTS') or ""))
  203. pkginfo.rreplaces = sortpkglist(squashspaces(getpkgvar(pkg, 'RREPLACES') or ""))
  204. pkginfo.rconflicts = sortpkglist(squashspaces(getpkgvar(pkg, 'RCONFLICTS') or ""))
  205. pkginfo.files = squashspaces(getpkgvar(pkg, 'FILES') or "")
  206. for filevar in pkginfo.filevars:
  207. pkginfo.filevars[filevar] = getpkgvar(pkg, filevar)
  208. # Gather information about packaged files
  209. pkgdestpkg = os.path.join(pkgdest, pkg)
  210. filelist = []
  211. pkginfo.size = 0
  212. for f in pkgfiles[pkg]:
  213. relpth = os.path.relpath(f, pkgdestpkg)
  214. fstat = os.lstat(f)
  215. pkginfo.size += fstat.st_size
  216. filelist.append(os.sep + relpth)
  217. filelist.sort()
  218. pkginfo.filelist = " ".join(filelist)
  219. write_pkghistory(pkginfo, d)
  220. }
  221. def write_recipehistory(rcpinfo, d):
  222. bb.debug(2, "Writing recipe history")
  223. pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True)
  224. infofile = os.path.join(pkghistdir, "latest")
  225. with open(infofile, "w") as f:
  226. if rcpinfo.pe != "0":
  227. f.write("PE = %s\n" % rcpinfo.pe)
  228. f.write("PV = %s\n" % rcpinfo.pv)
  229. f.write("PR = %s\n" % rcpinfo.pr)
  230. f.write("DEPENDS = %s\n" % rcpinfo.depends)
  231. f.write("PACKAGES = %s\n" % rcpinfo.packages)
  232. def write_pkghistory(pkginfo, d):
  233. bb.debug(2, "Writing package history for package %s" % pkginfo.name)
  234. pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True)
  235. pkgpath = os.path.join(pkghistdir, pkginfo.name)
  236. if not os.path.exists(pkgpath):
  237. bb.utils.mkdirhier(pkgpath)
  238. infofile = os.path.join(pkgpath, "latest")
  239. with open(infofile, "w") as f:
  240. if pkginfo.pe != "0":
  241. f.write("PE = %s\n" % pkginfo.pe)
  242. f.write("PV = %s\n" % pkginfo.pv)
  243. f.write("PR = %s\n" % pkginfo.pr)
  244. pkgvars = {}
  245. pkgvars['PKG'] = pkginfo.pkg if pkginfo.pkg != pkginfo.name else ''
  246. pkgvars['PKGE'] = pkginfo.pkge if pkginfo.pkge != pkginfo.pe else ''
  247. pkgvars['PKGV'] = pkginfo.pkgv if pkginfo.pkgv != pkginfo.pv else ''
  248. pkgvars['PKGR'] = pkginfo.pkgr if pkginfo.pkgr != pkginfo.pr else ''
  249. for pkgvar in pkgvars:
  250. val = pkgvars[pkgvar]
  251. if val:
  252. f.write("%s = %s\n" % (pkgvar, val))
  253. f.write("RPROVIDES = %s\n" % pkginfo.rprovides)
  254. f.write("RDEPENDS = %s\n" % pkginfo.rdepends)
  255. f.write("RRECOMMENDS = %s\n" % pkginfo.rrecommends)
  256. if pkginfo.rsuggests:
  257. f.write("RSUGGESTS = %s\n" % pkginfo.rsuggests)
  258. if pkginfo.rreplaces:
  259. f.write("RREPLACES = %s\n" % pkginfo.rreplaces)
  260. if pkginfo.rconflicts:
  261. f.write("RCONFLICTS = %s\n" % pkginfo.rconflicts)
  262. f.write("PKGSIZE = %d\n" % pkginfo.size)
  263. f.write("FILES = %s\n" % pkginfo.files)
  264. f.write("FILELIST = %s\n" % pkginfo.filelist)
  265. for filevar in pkginfo.filevars:
  266. filevarpath = os.path.join(pkgpath, "latest.%s" % filevar)
  267. val = pkginfo.filevars[filevar]
  268. if val:
  269. with open(filevarpath, "w") as f:
  270. f.write(val)
  271. else:
  272. if os.path.exists(filevarpath):
  273. os.unlink(filevarpath)
  274. buildhistory_get_installed() {
  275. mkdir -p $1
  276. # Get list of installed packages
  277. pkgcache="$1/installed-packages.tmp"
  278. list_installed_packages file | sort > $pkgcache
  279. cat $pkgcache | awk '{ print $1 }' > $1/installed-package-names.txt
  280. if [ -s $pkgcache ] ; then
  281. cat $pkgcache | awk '{ print $2 }' | xargs -n1 basename > $1/installed-packages.txt
  282. else
  283. printf "" > $1/installed-packages.txt
  284. fi
  285. # Produce dependency graph
  286. # First, filter out characters that cause issues for dot
  287. rootfs_list_installed_depends | sed -e 's:-:_:g' -e 's:\.:_:g' -e 's:+::g' > $1/depends.tmp
  288. # Change delimiter from pipe to -> and set style for recommend lines
  289. sed -i -e 's:|: -> :' -e 's:\[REC\]:[style=dotted]:' -e 's:$:;:' $1/depends.tmp
  290. # Add header, sorted and de-duped contents and footer and then delete the temp file
  291. printf "digraph depends {\n node [shape=plaintext]\n" > $1/depends.dot
  292. cat $1/depends.tmp | sort | uniq >> $1/depends.dot
  293. echo "}" >> $1/depends.dot
  294. rm $1/depends.tmp
  295. # Produce installed package sizes list
  296. printf "" > $1/installed-package-sizes.tmp
  297. cat $pkgcache | while read pkg pkgfile pkgarch
  298. do
  299. for vendor in ${TARGET_VENDOR} ${MULTILIB_VENDORS} ; do
  300. size=`oe-pkgdata-util read-value ${TMPDIR}/pkgdata $vendor-${TARGET_OS} "PKGSIZE" ${pkg}_${pkgarch}`
  301. if [ "$size" != "" ] ; then
  302. echo "$size $pkg" >> $1/installed-package-sizes.tmp
  303. fi
  304. done
  305. done
  306. cat $1/installed-package-sizes.tmp | sort -n -r | awk '{print $1 "\tKiB " $2}' > $1/installed-package-sizes.txt
  307. rm $1/installed-package-sizes.tmp
  308. # We're now done with the cache, delete it
  309. rm $pkgcache
  310. if [ "$2" != "sdk" ] ; then
  311. # Produce some cut-down graphs (for readability)
  312. grep -v kernel_image $1/depends.dot | grep -v kernel_2 | grep -v kernel_3 > $1/depends-nokernel.dot
  313. grep -v libc6 $1/depends-nokernel.dot | grep -v libgcc > $1/depends-nokernel-nolibc.dot
  314. grep -v update_ $1/depends-nokernel-nolibc.dot > $1/depends-nokernel-nolibc-noupdate.dot
  315. grep -v kernel_module $1/depends-nokernel-nolibc-noupdate.dot > $1/depends-nokernel-nolibc-noupdate-nomodules.dot
  316. fi
  317. # add complementary package information
  318. if [ -e ${WORKDIR}/complementary_pkgs.txt ]; then
  319. cp ${WORKDIR}/complementary_pkgs.txt $1
  320. fi
  321. }
  322. buildhistory_get_image_installed() {
  323. # Anything requiring the use of the packaging system should be done in here
  324. # in case the packaging files are going to be removed for this image
  325. if [ "${@base_contains('BUILDHISTORY_FEATURES', 'image', '1', '0', d)}" = "0" ] ; then
  326. return
  327. fi
  328. buildhistory_get_installed ${BUILDHISTORY_DIR_IMAGE}
  329. }
  330. buildhistory_get_sdk_installed() {
  331. # Anything requiring the use of the packaging system should be done in here
  332. # in case the packaging files are going to be removed for this SDK
  333. if [ "${@base_contains('BUILDHISTORY_FEATURES', 'sdk', '1', '0', d)}" = "0" ] ; then
  334. return
  335. fi
  336. buildhistory_get_installed ${BUILDHISTORY_DIR_SDK}/$1 sdk
  337. }
  338. buildhistory_list_files() {
  339. # List the files in the specified directory, but exclude date/time etc.
  340. # This awk script is somewhat messy, but handles where the size is not printed for device files under pseudo
  341. ( cd $1 && find . -ls | awk '{ if ( $7 ~ /[0-9]/ ) printf "%s %10-s %10-s %10s %s %s %s\n", $3, $5, $6, $7, $11, $12, $13 ; else printf "%s %10-s %10-s %10s %s %s %s\n", $3, $5, $6, 0, $10, $11, $12 }' | sort -k5 | sed 's/ *$//' > $2 )
  342. }
  343. buildhistory_get_imageinfo() {
  344. if [ "${@base_contains('BUILDHISTORY_FEATURES', 'image', '1', '0', d)}" = "0" ] ; then
  345. return
  346. fi
  347. buildhistory_list_files ${IMAGE_ROOTFS} ${BUILDHISTORY_DIR_IMAGE}/files-in-image.txt
  348. # Collect files requested in BUILDHISTORY_IMAGE_FILES
  349. rm -rf ${BUILDHISTORY_DIR_IMAGE}/image-files
  350. for f in ${BUILDHISTORY_IMAGE_FILES}; do
  351. if [ -f ${IMAGE_ROOTFS}/$f ] ; then
  352. mkdir -p ${BUILDHISTORY_DIR_IMAGE}/image-files/`dirname $f`
  353. cp ${IMAGE_ROOTFS}/$f ${BUILDHISTORY_DIR_IMAGE}/image-files/$f
  354. fi
  355. done
  356. # Record some machine-readable meta-information about the image
  357. printf "" > ${BUILDHISTORY_DIR_IMAGE}/image-info.txt
  358. cat >> ${BUILDHISTORY_DIR_IMAGE}/image-info.txt <<END
  359. ${@buildhistory_get_imagevars(d)}
  360. END
  361. imagesize=`du -ks ${IMAGE_ROOTFS} | awk '{ print $1 }'`
  362. echo "IMAGESIZE = $imagesize" >> ${BUILDHISTORY_DIR_IMAGE}/image-info.txt
  363. # Add some configuration information
  364. echo "${MACHINE}: ${IMAGE_BASENAME} configured for ${DISTRO} ${DISTRO_VERSION}" > ${BUILDHISTORY_DIR_IMAGE}/build-id
  365. cat >> ${BUILDHISTORY_DIR_IMAGE}/build-id <<END
  366. ${@buildhistory_get_layers(d)}
  367. END
  368. }
  369. buildhistory_get_sdkinfo() {
  370. if [ "${@base_contains('BUILDHISTORY_FEATURES', 'sdk', '1', '0', d)}" = "0" ] ; then
  371. return
  372. fi
  373. buildhistory_list_files ${SDK_OUTPUT} ${BUILDHISTORY_DIR_SDK}/files-in-sdk.txt
  374. # Record some machine-readable meta-information about the SDK
  375. printf "" > ${BUILDHISTORY_DIR_SDK}/sdk-info.txt
  376. cat >> ${BUILDHISTORY_DIR_SDK}/sdk-info.txt <<END
  377. ${@buildhistory_get_sdkvars(d)}
  378. END
  379. sdksize=`du -ks ${SDK_OUTPUT} | awk '{ print $1 }'`
  380. echo "SDKSIZE = $sdksize" >> ${BUILDHISTORY_DIR_SDK}/sdk-info.txt
  381. }
  382. # By prepending we get in before the removal of packaging files
  383. ROOTFS_POSTPROCESS_COMMAND =+ "buildhistory_get_image_installed ; "
  384. IMAGE_POSTPROCESS_COMMAND += " buildhistory_get_imageinfo ; "
  385. # We want these to be the last run so that we get called after complementary package installation
  386. POPULATE_SDK_POST_TARGET_COMMAND_append = "buildhistory_get_sdk_installed target ; "
  387. POPULATE_SDK_POST_HOST_COMMAND_append = "buildhistory_get_sdk_installed host ; "
  388. SDK_POSTPROCESS_COMMAND += "buildhistory_get_sdkinfo ; "
  389. def buildhistory_get_layers(d):
  390. layertext = "Configured metadata layers:\n%s\n" % '\n'.join(get_layers_branch_rev(d))
  391. return layertext
  392. def buildhistory_get_metadata_revs(d):
  393. # We want an easily machine-readable format here, so get_layers_branch_rev isn't quite what we want
  394. layers = (d.getVar("BBLAYERS", True) or "").split()
  395. medadata_revs = ["%-17s = %s:%s" % (os.path.basename(i), \
  396. base_get_metadata_git_branch(i, None).strip(), \
  397. base_get_metadata_git_revision(i, None)) \
  398. for i in layers]
  399. return '\n'.join(medadata_revs)
  400. def squashspaces(string):
  401. import re
  402. return re.sub("\s+", " ", string).strip()
  403. def outputvars(vars, listvars, d):
  404. vars = vars.split()
  405. listvars = listvars.split()
  406. ret = ""
  407. for var in vars:
  408. value = d.getVar(var, True) or ""
  409. if var in listvars:
  410. # Squash out spaces
  411. value = squashspaces(value)
  412. ret += "%s = %s\n" % (var, value)
  413. return ret.rstrip('\n')
  414. def buildhistory_get_imagevars(d):
  415. imagevars = "DISTRO DISTRO_VERSION USER_CLASSES IMAGE_CLASSES IMAGE_FEATURES IMAGE_LINGUAS IMAGE_INSTALL BAD_RECOMMENDATIONS ROOTFS_POSTPROCESS_COMMAND IMAGE_POSTPROCESS_COMMAND"
  416. listvars = "USER_CLASSES IMAGE_CLASSES IMAGE_FEATURES IMAGE_LINGUAS IMAGE_INSTALL BAD_RECOMMENDATIONS"
  417. return outputvars(imagevars, listvars, d)
  418. def buildhistory_get_sdkvars(d):
  419. sdkvars = "DISTRO DISTRO_VERSION SDK_NAME SDK_VERSION SDKMACHINE SDKIMAGE_FEATURES BAD_RECOMMENDATIONS"
  420. listvars = "SDKIMAGE_FEATURES BAD_RECOMMENDATIONS"
  421. return outputvars(sdkvars, listvars, d)
  422. buildhistory_commit() {
  423. if [ ! -d ${BUILDHISTORY_DIR} ] ; then
  424. # Code above that creates this dir never executed, so there can't be anything to commit
  425. return
  426. fi
  427. # Create a machine-readable list of metadata revisions for each layer
  428. cat > ${BUILDHISTORY_DIR}/metadata-revs <<END
  429. ${@buildhistory_get_metadata_revs(d)}
  430. END
  431. ( cd ${BUILDHISTORY_DIR}/
  432. # Initialise the repo if necessary
  433. if [ ! -d .git ] ; then
  434. git init -q
  435. fi
  436. # Check if there are new/changed files to commit (other than metadata-revs)
  437. repostatus=`git status --porcelain | grep -v " metadata-revs$"`
  438. HOSTNAME=`hostname 2>/dev/null || echo unknown`
  439. if [ "$repostatus" != "" ] ; then
  440. git add -A .
  441. # porcelain output looks like "?? packages/foo/bar"
  442. # Ensure we commit metadata-revs with the first commit
  443. for entry in `echo "$repostatus" | awk '{print $2}' | awk -F/ '{print $1}' | sort | uniq` ; do
  444. git commit $entry metadata-revs -m "$entry: Build ${BUILDNAME} of ${DISTRO} ${DISTRO_VERSION} for machine ${MACHINE} on $HOSTNAME" --author "${BUILDHISTORY_COMMIT_AUTHOR}" > /dev/null
  445. done
  446. if [ "${BUILDHISTORY_PUSH_REPO}" != "" ] ; then
  447. git push -q ${BUILDHISTORY_PUSH_REPO}
  448. fi
  449. else
  450. git commit ${BUILDHISTORY_DIR}/ --allow-empty -m "No changes: Build ${BUILDNAME} of ${DISTRO} ${DISTRO_VERSION} for machine ${MACHINE} on $HOSTNAME" --author "${BUILDHISTORY_COMMIT_AUTHOR}" > /dev/null
  451. fi) || true
  452. }
  453. python buildhistory_eventhandler() {
  454. if e.data.getVar('BUILDHISTORY_FEATURES', True).strip():
  455. if e.data.getVar("BUILDHISTORY_COMMIT", True) == "1":
  456. bb.note("Writing buildhistory")
  457. bb.build.exec_func("buildhistory_commit", e.data)
  458. }
  459. addhandler buildhistory_eventhandler
  460. buildhistory_eventhandler[eventmask] = "bb.event.BuildCompleted"
  461. # FIXME this ought to be moved into the fetcher
  462. def _get_srcrev_values(d):
  463. """
  464. Return the version strings for the current recipe
  465. """
  466. scms = []
  467. fetcher = bb.fetch.Fetch(d.getVar('SRC_URI', True).split(), d)
  468. urldata = fetcher.ud
  469. for u in urldata:
  470. if urldata[u].method.supports_srcrev():
  471. scms.append(u)
  472. autoinc_templ = 'AUTOINC+'
  473. dict_srcrevs = {}
  474. dict_tag_srcrevs = {}
  475. for scm in scms:
  476. ud = urldata[scm]
  477. for name in ud.names:
  478. rev = ud.method.sortable_revision(scm, ud, d, name)
  479. # Clean this up when we next bump bitbake version
  480. if type(rev) != str:
  481. autoinc, rev = rev
  482. elif rev.startswith(autoinc_templ):
  483. rev = rev[len(autoinc_templ):]
  484. dict_srcrevs[name] = rev
  485. if 'tag' in ud.parm:
  486. tag = ud.parm['tag'];
  487. key = name+'_'+tag
  488. dict_tag_srcrevs[key] = rev
  489. return (dict_srcrevs, dict_tag_srcrevs)
  490. do_fetch[postfuncs] += "write_srcrev"
  491. python write_srcrev() {
  492. pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True)
  493. srcrevfile = os.path.join(pkghistdir, 'latest_srcrev')
  494. srcrevs, tag_srcrevs = _get_srcrev_values(d)
  495. if srcrevs:
  496. if not os.path.exists(pkghistdir):
  497. bb.utils.mkdirhier(pkghistdir)
  498. old_tag_srcrevs = {}
  499. if os.path.exists(srcrevfile):
  500. with open(srcrevfile) as f:
  501. for line in f:
  502. if line.startswith('# tag_'):
  503. key, value = line.split("=", 1)
  504. key = key.replace('# tag_', '').strip()
  505. value = value.replace('"', '').strip()
  506. old_tag_srcrevs[key] = value
  507. with open(srcrevfile, 'w') as f:
  508. orig_srcrev = d.getVar('SRCREV', False) or 'INVALID'
  509. if orig_srcrev != 'INVALID':
  510. f.write('# SRCREV = "%s"\n' % orig_srcrev)
  511. if len(srcrevs) > 1:
  512. for name, srcrev in srcrevs.items():
  513. orig_srcrev = d.getVar('SRCREV_%s' % name, False)
  514. if orig_srcrev:
  515. f.write('# SRCREV_%s = "%s"\n' % (name, orig_srcrev))
  516. f.write('SRCREV_%s = "%s"\n' % (name, srcrev))
  517. else:
  518. f.write('SRCREV = "%s"\n' % srcrevs.itervalues().next())
  519. if len(tag_srcrevs) > 0:
  520. for name, srcrev in tag_srcrevs.items():
  521. f.write('# tag_%s = "%s"\n' % (name, srcrev))
  522. if name in old_tag_srcrevs and old_tag_srcrevs[name] != srcrev:
  523. pkg = d.getVar('PN', True)
  524. 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))
  525. else:
  526. if os.path.exists(srcrevfile):
  527. os.remove(srcrevfile)
  528. }