python-pyside: add shiboken-native as dependency and bump INC_PR
[openembedded.git] / classes / packagehistory.bbclass
blob492bbac218a175e4a685f60c6476c3f9d301a2c6
1 # Must inherit package first before changing PACKAGEFUNCS
2 inherit package
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)
21                 if val:
22                         return val
23                 val = bb.data.getVar('%s' % (var), d, 1)
25                 return val
27         def getlastversion(pkg):
28                 try:
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")))
32                         return (pe, pv, pr)
33                 except OSError:
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)
41                 
42                 #
43                 # Find out what the last version was
44                 # Make sure the version did not decrease
45                 #
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)
51                         if r < 0:
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")
67         # RDEPENDS removed?
68         # PKG changed?
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):
79                 os.makedirs(verpath)
81 def write_latestlink(pkg, pe, pv, pr, d):
82         pkghistdir = bb.data.getVar('PKGHIST_DIR', d, True)
84         def rm_link(path):
85                 try: 
86                         os.unlink(path)
87                 except OSError:
88                         return
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"))