[paludis-commits] r4102 - in trunk: . paludis/repositories/e/ebuild paludis/repositories/e/ebuild/utils

dleverton at svn.pioto.org dleverton at svn.pioto.org
Fri Dec 28 22:29:14 UTC 2007


Author: dleverton
Date: 2007-12-28 22:29:03 +0000 (Fri, 28 Dec 2007)
New Revision: 4102

Added:
   trunk/paludis/repositories/e/ebuild/source_functions.bash
   trunk/paludis/repositories/e/ebuild/utils/print_exports.cc
Modified:
   trunk/ChangeLog
   trunk/paludis/repositories/e/ebuild/Makefile.am
   trunk/paludis/repositories/e/ebuild/builtin_loadenv.bash
   trunk/paludis/repositories/e/ebuild/builtin_saveenv.bash
   trunk/paludis/repositories/e/ebuild/ebuild.bash
   trunk/paludis/repositories/e/ebuild/utils/Makefile.am
   trunk/paludis/repositories/e/ebuild/write_vdb_entry.bash
Log:
Rework environment filtering, removing the need to try to parse bash code with sed.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-12-27 19:05:00 UTC (rev 4101)
+++ trunk/ChangeLog	2007-12-28 22:29:03 UTC (rev 4102)
@@ -5,6 +5,11 @@
 only listed in SVN log. For a summary of what has changed between releases,
 see the NEWS file. This file is occasionally pruned to ChangeLog.old.bz2.
 
+2007-12-28 David Leverton
+
+	* paludis/repositories/e/ebuild/: Rework environment filtering,
+	removing the need to try to parse bash code with sed.
+
 2007-12-15 Fernando J. Pereda
 
 	* src/output/console_install_task.cc: Don't show suggestions for target

Modified: trunk/paludis/repositories/e/ebuild/Makefile.am
===================================================================
--- trunk/paludis/repositories/e/ebuild/Makefile.am	2007-12-27 19:05:00 UTC (rev 4101)
+++ trunk/paludis/repositories/e/ebuild/Makefile.am	2007-12-28 22:29:03 UTC (rev 4102)
@@ -39,6 +39,7 @@
 	pkg_setup.bash \
 	portage_stubs.bash \
 	sandbox.bash \
+	source_functions.bash \
 	src_compile.bash \
 	src_install.bash \
 	src_test.bash \

Modified: trunk/paludis/repositories/e/ebuild/builtin_loadenv.bash
===================================================================
--- trunk/paludis/repositories/e/ebuild/builtin_loadenv.bash	2007-12-27 19:05:00 UTC (rev 4101)
+++ trunk/paludis/repositories/e/ebuild/builtin_loadenv.bash	2007-12-28 22:29:03 UTC (rev 4102)
@@ -22,7 +22,7 @@
         || die "\$PALUDIS_LOADSAVEENV_DIR (\"${PALUDIS_LOADSAVEENV_DIR}\") not a directory"
     [[ -f "${PALUDIS_LOADSAVEENV_DIR}/loadsaveenv" ]] || \
         die "${PALUDIS_LOADSAVEENV_DIR}/loadsaveenv not a file"
-    source ${PALUDIS_LOADSAVEENV_DIR}/loadsaveenv
+    ebuild_safe_source ${PALUDIS_LOADSAVEENV_DIR}/loadsaveenv
 }
 
 ebuild_f_loadenv()

