rpm helpers: yet another fix to patch numbering
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 11 Jan 2013 14:36:28 +0000 (16:36 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 7 Jan 2014 14:21:30 +0000 (16:21 +0200)
'Patch:' does not indicate "patch number 0". Patch: and 'Patch0:' can
both be present in the same spec file.

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-test-tags.spec
tests/test_rpm_data/specs/gbp-test-updates-reference.spec
tests/test_rpm_data/specs/gbp-test-updates.spec
tests/test_rpm_data/specs/gbp-test2-reference.spec
tests/test_rpm_data/specs/gbp-test2-reference2.spec

index 08e782a4a866f0c4529c939d76d544cd9a3c8cce..4241bbebfa1b536b22f4eba489588dd2aed895cb 100644 (file)
@@ -43,9 +43,6 @@ except ImportError:
     gbp.log.debug("Failed to import '%s' as rpm python module, using host's default rpm library instead" % RpmPkgPolicy.python_rpmlib_module_name)
     import rpm
 
-# define a large number to check the valid id of source file
-MAX_SOURCE_NUMBER = 99999
-
 
 class NoSpecError(Exception):
     """Spec file parsing error"""
@@ -272,7 +269,7 @@ class SpecFile(object):
                         'setup_options': None, }
         # 'Patch:' tags
         elif tagname == 'patch':
-            tagnum = 0 if tagnum is None else tagnum
+            tagnum = -1 if tagnum is None else tagnum
             new_patch = {'name': matchobj.group('name').strip(),
                          'filename': matchobj.group('name'),
                          'apply': False,
@@ -349,7 +346,7 @@ class SpecFile(object):
             elif opts.patchnum:
                 directiveid = int(opts.patchnum)
             else:
-                directiveid = 0
+                directiveid = -1
 
             if opts.strip:
                 self.patches[directiveid]['strip'] = opts.strip
@@ -423,8 +420,6 @@ class SpecFile(object):
         # And, double-check that we parsed spec content correctly
         for (name, num, typ) in self._specinfo.sources:
             # workaround rpm parsing bug
-            if num >= MAX_SOURCE_NUMBER:
-                num = 0
             if typ == 1 or typ == 9:
                 if num in self.sources:
                     self.sources[num]['filename'] = os.path.basename(name)
@@ -442,6 +437,10 @@ class SpecFile(object):
                 else:
                     gbp.log.err("BUG: we didn't correctly parse all 'Source' tags!")
             if typ == 2 or typ == 10:
+                # Patch tag without any number defined is treated by RPM as
+                # having number (2^31-1), we use number -1
+                if num >= pow(2,30):
+                    num = -1
                 if num in self.patches:
                     self.patches[num]['filename'] = name
                 else:
index ad4525b8772c0ace240c1392884ab758cc1341a5..3e04fcd896ea99f6126ac91d99947c23b87823f8 100644 (file)
@@ -197,8 +197,8 @@ class TestSpecFile(object):
         prev = spec.protected('_delete_tag')('Vendor', None)
         spec.protected('_set_tag')('License', None, 'new license', prev)
         spec.protected('_delete_tag')('source', 0)
-        spec.protected('_delete_tag')('patch', 1)
         spec.protected('_delete_tag')('patch', 0)
+        spec.protected('_delete_tag')('patch', -1)
         prev = spec.protected('_delete_tag')('invalidtag', None)
 
         with assert_raises(GbpError):
@@ -209,9 +209,9 @@ class TestSpecFile(object):
             spec.set_tag('invalidtag', None, 'value')
 
         # Mangle macros
-        prev = spec.protected('_delete_special_macro')('patch', 0)
+        prev = spec.protected('_delete_special_macro')('patch', -1)
         spec.protected('_delete_special_macro')('patch', 123)
-        spec.protected('_set_special_macro')('patch', 1, 'my new args', prev)
+        spec.protected('_set_special_macro')('patch', 0, 'my new args', prev)
         with assert_raises(GbpError):
             spec.protected('_delete_special_macro')('invalidmacro', 0)
         with assert_raises(GbpError):
@@ -249,6 +249,8 @@ class TestSpecFile(object):
                                               (name, val['value'], rval))
             assert spec.ignorepatches == []
 
+            assert spec.patches.keys() == [0, -1]
+
 
 class TestUtilityFunctions(object):
     """Test utility functions of L{gbp.rpm}"""
