rpm: introduce new 'Gbp-Patch-Macros' special key in spec parsing
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Wed, 21 Nov 2012 10:54:04 +0000 (12:54 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 5 Jun 2014 11:20:06 +0000 (14:20 +0300)
This can be used to mark location where to add new patch macros when
updating the spec.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/rpm/__init__.py
tests/test_rpm.py
tests/test_rpm_data/rpmbuild/SPECS/gbp-test2.spec
tests/test_rpm_data/specs/gbp-test2-reference.spec [new file with mode: 0644]

index 91b270cfa47ba5eb761a981b72957c1bba954b18..8be38590c49aad8be09ef13f3fe04b5de31cbb3f 100644 (file)
@@ -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:
index d57ea575dd4d13cc50b6ce065c8eb8bdae7b27f0..a04bce3eb258ed8f958769fcb2333bb6d9817735 100644 (file)
@@ -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):
index d5a228fd19f92dc4064b363b33a55411cc5a5446..ffae7e999aa0849b03a6ca78b02562f760bb89d9 100644 (file)
@@ -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 (file)
index 0000000..fbb7ad8
--- /dev/null
@@ -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 <markus.lehtonen@linux.intel.com>
+
+%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}