rpm: enhance logic in guessing the prefix of source archives
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 8 Jun 2012 07:20:12 +0000 (10:20 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 14 Nov 2014 12:45:07 +0000 (14:45 +0200)
Now a prefix is guessed for all source archives (not for the one and
only "orig archive"). By default it is
'<archive_name>-<archive_version>/' if name and version can be
determined from the filename. If not, the archive basename (i.e.
filename less archive and compression extensions) is used.

In addition, more logic is applied to the "orig archive": gbp examines
the setup macro (if found) for the source and takes the prefix from
there. If some macros (in the '-n' option of the setup macro) cannot be
expanded archive basename us used as the prefix.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/scripts/buildpackage_rpm.py

index f6c72f205d3c606c4e38d8f99ebd1e2cd4f86590..3fff4e95a2ae22d22054bf2ea6d4812e3b606421 100755 (executable)
@@ -49,23 +49,23 @@ from gbp.scripts.pq_rpm import update_patch_series
 def git_archive(repo, spec, output_dir, treeish, comp_level, with_submodules):
     "create a compressed orig tarball in output_dir using git_archive"
     comp_opts = ''
-    if spec.orig_comp:
-        comp_opts = compressor_opts[spec.orig_comp][0]
+    if spec.orig_src['compression']:
+        comp_opts = compressor_opts[spec.orig_src['compression']][0]
 
-    output = os.path.join(output_dir, os.path.basename(spec.orig_file))
-    prefix = spec.orig_base
+    output = os.path.join(output_dir, spec.orig_src['filename'])
+    prefix = spec.orig_src['prefix']
 
     try:
         if repo.has_submodules() and with_submodules:
             repo.update_submodules()
             git_archive_submodules(repo, treeish, output, prefix,
-                                   spec.orig_comp, comp_level, comp_opts,
-                                   spec.orig_archive_fmt)
+                                   spec.orig_src['compression'], comp_level, comp_opts,
+                                   spec.orig_src['archive_fmt'])
 
         else:
             git_archive_single(repo, treeish, output, prefix,
-                               spec.orig_comp, comp_level, comp_opts,
-                               spec.orig_archive_fmt)
+                               spec.orig_src['compression'], comp_level, comp_opts,
+                               spec.orig_src['archive_fmt'])
     except (GitRepositoryError, CommandExecFailed):
         gbp.log.err("Error generating submodules' archives")
         return False
@@ -86,7 +86,7 @@ def prepare_upstream_tarball(repo, spec, options, output_dir):
     tarball_dir, symlinking or building it.
     """
     # look in tarball_dir first, if found force a symlink to it
-    orig_file = os.path.basename(spec.orig_file)
+    orig_file = spec.orig_src['filename']
     if options.tarball_dir:
         gbp.log.debug("Looking for orig tarball '%s' at '%s'" % (orig_file, options.tarball_dir))
         if not RpmPkgPolicy.symlink_orig(orig_file, options.tarball_dir, output_dir, force=True):
@@ -178,11 +178,11 @@ def git_archive_build_orig(repo, spec, output_dir, options):
     @rtype: C{str}
     """
     upstream_tree = get_upstream_tree(repo, spec, options)
-    gbp.log.info("%s does not exist, creating from '%s'" % (spec.orig_file,
+    gbp.log.info("%s does not exist, creating from '%s'" % (spec.orig_src['filename'],
                                                             upstream_tree))
-    if spec.orig_comp:
+    if spec.orig_src['compression']:
         gbp.log.debug("Building upstream source archive with compression '%s -%s'" %
-                      (spec.orig_comp, options.comp_level))
+                      (spec.orig_src['compression'], options.comp_level))
     if not git_archive(repo, spec, output_dir, upstream_tree,
                        options.comp_level,
                        options.with_submodules):
@@ -484,16 +484,16 @@ def main(argv):
 
             # Get/build the orig tarball
             if is_native(repo, options):
-                if spec.orig_file:
+                if spec.orig_src:
                     # Just build source archive from the exported tree
-                    gbp.log.info("Creating (native) source archive %s from '%s'" % (spec.orig_file, tree))
-                    if spec.orig_comp:
-                        gbp.log.debug("Building source archive with compression '%s -%s'" % (spec.orig_comp, options.comp_level))
+                    gbp.log.info("Creating (native) source archive %s from '%s'" % (spec.orig_src['filename'], tree))
+                    if spec.orig_src['compression']:
+                        gbp.log.debug("Building source archive with compression '%s -%s'" % (spec.orig_src['compression'], options.comp_level))
                     if not git_archive(repo, spec, source_dir, tree,
                                        options.comp_level, options.with_submodules):
                         raise GbpError, "Cannot create source tarball at '%s'" % export_dir
             # Non-native packages: create orig tarball from upstream
-            elif spec.orig_file:
+            elif spec.orig_src:
                  prepare_upstream_tarball(repo, spec, options, source_dir)
 
             # Run postexport hook