diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2011-11-21 16:49:25 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-12-05 16:23:53 +0000 |
commit | 45c4f0a5870cf3a089b0edd02f52297865f5b5db (patch) | |
tree | 2a1a1058d181db0b1b11a20dee5849e7959a3bb6 /meta/classes | |
parent | 4d6f8d4b74e6f6ab27d80ad0ad9871789b87c525 (diff) | |
download | poky-45c4f0a5870cf3a089b0edd02f52297865f5b5db.tar.gz |
classes/packagehistory: fix and extend
* Replace use of BASEPKG_TARGET_SYS which is no longer available
* Replace use of bb.data.getVar(...,d) with d.getVar(...)
* Change the file structure - use single files within PN/package subdirs
rather than having a subdir level for each part of the version. There
is a set of files for each recipe and for each package in directories
underneath.
* Record more information - PACKAGES, DEPENDS, RDEPENDS, RRECOMMENDS,
FILES, and the total size and a complete list of the packaged files.
* Record the values in simple text format. The "latest" file, rather
than a symlink has been changed to a copy of the latest file so that
if it is tracked in a VCS repository (e.g. git) you can compare it
easily to the previous version.
Implements [YOCTO #1565].
(From OE-Core rev: 09f79dd245ab82bf105b6efeb1dfbf2d180d9fc8)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
-rw-r--r-- | meta/classes/packagehistory.bbclass | 232 |
1 files changed, 192 insertions, 40 deletions
diff --git a/meta/classes/packagehistory.bbclass b/meta/classes/packagehistory.bbclass index 2cdf9d8a7c..5a1c84663a 100644 --- a/meta/classes/packagehistory.bbclass +++ b/meta/classes/packagehistory.bbclass | |||
@@ -2,66 +2,180 @@ | |||
2 | inherit package | 2 | inherit package |
3 | PACKAGEFUNCS += "emit_pkghistory" | 3 | PACKAGEFUNCS += "emit_pkghistory" |
4 | 4 | ||
5 | PKGHIST_DIR = "${TMPDIR}/pkghistory/${BASEPKG_TARGET_SYS}/" | 5 | PKGHIST_DIR = "${TMPDIR}/pkghistory/${MULTIMACH_TARGET_SYS}/" |
6 | |||
7 | 6 | ||
8 | # | 7 | # |
9 | # Called during do_package to write out metadata about this package | 8 | # Called during do_package to write out metadata about this package |
10 | # for comparision when writing future packages | 9 | # for comparision when writing future packages |
11 | # | 10 | # |
12 | python emit_pkghistory() { | 11 | python emit_pkghistory() { |
13 | packages = d.getVar('PACKAGES', True) | 12 | import re |
14 | pkghistdir = d.getVar('PKGHIST_DIR', True) | 13 | |
15 | 14 | pkghistdir = os.path.join(d.getVar('PKGHIST_DIR', True), d.getVar('PN', True)) | |
15 | |||
16 | class RecipeInfo: | ||
17 | def __init__(self, name): | ||
18 | self.name = name | ||
19 | self.pe = "0" | ||
20 | self.pv = "0" | ||
21 | self.pr = "r0" | ||
22 | self.depends = "" | ||
23 | self.packages = "" | ||
24 | |||
25 | class PackageInfo: | ||
26 | def __init__(self, name): | ||
27 | self.name = name | ||
28 | self.pe = "0" | ||
29 | self.pv = "0" | ||
30 | self.pr = "r0" | ||
31 | self.size = 0 | ||
32 | self.depends = "" | ||
33 | self.rdepends = "" | ||
34 | self.rrecommends = "" | ||
35 | self.files = "" | ||
36 | self.filelist = "" | ||
16 | 37 | ||
17 | # Should check PACKAGES here to see if anything removed | 38 | # Should check PACKAGES here to see if anything removed |
18 | 39 | ||
19 | def getpkgvar(pkg, var): | 40 | def getpkgvar(pkg, var): |
20 | val = bb.data.getVar('%s_%s' % (var, pkg), d, 1) | 41 | val = d.getVar('%s_%s' % (var, pkg), True) |
21 | if val: | 42 | if val: |
22 | return val | 43 | return val |
23 | val = bb.data.getVar('%s' % (var), d, 1) | 44 | val = d.getVar(var, True) |
24 | 45 | ||
25 | return val | 46 | return val |
26 | 47 | ||
27 | def getlastversion(pkg): | 48 | def readRecipeInfo(pn, histfile): |
49 | rcpinfo = RecipeInfo(pn) | ||
50 | f = open(histfile, "r") | ||
28 | try: | 51 | try: |
29 | pe = os.path.basename(os.readlink(os.path.join(pkghistdir, pkg, "latest"))) | 52 | for line in f: |
30 | pv = os.path.basename(os.readlink(os.path.join(pkghistdir, pkg, pe, "latest"))) | 53 | lns = line.split('=') |
31 | pr = os.path.basename(os.readlink(os.path.join(pkghistdir, pkg, pe, pv, "latest"))) | 54 | name = lns[0].strip() |
32 | return (pe, pv, pr) | 55 | value = lns[1].strip(" \t\r\n").strip('"') |
33 | except OSError: | 56 | if name == "PE": |
34 | return (None, None, None) | 57 | rcpinfo.pe = value |
58 | elif name == "PV": | ||
59 | rcpinfo.pv = value | ||
60 | elif name == "PR": | ||
61 | rcpinfo.pr = value | ||
62 | elif name == "DEPENDS": | ||
63 | rcpinfo.depends = value | ||
64 | elif name == "PACKAGES": | ||
65 | rcpinfo.packages = value | ||
66 | finally: | ||
67 | f.close() | ||
68 | return rcpinfo | ||
69 | |||
70 | def readPackageInfo(pkg, histfile): | ||
71 | pkginfo = PackageInfo(pkg) | ||
72 | f = open(histfile, "r") | ||
73 | try: | ||
74 | for line in f: | ||
75 | lns = line.split('=') | ||
76 | name = lns[0].strip() | ||
77 | value = lns[1].strip(" \t\r\n").strip('"') | ||
78 | if name == "PE": | ||
79 | pkginfo.pe = value | ||
80 | elif name == "PV": | ||
81 | pkginfo.pv = value | ||
82 | elif name == "PR": | ||
83 | pkginfo.pr = value | ||
84 | elif name == "RDEPENDS": | ||
85 | pkginfo.rdepends = value | ||
86 | elif name == "RRECOMMENDS": | ||
87 | pkginfo.rrecommends = value | ||
88 | elif name == "PKGSIZE": | ||
89 | pkginfo.size = long(value) | ||
90 | elif name == "FILES": | ||
91 | pkginfo.files = value | ||
92 | elif name == "FILELIST": | ||
93 | pkginfo.filelist = value | ||
94 | finally: | ||
95 | f.close() | ||
96 | return pkginfo | ||
97 | |||
98 | def getlastrecipeversion(pn): | ||
99 | try: | ||
100 | histfile = os.path.join(pkghistdir, "latest") | ||
101 | return readRecipeInfo(pn, histfile) | ||
102 | except EnvironmentError: | ||
103 | return None | ||
35 | 104 | ||
105 | def getlastpkgversion(pkg): | ||
106 | try: | ||
107 | histfile = os.path.join(pkghistdir, pkg, "latest") | ||
108 | return readPackageInfo(pkg, histfile) | ||
109 | except EnvironmentError: | ||
110 | return None | ||
111 | |||
112 | def squashspaces(string): | ||
113 | return re.sub("\s+", " ", string) | ||
114 | |||
115 | pn = d.getVar('PN', True) | ||
116 | pe = d.getVar('PE', True) or "0" | ||
117 | pv = d.getVar('PV', True) | ||
118 | pr = d.getVar('PR', True) | ||
119 | packages = squashspaces(d.getVar('PACKAGES', True)) | ||
120 | |||
121 | rcpinfo = RecipeInfo(pn) | ||
122 | rcpinfo.pe = pe | ||
123 | rcpinfo.pv = pv | ||
124 | rcpinfo.pr = pr | ||
125 | rcpinfo.depends = squashspaces(d.getVar('DEPENDS', True) or "") | ||
126 | rcpinfo.packages = packages | ||
127 | write_recipehistory(rcpinfo, d) | ||
128 | write_latestlink(None, pe, pv, pr, d) | ||
129 | |||
130 | # Apparently the version can be different on a per-package basis (see Python) | ||
131 | pkgdest = d.getVar('PKGDEST', True) | ||
36 | for pkg in packages.split(): | 132 | for pkg in packages.split(): |
37 | pe = getpkgvar(pkg, 'PE') or "0" | 133 | pe = getpkgvar(pkg, 'PE') or "0" |
38 | pv = getpkgvar(pkg, 'PV') | 134 | pv = getpkgvar(pkg, 'PV') |
39 | pr = getpkgvar(pkg, 'PR') | 135 | pr = getpkgvar(pkg, 'PR') |
40 | destdir = os.path.join(pkghistdir, pkg, pe, pv, pr) | ||
41 | |||
42 | # | 136 | # |
43 | # Find out what the last version was | 137 | # Find out what the last version was |
44 | # Make sure the version did not decrease | 138 | # Make sure the version did not decrease |
45 | # | 139 | # |
46 | lastversion = getlastversion(pkg) | 140 | lastversion = getlastpkgversion(pkg) |
47 | (last_pe, last_pv, last_pr) = lastversion | 141 | if lastversion: |
48 | 142 | last_pe = lastversion.pe | |
49 | if last_pe is not None: | 143 | last_pv = lastversion.pv |
50 | r = bb.utils.vercmp((pe, pv, pr), lastversion) | 144 | last_pr = lastversion.pr |
145 | r = bb.utils.vercmp((pe, pv, pr), (last_pe, last_pv, last_pr)) | ||
51 | if r < 0: | 146 | 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)) | 147 | 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 | 148 | ||
54 | write_pkghistory(pkg, pe, pv, pr, d) | 149 | pkginfo = PackageInfo(pkg) |
55 | 150 | pkginfo.pe = pe | |
56 | if last_pe is not None: | 151 | pkginfo.pv = pv |
57 | check_pkghistory(pkg, pe, pv, pr, lastversion) | 152 | pkginfo.pr = pr |
58 | 153 | pkginfo.rdepends = squashspaces(getpkgvar(pkg, 'RDEPENDS') or "") | |
59 | write_latestlink(pkg, pe, pv, pr, d) | 154 | pkginfo.rrecommends = squashspaces(getpkgvar(pkg, 'RRECOMMENDS') or "") |
155 | pkginfo.files = squashspaces(getpkgvar(pkg, 'FILES') or "") | ||
156 | |||
157 | # Gather information about packaged files | ||
158 | pkgdestpkg = os.path.join(pkgdest, pkg) | ||
159 | filelist = [] | ||
160 | pkginfo.size = 0 | ||
161 | for root, dirs, files in os.walk(pkgdestpkg): | ||
162 | relpth = os.path.relpath(root, pkgdestpkg) | ||
163 | for f in files: | ||
164 | fstat = os.lstat(os.path.join(root, f)) | ||
165 | pkginfo.size += fstat.st_size | ||
166 | filelist.append(os.sep + os.path.join(relpth, f)) | ||
167 | pkginfo.filelist = " ".join(filelist) | ||
168 | |||
169 | write_pkghistory(pkginfo, d) | ||
170 | |||
171 | if lastversion: | ||
172 | check_pkghistory(pkginfo, lastversion) | ||
173 | |||
174 | write_latestlink(pkg, pe, pv, pr, d) | ||
60 | } | 175 | } |
61 | 176 | ||
62 | 177 | ||
63 | def check_pkghistory(pkg, pe, pv, pr, lastversion): | 178 | def check_pkghistory(pkginfo, lastversion): |
64 | (last_pe, last_pv, last_pr) = lastversion | ||
65 | 179 | ||
66 | bb.debug(2, "Checking package history") | 180 | bb.debug(2, "Checking package history") |
67 | # RDEPENDS removed? | 181 | # RDEPENDS removed? |
@@ -69,17 +183,56 @@ def check_pkghistory(pkg, pe, pv, pr, lastversion): | |||
69 | # Each file list of each package for file removals? | 183 | # Each file list of each package for file removals? |
70 | 184 | ||
71 | 185 | ||
72 | def write_pkghistory(pkg, pe, pv, pr, d): | 186 | def write_recipehistory(rcpinfo, d): |
187 | bb.debug(2, "Writing recipe history") | ||
188 | |||
189 | pkghistdir = os.path.join(d.getVar('PKGHIST_DIR', True), d.getVar('PN', True)) | ||
190 | |||
191 | if not os.path.exists(pkghistdir): | ||
192 | os.makedirs(pkghistdir) | ||
193 | |||
194 | verfile = os.path.join(pkghistdir, "%s:%s-%s" % (rcpinfo.pe, rcpinfo.pv, rcpinfo.pr)) | ||
195 | f = open(verfile, "w") | ||
196 | try: | ||
197 | if rcpinfo.pe != "0": | ||
198 | f.write("PE = %s\n" % rcpinfo.pe) | ||
199 | f.write("PV = %s\n" % rcpinfo.pv) | ||
200 | f.write("PR = %s\n" % rcpinfo.pr) | ||
201 | f.write("DEPENDS = %s\n" % rcpinfo.depends) | ||
202 | f.write("PACKAGES = %s\n" % rcpinfo.packages) | ||
203 | finally: | ||
204 | f.close() | ||
205 | |||
206 | |||
207 | def write_pkghistory(pkginfo, d): | ||
73 | bb.debug(2, "Writing package history") | 208 | bb.debug(2, "Writing package history") |
74 | 209 | ||
75 | pkghistdir = d.getVar('PKGHIST_DIR', True) | 210 | pkghistdir = os.path.join(d.getVar('PKGHIST_DIR', True), d.getVar('PN', True)) |
76 | 211 | ||
77 | verpath = os.path.join(pkghistdir, pkg, pe, pv, pr) | 212 | verpath = os.path.join(pkghistdir, pkginfo.name) |
78 | if not os.path.exists(verpath): | 213 | if not os.path.exists(verpath): |
79 | os.makedirs(verpath) | 214 | os.makedirs(verpath) |
80 | 215 | ||
216 | verfile = os.path.join(verpath, "%s:%s-%s" % (pkginfo.pe, pkginfo.pv, pkginfo.pr)) | ||
217 | f = open(verfile, "w") | ||
218 | try: | ||
219 | if pkginfo.pe != "0": | ||
220 | f.write("PE = %s\n" % pkginfo.pe) | ||
221 | f.write("PV = %s\n" % pkginfo.pv) | ||
222 | f.write("PR = %s\n" % pkginfo.pr) | ||
223 | f.write("RDEPENDS = %s\n" % pkginfo.rdepends) | ||
224 | f.write("RRECOMMENDS = %s\n" % pkginfo.rrecommends) | ||
225 | f.write("PKGSIZE = %d\n" % pkginfo.size) | ||
226 | f.write("FILES = %s\n" % pkginfo.files) | ||
227 | f.write("FILELIST = %s\n" % pkginfo.filelist) | ||
228 | finally: | ||
229 | f.close() | ||
230 | |||
231 | |||
81 | def write_latestlink(pkg, pe, pv, pr, d): | 232 | def write_latestlink(pkg, pe, pv, pr, d): |
82 | pkghistdir = d.getVar('PKGHIST_DIR', True) | 233 | import shutil |
234 | |||
235 | pkghistdir = os.path.join(d.getVar('PKGHIST_DIR', True), d.getVar('PN', True)) | ||
83 | 236 | ||
84 | def rm_link(path): | 237 | def rm_link(path): |
85 | try: | 238 | try: |
@@ -87,11 +240,10 @@ def write_latestlink(pkg, pe, pv, pr, d): | |||
87 | except OSError: | 240 | except OSError: |
88 | return | 241 | return |
89 | 242 | ||
90 | rm_link(os.path.join(pkghistdir, pkg, "latest")) | 243 | if pkg: |
91 | rm_link(os.path.join(pkghistdir, pkg, pe, "latest")) | 244 | filedir = os.path.join(pkghistdir, pkg) |
92 | rm_link(os.path.join(pkghistdir, pkg, pe, pv, "latest")) | 245 | else: |
93 | 246 | filedir = pkghistdir | |
94 | os.symlink(os.path.join(pkghistdir, pkg, pe), os.path.join(pkghistdir, pkg, "latest")) | 247 | rm_link(os.path.join(filedir, "latest")) |
95 | os.symlink(os.path.join(pkghistdir, pkg, pe, pv), os.path.join(pkghistdir, pkg, pe, "latest")) | 248 | shutil.copy(os.path.join(filedir, "%s:%s-%s" % (pe, pv, pr)), os.path.join(filedir, "latest")) |
96 | os.symlink(os.path.join(pkghistdir, pkg, pe, pv, pr), os.path.join(pkghistdir, pkg, pe, pv, "latest")) | ||
97 | 249 | ||