rpm: add --orig-prefix option
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 14 Jun 2012 16:34:09 +0000 (19:34 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 7 Jan 2014 14:21:29 +0000 (16:21 +0200)
Adds a new option --orig-prefix that affects the prefix of the
generated/imported orig tarballs.

For git-buildpackage-rpm, it defines the prefix of tarballs generated by
the tool, 'auto' (default) makes gbp to guess the prefix, as before.
NOTE: this doesn't affect the tarballs checked out from pristine-tar
(i.e. if --pristine-tar is defined) or tarballs that are already present
(see --git-tarball-dir option).

For git-import-orig, this new option affects the prefix of tarballs
imported into pristine-tar branch. If set to 'auto' (default) gbp
doesn't mangle the prefix.

Other tools (e.g. git-import-srpm) are not affected.

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

index de45c237a82e50602e766d6bea5a776d0938028e..5a5f382afc1e0f8d8e055baf2d5e2f61b8f92ab1 100644 (file)
@@ -552,6 +552,7 @@ class GbpOptionParserRpm(GbpOptionParser):
                        'patch-export'           : 'False',
                        'patch-export-compress'  : '0',
                        'pristine-tarball-name'  : 'auto',
+                       'orig-prefix'            : 'auto',
                      } )
 
     help = dict(GbpOptionParser.help)
@@ -574,6 +575,8 @@ class GbpOptionParserRpm(GbpOptionParser):
                         "Compress (auto-generated) patches larger than given number of bytes, 0 never compresses, default is '%(patch-export-compress)s'",
                    'pristine-tarball-name':
                         "Filename to record to pristine-tar, set to 'auto' to not mangle the file name, default is '%(pristine-tarball-name)s'",
+                   'orig-prefix':
+                        "Prefix (dir) to be used when generating/importing tarballs, default is '%(orig-prefix)s'",
                  } )
 
 # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
index 9e24654950f5a3fe529feb2e31d0921daf3d90e5..70e09402b1ce082b01f21ef83f2bc9105513cccd 100755 (executable)
@@ -46,15 +46,16 @@ from gbp.pkg import (compressor_opts, compressor_aliases)
 from gbp.scripts.pq_rpm import update_patch_series
 
 
-def git_archive(repo, spec, output_dir, treeish, comp_level, with_submodules):
+def git_archive(repo, spec, output_dir, treeish, prefix, comp_level, with_submodules):
     "create a compressed orig tarball in output_dir using git_archive"
     comp_opts = ''
     if spec.orig_src['compression']:
         comp_opts = compressor_opts[spec.orig_src['compression']][0]
 
     output = os.path.join(output_dir, spec.orig_src['filename'])
-    prefix = spec.orig_src['prefix']
 
+    # Remove extra slashes from prefix, will be added by git_archive_x funcs
+    prefix = prefix.strip('/')
     try:
         if repo.has_submodules() and with_submodules:
             repo.update_submodules()
@@ -184,6 +185,7 @@ def git_archive_build_orig(repo, spec, output_dir, options):
         gbp.log.debug("Building upstream source archive with compression '%s -%s'" %
                       (spec.orig_src['compression'], options.comp_level))
     if not git_archive(repo, spec, output_dir, upstream_tree,
+                       options.orig_prefix,
                        options.comp_level,
                        options.with_submodules):
         raise GbpError("Cannot create upstream tarball at '%s'" % output_dir)
@@ -316,6 +318,7 @@ def parse_args(argv, prefix):
                       help="location to look for external tarballs")
     orig_group.add_config_file_option(option_name="compression-level", dest="comp_level",
                       help="Compression level, default is '%(compression-level)s'")
+    orig_group.add_config_file_option(option_name="orig-prefix", dest="orig_prefix")
     branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch")
     branch_group.add_config_file_option(option_name="packaging-branch", dest="packaging_branch")
     branch_group.add_boolean_config_file_option(option_name = "ignore-branch", dest="ignore_branch")
@@ -474,6 +477,14 @@ def main(argv):
                     raise GbpError, "Error exporting files: %s" % err
             spec.specdir = spec_dir
 
+            if options.orig_prefix != 'auto':
+                options.orig_prefix = options.orig_prefix % dict(spec.version,
+                                                                 version=RpmPkgPolicy.compose_full_version(spec.version),
+                                                                 name=spec.name,
+                                                                 vendor=options.vendor)
+            elif spec.orig_src:
+                options.orig_prefix = spec.orig_src['prefix']
+
             # Get/build the orig tarball
             if is_native(repo, options):
                 if spec.orig_src:
@@ -481,7 +492,7 @@ def main(argv):
                     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,
+                    if not git_archive(repo, spec, source_dir, tree, options.orig_prefix,
                                        options.comp_level, options.with_submodules):
                         raise GbpError, "Cannot create source tarball at '%s'" % export_dir
             # Non-native packages: create orig tarball from upstream
index 7c8e80e71a4d1c5fa36b0068599109ac73706ed2..d85ed9f4f520fcb42b4f97789d29837036047176 100755 (executable)
@@ -174,6 +174,8 @@ def parse_args(argv):
                       dest="filter_pristine_tar")
     import_group.add_config_file_option(option_name="pristine-tarball-name",
                       dest="pristine_tarball_name")
+    import_group.add_config_file_option(option_name="orig-prefix",
+                      dest="orig_prefix")
     import_group.add_config_file_option(option_name="import-msg",
                       dest="import_msg")
     cmd_group.add_config_file_option(option_name="postimport", dest="postimport")
@@ -234,7 +236,7 @@ def main(argv):
                 prepare_sources(source, sourcepackage, version,
                                 prepare_pristine, options.filters,
                                 options.filter_pristine_tar,
-                                None, tmpdir)
+                                options.orig_prefix, tmpdir)
 
         # Don't mess up our repo with git metadata from an upstream tarball
         if os.path.isdir(os.path.join(unpacked_orig, '.git/')):