From 03c415093173ade75ca21f7532601592c3546ab4 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Thu, 19 Jun 2008 19:41:50 +0000 Subject: [PATCH] Merged from trunk 10716:10726 | 10717 | Bug #228075 - Explicitly call gc.collect() to try and free | | zmedico | memory when checking for blockers. This avoids a heap | | | overflow that triggers 'Cannot allocate memory' errors | | | (reported with python-2.5). | | 10723 | Refactor the 'inherit.autotools' and 'IUSE.undefined' checks | | zmedico | into classes derived from LineCheck. | | 10725 | Pass a Package instance into LineCheck.new(), and use this | | zmedico | to avoid passing the ebuild mtime into the EbuildHeader | | | constructor (the mtime is given when the new() method is | | | called). | svn path=/main/branches/prefix/; revision=10728 --- pym/_emerge/__init__.py | 8 ++++ pym/repoman/checks.py | 104 +++++++++++++++++++++++++++------------- 2 files changed, 80 insertions(+), 32 deletions(-) diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index 197aec62d..6c5c34162 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -5866,6 +5866,12 @@ class MergeTask(object): if self._opts_ignore_blockers.intersection(self.myopts): return None + # Call gc.collect() here to avoid heap overflow that + # triggers 'Cannot allocate memory' errors (reported + # with python-2.5). + import gc + gc.collect() + blocker_dblinks = [] for blocking_pkg in self._blocker_db[ new_pkg.root].findInstalledBlockers(new_pkg, @@ -5879,6 +5885,8 @@ class MergeTask(object): self.pkgsettings[blocking_pkg.root], treetype="vartree", vartree=self.trees[blocking_pkg.root]["vartree"])) + gc.collect() + return blocker_dblinks def merge(self, mylist, favorites, mtimedb): diff --git a/pym/repoman/checks.py b/pym/repoman/checks.py index b4caff27f..4b002568f 100644 --- a/pym/repoman/checks.py +++ b/pym/repoman/checks.py @@ -16,11 +16,17 @@ class LineCheck(object): """A regular expression to determine whether to ignore the line""" ignore_line = False + def new(self, pkg): + pass + def check(self, num, line): """Run the check on line and return error if there is one""" if self.re.match(line): return self.error + def end(self): + pass + class EbuildHeader(LineCheck): """Ensure ebuilds have proper headers Copyright header errors @@ -39,9 +45,10 @@ class EbuildHeader(LineCheck): gentoo_license = r'# Distributed under the terms of the GNU General Public License v2' cvs_header = re.compile(r'^#\s*\$Header.*\$$') - def __init__(self, st_mtime): - self.modification_year = str(time.gmtime(st_mtime)[0]) - self.gentoo_copyright_re = re.compile(self.gentoo_copyright % self.modification_year) + def new(self, pkg): + self.modification_year = str(time.gmtime(pkg.mtime)[0]) + self.gentoo_copyright_re = re.compile( + self.gentoo_copyright % self.modification_year) def check(self, num, line): if num > 2: @@ -211,44 +218,77 @@ class EbuildQuotedA(LineCheck): if match: return "Quoted \"${A}\" on line: %d" +class InheritAutotools(LineCheck): + """ + Make sure appropriate functions are called in + ebuilds that inherit autotools.eclass. + """ + + repoman_check_name = 'inherit.autotools' + ignore_line = re.compile(r'(^|\s*)#') + _inherit_autotools_re = re.compile(r'^\s*inherit\s(.*\s)?autotools(\s|$)') + _autotools_funcs = ( + "eaclocal", "eautoconf", "eautoheader", + "eautomake", "eautoreconf", "_elibtoolize") + _autotools_func_re = re.compile(r'(^|\s)(' + \ + "|".join(_autotools_funcs) + ')(\s|$)') + + def new(self, pkg): + self._inherit_autotools = None + self._autotools_func_call = None + + def check(self, num, line): + if self._inherit_autotools is None: + self._inherit_autotools = self._inherit_autotools_re.match(line) + if self._inherit_autotools is not None and \ + self._autotools_func_call is None: + self._autotools_func_call = self._autotools_func_re.search(line) + + def end(self): + if self._inherit_autotools and self._autotools_func_call is None: + yield 'no eauto* function called' + +class IUseUndefined(LineCheck): + """ + Make sure the ebuild defines IUSE (style guideline + says to define IUSE even when empty). + """ + + repoman_check_name = 'IUSE.undefined' + _iuse_def_re = re.compile(r'^IUSE=.*') + + def new(self, pkg): + self._iuse_def = None + + def check(self, num, line): + if self._iuse_def is None: + self._iuse_def = self._iuse_def_re.match(line) + + def end(self): + if self._iuse_def is None: + yield 'IUSE is not defined' + _constant_checks = tuple((c() for c in ( - EbuildWhitespace, EbuildQuote, + EbuildHeader, EbuildWhitespace, EbuildQuote, EbuildAssignment, EbuildUselessDodoc, EbuildUselessCdS, EbuildNestedDie, - EbuildPatches, EbuildQuotedA))) - -_iuse_def_re = re.compile(r'^IUSE=.*') -_comment_re = re.compile(r'(^|\s*)#') -_inherit_autotools_re = re.compile(r'^\s*inherit\s(.*\s)?autotools(\s|$)') -_autotools_funcs = ( - "eaclocal", "eautoconf", "eautoheader", - "eautomake", "eautoreconf", "_elibtoolize") -_autotools_func_re = re.compile(r'(^|\s)(' + \ - "|".join(_autotools_funcs) + ')(\s|$)') + EbuildPatches, EbuildQuotedA, + IUseUndefined, InheritAutotools))) def run_checks(contents, pkg): - checks = list(_constant_checks) - checks.append(EbuildHeader(pkg.mtime)) - iuse_def = None - inherit_autotools = None - autotools_func_call = None + checks = _constant_checks + + for lc in checks: + lc.new(pkg) for num, line in enumerate(contents): - comment = _comment_re.match(line) - if comment is None: - if inherit_autotools is None: - inherit_autotools = _inherit_autotools_re.match(line) - if inherit_autotools is not None and \ - autotools_func_call is None: - autotools_func_call = _autotools_func_re.search(line) - if iuse_def is None: - iuse_def = _iuse_def_re.match(line) for lc in checks: ignore = lc.ignore_line if not ignore or not ignore.match(line): e = lc.check(num, line) if e: yield lc.repoman_check_name, e % (num + 1) - if iuse_def is None: - yield 'IUSE.undefined', 'IUSE is not defined' - if inherit_autotools and autotools_func_call is None: - yield 'inherit.autotools', 'no eauto* function called' + for lc in checks: + i = lc.end() + if i is not None: + for e in i: + yield lc.repoman_check_name, e -- 2.26.2