Patchwork [3/6] package_rpm.bbclass: archive the source to srpm package

login
register
mail settings
Submitter Robert Yang
Date March 11, 2014, 5:08 p.m.
Message ID <7337ad5ac0c8f13c3b23160f2a2ea6e9dc383f64.1394555880.git.liezhi.yang@windriver.com>
Download mbox | patch
Permalink /patch/68427/
State Accepted
Commit 2c7d20ce3849aba84e0552f0fc4bde649d96faa9
Headers show

Comments

Robert Yang - March 11, 2014, 5:08 p.m.
The archiver.bbclass will put the sources to ARCHIVER_OUTDIR according
to configuration, then the rpmbuild -bs will create the srpm.

[YOCTO #4986]
[YOCTO #5113]

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 meta/classes/package_rpm.bbclass | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)
Ross Burton - March 13, 2014, 5:39 p.m.
On 11 March 2014 17:08, Robert Yang <liezhi.yang@windriver.com> wrote:
> -        # Remove the source (SOURCE0, SOURCE1 ...)
> -        cmd = cmd + " --rmsource "

You probably want to keep this as otherwise
deploy/sources/MACHINE/RECIPE/ contains both the .src.rpm and the
separate sources.

Ross
Robert Yang - March 14, 2014, 2:14 a.m.
On 03/14/2014 01:39 AM, Burton, Ross wrote:
> On 11 March 2014 17:08, Robert Yang <liezhi.yang@windriver.com> wrote:
>> -        # Remove the source (SOURCE0, SOURCE1 ...)
>> -        cmd = cmd + " --rmsource "
>
> You probably want to keep this as otherwise
> deploy/sources/MACHINE/RECIPE/ contains both the .src.rpm and the
> separate sources.
>

I'd like to remove the sources in the first thought, but that would
cause a problem: if we only re-run the do_package_write_rpm, for example,
when the FILES is changed, then the sources are gone, and we would get
nothing in the .src.rpm. I thing that keep both the .src.rpm and.tar.gz
is not a big problem, so I changed the usage to:

We will always get .tar.gz and other sources, and the .src.rpm is optional:

ARCHIVER_MODE[srpm] ?= "1"


I think that we can move the rpmbuild related code to archiver.*bbclass to
fix  the problem, but that would change a lot of the code, I'd like to fix
it in  the next release:-)

// Robert

> Ross
>
>
Ross Burton - March 14, 2014, 10:59 a.m.
On 14 March 2014 02:14, Robert Yang <liezhi.yang@windriver.com> wrote:
> I'd like to remove the sources in the first thought, but that would
> cause a problem: if we only re-run the do_package_write_rpm, for example,
> when the FILES is changed, then the sources are gone, and we would get
> nothing in the .src.rpm. I thing that keep both the .src.rpm and.tar.gz
> is not a big problem, so I changed the usage to:

Good argument, fair enough.

Ross

Patch

diff --git a/meta/classes/package_rpm.bbclass b/meta/classes/package_rpm.bbclass
index bce5648..9e63878 100644
--- a/meta/classes/package_rpm.bbclass
+++ b/meta/classes/package_rpm.bbclass
@@ -6,7 +6,6 @@  RPM="rpm"
 RPMBUILD="rpmbuild"
 
 PKGWRITEDIRRPM = "${WORKDIR}/deploy-rpms"
-PKGWRITEDIRSRPM = "${DEPLOY_DIR}/sources/deploy-srpm"
 
 # Maintaining the perfile dependencies has singificant overhead when writing the 
 # packages. When set, this value merges them for efficiency.
