make.conf: recurse directories, bug #463266
authorZac Medico <zmedico@gentoo.org>
Tue, 26 Mar 2013 19:14:50 +0000 (12:14 -0700)
committerZac Medico <zmedico@gentoo.org>
Tue, 26 Mar 2013 20:05:45 +0000 (13:05 -0700)
pym/portage/package/ebuild/config.py
pym/portage/util/__init__.py

index 5f3e1c6b7861f5db4b57514149ba5bc8e07f5e96..1d2e4a60aed1c8d02e4abc142bb38ba78dceda9f 100644 (file)
@@ -339,7 +339,7 @@ class config(object):
                        for x in make_conf_paths:
                                mygcfg = getconfig(x,
                                        tolerant=tolerant, allow_sourcing=True,
-                                       expand=make_conf)
+                                       expand=make_conf, recursive=True)
                                if mygcfg is not None:
                                        make_conf.update(mygcfg)
                                        make_conf_count += 1
@@ -538,7 +538,7 @@ class config(object):
                        for x in make_conf_paths:
                                mygcfg.update(getconfig(x,
                                        tolerant=tolerant, allow_sourcing=True,
-                                       expand=expand_map) or {})
+                                       expand=expand_map, recursive=True) or {})
 
                        # Don't allow the user to override certain variables in make.conf
                        profile_only_variables = self.configdict["defaults"].get(
index dafc3e34d769168cc56563fb70aef3748dff4f20..59d4fa4c46f931c60134fceba6159acaeee03991 100644 (file)
@@ -483,6 +483,9 @@ def grabfile_package(myfilename, compatlevel=0, recursive=0, allow_wildcard=Fals
                                        atoms.append(pkg_orig)
        return atoms
 
+def _recursive_basename_filter(f):
+       return not f.startswith(".") and not f.endswith("~")
+
 def grablines(myfilename, recursive=0, remember_source_file=False):
        mylines=[]
        if recursive and os.path.isdir(myfilename):
@@ -499,7 +502,7 @@ def grablines(myfilename, recursive=0, remember_source_file=False):
                                raise
                dirlist.sort()
                for f in dirlist:
-                       if not f.startswith(".") and not f.endswith("~"):
+                       if _recursive_basename_filter(f):
                                mylines.extend(grablines(
                                        os.path.join(myfilename, f), recursive, remember_source_file))
        else:
@@ -558,7 +561,9 @@ class _tolerant_shlex(shlex.shlex):
 
 _invalid_var_name_re = re.compile(r'^\d|\W')
 
-def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True):
+def getconfig(mycfg, tolerant=False, allow_sourcing=False, expand=True,
+       recursive=False):
+
        if isinstance(expand, dict):
                # Some existing variable definitions have been
                # passed in, for use in substitutions.
@@ -567,6 +572,46 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True):
        else:
                expand_map = {}
        mykeys = {}
+
+       if recursive and os.path.isdir(mycfg):
+               # Use source commands so that syntax error messages
+               # can display real file names and line numbers.
+               recursive_files = []
+               for parent, dirs, files in os.walk(mycfg):
+                       try:
+                               parent = _unicode_decode(parent,
+                                       encoding=_encodings['fs'], errors='strict')
+                       except UnicodeDecodeError:
+                               continue
+                       for fname_enc in dirs[:]:
+                               try:
+                                       fname = _unicode_decode(fname_enc,
+                                               encoding=_encodings['fs'], errors='strict')
+                               except UnicodeDecodeError:
+                                       dirs.remove(fname_enc)
+                                       continue
+                               if fname in VCS_DIRS or not _recursive_basename_filter(fname):
+                                       dirs.remove(fname_enc)
+                       for fname in files:
+                               try:
+                                       fname = _unicode_decode(fname,
+                                               encoding=_encodings['fs'], errors='strict')
+                               except UnicodeDecodeError:
+                                       pass
+                               else:
+                                       if _recursive_basename_filter(fname):
+                                               fname = os.path.join(parent, fname)
+                                               if os.path.isfile(fname):
+                                                       recursive_files.append(fname)
+               recursive_files.sort()
+               if not expand:
+                       expand_map = False
+               for fname in recursive_files:
+                       mykeys.update(getconfig(fname, tolerant=tolerant,
+                               allow_sourcing=allow_sourcing, expand=expand_map,
+                               recursive=False) or {})
+               return mykeys
+
        f = None
        try:
                # NOTE: shlex doesn't support unicode objects with Python 2