Skip to contentSkip to conversation

package.bbclass: Clean up writing of runtime pkgdata files

PATCH In review Peter Kjellerstedt 2 participants 3 messages Jun 5, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package.bbclass: Clean up writing of runtime pkgdata files

This introduces a variable, PKGDATA_VARS, that contains the names of the variables that are to be output in the runtime pkgdata files.

---
 meta/classes/package.bbclass | 56 ++++++++++++------------------------
 1 file changed, 18 insertions(+), 38 deletions(-)
meta/classes/package.bbclass +18 -38
index 0694855504..20d72bba79 100644
@@ -1349,6 +1349,8 @@ EXPORT_FUNCTIONS package_name_hook
 
 PKGDESTWORK = "${WORKDIR}/pkgdata"
 
+PKGDATA_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 pkg_postinst pkg_postrm pkg_preinst pkg_prerm"
+
 python emit_pkgdata() {
     from glob import glob
     import json
@@ -1453,48 +1455,26 @@ fi
                 total_size += fstat.st_size
         d.setVar('FILES_INFO', json.dumps(files, sort_keys=True))
 
-        subdata_file = pkgdatadir + "/runtime/%s" % pkg
-        sf = open(subdata_file, 'w')
-        write_if_exists(sf, pkg, 'PN')
-        write_if_exists(sf, pkg, 'PE')
-        write_if_exists(sf, pkg, 'PV')
-        write_if_exists(sf, pkg, 'PR')
-        write_if_exists(sf, pkg, 'PKGE')
-        write_if_exists(sf, pkg, 'PKGV')
-        write_if_exists(sf, pkg, 'PKGR')
-        write_if_exists(sf, pkg, 'LICENSE')
-        write_if_exists(sf, pkg, 'DESCRIPTION')
-        write_if_exists(sf, pkg, 'SUMMARY')
-        write_if_exists(sf, pkg, 'RDEPENDS')
-        rprov = write_if_exists(sf, pkg, 'RPROVIDES')
-        write_if_exists(sf, pkg, 'RRECOMMENDS')
-        write_if_exists(sf, pkg, 'RSUGGESTS')
-        write_if_exists(sf, pkg, 'RREPLACES')
-        write_if_exists(sf, pkg, 'RCONFLICTS')
-        write_if_exists(sf, pkg, 'SECTION')
-        write_if_exists(sf, pkg, 'PKG')
-        write_if_exists(sf, pkg, 'ALLOW_EMPTY')
-        write_if_exists(sf, pkg, 'FILES')
-        write_if_exists(sf, pkg, 'CONFFILES')
         process_postinst_on_target(pkg, d.getVar("MLPREFIX"))
         add_set_e_to_scriptlets(pkg)
-        write_if_exists(sf, pkg, 'pkg_postinst')
-        write_if_exists(sf, pkg, 'pkg_postrm')
-        write_if_exists(sf, pkg, 'pkg_preinst')
-        write_if_exists(sf, pkg, 'pkg_prerm')
-        write_if_exists(sf, pkg, 'FILERPROVIDESFLIST')
-        write_if_exists(sf, pkg, 'FILES_INFO')
-        for dfile in (d.getVar('FILERPROVIDESFLIST_' + pkg) or "").split():
-            write_if_exists(sf, pkg, 'FILERPROVIDES_' + dfile)
-
-        write_if_exists(sf, pkg, 'FILERDEPENDSFLIST')
-        for dfile in (d.getVar('FILERDEPENDSFLIST_' + pkg) or "").split():
-            write_if_exists(sf, pkg, 'FILERDEPENDS_' + dfile)
-
-        sf.write('%s_%s: %d\n' % ('PKGSIZE', pkg, total_size))
-        sf.close()
+
+        subdata_file = pkgdatadir + "/runtime/%s" % pkg
+        with open(subdata_file, 'w') as sf:
+            for var in (d.getVar('PKGDATA_VARS') or "").split():
+                val = write_if_exists(sf, pkg, var)
+
+            write_if_exists(sf, pkg, 'FILERPROVIDESFLIST')
+            for dfile in (d.getVar('FILERPROVIDESFLIST_' + pkg) or "").split():
+                write_if_exists(sf, pkg, 'FILERPROVIDES_' + dfile)
+
+            write_if_exists(sf, pkg, 'FILERDEPENDSFLIST')
+            for dfile in (d.getVar('FILERDEPENDSFLIST_' + pkg) or "").split():
+                write_if_exists(sf, pkg, 'FILERDEPENDS_' + dfile)
+
+            sf.write('%s_%s: %d\n' % ('PKGSIZE', pkg, total_size))
 
         # Symlinks needed for rprovides lookup
+        rprov = d.getVar('RPROVIDES_%s' % pkg) or d.getVar('RPROVIDES')
         if rprov:
             for p in rprov.strip().split():
                 subdata_sym = pkgdatadir + "/runtime-rprovides/%s/%s" % (p, pkg)
Signature · 1 line
2.21.0
#1 lore raw
Quoted 2 lines · Peter Kjellerstedt

This introduces a variable, PKGDATA_VARS, that contains the names of the variables that are to be output in the runtime pkgdata files.

Its a good cleanup, I just know how people are going to use this variable to write out all kind of other data into pkgdata :(

Cheers,

Richard

#2 lore raw
Quoted 8 lines

-----Original Message-----
From: Richard Purdie <[email protected]>
Sent: den 5 juni 2019 16:07
To: Peter Kjellerstedt <[email protected]>; openembedded- [email protected]
Subject: Re: [OE-core] [PATCH] package.bbclass: Clean up writing of runtime pkgdata files

Quoted 6 lines
Quoted 2 lines · Peter Kjellerstedt

This introduces a variable, PKGDATA_VARS, that contains the names of the variables that are to be output in the runtime pkgdata files.

Its a good cleanup, I just know how people are going to use this variable to write out all kind of other data into pkgdata :(

This was of course triggered by Rob Walton's recent attempt at adding HOMEPAGE and my own earlier attempt at adding SRC_URI. But is it a problem (for OE-Core) that this possibility exists? As long as you do not accept the addition of those variables into OE-Core, then nothing has changed for you (except that the code is now a bit more tidy).

However, for us it means I can get rid of the horrible hack we have that adds SRC_URI to the pkgdata files, and instead replace it with a simple variable addition in our distro configuration.

Quoted 3 lines

Cheers,

Richard

//Peter