Implement variable assignment handling in python so that we can eventually
authorZac Medico <zmedico@gentoo.org>
Wed, 5 Mar 2008 09:20:27 +0000 (09:20 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 5 Mar 2008 09:20:27 +0000 (09:20 -0000)
make it more flexible and robust.

svn path=/main/trunk/; revision=9436

bin/ebuild.sh
bin/filter-bash-environment.py

index 6ccd3685637162a52a43175ca2c033238cba3bf2..6ca4d6a7565ee321a7137163c5a8e670e49600dd 100755 (executable)
@@ -1448,7 +1448,6 @@ filter_readonly_variables() {
        done
        set +f
        var_grep=${var_grep:1} # strip the first |
-       var_grep="(^|^declare[[:space:]]+-[^[:space:]]+[[:space:]]+|^export[[:space:]]+)(${var_grep})=.*"
        # The sed is to remove the readonly attribute from variables such as those
        # listed in READONLY_EBUILD_METADATA, since having any readonly attributes
        # persisting in the saved environment can be inconvenient when it
index 93b049768d20d936bcbf3598b60e9eb337050350..c35bf11ff3efeb93ce91b0fff762789c8d4e7753 100755 (executable)
@@ -15,6 +15,8 @@ here_doc_re = re.compile(r'.*\s<<[-]?(\w+)$')
 func_start_re = re.compile(r'^[-\w]+\s*\(\)\s*$')
 func_end_re = re.compile(r'^\}$')
 
+var_assign_re = re.compile(r'(^|^declare\s+-\S+\s+|^export\s+)([^=\s]+)=.*$')
+
 def compile_egrep_pattern(s):
        for k, v in egrep_compat_map.iteritems():
                s = s.replace(k, v)
@@ -46,8 +48,14 @@ def filter_bash_environment(pattern, file_in, file_out):
                if in_func is not None:
                        file_out.write(line)
                        continue
-               if pattern.match(line) is None:
-                       file_out.write(line)
+               var_assign_match = var_assign_re.match(line)
+               if var_assign_match is not None:
+                       if pattern.match(var_assign_match.group(2)) is None:
+                               file_out.write(line)
+                       continue
+               # TODO: properly handle multi-line variable assignments
+               # like those which the 'export' builtin can produce.
+               file_out.write(line)
 
 if __name__ == "__main__":
        description = "Filter out any lines that match a given PATTERN " + \