From: Markus Lehtonen Date: Wed, 21 Nov 2012 10:54:04 +0000 (+0200) Subject: rpm: introduce new 'Gbp-Patch-Macros' special key in spec parsing X-Git-Tag: tizen/0.6.15-20140828~122 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7ea7f2754cd26f709c66e57f705cd21a47223092;p=tools%2Fgit-buildpackage.git rpm: introduce new 'Gbp-Patch-Macros' special key in spec parsing This can be used to mark location where to add new patch macros when updating the spec. Signed-off-by: Markus Lehtonen --- diff --git a/gbp/rpm/__init__.py b/gbp/rpm/__init__.py index 91b270cf..8be38590 100644 --- a/gbp/rpm/__init__.py +++ b/gbp/rpm/__init__.py @@ -273,6 +273,8 @@ class SpecFile(object): if m.group('name').lower() == 'ignore-patches': dataitems = m.group('args').strip().split() ignorepatch = sorted([int(num) for num in dataitems]) + elif m.group('name').lower() == 'patch-macros': + ret['patchmacrostart'] = lineobj else: gbp.log.info("Found unrecognized Gbp tag on line %s: " "'%s'" % (i, line)) @@ -461,7 +463,10 @@ class SpecFile(object): "git-buildpackage:\n") # Determine where to add %patch macro lines - if last_removed_macro_line: + if 'patchmacrostart' in loc: + gbp.log.debug("Adding patch macros after the start marker") + line = loc['patchmacrostart'] + elif last_removed_macro_line: gbp.log.debug("Adding patch macros in place of the removed macros") line = last_removed_macro_line elif 'lastpatchmacro' in loc: diff --git a/tests/test_rpm.py b/tests/test_rpm.py index d57ea575..a04bce3e 100644 --- a/tests/test_rpm.py +++ b/tests/test_rpm.py @@ -152,7 +152,14 @@ class TestSpecFile(object): spec = SpecFile(tmp_spec) spec.update_patches(['new.patch']) spec.write_spec_file() + assert filecmp.cmp(tmp_spec, reference_spec) is True + # Test a second spec file + shutil.copy2(os.path.join(SPEC_DIR, 'gbp-test2.spec'), tmp_spec) + reference_spec = os.path.join(SPEC_DIR, 'gbp-test2-reference.spec') + spec = SpecFile(tmp_spec) + spec.update_patches(['new.patch']) + spec.write_spec_file() assert filecmp.cmp(tmp_spec, reference_spec) is True def test_quirks(self): diff --git a/tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec b/tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec index d5a228fd..ffae7e99 100644 --- a/tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec +++ b/tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec @@ -24,6 +24,9 @@ Package for testing the RPM functionality of git-buildpackage. %patch %patch -P 10 -p1 +echo "Do things" + +# Gbp-Patch-Macros %build make diff --git a/tests/test_rpm_data/specs/gbp-test2-reference.spec b/tests/test_rpm_data/specs/gbp-test2-reference.spec new file mode 100644 index 00000000..fbb7ad82 --- /dev/null +++ b/tests/test_rpm_data/specs/gbp-test2-reference.spec @@ -0,0 +1,47 @@ +Name: gbp-test2 +Summary: Test package 2 for git-buildpackage +Epoch: 2 +Version: 3.0 +Release: 0 +Group: Development/Libraries +License: GPLv2 +Source10: ftp://ftp.host.com/%{name}-%{version}.tar.gz +Source: foo.txt +Source20: bar.tar.gz +# Gbp-Ignore-Patches: 0 +Patch: my.patch +# Patches auto-generated by git-buildpackage: +Patch1: new.patch +Packager: Markus Lehtonen + +%description +Package for testing the RPM functionality of git-buildpackage. + + +%prep +%setup -T -n %{name}-%{version} -c -a 10 + +%patch + +echo "Do things" + +# Gbp-Patch-Macros +# new.patch +%patch1 -p1 + +%build +make + + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/%{_datadir}/%{name} +cp -R * %{buildroot}/%{_datadir}/%{name} +install %{SOURCE0} %{buildroot}/%{_datadir}/%{name} + + + +%files +%defattr(-,root,root,-) +%dir %{_datadir}/%{name} +%{_datadir}/%{name}