linux-omap 2.6.29: add support for the omap3-touchbook
[openembedded.git] / classes / packagehistory.bbclass
blobb435149d227239155b2cb0012601680d2dd8ae56
1 # Must inherit package first before changing PACKAGEFUNCS
2 inherit package
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)
20                 if val:
21                         return val
22                 val = bb.data.getVar('%s' % (var), d, 1)
24                 return val
26         def getlastversion(pkg):
27                 try:
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")))
31                         return (pe, pv, pr)
32                 except OSError:
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)
40                 
41                 #
42                 # Find out what the last version was
43                 # Make sure the version did not decrease
44                 #
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)
50                         if r < 0:
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):
63         import bb
65         (last_pe, last_pv, last_pr) = lastversion
67         bb.debug(2, "Checking package history")
68         # RDEPENDS removed?
69         # PKG changed?
70         # Each file list of each package for file removals?
73 def write_pkghistory(pkg, pe, pv, pr, d):
74         import bb, os
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):
81                 os.makedirs(verpath)
83 def write_latestlink(pkg, pe, pv, pr, d):
84         import bb, os
86         pkghistdir = bb.data.getVar('PKGHIST_DIR', d, True)
88         def rm_link(path):
89                 try: 
90                         os.unlink(path)
91                 except OSError:
92                         return
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"))