archiver.bbclass: fix the remove error
authorRobert Yang <liezhi.yang@windriver.com>
Fri, 24 Aug 2012 06:06:59 +0000 (14:06 +0800)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 29 Aug 2012 23:02:09 +0000 (16:02 -0700)
* The "tar-package" is used for saving the "Source" list for rpmbuild,
  there is no such a file when "ARCHIVER_MODE[type] ?= srpm", and there
  would be errors, it hadn't happen before was becuase that the remove
  function didn't work. Let the "rpmbuild --rmsource" to remove the
  Sources, and the remove function will just remove the tar-package file.

* Remove several unwanted "try ... exception" sentences, let the error
  raise rather than ignore them when the error happens.

* Remove several un-needed code.

[YOCTO #2619]

(From OE-Core rev: 6ac3e8be0307ecaea5e92f8bda94f1cd2193a47a)

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/archiver.bbclass
meta/classes/package_rpm.bbclass

index 19c5567..3146d02 100644 (file)
@@ -359,26 +359,22 @@ def store_package(d, package_name):
     """
     store tarbablls name to file "tar-package"
     """
-    try:
-        f = open(os.path.join(d.getVar('WORKDIR', True), 'tar-package'), 'a')
-        f.write(package_name + ' ')
-        f.close()
-    except IOError:
-        pass
+    f = open(os.path.join(d.getVar('WORKDIR', True), 'tar-package'), 'a')
+    f.write(package_name + ' ')
+    f.close()
 
 def get_package(d):
     """
     get tarballs name from "tar-package"
     """
     work_dir = (d.getVar('WORKDIR', True))
-    tarpackage = os.path.join(work_dir, 'tar-package')
-    try:
-        f = open(tarpackage, 'r')
-        line = list(set(f.readline().replace('\n', '').split()))
-    except UnboundLocalError, IOError:
-        pass
-    f.close()
-    return line
+    tarlist = os.path.join(work_dir, 'tar-package')
+    if os.path.exists(tarlist):
+        f = open(tarlist, 'r')
+        line = f.readline().rstrip('\n').split()
+        f.close()
+        return line
+    return []
 
 
 def archive_sources_patches(d, stage_name):
@@ -407,9 +403,9 @@ def archive_sources_patches(d, stage_name):
     if d.getVar('SOURCE_ARCHIVE_PACKAGE_TYPE', True) != 'srpm':
         move_tarball_deploy(d, [source_tar_name, patch_tar_name])
     else:
-        tarpackage = os.path.join(d.getVar('WORKDIR', True), 'tar-package')
-        if os.path.exists(tarpackage):
-            os.remove(tarpackage)
+        tarlist = os.path.join(d.getVar('WORKDIR', True), 'tar-package')
+        if os.path.exists(tarlist):
+            os.remove(tarlist)
         for package in os.path.basename(source_tar_name), patch_tar_name:
             if package:
                 store_package(d, str(package) + ' ')
@@ -558,18 +554,11 @@ python do_archive_linux_yocto(){
 do_kernel_checkout[postfuncs] += "do_archive_linux_yocto "
 
 # remove tarball for sources, patches and logs after creating srpm.
-python do_remove_tarball(){
-    if d.getVar('SOURCE_ARCHIVE_PACKAGE_TYPE', True) == 'srpm':
-        work_dir = d.getVar('WORKDIR', True)
-        try:
-            for file in os.listdir(os.getcwd()):
-                if file in get_package(d):
-                    os.remove(file)
-            os.remove(os.path.join(work_dir, 'tar-package'))
-        except (TypeError, OSError):
-            pass
+python do_remove_tarlist(){
+    work_dir = d.getVar('WORKDIR', True)
+    tarlist = os.path.join(work_dir, 'tar-package')
+    if os.path.exists(tarlist):
+        os.remove(tarlist)
 }
-do_remove_tarball[deptask] = "do_archive_scripts_logs"
-do_package_write_rpm[postfuncs] += "do_remove_tarball "
-export get_licenses
-export get_package
+do_remove_tarlist[deptask] = "do_archive_scripts_logs"
+do_package_write_rpm[postfuncs] += "do_remove_tarlist "
index d44ab4c..2c4c89a 100644 (file)
@@ -575,16 +575,11 @@ python write_specfile () {
             spec_files_bottom.append('%s' % "echo \"include logs and patches, Please check them in SOURCES\"")
             spec_files_bottom.append('')
 
-    # get the name of tarball for sources, patches and logs
-    def get_tarballs(d):
-        if d.getVar('SOURCE_ARCHIVE_PACKAGE_TYPE', True) == 'srpm':
-            return get_package(d)
-    
     # append the name of tarball to key word 'SOURCE' in xxx.spec.
-    def tail_source(d,source_list=[],patch_list=None):
+    def tail_source(d):
         if d.getVar('SOURCE_ARCHIVE_PACKAGE_TYPE', True) == 'srpm':
+            source_list = get_package(d)
             source_number = 0
-            patch_number = 0
             workdir = d.getVar('WORKDIR', True)
             for source in source_list:
                 # The rpmbuild doesn't need the root permission, but it needs
@@ -593,11 +588,6 @@ python write_specfile () {
                 os.chown("%s/%s" % (workdir, source), 0, 0)
                 spec_preamble_top.append('Source' + str(source_number) + ': %s' % source)
                 source_number += 1
-            if patch_list:
-                for patch in patch_list:
-                    os.chown("%s/%s" % (workdir, patch), 0, 0)
-                    print_deps(patch, "Patch" + str(patch_number), spec_preamble_top, d)
-                    patch_number += 1
     # We need a simple way to remove the MLPREFIX from the package name,
     # and dependency information...
     def strip_multilib(name, d):
@@ -915,8 +905,7 @@ python write_specfile () {
     spec_preamble_top.append('Group: %s' % srcsection)
     spec_preamble_top.append('Packager: %s' % srcmaintainer)
     spec_preamble_top.append('URL: %s' % srchomepage)
-    source_list = get_tarballs(d)
-    tail_source(d,source_list,None)
+    tail_source(d)
 
     # Replaces == Obsoletes && Provides
     if srcrreplaces and srcrreplaces.strip() != "":
@@ -1151,13 +1140,13 @@ python do_package_rpm () {
         cmd = cmd + " --define '_sourcedir " + workdir + "'"
         cmdsrpm = cmd + " --define '_srcrpmdir " + creat_srpm_dir(d) + "'"
         cmdsrpm = cmdsrpm + " -bs " + outspecfile
-    cmd = cmd + " -bb " + outspecfile
-
-    # Build the source rpm package !
-    if d.getVar('SOURCE_ARCHIVE_PACKAGE_TYPE', True) == 'srpm':
+        # 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!
     d.setVar('BUILDSPEC', cmd + "\n")