Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
DimStar77 opened this issue Feb 21, 2024 · 1 comment · Fixed by #320
Closed

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

DimStar77 opened this issue Feb 21, 2024 · 1 comment · Fixed by #320

Comments

@DimStar77
Copy link
Contributor

# %patch0 is desired

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

@seife
Copy link

seife commented Feb 23, 2024

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.

danigm added a commit to danigm/spec-cleaner that referenced this issue Feb 27, 2024
The usage of %patchN is not supported by RPM >= 4.20. The preferred way
to apply patches are, in order:
 * %autosetup -p1
 * %autosetup -N / %autopatch -p1
 * %setup / %patch -P <N> -p 1

This patch changes the usage of "%patchN" with the new format
"%patch -P N"

Thanks to Stefan Seyfried (@seife) for the initial patch.

Fix rpm-software-management#319
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants