1 # Must inherit package first before changing PACKAGEFUNCS
3 PACKAGEFUNCS += "emit_pkghistory"
5 PKGHIST_DIR = "${TMPDIR}/pkghistory/${BASEPKG_TARGET_SYS}/"
8 # Called during do_package to write out metadata about this package
9 # for comparision when writing future packages
11 python emit_pkghistory() {
12 packages = bb.data.getVar('PACKAGES', d, True)
13 pkghistdir = bb.data.getVar('PKGHIST_DIR', d, True)
16 # Should check PACKAGES here to see if anything removed
18 def getpkgvar(pkg, var):
19 val = bb.data.getVar('%s_%s' % (var, pkg), d, 1)
22 val = bb.data.getVar('%s' % (var), d, 1)
26 def getlastversion(pkg):
28 pe = os.path.basename(os.readlink(os.path.join(pkghistdir, pkg, "latest")))
29 pv = os.path.basename(os.readlink(os.path.join(pkghistdir, pkg, pe, "latest")))
30 pr = os.path.basename(os.readlink(os.path.join(pkghistdir, pkg, pe, pv, "latest")))
33 return (None, None, None)
35 for pkg in packages.split():
36 pe = getpkgvar(pkg, 'PE') or "0"
37 pv = getpkgvar(pkg, 'PV')
38 pr = getpkgvar(pkg, 'PR')
39 destdir = os.path.join(pkghistdir, pkg, pe, pv, pr)
42 # Find out what the last version was
43 # Make sure the version did not decrease
45 lastversion = getlastversion(pkg)
46 (last_pe, last_pv, last_pr) = lastversion
48 if last_pe is not None:
49 r = bb.utils.vercmp((pe, pv, pr), lastversion)
51 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))
53 write_pkghistory(pkg, pe, pv, pr, d)
55 if last_pe is not None:
56 check_pkghistory(pkg, pe, pv, pr, lastversion)
58 write_latestlink(pkg, pe, pv, pr, d)
62 def check_pkghistory(pkg, pe, pv, pr, lastversion):
65 (last_pe, last_pv, last_pr) = lastversion
67 bb.debug(2, "Checking package history")
70 # Each file list of each package for file removals?
73 def write_pkghistory(pkg, pe, pv, pr, d):
75 bb.debug(2, "Writing package history")
77 pkghistdir = bb.data.getVar('PKGHIST_DIR', d, True)
79 verpath = os.path.join(pkghistdir, pkg, pe, pv, pr)
80 if not os.path.exists(verpath):
83 def write_latestlink(pkg, pe, pv, pr, d):
86 pkghistdir = bb.data.getVar('PKGHIST_DIR', d, True)
94 rm_link(os.path.join(pkghistdir, pkg, "latest"))
95 rm_link(os.path.join(pkghistdir, pkg, pe, "latest"))
96 rm_link(os.path.join(pkghistdir, pkg, pe, pv, "latest"))
98 os.symlink(os.path.join(pkghistdir, pkg, pe), os.path.join(pkghistdir, pkg, "latest"))
99 os.symlink(os.path.join(pkghistdir, pkg, pe, pv), os.path.join(pkghistdir, pkg, pe, "latest"))
100 os.symlink(os.path.join(pkghistdir, pkg, pe, pv, pr), os.path.join(pkghistdir, pkg, pe, pv, "latest"))