@@ -87,23 +86,26 @@  python write_specfile () {
 
     # append information for logs and patches to %prep
     def add_prep(d,spec_files_bottom):
-        if d.getVar('SOURCE_ARCHIVE_PACKAGE_TYPE', True) == 'srpm':
+        if d.getVarFlag('ARCHIVER_MODE', 'srpm', True) == '1' and bb.data.inherits_class('archiver', d):
             spec_files_bottom.append('%%prep -n %s' % d.getVar('PN', True) )
             spec_files_bottom.append('%s' % "echo \"include logs and patches, Please check them in SOURCES\"")
             spec_files_bottom.append('')
 
     # append the name of tarball to key word 'SOURCE' in xxx.spec.
     def tail_source(d):
-        if d.getVar('SOURCE_ARCHIVE_PACKAGE_TYPE', True) == 'srpm':
-            source_list = get_package(d)
+        if d.getVarFlag('ARCHIVER_MODE', 'srpm', True) == '1' and bb.data.inherits_class('archiver', d):
+            ar_outdir = d.getVar('ARCHIVER_OUTDIR', True)
+            if not os.path.exists(ar_outdir):
+                return
+            source_list = os.listdir(ar_outdir)
             source_number = 0
-            workdir = d.getVar('WORKDIR', True)
             for source in source_list:
                 # The rpmbuild doesn't need the root permission, but it needs
                 # to know the file's user and group name, the only user and
                 # group in fakeroot is "root" when working in fakeroot.
-                os.chown("%s/%s" % (workdir, source), 0, 0)
-                spec_preamble_top.append('Source' + str(source_number) + ': %s' % source)
+                f = os.path.join(ar_outdir, source)
+                os.chown(f, 0, 0)
+                spec_preamble_top.append('Source%s: %s' % (source_number, source))
                 source_number += 1
     # We need a simple way to remove the MLPREFIX from the package name,
     # and dependency information...
@@ -611,15 +613,6 @@  python write_specfile () {
 }
 
 python do_package_rpm () {
-    def creat_srpm_dir(d):
-        if d.getVar('SOURCE_ARCHIVE_PACKAGE_TYPE', True) == 'srpm':
-            clean_licenses = get_licenses(d)
-            pkgwritesrpmdir = bb.data.expand('${PKGWRITEDIRSRPM}/${PACKAGE_ARCH_EXTEND}', d)
-            pkgwritesrpmdir = pkgwritesrpmdir + '/' + clean_licenses
-            bb.utils.mkdirhier(pkgwritesrpmdir)
-            os.chmod(pkgwritesrpmdir, 0755)
-            return pkgwritesrpmdir
-            
     # We need a simple way to remove the MLPREFIX from the package name,
     # and dependency information...
     def strip_multilib(name, d):
@@ -687,16 +680,14 @@  python do_package_rpm () {
     cmd = cmd + " --define 'debug_package %{nil}'"
     cmd = cmd + " --define '_rpmfc_magic_path " + magicfile + "'"
     cmd = cmd + " --define '_tmppath " + workdir + "'"
-    if d.getVar('SOURCE_ARCHIVE_PACKAGE_TYPE', True) == 'srpm':
-        cmd = cmd + " --define '_sourcedir " + workdir + "'"
-        cmdsrpm = cmd + " --define '_srcrpmdir " + creat_srpm_dir(d) + "'"
+    if d.getVarFlag('ARCHIVER_MODE', 'srpm', True) == '1' and bb.data.inherits_class('archiver', d):
+        cmd = cmd + " --define '_sourcedir " + d.getVar('ARCHIVER_OUTDIR', True) + "'"
+        cmdsrpm = cmd + " --define '_srcrpmdir " + d.getVar('ARCHIVER_OUTDIR', True) + "'"
         cmdsrpm = cmdsrpm + " -bs " + outspecfile
         # Build the .src.rpm
         d.setVar('SBUILDSPEC', cmdsrpm + "\n")
         d.setVarFlag('SBUILDSPEC', 'func', '1')
         bb.build.exec_func('SBUILDSPEC', d)
-        # Remove the source (SOURCE0, SOURCE1 ...)
-        cmd = cmd + " --rmsource "
     cmd = cmd + " -bb " + outspecfile
 
     # Build the rpm package!