Implement the sed-based declare -r filter in python.
authorZac Medico <zmedico@gentoo.org>
Thu, 6 Mar 2008 01:03:42 +0000 (01:03 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 6 Mar 2008 01:03:42 +0000 (01:03 -0000)
svn path=/main/trunk/; revision=9446

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

index 542fca9e2f87378d3c3ea0d8845d8db5126d111e..cfe22500603280bf707df9341953fe0860b90717 100755 (executable)
@@ -1441,15 +1441,7 @@ filter_readonly_variables() {
                "
        fi
 
-       # TODO: Take the the below sed-based declare -r filter and integrate it
-       #       directly into filter-bash-environment.py.
-       # 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
-       # eventually needs to be reloaded.
-       "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}" | sed -r \
-               -e 's:^declare[[:space:]]+-r[[:space:]]+:declare :' \
-               -e 's:^declare[[:space:]]+-([[:alnum:]]*)r([[:alnum:]]*)[[:space:]]+:declare -\1\2 :'
+       "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}"
 }
 
 # @FUNCTION: preprocess_ebuild_env
index ab348d992393fa5906ac32dd7f9ef68695311c37..5e109295f0d16c001c6f932e0c9af47de5d01781 100755 (executable)
@@ -17,6 +17,7 @@ func_end_re = re.compile(r'^\}$')
 
 var_assign_re = re.compile(r'(^|^declare\s+-\S+\s+|^export\s+)([^=\s]+)=("|\')?.*$')
 close_quote_re = re.compile(r'(\\"|"|\')\s*$')
+readonly_re = re.compile(r'^declare\s+-(\S*)r(\S*)\s+')
 
 def compile_egrep_pattern(s):
        for k, v in egrep_compat_map.iteritems():
@@ -57,6 +58,18 @@ def filter_bash_environment(pattern, file_in, file_out):
                                        multi_line_quote = quote
                                        multi_line_quote_filter = filter_this
                                if not filter_this:
+                                       readonly_match = readonly_re.match(line)
+                                       if readonly_match is not None:
+                                               declare_opts = ""
+                                               for i in (1, 2):
+                                                       group = readonly_match.group(i)
+                                                       if group is not None:
+                                                               declare_opts += group
+                                               if declare_opts:
+                                                       line = "declare -%s %s" % \
+                                                               (declare_opts, line[readonly_match.end():])
+                                               else:
+                                                       line = "declare " + line[readonly_match.end():]
                                        file_out.write(line)
                                continue
                if here_doc_delim is not None: