rpm-software-management / spec-cleaner

spec-cleaner
BSD 3-Clause "New" or "Revised" License
27 stars 33 forks source link

spec-cleaner puts %patch0 instead of %patch -P 0 => breaks with RPM 4.20 #319

Closed DimStar77 closed 4 months ago

DimStar77 commented 4 months ago

https://github.com/rpm-software-management/spec-cleaner/blob/2ff2cb60332eb15ca3f0920d8141c8145ec20315/spec_cleaner/rpmprep.py#L72

That code is the wrong way around: %patch0 will fail to build with RPM 4.20; this needs to be %patch -P 0

seife commented 4 months ago
diff --git a/spec_cleaner/rpmprep.py b/spec_cleaner/rpmprep.py
index da2a96c..7f474d7 100644
--- a/spec_cleaner/rpmprep.py
+++ b/spec_cleaner/rpmprep.py
@@ -58,7 +58,7 @@ class RpmPrep(Section):
         """
         Convert patchlines to something pretty.

-        E.g. it converts "%patch -P 50 -p10" to "%patch50 -p10" and so on.
+        E.g. it converts "%patch50 -p10" to "%patch -P 50 -p10" and so on.

         Args:
             line: A string representing a line to process.
@@ -69,16 +69,15 @@ class RpmPrep(Section):
         # -p0 is default
         if line.startswith('%patch'):
             line = line.replace('-p0', '')
-        # %patch0 is desired
+        # %patch without -P was %patch0 before, convert to %patch0 for the reges
         if (line.startswith('%patch ') or line == '%patch') and '-P' not in line:
             line = line.replace('%patch', '%patch0')

-        # convert the %patch -P 50 -p10 to %patch50 -p10
-        # this apply only if there is ONE -P on the line, not multiple ones
+        # convert the %patch50 -p10 to %patch -P 50 -p10
         match = self.reg.re_patch_prep.match(line)
         if match:
             line = self.strip_useless_spaces(
-                '%%patch%s %s %s' % (match.group(2), match.group(1), match.group(3))
+                '%%patch -P %s %s' % (match.group(1), match.group(2))
             )

         return line
diff --git a/spec_cleaner/rpmregexp.py b/spec_cleaner/rpmregexp.py
index 97b59b1..4483d68 100644
--- a/spec_cleaner/rpmregexp.py
+++ b/spec_cleaner/rpmregexp.py
@@ -167,7 +167,7 @@ class Regexp(object):
     re_rm_double = re.compile(r'(\.|{)a')

     # rpmprep
-    re_patch_prep = re.compile(r'^%patch\s*([^P]*)-P\s*(\d*)\s*([^P]*)$')
+    re_patch_prep = re.compile(r'^%patch(\d+)\s*(.*)$')
     re_setup = re.compile(r'\s*-n\s+"?%{name}-%{version}"?($|\s)')
     re_dephell_setup = re.compile(r'\s*dephell[s]?.*convert')

this should suffice. Unfortunately I don't understand a single word of the "contribution guidelines" in the Readme, so I don't dare creating a proper pullrequest.