1 # Must inherit package first before changing PACKAGEFUNCS
3 PACKAGEFUNCS += "emit_pkghistory"
5 PKGHIST_DIR = "${TMPDIR}/pkghistory/${BASEPKG_TARGET_SYS}/"
9 # Called during do_package to write out metadata about this package
10 # for comparision when writing future packages
12 python emit_pkghistory() {
13 packages = bb.data.getVar('PACKAGES', d, True)
14 pkghistdir = bb.data.getVar('PKGHIST_DIR', d, True)
17 # Should check PACKAGES here to see if anything removed
19 def getpkgvar(pkg, var):
20 val = bb.data.getVar('%s_%s' % (var, pkg), d, 1)
23 val = bb.data.getVar('%s' % (var), d, 1)
27 def getlastversion(pkg):
29 pe = os.path.basename(os.readlink(os.path.join(pkghistdir, pkg, "latest")))
30 pv = os.path.basename(os.readlink(os.path.join(pkghistdir, pkg, pe, "latest")))
31 pr = os.path.basename(os.readlink(os.path.join(pkghistdir, pkg, pe, pv, "latest")))
34 return (None, None, None)
36 for pkg in packages.split():
37 pe = getpkgvar(pkg, 'PE') or "0"
38 pv = getpkgvar(pkg, 'PV')
39 pr = getpkgvar(pkg, 'PR')
40 destdir = os.path.join(pkghistdir, pkg, pe, pv, pr)
43 # Find out what the last version was
44 # Make sure the version did not decrease
46 lastversion = getlastversion(pkg)
47 (last_pe, last_pv, last_pr) = lastversion
49 if last_pe is not None:
50 r = bb.utils.vercmp((pe, pv, pr), lastversion)
52 bb.fatal("Package version for package %s went backwards which would break package feeds from (%s:%s-%s to %s:%s-%s)" % (pkg, last_pe, last_pv, last_pr, pe, pv, pr))
54 write_pkghistory(pkg, pe, pv, pr, d)
56 if last_pe is not None:
57 check_pkghistory(pkg, pe, pv, pr, lastversion)
59 write_latestlink(pkg, pe, pv, pr, d)
63 def check_pkghistory(pkg, pe, pv, pr, lastversion):
64 (last_pe, last_pv, last_pr) = lastversion
66 bb.debug(2, "Checking package history")
69 # Each file list of each package for file removals?
72 def write_pkghistory(pkg, pe, pv, pr, d):
73 bb.debug(2, "Writing package history")
75 pkghistdir = bb.data.getVar('PKGHIST_DIR', d, True)
77 verpath = os.path.join(pkghistdir, pkg, pe, pv, pr)
78 if not os.path.exists(verpath):
81 def write_latestlink(pkg, pe, pv, pr, d):
82 pkghistdir = bb.data.getVar('PKGHIST_DIR', d, True)
90 rm_link(os.path.join(pkghistdir, pkg, "latest"))
91 rm_link(os.path.join(pkghistdir, pkg, pe, "latest"))
92 rm_link(os.path.join(pkghistdir, pkg, pe, pv, "latest"))
94 os.symlink(os.path.join(pkghistdir, pkg, pe), os.path.join(pkghistdir, pkg, "latest"))
95 os.symlink(os.path.join(pkghistdir, pkg, pe, pv), os.path.join(pkghistdir, pkg, pe, "latest"))
96 os.symlink(os.path.join(pkghistdir, pkg, pe, pv, pr), os.path.join(pkghistdir, pkg, pe, pv, "latest"))