Modified: trunk/paludis/repositories/e/ebuild/builtin_saveenv.bash
===================================================================
--- trunk/paludis/repositories/e/ebuild/builtin_saveenv.bash	2007-12-27 19:05:00 UTC (rev 4101)
+++ trunk/paludis/repositories/e/ebuild/builtin_saveenv.bash	2007-12-28 22:29:03 UTC (rev 4102)
@@ -20,20 +20,7 @@
 {
     [[ -d "${PALUDIS_LOADSAVEENV_DIR}" ]] || die "\$PALUDIS_LOADSAVEENV_DIR (\"${PALUDIS_LOADSAVEENV_DIR}\") not a directory"
     [[ -f "${PALUDIS_LOADSAVEENV_DIR}/loadsaveenv" ]] && rm -f "${PALUDIS_LOADSAVEENV_DIR}/loadsaveenv"
-    ( set ; export -p ) | sed \
-        -e '/^BASH_\(ARGC\|ARGV\|LINENO\|SOURCE\)=/d' \
-        -e '/^\(FUNCNAME\|GROUPS\)=/d' \
-        -e '/^\(declare -[rx]\+ \)\?SANDBOX_/d' \
-        -e '/^\(declare -[rx]\+ \)\?.\?[UP]ID/d' \
-        -e '/^\(declare -[rx]\+ \)\?BASH_REMATCH/d' \
-        -e '/^\(declare -[rx]\+ \)\?BASH_VERSINFO/d' \
-        -e '/^\(declare -[rx]\+ \)\?PALUDIS_LOADSAVEENV_DIR/d' \
-        -e '/^\(declare -[rx]\+ \)\?PALUDIS_DO_NOTHING_SANDBOXY/d' \
-        -e '/^\(declare -[rx]\+ \)\?SHELLOPTS/d' \
-        -e '/^\(declare -[rx]\+ \)\?EBUILD_KILL_PID/d' \
-        -e 's:^declare -rx:declare -x:' \
-        -e 's:^declare -x :export :' \
-        > ${PALUDIS_LOADSAVEENV_DIR}/loadsaveenv
+    ( set ; print_exports ) > ${PALUDIS_LOADSAVEENV_DIR}/loadsaveenv
 }
 
 ebuild_f_saveenv()

Modified: trunk/paludis/repositories/e/ebuild/ebuild.bash
===================================================================
--- trunk/paludis/repositories/e/ebuild/ebuild.bash	2007-12-27 19:05:00 UTC (rev 4101)
+++ trunk/paludis/repositories/e/ebuild/ebuild.bash	2007-12-28 22:29:03 UTC (rev 4102)
@@ -105,6 +105,7 @@
 ebuild_load_module build_functions
 ebuild_load_module eclass_functions
 ebuild_load_module exlib_functions
+ebuild_load_module source_functions
 
 export PALUDIS_HOME="$(canonicalise ${PALUDIS_HOME:-${HOME}} )"
 
