Merge branch 'org.openembedded.dev' of git@git.openembedded.net:openembedded into...
[openembedded.git] / classes / packagehistory.bbclass
1 # Must inherit package first before changing PACKAGEFUNCS
2 inherit package
3 PACKAGEFUNCS += "emit_pkghistory"
4
5 PKGHIST_DIR = "${TMPDIR}/pkghistory/${BASEPKG_TARGET_SYS}/"
6
7
8 #
9 # Called during do_package to write out metadata about this package
10 # for comparision when writing future packages
11 #
12 python emit_pkghistory() {
13         packages = bb.data.getVar('PACKAGES', d, True)
14         pkghistdir = bb.data.getVar('PKGHIST_DIR', d, True)
15
16
17         # Should check PACKAGES here to see if anything removed
18
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)
24
25                 return val
26
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)                       
35
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
48
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))
53
54                 write_pkghistory(pkg, pe, pv, pr, d)
55
56                 if last_pe is not None:
57                         check_pkghistory(pkg, pe, pv, pr, lastversion)
58
59                 write_latestlink(pkg, pe, pv, pr, d)            
60 }
61
62
63 def check_pkghistory(pkg, pe, pv, pr, lastversion):
64         (last_pe, last_pv, last_pr) = lastversion
65
66         bb.debug(2, "Checking package history")
67         # RDEPENDS removed?
68         # PKG changed?
69         # Each file list of each package for file removals?
70
71
72 def write_pkghistory(pkg, pe, pv, pr, d):
73         bb.debug(2, "Writing package history")
74
75         pkghistdir = bb.data.getVar('PKGHIST_DIR', d, True)
76
77         verpath = os.path.join(pkghistdir, pkg, pe, pv, pr)
78         if not os.path.exists(verpath):
79                 os.makedirs(verpath)
80
81 def write_latestlink(pkg, pe, pv, pr, d):
82         pkghistdir = bb.data.getVar('PKGHIST_DIR', d, True)
83
84         def rm_link(path):
85                 try: 
86                         os.unlink(path)
87                 except OSError:
88                         return
89
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"))
93
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"))
97