diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2012-06-14 19:34:09 +0300 |
---|---|---|
committer | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2013-03-08 13:13:37 +0200 |
commit | 772375f01408d359b4c65b11d6a5a3713b5a8a56 (patch) | |
tree | 9b518a049c82e80b11b0d5333e9101ba511cc28f | |
parent | 907bc6177d88901ce75e955edabf85d496d2b480 (diff) | |
download | git-buildpackage-772375f01408d359b4c65b11d6a5a3713b5a8a56.tar.gz git-buildpackage-772375f01408d359b4c65b11d6a5a3713b5a8a56.tar.bz2 git-buildpackage-772375f01408d359b4c65b11d6a5a3713b5a8a56.zip |
rpm: add --orig-prefix option
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>
-rw-r--r-- | gbp/config.py | 3 | ||||
-rwxr-xr-x | gbp/scripts/buildpackage_rpm.py | 15 | ||||
-rwxr-xr-x | gbp/scripts/import_orig_rpm.py | 73 |
3 files changed, 68 insertions, 23 deletions
diff --git a/gbp/config.py b/gbp/config.py index 11f25e8a..78368a4e 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -489,6 +489,7 @@ class GbpOptionParserRpm(GbpOptionParser): 'patch-export-ignore-regex' : '^GBP: patch-export-ignore', 'patch-export-compress' : '0', 'pristine-tarball-name' : 'auto', + 'orig-prefix' : 'auto', } ) help = dict(GbpOptionParser.help) @@ -513,6 +514,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\:·: diff --git a/gbp/scripts/buildpackage_rpm.py b/gbp/scripts/buildpackage_rpm.py index f0853e02..d96ed6e7 100755 --- a/gbp/scripts/buildpackage_rpm.py +++ b/gbp/scripts/buildpackage_rpm.py @@ -44,14 +44,13 @@ from gbp.scripts.common.buildpackage import (index_name, wc_names, from gbp.pkg import (compressor_opts, compressor_aliases) from gbp.scripts.pq_rpm import write_patch -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'] try: if repo.has_submodules() and with_submodules: @@ -182,6 +181,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) @@ -353,6 +353,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") @@ -512,6 +513,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: @@ -519,7 +528,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 diff --git a/gbp/scripts/import_orig_rpm.py b/gbp/scripts/import_orig_rpm.py index e5d6ebcd..145a246f 100755 --- a/gbp/scripts/import_orig_rpm.py +++ b/gbp/scripts/import_orig_rpm.py @@ -24,6 +24,7 @@ import sys import tempfile import gbp.command_wrappers as gbpc import string +import shutil from gbp.pkg import parse_archive_filename from gbp.rpm import (RpmUpstreamSource, SpecFile, NoSpecError, parse_spec, guess_spec, guess_spec_repo) @@ -46,7 +47,7 @@ except ImportError: pass -def symlink_orig(archive, name, version, link_format_str): +def symlink_orig(archive, link): """ Create a symlink from I{archive} to I{<link_format_str>} so pristine-tar will see the desired filename for the archive. @@ -56,14 +57,6 @@ def symlink_orig(archive, name, version, link_format_str): """ if os.path.isdir(archive): return None - filename = os.path.basename(archive) - base_name, archive_fmt, comp = parse_archive_filename(filename) - ext = string.replace(filename, base_name, '', 1) - link = "../" + "%s" % link_format_str % {'name': name, - 'version': version, - 'upstreamversion': version, - 'filename_base': base_name, - 'filename_ext': ext} if os.path.basename(archive) != os.path.basename(link): try: if not is_link_target(archive, link): @@ -141,6 +134,25 @@ def find_source(options, args): return RpmUpstreamSource(args[0]) +def pristine_tarball_name(source, name, version, options): + old_filename = os.path.basename(source.path) + new_filename = old_filename + base_name, archive_fmt, comp = parse_archive_filename(old_filename) + ext = string.replace(old_filename, base_name, '', 1) + + if options.pristine_tarball_name != 'auto': + new_filename = options.pristine_tarball_name % {'name': name, + 'version': version, + 'upstreamversion': version, + 'filename_base': base_name, + 'filename_ext': ext} + # Need to repack and mangle filename if the archive is not + # pristine-tar-compatible -> we decide to create bz2 compressed tarball + elif not source.is_tarball(): + new_filename = "%s.tar.bz2" % base_name + return new_filename + + def set_bare_repo_options(options): """Modify options for import into a bare repository""" if options.pristine_tar or options.merge: @@ -195,6 +207,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") @@ -213,7 +227,7 @@ def parse_args(argv): def main(argv): ret = 0 - tmpdir = '' + tmpdir = tempfile.mkdtemp(dir='../') pristine_orig = None (options, args) = parse_args(argv) @@ -243,18 +257,37 @@ def main(argv): set_bare_repo_options(options) if not source.is_dir(): - tmpdir = tempfile.mkdtemp(dir=os.path.dirname(repo.path)) - source.unpack(tmpdir, options.filters) + unpack_dir = tempfile.mkdtemp(prefix='unpack', dir=tmpdir) + source.unpack(unpack_dir, options.filters) gbp.log.debug("Unpacked '%s' to '%s'" % (source.path, source.unpacked)) - if orig_needs_repack(source, options): - gbp.log.debug("Filter pristine-tar: repacking '%s' from '%s'" % (source.path, source.unpacked)) - (source, tmpdir) = repack_source(source, sourcepackage, version, tmpdir, options.filters) - - if options.pristine_tarball_name != 'auto': - pristine_orig = symlink_orig(source.path, sourcepackage, version, options.pristine_tarball_name) - else: - pristine_orig = source.path + # Name of tarball to be committed to pristine-tar branch + pristine_orig_name = pristine_tarball_name(source, sourcepackage, version, options) + + # Determine the prefix in the tarball to be committed to pristine-tar branch + new_prefix = None + if options.orig_prefix != 'auto': + new_prefix = options.orig_prefix % {'name': sourcepackage, + 'version': version, + 'upstreamversion': version} + if new_prefix == os.path.basename(source.unpacked): + new_prefix = None + + # Get compressions formats of tarballs (original and pristine-tar) + dummy, dummy, old_comp = parse_archive_filename(os.path.basename(source.path)) + dummy, dummy, pristine_comp = parse_archive_filename(pristine_orig_name) + + if orig_needs_repack(source, options) or new_prefix != None or old_comp != pristine_comp: + gbp.log.debug("Repacking '%s' from '%s'" % (source.path, source.unpacked)) + repack_dir = tempfile.mkdtemp(prefix='repack', dir=tmpdir) + source = repack_source(source, + os.path.join(tmpdir, pristine_orig_name), + repack_dir, + options.filters, + new_prefix) + + # Create symlink for mangling of the pristine tarball name + pristine_orig = symlink_orig(source.path, os.path.join(tmpdir, pristine_orig_name)) # Don't mess up our repo with git metadata from an upstream tarball try: |