@@ -198,28 +199,15 @@
 
 ebuild_scrub_environment()
 {
-    local filters=(
-        -e '/^\(EU\|PP\|U\)ID=/d'
-        -e '/^BASH_\(ARGC\|ARGV\|LINENO\|SOURCE\|VERSINFO\|REMATCH\)=/d'
-        -e '/^BASH_COMPLETION\(_DIR\)\?=/d'
-        -e '/^PALUDIS_SOURCE_MERGED_VARIABLES=/d'
-        -e '/^bash[0-9]\+[a-z]\?=/d'
-        -e '/^\(FUNCNAME\|GROUPS\|SHELLOPTS\)=/d'
-        -e '/^\(declare -x \|export \)\?SANDBOX_ACTIVE=/d'
-    )
-
-    sed -i "${filters[@]}" "${1}"
-
     (
-        source "${1}" || exit 1
+        ebuild_safe_source "${1}" PATH PALUDIS_SOURCE_MERGED_VARIABLES || exit 1
 
         unset -f diefunc perform_hook inherit builtin_loadenv builtin_saveenv
-        unset -f portageq best_version has_version
+        unset -f ebuild_safe_source portageq best_version has_version
 
-        unset -v PATH ROOTPATH T HOME TMPDIR PALUDIS_TMPDIR PALUDIS_EBUILD_LOG_LEVEL
+        unset -v ROOTPATH T HOME TMPDIR PALUDIS_TMPDIR PALUDIS_EBUILD_LOG_LEVEL
         unset -v PORTDIR FILESDIR ECLASSDIR DISTDIR PALUDIS_EBUILD_DIR
-        unset -v PALUDIS_EXTRA_DIE_MESSAGE PALUDIS_COMMAND PALUDIS_CLIENT
-        unset -v PALUDIS_LOADSAVEENV_DIR SKIP_FUNCTIONS PALUDIS_DO_NOTHING_SANDBOXY
+        unset -v PALUDIS_EXTRA_DIE_MESSAGE PALUDIS_COMMAND SKIP_FUNCTIONS
         unset -v FETCHEDDIR REPODIR
 
         unset -v ${!PALUDIS_CMDLINE_*} PALUDIS_OPTIONS
@@ -228,35 +216,34 @@
         unset -v ${!ADJUTRIX_CMDLINE_*} ADJUTRIX_OPTIONS
         unset -v ${!QUALUDIS_CMDLINE_*} QUALUDIS_OPTIONS
         unset -v ${!RECONCILIO_CMDLINE_*} RECONCILIO_OPTIONS
+        eval unset -v $(
+            PALUDIS_CLIENT_UPPER=$(tr a-z A-Z <<<${PALUDIS_CLIENT})
+            echo "\${!${PALUDIS_CLIENT_UPPER}_CMDLINE_*} ${PALUDIS_CLIENT_UPPER}_OPTIONS" )
+        unset -v PALUDIS_CLIENT
 
-        unset -v PALUDIS_HOME PALUDIS_PID EBUILD_KILL_PID ROOT
+        unset -v PALUDIS_HOME PALUDIS_PID ROOT
         unset -v CATEGORY PN PV P PVR PF ${!LD_*}
 
         unset -v ebuild EBUILD
-        for v in ${PALUDIS_SOURCE_MERGED_VARIABLES} ; do
-            e_v=E_${v}
-            unset -v ${e_v}
-        done
+        unset -v $(
+            for v in ${PALUDIS_SOURCE_MERGED_VARIABLES} ; do
+                echo E_${v}
+            done )
 
-        for v in ${!SANDBOX*}; do
-            [[ "${v}" == SANDBOX_ACTIVE ]] || unset "${v}"
-        done
+        unset -v $(
+            for v in ${!SANDBOX_*}; do
+                [[ ${v} != SANDBOX_ACTIVE ]] && echo ${v}
+            done )
+        export -n SANDBOX_ACTIVE
 
-        for v in ${!BASH_*}; do
-            case "${v#BASH_}" in
-                ARGC|ARGV|LINENO|SOURCE|VERSINFO) ;;
-                *) unset -v "${v}"
-            esac
-        done
+        unset -v $(
+            for v in ${!BASH_*}; do
+                [[ ${v#BASH_} != @(ARGC|ARGV|LINENO|SOURCE|VERSINFO|REMATCH) ]] && echo ${v}
+            done )
 
         set >"${1}"
-        export -p >>"${1}"
-    ) || return $?
-
-    sed -i \
-        -e 's:^declare -rx:declare -x:' \
-        -e 's:^declare -x :export :' \
-        "${filters[@]}" "${1}"
+        print_exports >>"${1}"
+    )
 }
 
 ebuild_load_environment()
@@ -291,8 +278,8 @@
         ebuild_scrub_environment "${PALUDIS_TMPDIR}/environment-${CATEGORY}-${PF}-$$" \
             || die "Can't load saved environment for cleaning"
 
-        echo source "${PALUDIS_TMPDIR}/environment-${CATEGORY}-${PF}-$$" 1>&2
-        source "${PALUDIS_TMPDIR}/environment-${CATEGORY}-${PF}-$$" \
+        echo ebuild_safe_source "${PALUDIS_TMPDIR}/environment-${CATEGORY}-${PF}-$$" 1>&2
+        ebuild_safe_source "${PALUDIS_TMPDIR}/environment-${CATEGORY}-${PF}-$$" \
             || die "Can't load saved environment"
 
         export PALUDIS_EXTRA_DIE_MESSAGE="${save_PALUDIS_EXTRA_DIE_MESSAGE}"

