From 393edba385ba101ff6c8cba222a9da5fb7fe5c65 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Thu, 17 Jan 2013 10:41:18 +0200 Subject: buildpackage-rpm: support setting the 'VCS:' tag in spec Now gbp buildpackage-rpm is able to update the 'VCS:' tag in the exported spec file. A new config option 'spec-vcs-tag' controls the format: - if empty, no 'VCS' tag is inserted and possible old 'VCS' tag is removed - otherwise, a 'VCS' tag is inserted or the old 'VCS' tag is updated The spec-vcs-tag is a format string which supports the following keywords: - '%(commit)' expands to the full commit sha1 - '%(commitish)' expands to the sha1 of the exported object (commit or tag) - '%(tagname)s' expands to the long tag name (from git-describe) Signed-off-by: Markus Lehtonen --- docs/manpages/gbp-buildpackage-rpm.xml | 17 +++++++++++++++++ gbp/config.py | 4 ++++ gbp/scripts/buildpackage_rpm.py | 5 +++++ tests/component/rpm/test_buildpackage_rpm.py | 18 ++++++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/docs/manpages/gbp-buildpackage-rpm.xml b/docs/manpages/gbp-buildpackage-rpm.xml index 251bf528..9f8f4381 100644 --- a/docs/manpages/gbp-buildpackage-rpm.xml +++ b/docs/manpages/gbp-buildpackage-rpm.xml @@ -63,6 +63,7 @@ =ARCHITECTURE =OPTIONS =ROOT + =TAG_FORMAT @@ -610,6 +611,22 @@ + + =TAG_FORMAT + + + + &gbp-buildpackage-rpm; always automatically sets/updates the 'VCS:' + tag in the spec file after exporting. This option defines the format + string for the 'VCS:' tag. An empty value causes no 'VCS:' tag to be + inserted and possible old 'VCS:' tag to be removed. Otherwise, the + old 'VCS:' tag is updated or a new 'VCS:' tag is added if one does + not exist. In the format string '%(tagname)s' expands to the long tag + name (from git-describe) and '%(commit)s' expans to the sha1 of the + exported commit. + + + diff --git a/gbp/config.py b/gbp/config.py index 08293d34..dceb011e 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -787,6 +787,7 @@ class GbpOptionParserRpm(GbpOptionParser): 'changelog-revision': '', 'spawn-editor': 'always', 'editor-cmd': 'vim', + 'spec-vcs-tag': '', }) help = dict(GbpOptionParser.help) @@ -848,6 +849,9 @@ class GbpOptionParserRpm(GbpOptionParser): 'git-author': "Use name and email from git-config for the changelog header, " "default is '%(git-author)s'", + 'spec-vcs-tag': + "Set/update the 'VCS:' tag in the spec file, empty value " + "removes the tag entirely, default is '%(spec-vcs-tag)s'", }) def _warn_old_gbp_conf(self, gbp_conf): diff --git a/gbp/scripts/buildpackage_rpm.py b/gbp/scripts/buildpackage_rpm.py index 85024973..16b5eb56 100644 --- a/gbp/scripts/buildpackage_rpm.py +++ b/gbp/scripts/buildpackage_rpm.py @@ -430,6 +430,7 @@ def build_parser(name, prefix=None, git_treeish=None): dest="packaging_dir") export_group.add_config_file_option(option_name="spec-file", dest="spec_file") + export_group.add_config_file_option("spec-vcs-tag", dest="spec_vcs_tag") return parser @@ -615,6 +616,10 @@ def main(argv): 'GBP_SHA1': sha})() else: vcs_info = get_vcs_info(repo, tree) + + # Put 'VCS:' tag to .spec + spec.set_tag('VCS', None, format_str(options.spec_vcs_tag, vcs_info)) + spec.write_spec_file() except KeyboardInterrupt: retval = 1 gbp.log.err("Interrupted. Aborting.") diff --git a/tests/component/rpm/test_buildpackage_rpm.py b/tests/component/rpm/test_buildpackage_rpm.py index 0f50ad14..78e9ff37 100644 --- a/tests/component/rpm/test_buildpackage_rpm.py +++ b/tests/component/rpm/test_buildpackage_rpm.py @@ -605,3 +605,21 @@ class TestGbpRpm(RpmRepoTestBase): # Packaging dir should be taken from spec file if it is defined eq_(mock_gbp(['--git-packaging-dir=foo', '--git-spec-file=packaging/gbp-test-native.spec']), 0) + + def test_option_spec_vcs_tag(self): + """Test the --git-spec-vcs-tag cmdline option""" + repo = self.init_test_repo('gbp-test-native') + + eq_(mock_gbp(['--git-spec-vcs-tag=foobar-%(commit)s']), 0) + sha1 = repo.rev_parse('HEAD') + num_tags = 0 + with open('../rpmbuild/SPECS/gbp-test-native.spec') as fobj: + for line in fobj.readlines(): + if line.startswith('VCS: '): + ok_(re.match(r'VCS:\s+foobar-%s\n$' % sha1, line)) + num_tags += 1 + eq_(num_tags, 1) + + # Test invalid key + eq_(mock_gbp(['--git-spec-vcs-tag=%(invalid-key)s']), 1) + self._check_log(-1, r".*Failed to format %\(invalid-key\)s") -- cgit v1.2.3