index 4180a87788d2106fd6263f0483225fff53efdfa4..dd9e2ec2ef39f61675010334d9c15cb58919877a 100644 (file)
@@ -8,7 +8,7 @@ License:    GPLv2
 Source10:   ftp://ftp.host.com/%{name}-%{version}.tar.gz
 Source:     foo.txt
 Source20:   bar.tar.gz
-# Gbp-Ignore-Patches: 0
+# Gbp-Ignore-Patches: -1
 Patch:      my.patch
 Patch10:    my2.patch
 Patch20:    my3.patch
index 9841a39ef74d58e6427d744b73d6d29a26372d44..47421a9db592e734ebfeacdb30bbbd95adefc727 100644 (file)
@@ -27,7 +27,8 @@ Packager:       my_packager
 Url:            my_url
 Vcs:            my_vcs
 Source:         my_source
-Patch0:         my_patch
+Patch:          my_patch
+Patch0:         my_patch0
 Nosource:       0
 Nopatch:        0
 #Icon:           my_icon
index eae2739a9bd0c6a04ad4c51e7802ba8556c16503..ff56f589a58f2c64657d1cd9e2ac2adba421d457 100644 (file)
@@ -16,7 +16,7 @@ Packager:       my_packager
 Url:            my_url
 Vcs:            my_vcs
 Nosource:       0
-Nopatch:        1
+Nopatch:        0
 BuildRoot:      my_buildroot
 Provides:       my_provides
 Requires:       my_requires
@@ -37,7 +37,7 @@ Package for testing GBP.
 %prep
 %setup -n my_prefix
 
-%patch1 my new args
+%patch0 my new args
 
 %build
 
index 0bc157122b257f73066eef344c94381eee2631ac..dc8ffbf984593ea33b6f2f696a2f5c81a3dc719e 100644 (file)
@@ -18,9 +18,9 @@ Url:            my_url
 Vcs:            my_vcs
 Source:         my_source
 Patch:          my_%patch_fn_base
-Patch1:         my_%{patch_fn_base}1
+Patch0:         my_%{patch_fn_base}0
 Nosource:       0
-Nopatch:        1
+Nopatch:        0
 BuildRoot:      my_buildroot
 Provides:       my_provides
 Requires:       my_requires
@@ -42,7 +42,7 @@ Package for testing GBP.
 %setup -n my_prefix
 
 %patch -b my_patch
-%patch -P1 -b my_patch0
+%patch -P0 -b my_patch0
 
 %build
 
index fbb7ad828a17e3a3fed578b40bc99c6683fdbb85..e31930d7f074f9ab524ef409a44193365fd9d984 100644 (file)
@@ -8,10 +8,10 @@ License:    GPLv2
 Source10:   ftp://ftp.host.com/%{name}-%{version}.tar.gz
 Source:     foo.txt
 Source20:   bar.tar.gz
-# Gbp-Ignore-Patches: 0
+# Gbp-Ignore-Patches: -1
 Patch:      my.patch
 # Patches auto-generated by git-buildpackage:
-Patch1:     new.patch
+Patch0:     new.patch
 Packager:   Markus Lehtonen <markus.lehtonen@linux.intel.com>
 
 %description
@@ -27,7 +27,7 @@ echo "Do things"
 
 # Gbp-Patch-Macros
 # new.patch
-%patch1 -p1
+%patch0 -p1
 
 %build
 make
index 02356d0a60418a556f19971aa4cb070e40ad6760..095600d33d24936fcef067897f02757ee376c1cb 100644 (file)
@@ -8,10 +8,10 @@ License:    GPLv2
 Source10:   ftp://ftp.host.com/%{name}-%{version}.tar.gz
 Source:     foo.txt
 Source20:   bar.tar.gz
-# Gbp-Ignore-Patches: 0
+# Gbp-Ignore-Patches: -1
 Patch:      my.patch
 # Patches auto-generated by git-buildpackage:
-Patch1:     new.patch
+Patch0:     new.patch
 Packager:   Markus Lehtonen <markus.lehtonen@linux.intel.com>
 VCS:        myvcstag
 
@@ -28,7 +28,7 @@ echo "Do things"
 
 # Gbp-Patch-Macros
 # new.patch
-%patch1 -p1
+%patch0 -p1
 
 %build
 make