diff options
author | Guido Günther <agx@sigxcpu.org> | 2015-05-30 13:36:25 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2015-05-30 15:24:49 +0200 |
commit | 474acd99ecd4e03d9574c5db65721e6fa8b3d54d (patch) | |
tree | 81dbaccdb228378e0138db37175423967ab5fd7d | |
parent | 3775a4d7e61c4d5d55249720e1277c754f421a7c (diff) |
Allow to automatically etermine the dist to build for
Setting --git-dist=DEP14 will follow the DEP14 proposal to determine the
suite to build for via vendor/suite. The exception is sid where DIST is
just set to be empty as well as native packages.
-rw-r--r-- | docs/manpages/gbp-buildpackage.sgml | 9 | ||||
-rw-r--r-- | gbp/deb/__init__.py | 5 | ||||
-rwxr-xr-x | gbp/scripts/buildpackage.py | 35 | ||||
-rw-r--r-- | tests/22_test_gbp_buildpackage.py | 76 |
4 files changed, 121 insertions, 4 deletions
diff --git a/docs/manpages/gbp-buildpackage.sgml b/docs/manpages/gbp-buildpackage.sgml index fb2879a5..ab99d24e 100644 --- a/docs/manpages/gbp-buildpackage.sgml +++ b/docs/manpages/gbp-buildpackage.sgml @@ -197,7 +197,14 @@ <para> Build for distribution <replaceable>DIST</replaceable> when using <command>--git-pbuilder</command>. If unset build for the unstable - distribution. + distribution. The special value <option>DEP14</option> will set + the distribution to build for from the branch name. I.e. if you're + starting the build from a branch named + <replaceable>debian/wheezy-backports</replaceable> the + distribution is set + to <replaceable>wheezy-backports</replaceable>. If the branch is + named <replaceable>downstream/sid</replaceable> the distribution + would be set to <replaceable>downstream_sid</replaceable>. </para> </listitem> </varlistentry> diff --git a/gbp/deb/__init__.py b/gbp/deb/__init__.py index 8015e6e1..00828cdf 100644 --- a/gbp/deb/__init__.py +++ b/gbp/deb/__init__.py @@ -103,4 +103,9 @@ def compare_versions(version1, version2): return DpkgCompareVersions()(version1, version2) +def get_vendor(): + pipe = subprocess.Popen(["dpkg-vendor", "--query", "Vendor"], shell=False, stdout=subprocess.PIPE) + return pipe.stdout.readline().strip() + + # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py index 18b89072..e8740bf3 100755 --- a/gbp/scripts/buildpackage.py +++ b/gbp/scripts/buildpackage.py @@ -328,12 +328,39 @@ def guess_comp_type(repo, comp_type, cp, tarball_dir): return comp_type -def setup_pbuilder(options): +def get_pbuilder_dist(options, repo, native=False): + """ + Determin the dist to build for with pbuilder/cowbuilder + """ + if options.pbuilder_dist == 'DEP14': + branch = repo.branch + if not branch: + raise GbpError("Failed to setup DIST for %s. " + "Can't determine current branch." % options.builder) + else: + parts = branch.rsplit('/') + if len(parts) == 2: + vendor = du.get_vendor().lower() + suite = parts[1] + if vendor == parts[0]: + dist = '' if suite == 'sid' else suite + else: + dist = '%s_%s' % (parts[0], suite) + elif len(parts) == 1 and native and branch in ['master', 'sid']: + dist = '' + else: + raise GbpError("DEP14 DIST setup needs branch name to be vendor/suite") + else: + dist = options.pbuilder_dist + return dist + + +def setup_pbuilder(options, repo, native): """setup everything to use git-pbuilder""" if options.use_pbuilder or options.use_qemubuilder: options.builder = 'git-pbuilder' options.cleaner = '/bin/true' - os.environ['DIST'] = options.pbuilder_dist + os.environ['DIST'] = get_pbuilder_dist(options, repo, native) if options.pbuilder_arch: os.environ['ARCH'] = options.pbuilder_arch if options.use_qemubuilder: @@ -342,6 +369,8 @@ def setup_pbuilder(options): os.environ['GIT_PBUILDER_AUTOCONF'] = "no" if options.pbuilder_options: os.environ['GIT_PBUILDER_OPTIONS'] = options.pbuilder_options + gbp.log.info("Building with %s for %s" % (os.getenv('BUILDER') or '(cowbuilder)', + os.getenv('DIST') or '(sid)')) def disable_hooks(options): @@ -586,7 +615,7 @@ def main(argv): extra_env={'GBP_GIT_DIR': repo.git_dir, 'GBP_BUILD_DIR': build_dir})(dir=build_dir) - setup_pbuilder(options) + setup_pbuilder(options, repo, source.is_native()) # Finally build the package: RunAtCommand(options.builder, dpkg_args, shell=True, extra_env={'GBP_BUILD_DIR': build_dir})(dir=build_dir) diff --git a/tests/22_test_gbp_buildpackage.py b/tests/22_test_gbp_buildpackage.py new file mode 100644 index 00000000..bbc0e326 --- /dev/null +++ b/tests/22_test_gbp_buildpackage.py @@ -0,0 +1,76 @@ +# vim: set fileencoding=utf-8 : +"""Test L{gbp.command_wrappers.Command}'s tarball unpack""" + +from gbp.scripts.buildpackage import get_pbuilder_dist, GbpError +from . testutils import DebianGitTestRepo + +from mock import patch + + +class TestGbpBuildpackage(DebianGitTestRepo): + class Options(object): + pass + + def setUp(self): + DebianGitTestRepo.setUp(self) + self.add_file('doesnotmatter') + self.options = self.Options() + self.options.pbuilder_dist = 'DEP14' + + @patch('gbp.deb.get_vendor', return_value='Debian') + def test_get_pbuilder_dist_no_dep14(self, patch): + self.options.pbuilder_dist = 'notdep14' + self.assertEqual(get_pbuilder_dist(self.options, self.repo), + self.options.pbuilder_dist) + + @patch('gbp.deb.get_vendor', return_value='Debian') + def test_get_pbuilder_dist_dep14_debian_sid(self, patch): + branch = 'debian/sid' + self.repo.create_branch(branch) + self.repo.set_branch(branch) + self.assertEqual(get_pbuilder_dist(self.options, self.repo), '') + patch.assert_called_once_with() + + @patch('gbp.deb.get_vendor', return_value='Debian') + def test_get_pbuilder_dist_dep14_debian_suite(self, patch): + branch = 'debian/squeeze-lts' + self.repo.create_branch(branch) + self.repo.set_branch(branch) + self.assertEqual(get_pbuilder_dist(self.options, self.repo), 'squeeze-lts') + patch.assert_called_once_with() + + @patch('gbp.deb.get_vendor', return_value='Debian') + def test_get_pbuilder_dist_dep14_debian_native(self, patch): + self.assertEqual(get_pbuilder_dist(self.options, self.repo, True), '') + + @patch('gbp.deb.get_vendor', return_value='Debian') + def test_get_pbuilder_dist_dep14_vendor_sid(self, patch): + branch = 'downstream/sid' + self.repo.create_branch(branch) + self.repo.set_branch(branch) + self.assertEqual(get_pbuilder_dist(self.options, self.repo), 'downstream_sid') + patch.assert_called_once_with() + + @patch('gbp.deb.get_vendor', return_value='Debian') + def test_get_pbuilder_dist_dep14_vendor_suite(self, patch): + branch = 'downstream/mies-lts' + self.repo.create_branch(branch) + self.repo.set_branch(branch) + self.assertEqual(get_pbuilder_dist(self.options, self.repo), 'downstream_mies-lts') + + @patch('gbp.deb.get_vendor', return_value='Debian') + def test_get_pbuilder_dist_dep14_no_vendor(self, patch): + branch = 'sid' + self.repo.create_branch(branch) + self.repo.set_branch(branch) + with self.assertRaisesRegexp(GbpError, + 'DEP14 DIST setup needs branch name to be vendor/suite'): + get_pbuilder_dist(self.options, self.repo) + + def test_get_pbuilder_dist_dep14_too_many_slashes(self): + branch = 'too/many/slashed' + self.repo.create_branch(branch) + self.repo.set_branch(branch) + with self.assertRaisesRegexp(GbpError, + 'DEP14 DIST setup needs branch name to be vendor/suite'): + get_pbuilder_dist(self.options, self.repo) |