aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2007-12-28 22:29:03 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2007-12-28 22:29:03 +0000
commitc4f5000e486d21f9d5a2d4e63529f452935eac81 (patch)
tree3b671e37610c414c37e6a51f8d452c6bfb2e3ae9
parent7c70f1f2c1faa9da8ebb5bc4431fbc41d89660e3 (diff)
downloadpaludis-c4f5000e486d21f9d5a2d4e63529f452935eac81.tar.gz
paludis-c4f5000e486d21f9d5a2d4e63529f452935eac81.tar.xz
Rework environment filtering, removing the need to try to parse bash code with sed.
-rw-r--r--paludis/repositories/e/ebuild/Makefile.am1
-rw-r--r--paludis/repositories/e/ebuild/builtin_loadenv.bash2
-rw-r--r--paludis/repositories/e/ebuild/builtin_saveenv.bash15
-rwxr-xr-xpaludis/repositories/e/ebuild/ebuild.bash71
-rw-r--r--paludis/repositories/e/ebuild/source_functions.bash41
-rw-r--r--paludis/repositories/e/ebuild/utils/Makefile.am5
-rw-r--r--paludis/repositories/e/ebuild/utils/print_exports.cc33
-rwxr-xr-xpaludis/repositories/e/ebuild/write_vdb_entry.bash3
8 files changed, 113 insertions, 58 deletions
diff --git a/paludis/repositories/e/ebuild/Makefile.am b/paludis/repositories/e/ebuild/Makefile.am
index cc2a4e1..e9ec9a8 100644
--- a/paludis/repositories/e/ebuild/Makefile.am
+++ b/paludis/repositories/e/ebuild/Makefile.am
@@ -39,6 +39,7 @@ libexecprog_SCRIPTS = \
pkg_setup.bash \
portage_stubs.bash \
sandbox.bash \
+ source_functions.bash \
src_compile.bash \
src_install.bash \
src_test.bash \
diff --git a/paludis/repositories/e/ebuild/builtin_loadenv.bash b/paludis/repositories/e/ebuild/builtin_loadenv.bash
index 1a6e6f3..36de8f4 100644
--- a/paludis/repositories/e/ebuild/builtin_loadenv.bash
+++ b/paludis/repositories/e/ebuild/builtin_loadenv.bash
@@ -22,7 +22,7 @@ builtin_loadenv()
|| 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()
diff --git a/paludis/repositories/e/ebuild/builtin_saveenv.bash b/paludis/repositories/e/ebuild/builtin_saveenv.bash
index 37dd41f..f2f3468 100644
--- a/paludis/repositories/e/ebuild/builtin_saveenv.bash
+++ b/paludis/repositories/e/ebuild/builtin_saveenv.bash
@@ -20,20 +20,7 @@ builtin_saveenv()
{
[[ -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()
diff --git a/paludis/repositories/e/ebuild/ebuild.bash b/paludis/repositories/e/ebuild/ebuild.bash
index 76a4d24..95bcf34 100755
--- a/paludis/repositories/e/ebuild/ebuild.bash
+++ b/paludis/repositories/e/ebuild/ebuild.bash
@@ -105,6 +105,7 @@ ebuild_load_module install_functions
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 @@ export REAL_CHOST="${CHOST}"
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 @@ ebuild_scrub_environment()
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
-
- for v in ${!SANDBOX*}; do
- [[ "${v}" == SANDBOX_ACTIVE ]] || unset "${v}"
- done
-
- for v in ${!BASH_*}; do
- case "${v#BASH_}" in
- ARGC|ARGV|LINENO|SOURCE|VERSINFO) ;;
- *) unset -v "${v}"
- esac
- done
+ unset -v $(
+ for v in ${PALUDIS_SOURCE_MERGED_VARIABLES} ; do
+ echo E_${v}
+ done )
+
+ unset -v $(
+ for v in ${!SANDBOX_*}; do
+ [[ ${v} != SANDBOX_ACTIVE ]] && echo ${v}
+ done )
+ export -n SANDBOX_ACTIVE
+
+ 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_load_environment()
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}"
diff --git a/paludis/repositories/e/ebuild/source_functions.bash b/paludis/repositories/e/ebuild/source_functions.bash
new file mode 100644
index 0000000..4a5f588
--- /dev/null
+++ b/paludis/repositories/e/ebuild/source_functions.bash
@@ -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 ${?}"
+}
+
diff --git a/paludis/repositories/e/ebuild/utils/Makefile.am b/paludis/repositories/e/ebuild/utils/Makefile.am
index 86a8086..bf575f3 100644
--- a/paludis/repositories/e/ebuild/utils/Makefile.am
+++ b/paludis/repositories/e/ebuild/utils/Makefile.am
@@ -57,6 +57,11 @@ libexecprog_SCRIPTS = \
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 \
diff --git a/paludis/repositories/e/ebuild/utils/print_exports.cc b/paludis/repositories/e/ebuild/utils/print_exports.cc
new file mode 100644
index 0000000..c7fc24a
--- /dev/null
+++ b/paludis/repositories/e/ebuild/utils/print_exports.cc
@@ -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;
+ }
+}
+
diff --git a/paludis/repositories/e/ebuild/write_vdb_entry.bash b/paludis/repositories/e/ebuild/write_vdb_entry.bash
index 650b9f7..f8f57e5 100755
--- a/paludis/repositories/e/ebuild/write_vdb_entry.bash
+++ b/paludis/repositories/e/ebuild/write_vdb_entry.bash
@@ -46,6 +46,7 @@ ebuild_load_module()
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 @@ main()
ebuild_section "Writing VDB entry to '${vdbdir}'..."
- source ${envfile}
+ ebuild_safe_source ${envfile}
ebuild_section "Writing VDB entry keys ..."