vala vala-native: Make use of GNOME_MIRROR in SRC_URI
[vuplus_openembedded] / 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 # Called during do_package to write out metadata about this package
9 # for comparision when writing future packages
10 #
11 python emit_pkghistory() {
12         packages = bb.data.getVar('PACKAGES', d, True)
13         pkghistdir = bb.data.getVar('PKGHIST_DIR', d, True)
14
15
16         # Should check PACKAGES here to see if anything removed
17
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)
23
24                 return val
25
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)                       
34
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
47
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))
52
53                 write_pkghistory(pkg, pe, pv, pr, d)
54
55                 if last_pe is not None:
56                         check_pkghistory(pkg, pe, pv, pr, lastversion)
57
58                 write_latestlink(pkg, pe, pv, pr, d)            
59 }
60
61
62 def check_pkghistory(pkg, pe, pv, pr, lastversion):
63         import bb
64
65         (last_pe, last_pv, last_pr) = lastversion
66
67         bb.debug(2, "Checking package history")
68         # RDEPENDS removed?
69         # PKG changed?
70         # Each file list of each package for file removals?
71
72
73 def write_pkghistory(pkg, pe, pv, pr, d):
74         import bb, os
75         bb.debug(2, "Writing package history")
76
77         pkghistdir = bb.data.getVar('PKGHIST_DIR', d, True)
78
79         verpath = os.path.join(pkghistdir, pkg, pe, pv, pr)
80         if not os.path.exists(verpath):
81                 os.makedirs(verpath)
82
83 def write_latestlink(pkg, pe, pv, pr, d):
84         import bb, os
85
86         pkghistdir = bb.data.getVar('PKGHIST_DIR', d, True)
87
88         def rm_link(path):
89                 try: 
90                         os.unlink(path)
91                 except OSError:
92                         return
93
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"))
97
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"))
101