diff options
Diffstat (limited to 'meta/lib/oe')
-rw-r--r-- | meta/lib/oe/packagedata.py | 178 |
1 files changed, 178 insertions, 0 deletions
diff --git a/meta/lib/oe/packagedata.py b/meta/lib/oe/packagedata.py index ff260f405c..efa600ddcd 100644 --- a/meta/lib/oe/packagedata.py +++ b/meta/lib/oe/packagedata.py | |||
@@ -6,6 +6,11 @@ | |||
6 | 6 | ||
7 | import codecs | 7 | import codecs |
8 | import os | 8 | import os |
9 | import json | ||
10 | import bb.compress.zstd | ||
11 | import oe.path | ||
12 | |||
13 | from glob import glob | ||
9 | 14 | ||
10 | def packaged(pkg, d): | 15 | def packaged(pkg, d): |
11 | return os.access(get_subpkgedata_fn(pkg, d) + '.packaged', os.R_OK) | 16 | return os.access(get_subpkgedata_fn(pkg, d) + '.packaged', os.R_OK) |
@@ -162,4 +167,177 @@ def runtime_mapping_rename(varname, pkg, d): | |||
162 | 167 | ||
163 | #bb.note("%s after: %s" % (varname, d.getVar(varname))) | 168 | #bb.note("%s after: %s" % (varname, d.getVar(varname))) |
164 | 169 | ||
170 | def emit_pkgdata(pkgfiles, d): | ||
171 | def process_postinst_on_target(pkg, mlprefix): | ||
172 | pkgval = d.getVar('PKG:%s' % pkg) | ||
173 | if pkgval is None: | ||
174 | pkgval = pkg | ||
175 | |||
176 | defer_fragment = """ | ||
177 | if [ -n "$D" ]; then | ||
178 | $INTERCEPT_DIR/postinst_intercept delay_to_first_boot %s mlprefix=%s | ||
179 | exit 0 | ||
180 | fi | ||
181 | """ % (pkgval, mlprefix) | ||
182 | |||
183 | postinst = d.getVar('pkg_postinst:%s' % pkg) | ||
184 | postinst_ontarget = d.getVar('pkg_postinst_ontarget:%s' % pkg) | ||
185 | |||
186 | if postinst_ontarget: | ||
187 | bb.debug(1, 'adding deferred pkg_postinst_ontarget() to pkg_postinst() for %s' % pkg) | ||
188 | if not postinst: | ||
189 | postinst = '#!/bin/sh\n' | ||
190 | postinst += defer_fragment | ||
191 | postinst += postinst_ontarget | ||
192 | d.setVar('pkg_postinst:%s' % pkg, postinst) | ||
193 | |||
194 | def add_set_e_to_scriptlets(pkg): | ||
195 | for scriptlet_name in ('pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm'): | ||
196 | scriptlet = d.getVar('%s:%s' % (scriptlet_name, pkg)) | ||
197 | if scriptlet: | ||
198 | scriptlet_split = scriptlet.split('\n') | ||
199 | if scriptlet_split[0].startswith("#!"): | ||
200 | scriptlet = scriptlet_split[0] + "\nset -e\n" + "\n".join(scriptlet_split[1:]) | ||
201 | else: | ||
202 | scriptlet = "set -e\n" + "\n".join(scriptlet_split[0:]) | ||
203 | d.setVar('%s:%s' % (scriptlet_name, pkg), scriptlet) | ||
204 | |||
205 | def write_if_exists(f, pkg, var): | ||
206 | def encode(str): | ||
207 | import codecs | ||
208 | c = codecs.getencoder("unicode_escape") | ||
209 | return c(str)[0].decode("latin1") | ||
210 | |||
211 | val = d.getVar('%s:%s' % (var, pkg)) | ||
212 | if val: | ||
213 | f.write('%s:%s: %s\n' % (var, pkg, encode(val))) | ||
214 | return val | ||
215 | val = d.getVar('%s' % (var)) | ||
216 | if val: | ||
217 | f.write('%s: %s\n' % (var, encode(val))) | ||
218 | return val | ||
219 | |||
220 | def write_extra_pkgs(variants, pn, packages, pkgdatadir): | ||
221 | for variant in variants: | ||
222 | with open("%s/%s-%s" % (pkgdatadir, variant, pn), 'w') as fd: | ||
223 | fd.write("PACKAGES: %s\n" % ' '.join( | ||
224 | map(lambda pkg: '%s-%s' % (variant, pkg), packages.split()))) | ||
225 | |||
226 | def write_extra_runtime_pkgs(variants, packages, pkgdatadir): | ||
227 | for variant in variants: | ||
228 | for pkg in packages.split(): | ||
229 | ml_pkg = "%s-%s" % (variant, pkg) | ||
230 | subdata_file = "%s/runtime/%s" % (pkgdatadir, ml_pkg) | ||
231 | with open(subdata_file, 'w') as fd: | ||
232 | fd.write("PKG:%s: %s" % (ml_pkg, pkg)) | ||
233 | |||
234 | packages = d.getVar('PACKAGES') | ||
235 | pkgdest = d.getVar('PKGDEST') | ||
236 | pkgdatadir = d.getVar('PKGDESTWORK') | ||
237 | |||
238 | data_file = pkgdatadir + d.expand("/${PN}") | ||
239 | with open(data_file, 'w') as fd: | ||
240 | fd.write("PACKAGES: %s\n" % packages) | ||
241 | |||
242 | pkgdebugsource = d.getVar("PKGDEBUGSOURCES") or [] | ||
243 | |||
244 | pn = d.getVar('PN') | ||
245 | global_variants = (d.getVar('MULTILIB_GLOBAL_VARIANTS') or "").split() | ||
246 | variants = (d.getVar('MULTILIB_VARIANTS') or "").split() | ||
247 | |||
248 | if bb.data.inherits_class('kernel', d) or bb.data.inherits_class('module-base', d): | ||
249 | write_extra_pkgs(variants, pn, packages, pkgdatadir) | ||
250 | |||
251 | if bb.data.inherits_class('allarch', d) and not variants \ | ||
252 | and not bb.data.inherits_class('packagegroup', d): | ||
253 | write_extra_pkgs(global_variants, pn, packages, pkgdatadir) | ||
254 | |||
255 | workdir = d.getVar('WORKDIR') | ||
256 | |||
257 | for pkg in packages.split(): | ||
258 | pkgval = d.getVar('PKG:%s' % pkg) | ||
259 | if pkgval is None: | ||
260 | pkgval = pkg | ||
261 | d.setVar('PKG:%s' % pkg, pkg) | ||
262 | |||
263 | extended_data = { | ||
264 | "files_info": {} | ||
265 | } | ||
266 | |||
267 | pkgdestpkg = os.path.join(pkgdest, pkg) | ||
268 | files = {} | ||
269 | files_extra = {} | ||
270 | total_size = 0 | ||
271 | seen = set() | ||
272 | for f in pkgfiles[pkg]: | ||
273 | fpath = os.sep + os.path.relpath(f, pkgdestpkg) | ||
274 | |||
275 | fstat = os.lstat(f) | ||
276 | files[fpath] = fstat.st_size | ||
277 | |||
278 | extended_data["files_info"].setdefault(fpath, {}) | ||
279 | extended_data["files_info"][fpath]['size'] = fstat.st_size | ||
280 | |||
281 | if fstat.st_ino not in seen: | ||
282 | seen.add(fstat.st_ino) | ||
283 | total_size += fstat.st_size | ||
284 | |||
285 | if fpath in pkgdebugsource: | ||
286 | extended_data["files_info"][fpath]['debugsrc'] = pkgdebugsource[fpath] | ||
287 | del pkgdebugsource[fpath] | ||
288 | |||
289 | d.setVar('FILES_INFO:' + pkg , json.dumps(files, sort_keys=True)) | ||
290 | |||
291 | process_postinst_on_target(pkg, d.getVar("MLPREFIX")) | ||
292 | add_set_e_to_scriptlets(pkg) | ||
293 | |||
294 | subdata_file = pkgdatadir + "/runtime/%s" % pkg | ||
295 | with open(subdata_file, 'w') as sf: | ||
296 | for var in (d.getVar('PKGDATA_VARS') or "").split(): | ||
297 | val = write_if_exists(sf, pkg, var) | ||
298 | |||
299 | write_if_exists(sf, pkg, 'FILERPROVIDESFLIST') | ||
300 | for dfile in sorted((d.getVar('FILERPROVIDESFLIST:' + pkg) or "").split()): | ||
301 | write_if_exists(sf, pkg, 'FILERPROVIDES:' + dfile) | ||
302 | |||
303 | write_if_exists(sf, pkg, 'FILERDEPENDSFLIST') | ||
304 | for dfile in sorted((d.getVar('FILERDEPENDSFLIST:' + pkg) or "").split()): | ||
305 | write_if_exists(sf, pkg, 'FILERDEPENDS:' + dfile) | ||
306 | |||
307 | sf.write('%s:%s: %d\n' % ('PKGSIZE', pkg, total_size)) | ||
308 | |||
309 | subdata_extended_file = pkgdatadir + "/extended/%s.json.zstd" % pkg | ||
310 | num_threads = int(d.getVar("BB_NUMBER_THREADS")) | ||
311 | with bb.compress.zstd.open(subdata_extended_file, "wt", encoding="utf-8", num_threads=num_threads) as f: | ||
312 | json.dump(extended_data, f, sort_keys=True, separators=(",", ":")) | ||
313 | |||
314 | # Symlinks needed for rprovides lookup | ||
315 | rprov = d.getVar('RPROVIDES:%s' % pkg) or d.getVar('RPROVIDES') | ||
316 | if rprov: | ||
317 | for p in bb.utils.explode_deps(rprov): | ||
318 | subdata_sym = pkgdatadir + "/runtime-rprovides/%s/%s" % (p, pkg) | ||
319 | bb.utils.mkdirhier(os.path.dirname(subdata_sym)) | ||
320 | oe.path.symlink("../../runtime/%s" % pkg, subdata_sym, True) | ||
321 | |||
322 | allow_empty = d.getVar('ALLOW_EMPTY:%s' % pkg) | ||
323 | if not allow_empty: | ||
324 | allow_empty = d.getVar('ALLOW_EMPTY') | ||
325 | root = "%s/%s" % (pkgdest, pkg) | ||
326 | os.chdir(root) | ||
327 | g = glob('*') | ||
328 | if g or allow_empty == "1": | ||
329 | # Symlinks needed for reverse lookups (from the final package name) | ||
330 | subdata_sym = pkgdatadir + "/runtime-reverse/%s" % pkgval | ||
331 | oe.path.symlink("../runtime/%s" % pkg, subdata_sym, True) | ||
332 | |||
333 | packagedfile = pkgdatadir + '/runtime/%s.packaged' % pkg | ||
334 | open(packagedfile, 'w').close() | ||
335 | |||
336 | if bb.data.inherits_class('kernel', d) or bb.data.inherits_class('module-base', d): | ||
337 | write_extra_runtime_pkgs(variants, packages, pkgdatadir) | ||
338 | |||
339 | if bb.data.inherits_class('allarch', d) and not variants \ | ||
340 | and not bb.data.inherits_class('packagegroup', d): | ||
341 | write_extra_runtime_pkgs(global_variants, packages, pkgdatadir) | ||
342 | |||
165 | 343 | ||