[OE-core] [PATCH 1/2] package_rpm.bbclass: add srpm function in spec file

Mark Hatle mark.hatle at windriver.com
Mon Jan 9 16:17:06 UTC 2012


On 1/8/12 1:11 AM, Xiaofeng Yan wrote:
> From: Xiaofeng Yan<xiaofeng.yan at windriver.com>
>
> For packaging source codes to source rpm package, adding Sources,\
>   Patches and prep stage in spec file.
> "Sources" include source codes (type of tar.gz) and \
> log files including log.do_patch and log.do_configure (type of tar.gz)
> "Patches" include all patches called in bb file.
> "prep" is for user viewing the result in the stage of doing patch and configuration
> for example:
> User can use the following command to run the stage of prep.
> $rpmbuild -bp package.spec
> <show the result of log.do_patch and log.configure>
>
> [YOCTO #1655]
>
> Signed-off-by: Xiaofeng Yan<xiaofeng.yan at windriver.com>
> ---
>   meta/classes/package_rpm.bbclass |   65 ++++++++++++++++++++++++++++++++------
>   1 files changed, 55 insertions(+), 10 deletions(-)
>
> diff --git a/meta/classes/package_rpm.bbclass b/meta/classes/package_rpm.bbclass
> index d03dc3f..3e0ca15 100644
> --- a/meta/classes/package_rpm.bbclass
> +++ b/meta/classes/package_rpm.bbclass
> @@ -6,6 +6,7 @@ RPM="rpm"
>   RPMBUILD="rpmbuild"
>
>   PKGWRITEDIRRPM = "${WORKDIR}/deploy-rpms"
> +PKGWRITEDIRSRPM = "${WORKDIR}/deploy-srpm"
>
>   python package_rpm_fn () {
>   	d.setVar('PKGFN', d.getVar('PKG'))
> @@ -422,6 +423,19 @@ python write_specfile () {
>   	import textwrap
>   	import oe.packagedata
>
> +	def add_prep(spec_files_bottom):
> +		bb.build.exec_func('not_srpm', d)
> +		if not d.getVar('NOTSRPM', True) and d.getVar('ARCHIVE_TYPE', True) == 'SRPM':
> +			spec_files_bottom.append('%%prep -n %s' % d.getVar('PN', True) )
> +			spec_files_bottom.append('%s' % "set +x")
> +			spec_files_bottom.append('%s' % "cd $RPM_SOURCE_BUILD")
> +			spec_files_bottom.append('%s' % "tar zxvf $RPM_SOURCE_DIR/log.tar.gz")
> +			spec_files_bottom.append('%s' % "echo \"============ do patch ==============\"")
> +			spec_files_bottom.append('%s' % "cat log.do_patch*")
> +			spec_files_bottom.append('%s' % "echo \"============ do configure ==========\"")
> +			spec_files_bottom.append('%s' % "cat log.do_configure*")
> +			spec_files_bottom.append('')

The above will simply print the output of the do_patch and do_configure steps. 
It would probably be better to simply include the steps themselves... but with 
the python based steps I'm not sure that is possible.  So returning the log 
entries is likely the next best thing.

Note, you don't need the wild cards in this, you should simply cat out the 
version log.do_patch instead of log.do_patch* -- bitbake ensures that the last 
log file is always the one with the symbolic link.

--Mark

> +
>   	# We need a simple way to remove the MLPREFIX from the package name,
>   	# and dependency information...
>   	def strip_multilib(name, d):
> @@ -533,6 +547,13 @@ python write_specfile () {
>   	srcmaintainer  = d.getVar('MAINTAINER', True)
>   	srchomepage    = d.getVar('HOMEPAGE', True)
>   	srcdescription = d.getVar('DESCRIPTION', True) or "."
> +	
> +	bb.build.exec_func('not_srpm', d)
> +	if not d.getVar('NOTSRPM', True) and d.getVar('ARCHIVE_TYPE', True) == 'SRPM':
> +		tpkg_name = d.getVar('PF',True)
> +		srctargz  = tpkg_name + ".tar.gz"
> +		logtargz = "log.tar.gz"
> +
>
>   	srcdepends     = strip_multilib(d.getVar('DEPENDS', True), d)
>   	srcrdepends    = []
> @@ -557,6 +578,11 @@ python write_specfile () {
>   	spec_files_top = []
>   	spec_files_bottom = []
>
> +	if not d.getVar('NOTSRPM', True) and d.getVar('ARCHIVE_TYPE', True) == 'SRPM':
> +		srcpatches = []	
> +		bb.build.exec_func('get_patches', d)
> +		srcpatches = d.getVar('PLIST',True)
> +	
>   	for pkg in packages.split():
>   		localdata = bb.data.createCopy(d)
>
> @@ -637,7 +663,7 @@ python write_specfile () {
>   				else:
>   					bb.note("Creating EMPTY RPM Package for %s" % splitname)
>   				spec_files_top.append('')
> -
> +				
>   			bb.utils.unlockfile(lf)
>   			continue
>
> @@ -714,7 +740,7 @@ python write_specfile () {
>   			spec_scriptlets_bottom.append('# %s - %s' % (splitname, script))
>   			spec_scriptlets_bottom.append(scriptvar)
>   			spec_scriptlets_bottom.append('')
> -
> +		
>   		# Now process files
>   		file_list = []
>   		walk_files(root, file_list, conffiles)
> @@ -732,7 +758,8 @@ python write_specfile () {
>
>   		del localdata
>   		bb.utils.unlockfile(lf)
> -
> +	
> +	add_prep(spec_files_bottom)
>   	spec_preamble_top.append('Summary: %s' % srcsummary)
>   	spec_preamble_top.append('Name: %s' % srcname)
>   	spec_preamble_top.append('Version: %s' % srcversion)
> @@ -743,6 +770,11 @@ python write_specfile () {
>   	spec_preamble_top.append('Group: %s' % srcsection)
>   	spec_preamble_top.append('Packager: %s' % srcmaintainer)
>   	spec_preamble_top.append('URL: %s' % srchomepage)
> +	
> +	if not d.getVar('NOTSRPM', True) and d.getVar('ARCHIVE_TYPE', True) == 'SRPM':
> +		spec_preamble_top.append('Source: %s' % srctargz)
> +		spec_preamble_top.append('Source1: %s' % logtargz)
> +
>
>   	# Replaces == Obsoletes&&  Provides
>   	if srcrreplaces and srcrreplaces.strip() != "":
> @@ -764,6 +796,11 @@ python write_specfile () {
>   	print_deps(srcrsuggests, 	"Recommends", spec_preamble_top, d)
>   	print_deps(srcrprovides, 	"Provides", spec_preamble_top, d)
>   	print_deps(srcrobsoletes, 	"Obsoletes", spec_preamble_top, d)
> +	if not d.getVar('NOTSRPM', True) and d.getVar('ARCHIVE_TYPE', True) == 'SRPM':
> +		numid = 1
> +		for patch in srcpatches:
> +			print_deps(patch, "Patch" + str(numid), spec_preamble_top, d)
> +			numid += 1
>
>   	# conflicts can not be in a provide!  We will need to filter it.
>   	if srcrconflicts:
> @@ -817,12 +854,6 @@ python write_specfile () {
>   	except OSError:
>   		raise bb.build.FuncFailed("unable to open spec file for writing.")
>
> -	# RPMSPEC_PREAMBLE is a way to add arbitrary text to the top
> -	# of the generated spec file
> -	external_preamble = d.getVar("RPMSPEC_PREAMBLE", True)
> -	if external_preamble:
> -		specfile.write(external_preamble + "\n")
> -
>   	for line in spec_preamble_top:
>   		specfile.write(line + "\n")
>
> @@ -947,9 +978,14 @@ python do_package_rpm () {
>   		d.setVar('PACKAGE_ARCH_EXTEND', package_arch)
>   	pkgwritedir = bb.data.expand('${PKGWRITEDIRRPM}/${PACKAGE_ARCH_EXTEND}', d)
>   	pkgarch = bb.data.expand('${PACKAGE_ARCH_EXTEND}${TARGET_VENDOR}-${TARGET_OS}', d)
> -	magicfile = bb.data.expand('${STAGING_DIR_NATIVE}${datadir_native}/misc/magic.mgc', d)
> +	magicfile = bb.data.expand('${STAGING_DIR_NATIVE}/usr/share/misc/magic.mgc', d)
>   	bb.mkdirhier(pkgwritedir)
>   	os.chmod(pkgwritedir, 0755)
> +	if not d.getVar('NOTSRPM', True) and d.getVar('ARCHIVE_TYPE', True):
> +		pkgwritesrpmdir = bb.data.expand('${PKGWRITEDIRSRPM}/${PACKAGE_ARCH_EXTEND}', d)
> +		bb.mkdirhier(pkgwritesrpmdir)
> +		os.chmod(pkgwritesrpmdir, 0755)
> +	
>
>   	cmd = rpmbuild
>   	cmd = cmd + " --nodeps --short-circuit --target " + pkgarch + " --buildroot " + pkgd
> @@ -962,8 +998,17 @@ python do_package_rpm () {
>   	cmd = cmd + " --define 'debug_package %{nil}'"
>   	cmd = cmd + " --define '_rpmfc_magic_path " + magicfile + "'"
>   	cmd = cmd + " --define '_tmppath " + workdir + "'"
> +	if not d.getVar('NOTSRPM', True) and d.getVar('ARCHIVE_TYPE', True) == 'SRPM':
> +		cmdsrpm = cmd + " --define '_sourcedir " + workdir + "' --define '_srcrpmdir " + pkgwritesrpmdir + "'"
> +		cmdsrpm = cmdsrpm + " -bs " + outspecfile
>   	cmd = cmd + " -bb " + outspecfile
>
> +	# Build the source rpm package !
> +	if not d.getVar('NOTSRPM', True) and d.getVar('ARCHIVE_TYPE', True) == 'SRPM':
> +		d.setVar('SBUILDSPEC', cmdsrpm + "\n")
> +		d.setVarFlag('SBUILDSPEC', 'func', '1')
> +		bb.build.exec_func('SBUILDSPEC', d)
> +
>   	# Build the rpm package!
>   	d.setVar('BUILDSPEC', cmd + "\n")
>   	d.setVarFlag('BUILDSPEC', 'func', '1')





More information about the Openembedded-core mailing list