Added: trunk/paludis/repositories/e/ebuild/source_functions.bash
===================================================================
--- trunk/paludis/repositories/e/ebuild/source_functions.bash	                        (rev 0)
+++ trunk/paludis/repositories/e/ebuild/source_functions.bash	2007-12-28 22:29:03 UTC (rev 4102)
@@ -0,0 +1,41 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+# Copyright (c) 2007 David Leverton
+#
+# Based in part upon ebuild.sh from Portage, which is Copyright 1995-2005
+# Gentoo Foundation and distributed under the terms of the GNU General
+# Public License v2.
+#
+# This file is part of the Paludis package manager. Paludis is free software;
+# you can redistribute it and/or modify it under the terms of the GNU General
+# Public License, version 2, as published by the Free Software Foundation.
+#
+# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place, Suite 330, Boston, MA  02111-1307  USA
+
+ebuild_safe_source()
+{
+    set -- "${@}" \
+        EUID PPID UID FUNCNAME GROUPS SHELLOPTS \
+        'BASH_@(ARGC|ARGV|LINENO|SOURCE|VERSINFO|REMATCH)' \
+        'BASH_COMPLETEION?(_DIR)' 'bash+([0-9])?([a-z])' \
+        EBUILD_KILL_PID PALUDIS_LOADSAVEENV_DIR PALUDIS_DO_NOTHING_SANDBOXY SANDBOX_ACTIVE
+
+    trap DEBUG
+    set -T
+    shopt -s extdebug
+    trap "[[ \${BASH_COMMAND%% *} == @(eval|trap) ||
+              ( \${BASH_COMMAND} != *([^\$'\n'])=* && \${BASH_COMMAND} != export\ * ) ||
+              \${BASH_COMMAND} != ?(export\ )@($(IFS='|'; shift; echo "${*}"))?(=*) ]]" DEBUG
+
+    source "${1}"
+    eval "trap DEBUG; shopt -u extdebug; set +T; return ${?}"
+}
+

Modified: trunk/paludis/repositories/e/ebuild/utils/Makefile.am
===================================================================
--- trunk/paludis/repositories/e/ebuild/utils/Makefile.am	2007-12-27 19:05:00 UTC (rev 4101)
+++ trunk/paludis/repositories/e/ebuild/utils/Makefile.am	2007-12-28 22:29:03 UTC (rev 4102)
@@ -57,6 +57,11 @@
 	awk \
 	patch
 
+libexecbindir = $(libexecdir)/paludis/utils
+libexecbin_PROGRAMS = print_exports
+
+print_exports_SOURCES = print_exports.cc
+
 AM_CXXFLAGS = -I$(top_srcdir) @PALUDIS_CXXFLAGS@
 
 TESTS_ENVIRONMENT = env \

Added: trunk/paludis/repositories/e/ebuild/utils/print_exports.cc
===================================================================
--- trunk/paludis/repositories/e/ebuild/utils/print_exports.cc	                        (rev 0)
+++ trunk/paludis/repositories/e/ebuild/utils/print_exports.cc	2007-12-28 22:29:03 UTC (rev 4102)
@@ -0,0 +1,33 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 David Leverton
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <string>
+#include <iostream>
+#include <unistd.h>
+
+int
+main()
+{
+    for (char ** it = environ; 0 != *it; ++it)
+    {
+        std::string str(*it);
+        std::cout << "export " << str.substr(0, str.find('=')) << std::endl;
+    }
+}
+

Modified: trunk/paludis/repositories/e/ebuild/write_vdb_entry.bash
===================================================================
--- trunk/paludis/repositories/e/ebuild/write_vdb_entry.bash	2007-12-27 19:05:00 UTC (rev 4101)
+++ trunk/paludis/repositories/e/ebuild/write_vdb_entry.bash	2007-12-28 22:29:03 UTC (rev 4102)
@@ -46,6 +46,7 @@
 
 ebuild_load_module die_functions
 ebuild_load_module echo_functions
+ebuild_load_module source_functions
 
 export PALUDIS_HOME="$(canonicalise ${PALUDIS_HOME:-${HOME}} )"
 
@@ -60,7 +61,7 @@
 
     ebuild_section "Writing VDB entry to '${vdbdir}'..."
 
-    source ${envfile}
+    ebuild_safe_source ${envfile}
 
     ebuild_section "Writing VDB entry keys ..."
 



More information about the paludis-commits mailing list