From e9e9f7323a65a704ebb62b849c8716876b0b98a8 Mon Sep 17 00:00:00 2001 From: Olav Vitters Date: Wed, 9 Jul 2014 22:55:15 +0200 Subject: detect lack of apply_patches, clean unneeded setup option --- mgagnome | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/mgagnome b/mgagnome index c5ebf60..1b8ebd9 100755 --- a/mgagnome +++ b/mgagnome @@ -341,7 +341,7 @@ class SpecFile(object): re_update_release = re.compile(r'^(?P
Release:\s*)(?P%mkrel \d+)(?P\s*)$', re.MULTILINE + re.IGNORECASE)
     re_update_patch = re.compile(r'^(?P
Patch)(?P[0-9]*)(?P:\s*)(?P.+)(?P\s*)\n', re.MULTILINE + re.IGNORECASE)
 
-    re_br_part = re.compile(r'(?P
[^\s%{},<>=][^\s%{},<>=]*)\b(?P\s*(?:(?P=|>=|<=|>|<)\s*(?P[^\s%{},]+|\%\{[^\s{%}]+\}|\%[^\s%{},]+)\b)?)') + re_br_part = re.compile(r'(?P
[^\s%{},<>=][^\s%{},<>=]*)\b(?P\s*(?:(?P=|>=|<=|=<|=>|>|<)\s*(?P[^\s%{},]+|\%\{[^\s{%}]+\}|\%[^\s%{},]+)\b)?)') #re_update_br = re.compile(r'^(?P
BuildRequires:\s*)(?P
[^\s%{},]+?)(?P\s*(?:(?:[<>]=?|=)\s+[^\s%{},]+?)?\s*\n)', re.MULTILINE + re.IGNORECASE) re_update_br = re.compile(r'^(?P
BuildRequires:\s*)(?P
[^\s%{},]+?)(?P\s*(?:(?:[<>]=?|=)\s+(?:[^\s%{},]+|\%\{[^\s{%}]+\}|\%[^\s%{},]+))?\s*\n)', re.MULTILINE + re.IGNORECASE) @@ -385,8 +385,9 @@ class SpecFile(object): # remove %defattr ('remove defattr', re.compile(r'(?P^\%files(?:[ \t]+[^\n]*)?\n(?:^\%doc [^\n]+\n)?)^\%defattr\s*\(- *, *root *, *root *(?:, *-)?\)\s*\n', re.MULTILINE + re.IGNORECASE)), ('remove cleaning buildroot in install', re.compile(r'(?P^\%install(?:[ \t]+[^\n]*)?\n)' + re_rm_buildroot + r'\n?', re.MULTILINE + re.IGNORECASE)), - ('remove clean section', re.compile(r'^\%clean[ \t]*\n(?:' + re_rm_buildroot + r')?\s*(?P^(?:\%files|\%post|\%pre|\%trigger|\%install|\%package|\%check|\%_font_pkg|$(?!.|\n)))', re.MULTILINE + re.IGNORECASE)), + ('remove clean section', re.compile(r'^\%clean[ \t]*\n(?:' + re_rm_buildroot + r')?\s*(?P(?:^#[^%\n]+\n)*^(?:\%files|\%post|\%pre|\%trigger|\%install|\%package|\%check|\%_font_pkg|$(?!.|\n)))', re.MULTILINE + re.IGNORECASE)), ('remove buildroot definition', re.compile(r'^BuildRoot:[^\n]+\n', re.MULTILINE + re.IGNORECASE)), + ('remove unneeded setup option', re.compile(r'^(?P\%setup -q )-n (?:\%name|\%\{name\})-(?:\%version|\%\{version\})(?P\n)', re.MULTILINE + re.IGNORECASE)), ] re_convert_br = [ ('remove py_requires', ('python',), re.compile(r'^\%(?:py_requires|\{py_requires\})[ \t]*\n', re.MULTILINE)), @@ -451,6 +452,12 @@ class SpecFile(object): data = data.lstrip() self._changes.append('SILENT remove variable definition(s) %s' % ", ".join(converted_defines)) + # Make use of %apply_patches + patches = self.patches + if patches and not self.uses_apply_patches: + print "WARNING: Patches, no %%apply_patches for %s" % self.module + print self.module, patches + # Overwrite file with new version number if made_changes: write_file(self.path, data) @@ -584,6 +591,7 @@ class SpecFile(object): print >>sys.stderr, "ERROR: Problem in %prep phase" return False finally: + # bm command doesn't cleanup after itself and the option it has to do that removes spec file + sources! buildpath = os.path.join(self.cwd, '..', 'BUILD', '%s-%s' % (self.module, self.version)) if os.path.exists(buildpath): shutil.rmtree(buildpath, ignore_errors=True) @@ -596,23 +604,25 @@ class SpecFile(object): # XXX - doesn't handle buildrequires with version numbers :-( made_changes = False + re_patch = re.compile(r'^\%patch(?P[0-9]*)(?:[ \t]+-p(P[0-9]+))?(?:[ \t]+-b[ \t]+\S+)?\n', re.MULTILINE) + with open(self.path, "rw") as f: data = f.read() data_before=data - # Change =< and => operators into <= and >= - # XXX - pretty ugly - data, nr = self.re_update_br_fix_operator.subn(lambda mo: mo.group(0).replace('=>', '>=').replace('=<', '<') if self.re_update_br.match(mo.group(0).replace('=>', '>=').replace('=<', '<')) else mo.group(0), data) + # Change any "," in buildrequires into multiple lines + data, nr = self.re_update_br_unsplit.subn(lambda mo: ''.join((''.join((mo.group('pre'), mo2.group(0), mo.group('unsplitpost'))) for mo2 in self.re_br_part.finditer(mo.group('unsplit')) if mo.group(0).strip() != '')), data) if data_before != data: made_changes = True - self._changes.append('SILENT fix operator in buildrequires') + self._changes.append('SILENT one line per buildrequirement') data_before = data - # Change any "," in buildrequires into multiple lines - data, nr = self.re_update_br_unsplit.subn(lambda mo: ''.join((''.join((mo.group('pre'), mo2.group(0), mo.group('unsplitpost'))) for mo2 in self.re_br_part.finditer(mo.group('unsplit')) if mo.group(0).strip() != '')), data) + # Change =< and => operators into <= and >= + # XXX - pretty ugly + data, nr = self.re_update_br_fix_operator.subn(lambda mo: mo.group(0).replace('=>', '>=').replace('=<', '<') if self.re_update_br.match(mo.group(0).replace('=>', '>=').replace('=<', '<')) else mo.group(0), data) if data_before != data: made_changes = True - self._changes.append('SILENT one line per buildrequirement') + self._changes.append('SILENT fix operator in buildrequires') data_before = data # Now update buildrequires if any -- cgit v1.2.1