aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2016-05-27 10:07:49 +0200
committerGuido Günther <agx@sigxcpu.org>2016-05-27 10:07:49 +0200
commit22435b270da1676412b10d4f233f945c5b120b2e (patch)
tree10106c9138f30a82e0aa2df2ce2eeffffdfd0db0
parente71b3e867d405e1efd254a28575e7f97eb8701b7 (diff)
buildpackage: Check for existence of subtarballs as well
-rw-r--r--gbp/pkg/__init__.py50
-rwxr-xr-xgbp/scripts/buildpackage.py21
-rw-r--r--tests/05_test_detection.py20
3 files changed, 60 insertions, 31 deletions
diff --git a/gbp/pkg/__init__.py b/gbp/pkg/__init__.py
index e347a6f..b693829 100644
--- a/gbp/pkg/__init__.py
+++ b/gbp/pkg/__init__.py
@@ -196,34 +196,48 @@ class PkgPolicy(object):
return ('', '')
@staticmethod
- def has_orig(orig_file, dir):
- "Check if orig tarball exists in dir"
- return os.path.exists(os.path.join(dir, orig_file))
+ def has_origs(orig_files, dir):
+ "Check orig tarball and sub tarballs exists in dir"
+ for o in orig_files:
+ if not os.path.exists(os.path.join(dir, o)):
+ return False
+ return True
+
+ @classmethod
+ def has_orig(cls, orig_file, dir):
+ return cls.has_origs([orig_file], dir)
@staticmethod
- def symlink_orig(orig_file, orig_dir, output_dir, force=False):
+ def symlink_origs(orig_files, orig_dir, output_dir, force=False):
"""
symlink orig tarball from orig_dir to output_dir
- @return: True if link was created or src == dst
- False in case of error or src doesn't exist
+ @return: [] if all links were created, list of
+ failed links otherwise
"""
orig_dir = os.path.abspath(orig_dir)
output_dir = os.path.abspath(output_dir)
+ err = []
if orig_dir == output_dir:
- return True
+ return []
+
+ for f in orig_files:
+ src = os.path.join(orig_dir, f)
+ dst = os.path.join(output_dir, f)
+ if not os.access(src, os.F_OK):
+ err.append(f)
+ continue
+ try:
+ if os.path.exists(dst) and force:
+ os.unlink(dst)
+ os.symlink(src, dst)
+ except OSError:
+ err.append(f)
+ return err
- src = os.path.join(orig_dir, orig_file)
- dst = os.path.join(output_dir, orig_file)
- if not os.access(src, os.F_OK):
- return False
- try:
- if os.access(dst, os.F_OK) and force:
- os.unlink(dst)
- os.symlink(src, dst)
- except OSError:
- return False
- return True
+ @classmethod
+ def symlink_orig(cls, orig_file, orig_dir, output_dir, force=False):
+ return cls.symlink_origs([orig_file], orig_dir, output_dir, force=force)
class UpstreamSource(object):
diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py
index e494155..6965815 100755
--- a/gbp/scripts/buildpackage.py
+++ b/gbp/scripts/buildpackage.py
@@ -87,25 +87,28 @@ def prepare_upstream_tarball(repo, cp, options, tarball_dir, output_dir):
options.comp_type,
cp,
options.tarball_dir)
- orig_file = du.orig_file(cp, options.comp_type)
+
+ orig_files = [du.orig_file(cp, options.comp_type)]
+ if options.subtarballs:
+ orig_files += [du.orig_file(cp, options.comp_type, sub) for sub in options.subtarballs]
# look in tarball_dir first, if found force a symlink to it
- # FIXME: check for and symlink component tarballs as well
if options.tarball_dir:
- gbp.log.debug("Looking for orig tarball '%s' at '%s'" % (orig_file, tarball_dir))
- if not du.DebianPkgPolicy.symlink_orig(orig_file, tarball_dir, output_dir, force=True):
- gbp.log.info("Orig tarball '%s' not found at '%s'" % (orig_file, tarball_dir))
+ gbp.log.debug("Looking for orig tarballs '%s' at '%s'" % (", ".join(orig_files), tarball_dir))
+ missing = du.DebianPkgPolicy.symlink_origs(orig_files, tarball_dir, output_dir, force=True)
+ if missing:
+ msg = "Tarballs '%s' not found at '%s'" % (", ".join(missing), tarball_dir)
else:
- gbp.log.info("Orig tarball '%s' found at '%s'" % (orig_file, tarball_dir))
+ msg = "All Orig tarballs '%s' found at '%s'" % (", ".join(orig_files), tarball_dir)
+ gbp.log.info(msg)
if options.no_create_orig:
return
# Create tarball if missing or forced
- # FIXME: check for component tarballs as well
- if not du.DebianPkgPolicy.has_orig(orig_file, output_dir) or options.force_create:
+ if not du.DebianPkgPolicy.has_origs(orig_files, output_dir) or options.force_create:
if not pristine_tar_build_orig(repo, cp, output_dir, options):
upstream_tree = git_archive_build_orig(repo, cp, output_dir, options)
if options.pristine_tar_commit:
- pristine_tar_commit(repo, cp, options, output_dir, orig_file, upstream_tree)
+ pristine_tar_commit(repo, cp, options, output_dir, orig_files[0], upstream_tree)
def pristine_tar_commit(repo, cp, options, output_dir, orig_file, upstream_tree):
diff --git a/tests/05_test_detection.py b/tests/05_test_detection.py
index 126a299..9b902e1 100644
--- a/tests/05_test_detection.py
+++ b/tests/05_test_detection.py
@@ -67,12 +67,24 @@ class TestDetection(unittest.TestCase):
repo, 'auto', self.cp, str(self.tmpdir))
self.assertEqual("bzip2", guessed)
- def test_has_orig_false(self):
- self.assertFalse(DebianPkgPolicy.has_orig(orig_file(self.cp, 'gzip'), str(self.tmpdir)))
+ def test_has_orig_single_false(self):
+ self.assertFalse(DebianPkgPolicy.has_origs([orig_file(self.cp, 'gzip')], str(self.tmpdir)))
- def test_has_orig_true(self):
+ def test_has_orig_single_true(self):
open(self.tmpdir.join('source_1.2.orig.tar.gz'), "w").close()
- self.assertTrue(DebianPkgPolicy.has_orig(orig_file(self.cp, 'gzip'), str(self.tmpdir)))
+ self.assertTrue(DebianPkgPolicy.has_origs([orig_file(self.cp, 'gzip')], str(self.tmpdir)))
+
+ def test_has_orig_multiple_false(self):
+ orig_files = [orig_file(self.cp, 'gzip')] + \
+ [orig_file(self.cp, 'gzip', sub) for sub in ['foo', 'bar']]
+ self.assertFalse(DebianPkgPolicy.has_origs(orig_files, str(self.tmpdir)))
+
+ def test_has_orig_multiple_true(self):
+ for ext in ['', '-foo', '-bar']:
+ open(self.tmpdir.join('source_1.2.orig%s.tar.gz' % ext), "w").close()
+ orig_files = [orig_file(self.cp, 'gzip')] + \
+ [orig_file(self.cp, 'gzip', sub) for sub in ['foo', 'bar']]
+ self.assertTrue(DebianPkgPolicy.has_origs(orig_files, str(self.tmpdir)))
def test_guess_comp_type_bzip2(self):
repo = MockGitRepository(with_branch=False)