diff options
author | Richard Purdie <richard@openedhand.com> | 2008-08-18 08:01:41 +0000 |
---|---|---|
committer | Marcin Juszkiewicz <hrw@openembedded.org> | 2009-03-19 20:22:36 +0100 |
commit | 69ac369a10e51f6f2d59e4e1da86d99f64285f71 (patch) | |
tree | 7ea135cecafbd1f9a2003fda3e3f0cb45f666f8c /classes | |
parent | 3166def12852386f1b4fec51140b574909d04dab (diff) |
package_rpm.bbclass: added from Poky
Squashed changes from Poky:
svn r5067 - package_rpm.bbclass: Update against recent packaging changes
and start to implement dependency handling.
svn r5100 - package_rpm.bbclass: Fix empty package handling, handle
package dependency renaming by adding a missing function
call and expand RPMBUILD before changing the dictonary so
local PV/PR changes don't break the WORKDIR variable
expansion
svn r5111 - package_rpm.bbclass: Stop autogenerated dependencies for
now, its not functioning correctly
svn r5116 - package_rpm.bbclass: files needs to start from /
svn r5129 - package_rpm.bbclass: Fix problems with package version with
'-' in the version (replace with '+'), improve the Requires
and Recommends generation code
svn r5131 - package_rpm.bbclass: Add support for postinst and preinst scripts
svn r5381 - classes: Split rpm feeds by PACKAGE_ARCH
svn r5390 - package_rpm.bbclass: Improve handling of '-' characters in Requires
and Recommends fields
svn r5393 - package_rpm.bbclass: Fix package version fixing for PKG renamed packages
svn r5397 - package_rpm.bbclass: Fix dependency rebuilding bug
svn r5413 - package_rpm.bbclass: save value of RPMBUILDPATH as it is needed for
packaging
package_rpm.bbclass: Don't use the system wide RPM macros.
This fixes the build on Fedora 10 where the RPM system macros obliterate
the value of BuildRoot that is set in the spec file.
package_rpm.bbclass: fix indentation package_rpm.bbclass: fix syntax errors
package_rpm.bbclass: save RPROVIDES in packages
Diffstat (limited to 'classes')
-rw-r--r-- | classes/package_rpm.bbclass | 140 |
1 files changed, 109 insertions, 31 deletions
diff --git a/classes/package_rpm.bbclass b/classes/package_rpm.bbclass index f0055a1e63..7f55e384fe 100644 --- a/classes/package_rpm.bbclass +++ b/classes/package_rpm.bbclass @@ -1,19 +1,31 @@ inherit package -inherit rpm_core RPMBUILD="rpmbuild --short-circuit ${RPMOPTS}" IMAGE_PKGTYPE ?= "rpm" +RPMBUILDPATH="${WORKDIR}/rpm" + +RPMOPTS="--rcfile=${WORKDIR}/rpmrc" +RPMOPTS="--rcfile=${WORKDIR}/rpmrc --target ${TARGET_SYS}" +RPM="rpm ${RPMOPTS}" + python write_specfile() { from bb import data, build import sys + + version = bb.data.getVar('PV', d, 1) + version = version.replace('-', '+') + bb.data.setVar('RPMPV', version, d) + out_vartranslate = { "PKG": "Name", - "PV": "Version", + "RPMPV": "Version", "DESCRIPTION": "%description", "ROOT": "BuildRoot", "LICENSE": "License", "SECTION": "Group", + "pkg_postinst": "%post", + "pkg_preinst": "%pre", } root = bb.data.getVar('ROOT', d) @@ -38,9 +50,9 @@ python write_specfile() { del files[files.index(r)] except ValueError: pass - if not files: + if not files and bb.data.getVar('ALLOW_EMPTY', d) != "1": from bb import note - note("Not creating empty archive for %s" % (bb.data.expand('${PKG}-${PV}-${PR}${DISTRO_PR}', d, True)) + note("Not creating empty archive for %s" % (bb.data.expand('${PKG}-${PV}-${PR}${DISTRO_PR}', d, True))) return # output .spec using this metadata store @@ -56,15 +68,56 @@ python write_specfile() { for var in out_vartranslate.keys(): if out_vartranslate[var][0] == "%": continue - fd.write("%s\t: %s\n" % (out_vartranslate[var], bb.data.getVar(var, d))) - fd.write("Release\t: %s\n" % bb.data.expand('${PR}${DISTRO_PR}', d, True) + val = bb.data.getVar(var, d, 1) + if val: + fd.write("%s\t: %s\n" % (out_vartranslate[var], val)) + + fd.write("AutoReqProv: no\n") + + def fix_dep_versions(varname): + depends = bb.utils.explode_dep_versions(bb.data.getVar(varname, d, True) or "") + newdeps = [] + for dep in depends: + ver = depends[dep] + if dep and ver: + if '-' in ver: + subd = read_subpkgdata_dict(dep, d) + pv = subd['PV'] + reppv = pv.replace('-', '+') + ver = ver.replace(pv, reppv) + newdeps.append("%s (%s)" % (dep, ver)) + elif dep: + newdeps.append(dep) + bb.data.setVar(varname, " ".join(newdeps), d) + + fix_dep_versions('RDEPENDS') + fix_dep_versions('RRECOMMENDS') + + bb.build.exec_func("mapping_rename_hook", d) + + def write_dep_field(varname, outstring): + depends = bb.utils.explode_dep_versions(bb.data.getVar(varname, d, True) or "") + for dep in depends: + ver = depends[dep] + if dep and ver: + fd.write("%s: %s %s\n" % (outstring, dep, ver)) + elif dep: + fd.write("%s: %s\n" % (outstring, dep)) + + write_dep_field('RDEPENDS', 'Requires') + write_dep_field('RRECOMMENDS', 'Recommends') + write_dep_field('RPROVIDES', 'Provides') + + fd.write("Release\t: %s\n" % bb.data.expand('${PR}${DISTRO_PR}', d, True)) fd.write("Summary\t: .\n") for var in out_vartranslate.keys(): if out_vartranslate[var][0] != "%": continue - fd.write(out_vartranslate[var] + "\n") - fd.write(bb.data.getVar(var, d) + "\n\n") + val = bb.data.getVar(var, d) + if val: + fd.write(out_vartranslate[var] + "\n") + fd.write(val + "\n\n") fd.write("%files\n") for file in files: @@ -74,61 +127,85 @@ python write_specfile() { # call out rpm -bb on the .spec, thereby creating an rpm + bb.note(bb.data.expand("${RPMBUILD} -bb ${OUTSPECFILE}", d)) + bb.data.setVar('BUILDSPEC', "${RPMBUILD} -bb ${OUTSPECFILE}\n", d) bb.data.setVarFlag('BUILDSPEC', 'func', '1', d) bb.build.exec_func('BUILDSPEC', d) # move the rpm into the pkgoutdir - rpm = bb.data.expand('${RPMBUILDPATH}/RPMS/${TARGET_ARCH}/${PKG}-${PV}-${PR}${DISTRO_PR}.${TARGET_ARCH}.rpm', d) - outrpm = bb.data.expand('${DEPLOY_DIR_RPM}/${PKG}-${PV}-${PR}${DISTRO_PR}.${TARGET_ARCH}.rpm', d) + rpm = bb.data.expand('${RPMBUILDPATH}/RPMS/${TARGET_ARCH}/${PKG}-${RPMPV}-${PR}.${TARGET_ARCH}.rpm', d) + outrpm = bb.data.expand('${DEPLOY_DIR_RPM}/${PACKAGE_ARCH}/${PKG}-${RPMPV}-${PR}.${TARGET_ARCH}.rpm', d) bb.movefile(rpm, outrpm) } +rpm_prep() { + if [ ! -e ${WORKDIR}/rpmrc ]; then + mkdir -p ${RPMBUILDPATH}/{SPECS,RPMS/{i386,i586,i686,noarch,ppc,mips,mipsel,arm},SRPMS,SOURCES,BUILD} + echo 'macrofiles:${STAGING_DIR_NATIVE}/usr/lib/rpm/macros:${WORKDIR}/macros' > ${WORKDIR}/rpmrc + echo '%_topdir ${RPMBUILDPATH}' > ${WORKDIR}/macros + echo '%_repackage_dir ${WORKDIR}' >> ${WORKDIR}/macros + fi +} + python do_package_rpm () { - workdir = bb.data.getVar('WORKDIR', d) + workdir = bb.data.getVar('WORKDIR', d, 1) if not workdir: - raise bb.build.FuncFailed("WORKDIR not defined") - workdir = bb.data.expand(workdir, d) + bb.error("WORKDIR not defined, unable to package") + return import os # path manipulations - outdir = bb.data.getVar('DEPLOY_DIR_RPM', d) + outdir = bb.data.getVar('DEPLOY_DIR_RPM', d, 1) if not outdir: - raise bb.build.FuncFailed("DEPLOY_DIR_RPM not defined") - outdir = bb.data.expand(outdir, d) + bb.error("DEPLOY_DIR_RPM not defined, unable to package") + return bb.mkdirhier(outdir) - packages = bb.data.getVar('PACKAGES', d) + packages = bb.data.getVar('PACKAGES', d, 1) if not packages: - packages = "${PN}" - bb.data.setVar('FILES', '', d) - ddir = bb.data.expand(bb.data.getVar('D', d), d) - bb.mkdirhier(ddir) - bb.data.setVar(bb.data.expand('FILES_${PN}', d), ''.join([ "./%s" % x for x in os.listdir(ddir)]), d) - packages = bb.data.expand(packages, d) + bb.debug(1, "PACKAGES not defined, nothing to package") + return + + if packages == []: + bb.debug(1, "No packages; nothing to do") + return + + # If "rpm" comes into overrides the presence of this function causes problems. + # Since we don't need it, remove it for now - hacky. + bb.data.delVar("do_package_write_rpm", d) for pkg in packages.split(): localdata = bb.data.createCopy(d) - root = "%s/install/%s" % (workdir, pkg) + pkgdest = bb.data.getVar('PKGDEST', d, 1) + root = "%s/%s" % (pkgdest, pkg) + + lf = bb.utils.lockfile(root + ".lock") bb.data.setVar('ROOT', '', localdata) bb.data.setVar('ROOT_%s' % pkg, root, localdata) - bb.data.setVar('PKG', pkg, localdata) + pkgname = bb.data.getVar('PKG_%s' % pkg, localdata, 1) + if not pkgname: + pkgname = pkg + bb.data.setVar('PKG', pkgname, localdata) overrides = bb.data.getVar('OVERRIDES', localdata) if not overrides: raise bb.build.FuncFailed('OVERRIDES not defined') overrides = bb.data.expand(overrides, localdata) - bb.data.setVar('OVERRIDES', '%s:%s' % (overrides, pkg), localdata) + bb.data.setVar('OVERRIDES', overrides + ':' + pkg, localdata) bb.data.update_data(localdata) - root = bb.data.getVar('ROOT', localdata) - basedir = os.path.dirname(root) - pkgoutdir = outdir + basedir = os.path.join(os.path.dirname(root)) + pkgoutdir = os.path.join(outdir, bb.data.getVar('PACKAGE_ARCH', localdata, 1)) bb.mkdirhier(pkgoutdir) bb.data.setVar('OUTSPECFILE', os.path.join(workdir, "%s.spec" % pkg), localdata) + # Save the value of RPMBUILD expanded into the new dictonary so any + # changes in the compoents that make up workdir don't break packaging + bb.data.setVar('RPMBUILD', bb.data.getVar("RPMBUILD", d, True), localdata) + bb.data.setVar('RPMBUILDPATH', bb.data.getVar("RPMBUILDPATH", d, True), localdata) bb.build.exec_func('write_specfile', localdata) - del localdata + bb.utils.unlockfile(lf) } python () { @@ -143,7 +220,8 @@ python () { python do_package_write_rpm () { bb.build.exec_func("read_subpackage_metadata", d) + bb.build.exec_func("rpm_prep", d) bb.build.exec_func("do_package_rpm", d) } do_package_write_rpm[dirs] = "${D}" -addtask package_write_rpm before do_build after do_package +addtask package_write_rpm before do_package_write after do_package |