Merged from trunk 10716:10726
authorFabian Groffen <grobian@gentoo.org>
Thu, 19 Jun 2008 19:41:50 +0000 (19:41 -0000)
committerFabian Groffen <grobian@gentoo.org>
Thu, 19 Jun 2008 19:41:50 +0000 (19:41 -0000)
   | 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
pym/repoman/checks.py

index 197aec62db2cb6ec29f6b59b763188a7f374c90e..6c5c3416226e50ae44df452236cbc0dc1af93f45 100644 (file)
@@ -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):
index b4caff27ff1537b72b66d0ac54ef383bae9b5f8b..4b002568f74376b31b11db09cd86260290c14859 100644 (file)
@@ -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