summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2023-01-04 13:34:06 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-01-05 11:52:50 +0000
commitb3573d38ef2653a6da58a73fa8aa647009086bee (patch)
tree40b49e90a979c0c0d126467122066b51ee17ac23 /meta
parenta099ed2125fbd822342b7fc124e3c659b26d29c9 (diff)
downloadpoky-b3573d38ef2653a6da58a73fa8aa647009086bee.tar.gz
package: Move emit_pkgdata to packagedata.py
Move one of the PACKAGEFUNCS from the package bbclass to packagedata library code for parsing efficiency. (From OE-Core rev: ceba33bf2897f7dd5b1ffe6b742c47bf616243c8) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/classes-global/package.bbclass179
-rw-r--r--meta/conf/bitbake.conf1
-rw-r--r--meta/lib/oe/packagedata.py178
3 files changed, 181 insertions, 177 deletions
diff --git a/meta/classes-global/package.bbclass b/meta/classes-global/package.bbclass
index 72e39f6914..389c857804 100644
--- a/meta/classes-global/package.bbclass
+++ b/meta/classes-global/package.bbclass
@@ -1232,185 +1232,10 @@ PKGDESTWORK = "${WORKDIR}/pkgdata"
1232PKGDATA_VARS = "PN PE PV PR PKGE PKGV PKGR LICENSE DESCRIPTION SUMMARY RDEPENDS RPROVIDES RRECOMMENDS RSUGGESTS RREPLACES RCONFLICTS SECTION PKG ALLOW_EMPTY FILES CONFFILES FILES_INFO PACKAGE_ADD_METADATA pkg_postinst pkg_postrm pkg_preinst pkg_prerm" 1232PKGDATA_VARS = "PN PE PV PR PKGE PKGV PKGR LICENSE DESCRIPTION SUMMARY RDEPENDS RPROVIDES RRECOMMENDS RSUGGESTS RREPLACES RCONFLICTS SECTION PKG ALLOW_EMPTY FILES CONFFILES FILES_INFO PACKAGE_ADD_METADATA pkg_postinst pkg_postrm pkg_preinst pkg_prerm"
1233 1233
1234python emit_pkgdata() { 1234python emit_pkgdata() {
1235 from glob import glob 1235 import oe.packagedata
1236 import json 1236 oe.packagedata.emit_pkgdata(pkgfiles, d)
1237 import bb.compress.zstd
1238
1239 def process_postinst_on_target(pkg, mlprefix):
1240 pkgval = d.getVar('PKG:%s' % pkg)
1241 if pkgval is None:
1242 pkgval = pkg
1243
1244 defer_fragment = """
1245if [ -n "$D" ]; then
1246 $INTERCEPT_DIR/postinst_intercept delay_to_first_boot %s mlprefix=%s
1247 exit 0
1248fi
1249""" % (pkgval, mlprefix)
1250
1251 postinst = d.getVar('pkg_postinst:%s' % pkg)
1252 postinst_ontarget = d.getVar('pkg_postinst_ontarget:%s' % pkg)
1253
1254 if postinst_ontarget:
1255 bb.debug(1, 'adding deferred pkg_postinst_ontarget() to pkg_postinst() for %s' % pkg)
1256 if not postinst:
1257 postinst = '#!/bin/sh\n'
1258 postinst += defer_fragment
1259 postinst += postinst_ontarget
1260 d.setVar('pkg_postinst:%s' % pkg, postinst)
1261
1262 def add_set_e_to_scriptlets(pkg):
1263 for scriptlet_name in ('pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm'):
1264 scriptlet = d.getVar('%s:%s' % (scriptlet_name, pkg))
1265 if scriptlet:
1266 scriptlet_split = scriptlet.split('\n')
1267 if scriptlet_split[0].startswith("#!"):
1268 scriptlet = scriptlet_split[0] + "\nset -e\n" + "\n".join(scriptlet_split[1:])
1269 else:
1270 scriptlet = "set -e\n" + "\n".join(scriptlet_split[0:])
1271 d.setVar('%s:%s' % (scriptlet_name, pkg), scriptlet)
1272
1273 def write_if_exists(f, pkg, var):
1274 def encode(str):
1275 import codecs
1276 c = codecs.getencoder("unicode_escape")
1277 return c(str)[0].decode("latin1")
1278
1279 val = d.getVar('%s:%s' % (var, pkg))
1280 if val:
1281 f.write('%s:%s: %s\n' % (var, pkg, encode(val)))
1282 return val
1283 val = d.getVar('%s' % (var))
1284 if val:
1285 f.write('%s: %s\n' % (var, encode(val)))
1286 return val
1287
1288 def write_extra_pkgs(variants, pn, packages, pkgdatadir):
1289 for variant in variants:
1290 with open("%s/%s-%s" % (pkgdatadir, variant, pn), 'w') as fd:
1291 fd.write("PACKAGES: %s\n" % ' '.join(
1292 map(lambda pkg: '%s-%s' % (variant, pkg), packages.split())))
1293
1294 def write_extra_runtime_pkgs(variants, packages, pkgdatadir):
1295 for variant in variants:
1296 for pkg in packages.split():
1297 ml_pkg = "%s-%s" % (variant, pkg)
1298 subdata_file = "%s/runtime/%s" % (pkgdatadir, ml_pkg)
1299 with open(subdata_file, 'w') as fd:
1300 fd.write("PKG:%s: %s" % (ml_pkg, pkg))
1301
1302 packages = d.getVar('PACKAGES')
1303 pkgdest = d.getVar('PKGDEST')
1304 pkgdatadir = d.getVar('PKGDESTWORK')
1305
1306 data_file = pkgdatadir + d.expand("/${PN}")
1307 with open(data_file, 'w') as fd:
1308 fd.write("PACKAGES: %s\n" % packages)
1309
1310 pkgdebugsource = d.getVar("PKGDEBUGSOURCES") or []
1311
1312 pn = d.getVar('PN')
1313 global_variants = (d.getVar('MULTILIB_GLOBAL_VARIANTS') or "").split()
1314 variants = (d.getVar('MULTILIB_VARIANTS') or "").split()
1315
1316 if bb.data.inherits_class('kernel', d) or bb.data.inherits_class('module-base', d):
1317 write_extra_pkgs(variants, pn, packages, pkgdatadir)
1318
1319 if bb.data.inherits_class('allarch', d) and not variants \
1320 and not bb.data.inherits_class('packagegroup', d):
1321 write_extra_pkgs(global_variants, pn, packages, pkgdatadir)
1322
1323 workdir = d.getVar('WORKDIR')
1324
1325 for pkg in packages.split():
1326 pkgval = d.getVar('PKG:%s' % pkg)
1327 if pkgval is None:
1328 pkgval = pkg
1329 d.setVar('PKG:%s' % pkg, pkg)
1330
1331 extended_data = {
1332 "files_info": {}
1333 }
1334
1335 pkgdestpkg = os.path.join(pkgdest, pkg)
1336 files = {}
1337 files_extra = {}
1338 total_size = 0
1339 seen = set()
1340 for f in pkgfiles[pkg]:
1341 fpath = os.sep + os.path.relpath(f, pkgdestpkg)
1342
1343 fstat = os.lstat(f)
1344 files[fpath] = fstat.st_size
1345
1346 extended_data["files_info"].setdefault(fpath, {})
1347 extended_data["files_info"][fpath]['size'] = fstat.st_size
1348
1349 if fstat.st_ino not in seen:
1350 seen.add(fstat.st_ino)
1351 total_size += fstat.st_size
1352
1353 if fpath in pkgdebugsource:
1354 extended_data["files_info"][fpath]['debugsrc'] = pkgdebugsource[fpath]
1355 del pkgdebugsource[fpath]
1356
1357 d.setVar('FILES_INFO:' + pkg , json.dumps(files, sort_keys=True))
1358
1359 process_postinst_on_target(pkg, d.getVar("MLPREFIX"))
1360 add_set_e_to_scriptlets(pkg)
1361
1362 subdata_file = pkgdatadir + "/runtime/%s" % pkg
1363 with open(subdata_file, 'w') as sf:
1364 for var in (d.getVar('PKGDATA_VARS') or "").split():
1365 val = write_if_exists(sf, pkg, var)
1366
1367 write_if_exists(sf, pkg, 'FILERPROVIDESFLIST')
1368 for dfile in sorted((d.getVar('FILERPROVIDESFLIST:' + pkg) or "").split()):
1369 write_if_exists(sf, pkg, 'FILERPROVIDES:' + dfile)
1370
1371 write_if_exists(sf, pkg, 'FILERDEPENDSFLIST')
1372 for dfile in sorted((d.getVar('FILERDEPENDSFLIST:' + pkg) or "").split()):
1373 write_if_exists(sf, pkg, 'FILERDEPENDS:' + dfile)
1374
1375 sf.write('%s:%s: %d\n' % ('PKGSIZE', pkg, total_size))
1376
1377 subdata_extended_file = pkgdatadir + "/extended/%s.json.zstd" % pkg
1378 num_threads = int(d.getVar("BB_NUMBER_THREADS"))
1379 with bb.compress.zstd.open(subdata_extended_file, "wt", encoding="utf-8", num_threads=num_threads) as f:
1380 json.dump(extended_data, f, sort_keys=True, separators=(",", ":"))
1381
1382 # Symlinks needed for rprovides lookup
1383 rprov = d.getVar('RPROVIDES:%s' % pkg) or d.getVar('RPROVIDES')
1384 if rprov:
1385 for p in bb.utils.explode_deps(rprov):
1386 subdata_sym = pkgdatadir + "/runtime-rprovides/%s/%s" % (p, pkg)
1387 bb.utils.mkdirhier(os.path.dirname(subdata_sym))
1388 oe.path.symlink("../../runtime/%s" % pkg, subdata_sym, True)
1389
1390 allow_empty = d.getVar('ALLOW_EMPTY:%s' % pkg)
1391 if not allow_empty:
1392 allow_empty = d.getVar('ALLOW_EMPTY')
1393 root = "%s/%s" % (pkgdest, pkg)
1394 os.chdir(root)
1395 g = glob('*')
1396 if g or allow_empty == "1":
1397 # Symlinks needed for reverse lookups (from the final package name)
1398 subdata_sym = pkgdatadir + "/runtime-reverse/%s" % pkgval
1399 oe.path.symlink("../runtime/%s" % pkg, subdata_sym, True)
1400
1401 packagedfile = pkgdatadir + '/runtime/%s.packaged' % pkg
1402 open(packagedfile, 'w').close()
1403
1404 if bb.data.inherits_class('kernel', d) or bb.data.inherits_class('module-base', d):
1405 write_extra_runtime_pkgs(variants, packages, pkgdatadir)
1406
1407 if bb.data.inherits_class('allarch', d) and not variants \
1408 and not bb.data.inherits_class('packagegroup', d):
1409 write_extra_runtime_pkgs(global_variants, packages, pkgdatadir)
1410
1411} 1237}
1412emit_pkgdata[dirs] = "${PKGDESTWORK}/runtime ${PKGDESTWORK}/runtime-reverse ${PKGDESTWORK}/runtime-rprovides ${PKGDESTWORK}/extended" 1238emit_pkgdata[dirs] = "${PKGDESTWORK}/runtime ${PKGDESTWORK}/runtime-reverse ${PKGDESTWORK}/runtime-rprovides ${PKGDESTWORK}/extended"
1413emit_pkgdata[vardepsexclude] = "BB_NUMBER_THREADS"
1414 1239
1415ldconfig_postinst_fragment() { 1240ldconfig_postinst_fragment() {
1416if [ x"$D" = "x" ]; then 1241if [ x"$D" = "x" ]; then
diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index bfa28d3bc9..05d5a844de 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -973,3 +973,4 @@ oe.sstatesig.find_sstate_manifest[vardepsexclude] = "BBEXTENDCURR BBEXTENDVARIAN
973oe.utils.get_multilib_datastore[vardepsexclude] = "DEFAULTTUNE_MULTILIB_ORIGINAL OVERRIDES" 973oe.utils.get_multilib_datastore[vardepsexclude] = "DEFAULTTUNE_MULTILIB_ORIGINAL OVERRIDES"
974oe.path.format_display[vardepsexclude] = "TOPDIR" 974oe.path.format_display[vardepsexclude] = "TOPDIR"
975oe.utils.multiprocess_launch[vardepsexclude] = "BB_NUMBER_THREADS" 975oe.utils.multiprocess_launch[vardepsexclude] = "BB_NUMBER_THREADS"
976oe.packagedata.emit_pkgdata[vardepsexclude] = "BB_NUMBER_THREADS"
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
7import codecs 7import codecs
8import os 8import os
9import json
10import bb.compress.zstd
11import oe.path
12
13from glob import glob
9 14
10def packaged(pkg, d): 15def 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
170def 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 = """
177if [ -n "$D" ]; then
178 $INTERCEPT_DIR/postinst_intercept delay_to_first_boot %s mlprefix=%s
179 exit 0
180fi
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