2 # Copyright 1999-2011 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
5 PORTAGE_BIN_PATH="${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"
6 PORTAGE_PYM_PATH="${PORTAGE_PYM_PATH:-/usr/lib/portage/pym}"
8 if [[ $PORTAGE_SANDBOX_COMPAT_LEVEL -lt 22 ]] ; then
9 # Ensure that /dev/std* streams have appropriate sandbox permission for
10 # bug #288863. This can be removed after sandbox is fixed and portage
11 # depends on the fixed version (sandbox-2.2 has the fix but it is
12 # currently unstable).
13 export SANDBOX_WRITE="${SANDBOX_WRITE:+${SANDBOX_WRITE}:}/dev/stdout:/dev/stderr"
14 export SANDBOX_READ="${SANDBOX_READ:+${SANDBOX_READ}:}/dev/stdin"
17 # Don't use sandbox's BASH_ENV for new shells because it does
18 # 'source /etc/profile' which can interfere with the build
19 # environment by modifying our PATH.
22 ROOTPATH=${ROOTPATH##:}
23 ROOTPATH=${ROOTPATH%%:}
24 PREROOTPATH=${PREROOTPATH##:}
25 PREROOTPATH=${PREROOTPATH%%:}
26 PATH=$PORTAGE_BIN_PATH/ebuild-helpers:$PREROOTPATH${PREROOTPATH:+:}/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin${ROOTPATH:+:}$ROOTPATH
29 # This is just a temporary workaround for portage-9999 users since
30 # earlier portage versions do not detect a version change in this case
31 # (9999 to 9999) and therefore they try execute an incompatible version of
32 # ebuild.sh during the upgrade.
33 export PORTAGE_BZIP2_COMMAND=${PORTAGE_BZIP2_COMMAND:-bzip2}
35 # These two functions wrap sourcing and calling respectively. At present they
36 # perform a qa check to make sure eclasses and ebuilds and profiles don't mess
37 # with shell opts (shopts). Ebuilds/eclasses changing shopts should reset them
41 local shopts=$(shopt) OLDIFS="$IFS"
46 [[ $shopts != $(shopt) ]] &&
47 eqawarn "QA Notice: Global shell options changed and were not restored while sourcing '$*'"
48 [[ "$IFS" != "$OLDIFS" ]] &&
49 eqawarn "QA Notice: Global IFS changed and was not restored while sourcing '$*'"
54 local shopts=$(shopt) OLDIFS="$IFS"
59 [[ $shopts != $(shopt) ]] &&
60 eqawarn "QA Notice: Global shell options changed and were not restored while calling '$*'"
61 [[ "$IFS" != "$OLDIFS" ]] &&
62 eqawarn "QA Notice: Global IFS changed and was not restored while calling '$*'"
70 # Prevent aliases from causing portage to act inappropriately.
71 # Make sure it's before everything so we don't mess aliases that follow.
74 # Unset some variables that break things.
75 unset GZIP BZIP BZIP2 CDPATH GREP_OPTIONS GREP_COLOR GLOBIGNORE
77 source "${PORTAGE_BIN_PATH}/isolated-functions.sh" &>/dev/null
79 [[ $PORTAGE_QUIET != "" ]] && export PORTAGE_QUIET
81 # sandbox support functions; defined prior to profile.bashrc srcing, since the profile might need to add a default exception (/usr/lib64/conftest fex)
84 local var="SANDBOX_${_v}"
85 [[ -z $1 || -n $2 ]] && die "Usage: add$(echo ${_v} | \
86 LC_ALL=C tr [:upper:] [:lower:]) <colon-delimited list of paths>"
87 export ${var}="${!var:+${!var}:}$1"
90 # local var="SANDBOX_${1^^}"
91 # addread() { _sb_append_var ${0#add} "$@" ; }
92 addread() { _sb_append_var READ "$@" ; }
93 addwrite() { _sb_append_var WRITE "$@" ; }
94 adddeny() { _sb_append_var DENY "$@" ; }
95 addpredict() { _sb_append_var PREDICT "$@" ; }
97 addwrite "${PORTAGE_TMPDIR}"
98 addread "/:${PORTAGE_TMPDIR}"
99 [[ -n ${PORTAGE_GPG_DIR} ]] && addpredict "${PORTAGE_GPG_DIR}"
101 # Avoid sandbox violations in temporary directories.
102 if [[ -w $T ]] ; then
106 elif [[ $SANDBOX_ON = 1 ]] ; then
107 for x in TEMP TMP TMPDIR ; do
108 [[ -n ${!x} ]] && addwrite "${!x}"
113 # the sandbox is disabled by default except when overridden in the relevant stages
117 # Custom version of esyslog() to take care of the "Red Star" bug.
118 # MUST follow functions.sh to override the "" parameter problem.
123 if [ "${EBUILD_PHASE}" == "depend" ]; then
124 die "portageq calls are not allowed in the global scope"
127 PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
128 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" "$@"
131 register_die_hook() {
134 has $x $EBUILD_DEATH_HOOKS || \
135 export EBUILD_DEATH_HOOKS="$EBUILD_DEATH_HOOKS $x"
139 register_success_hook() {
142 has $x $EBUILD_SUCCESS_HOOKS || \
143 export EBUILD_SUCCESS_HOOKS="$EBUILD_SUCCESS_HOOKS $x"
147 # Ensure that $PWD is sane whenever possible, to protect against
148 # exploitation of insecure search path for python -c in ebuilds.
150 if ! has "$EBUILD_PHASE" clean cleanrm depend help ; then
151 cd "$PORTAGE_BUILDDIR" || \
152 die "PORTAGE_BUILDDIR does not exist: '$PORTAGE_BUILDDIR'"
155 #if no perms are specified, dirs/files will have decent defaults
156 #(not secretive, but not stupid)
159 strip_duplicate_slashes() {
160 if [[ -n $1 ]] ; then
162 while [[ ${removed} == *//* ]] ; do
163 removed=${removed//\/\///}
169 # debug-print() gets called from many places with verbose status information useful
170 # for tracking down problems. The output is in $T/eclass-debug.log.
171 # You can set ECLASS_DEBUG_OUTPUT to redirect the output somewhere else as well.
172 # The special "on" setting echoes the information, mixing it with the rest of the
174 # You can override the setting by exporting a new one from the console, or you can
175 # set a new default in make.*. Here the default is "" or unset.
177 # in the future might use e* from /etc/init.d/functions.sh if i feel like it
179 # if $T isn't defined, we're in dep calculation mode and
180 # shouldn't do anything
181 [[ $EBUILD_PHASE = depend || ! -d ${T} || ${#} -eq 0 ]] && return 0
183 if [[ ${ECLASS_DEBUG_OUTPUT} == on ]]; then
184 printf 'debug: %s\n' "${@}" >&2
185 elif [[ -n ${ECLASS_DEBUG_OUTPUT} ]]; then
186 printf 'debug: %s\n' "${@}" >> "${ECLASS_DEBUG_OUTPUT}"
189 if [[ -w $T ]] ; then
191 printf '%s\n' "${@}" >> "${T}/eclass-debug.log"
192 # let the portage user own/write to this file
193 chgrp portage "${T}/eclass-debug.log" &>/dev/null
194 chmod g+w "${T}/eclass-debug.log" &>/dev/null
198 # The following 2 functions are debug-print() wrappers
200 debug-print-function() {
201 debug-print "${1}: entering function, parameters: ${*:2}"
204 debug-print-section() {
205 debug-print "now in section ${*}"
208 # Sources all eclasses in parameters
209 declare -ix ECLASS_DEPTH=0
211 ECLASS_DEPTH=$(($ECLASS_DEPTH + 1))
212 if [[ ${ECLASS_DEPTH} > 1 ]]; then
213 debug-print "*** Multiple Inheritence (Level: ${ECLASS_DEPTH})"
216 if [[ -n $ECLASS && -n ${!__export_funcs_var} ]] ; then
217 echo "QA Notice: EXPORT_FUNCTIONS is called before inherit in" \
218 "$ECLASS.eclass. For compatibility with <=portage-2.1.6.7," \
219 "only call EXPORT_FUNCTIONS after inherit(s)." \
220 | fmt -w 75 | while read -r ; do eqawarn "$REPLY" ; done
227 # These variables must be restored before returning.
228 local PECLASS=$ECLASS
229 local prev_export_funcs_var=$__export_funcs_var
237 location="${ECLASSDIR}/${1}.eclass"
241 __export_funcs_var=__export_functions_$ECLASS_DEPTH
242 unset $__export_funcs_var
244 if [ "${EBUILD_PHASE}" != "depend" ] && \
245 [[ ${EBUILD_PHASE} != *rm ]] && \
246 [[ ${EMERGE_FROM} != "binary" ]] ; then
247 # This is disabled in the *rm phases because they frequently give
248 # false alarms due to INHERITED in /var/db/pkg being outdated
249 # in comparison the the eclasses from the portage tree.
250 if ! has $ECLASS $INHERITED $__INHERITED_QA_CACHE ; then
251 eqawarn "QA Notice: ECLASS '$ECLASS' inherited illegally in $CATEGORY/$PF $EBUILD_PHASE"
255 # any future resolution code goes here
256 if [ -n "$PORTDIR_OVERLAY" ]; then
258 for overlay in ${PORTDIR_OVERLAY}; do
259 olocation="${overlay}/eclass/${1}.eclass"
260 if [ -e "$olocation" ]; then
261 location="${olocation}"
262 debug-print " eclass exists: ${location}"
266 debug-print "inherit: $1 -> $location"
267 [ ! -e "$location" ] && die "${1}.eclass could not be found by inherit()"
269 if [ "${location}" == "${olocation}" ] && \
270 ! has "${location}" ${EBUILD_OVERLAY_ECLASSES} ; then
271 EBUILD_OVERLAY_ECLASSES="${EBUILD_OVERLAY_ECLASSES} ${location}"
274 #We need to back up the value of DEPEND and RDEPEND to B_DEPEND and B_RDEPEND
275 #(if set).. and then restore them after the inherit call.
277 #turn off glob expansion
280 # Retain the old data and restore it later.
281 unset B_IUSE B_REQUIRED_USE B_DEPEND B_RDEPEND B_PDEPEND
282 [ "${IUSE+set}" = set ] && B_IUSE="${IUSE}"
283 [ "${REQUIRED_USE+set}" = set ] && B_REQUIRED_USE="${REQUIRED_USE}"
284 [ "${DEPEND+set}" = set ] && B_DEPEND="${DEPEND}"
285 [ "${RDEPEND+set}" = set ] && B_RDEPEND="${RDEPEND}"
286 [ "${PDEPEND+set}" = set ] && B_PDEPEND="${PDEPEND}"
287 unset IUSE REQUIRED_USE DEPEND RDEPEND PDEPEND
288 #turn on glob expansion
291 qa_source "$location" || die "died sourcing $location in inherit()"
293 #turn off glob expansion
296 # If each var has a value, append it to the global variable E_* to
297 # be applied after everything is finished. New incremental behavior.
298 [ "${IUSE+set}" = set ] && export E_IUSE="${E_IUSE} ${IUSE}"
299 [ "${REQUIRED_USE+set}" = set ] && export E_REQUIRED_USE="${E_REQUIRED_USE} ${REQUIRED_USE}"
300 [ "${DEPEND+set}" = set ] && export E_DEPEND="${E_DEPEND} ${DEPEND}"
301 [ "${RDEPEND+set}" = set ] && export E_RDEPEND="${E_RDEPEND} ${RDEPEND}"
302 [ "${PDEPEND+set}" = set ] && export E_PDEPEND="${E_PDEPEND} ${PDEPEND}"
304 [ "${B_IUSE+set}" = set ] && IUSE="${B_IUSE}"
305 [ "${B_IUSE+set}" = set ] || unset IUSE
307 [ "${B_REQUIRED_USE+set}" = set ] && REQUIRED_USE="${B_REQUIRED_USE}"
308 [ "${B_REQUIRED_USE+set}" = set ] || unset REQUIRED_USE
310 [ "${B_DEPEND+set}" = set ] && DEPEND="${B_DEPEND}"
311 [ "${B_DEPEND+set}" = set ] || unset DEPEND
313 [ "${B_RDEPEND+set}" = set ] && RDEPEND="${B_RDEPEND}"
314 [ "${B_RDEPEND+set}" = set ] || unset RDEPEND
316 [ "${B_PDEPEND+set}" = set ] && PDEPEND="${B_PDEPEND}"
317 [ "${B_PDEPEND+set}" = set ] || unset PDEPEND
319 #turn on glob expansion
322 if [[ -n ${!__export_funcs_var} ]] ; then
323 for x in ${!__export_funcs_var} ; do
324 debug-print "EXPORT_FUNCTIONS: $x -> ${ECLASS}_$x"
325 declare -F "${ECLASS}_$x" >/dev/null || \
326 die "EXPORT_FUNCTIONS: ${ECLASS}_$x is not defined"
327 eval "$x() { ${ECLASS}_$x \"\$@\" ; }" > /dev/null
330 unset $__export_funcs_var
332 has $1 $INHERITED || export INHERITED="$INHERITED $1"
336 ((--ECLASS_DEPTH)) # Returns 1 when ECLASS_DEPTH reaches 0.
337 if (( ECLASS_DEPTH > 0 )) ; then
338 export ECLASS=$PECLASS
339 __export_funcs_var=$prev_export_funcs_var
341 unset ECLASS __export_funcs_var
346 # Exports stub functions that call the eclass's functions, thereby making them default.
347 # For example, if ECLASS="base" and you call "EXPORT_FUNCTIONS src_unpack", the following
348 # code will be eval'd:
349 # src_unpack() { base_src_unpack; }
351 if [ -z "$ECLASS" ]; then
352 die "EXPORT_FUNCTIONS without a defined ECLASS"
354 eval $__export_funcs_var+=\" $*\"
357 # this is a function for removing any directory matching a passed in pattern from
359 remove_path_entry() {
362 stripped_path="${PATH}"
363 while [ -n "$1" ]; do
365 for p in ${stripped_path}; do
366 if [ "${p/${1}}" == "${p}" ]; then
367 cur_path="${cur_path}:${p}"
370 stripped_path="${cur_path#:*}"
374 PATH="${stripped_path}"
377 # Set given variables unless these variable have been already set (e.g. during emerge
378 # invocation) to values different than values set in make.conf.
379 set_unless_changed() {
380 if [[ $# -lt 1 ]]; then
381 die "${FUNCNAME}() requires at least 1 argument: VARIABLE=VALUE"
384 local argument value variable
385 for argument in "$@"; do
386 if [[ ${argument} != *=* ]]; then
387 die "${FUNCNAME}(): Argument '${argument}' has incorrect syntax"
389 variable="${argument%%=*}"
390 value="${argument#*=}"
391 if eval "[[ \${${variable}} == \$(env -u ${variable} portageq envvar ${variable}) ]]"; then
392 eval "${variable}=\"\${value}\""
397 # Unset given variables unless these variable have been set (e.g. during emerge
398 # invocation) to values different than values set in make.conf.
399 unset_unless_changed() {
400 if [[ $# -lt 1 ]]; then
401 die "${FUNCNAME}() requires at least 1 argument: VARIABLE"
405 for variable in "$@"; do
406 if eval "[[ \${${variable}} == \$(env -u ${variable} portageq envvar ${variable}) ]]"; then
412 PORTAGE_BASHRCS_SOURCED=0
414 # @FUNCTION: source_all_bashrcs
416 # Source a relevant bashrc files and perform other miscellaneous
417 # environment initialization when appropriate.
419 # If EAPI is set then define functions provided by the current EAPI:
421 # * default_* aliases for the current EAPI phase functions
422 # * A "default" function which is an alias for the default phase
423 # function for the current phase.
425 source_all_bashrcs() {
426 [[ $PORTAGE_BASHRCS_SOURCED = 1 ]] && return 0
427 PORTAGE_BASHRCS_SOURCED=1
430 local OCC="${CC}" OCXX="${CXX}"
432 if [[ $EBUILD_PHASE != depend ]] ; then
433 # source the existing profile.bashrcs.
436 local path_array=($PROFILE_PATHS)
438 for x in "${path_array[@]}" ; do
439 [ -f "$x/profile.bashrc" ] && qa_source "$x/profile.bashrc"
443 # We assume if people are changing shopts in their bashrc they do so at their
444 # own peril. This is the ONLY non-portage bit of code that can change shopts
445 # without a QA violation.
446 for x in "${PORTAGE_BASHRC}" "${PM_EBUILD_HOOK_DIR}"/${CATEGORY}/{${PN},${PN}:${SLOT},${P},${PF}}; do
447 if [ -r "${x}" ]; then
448 # If $- contains x, then tracing has already enabled elsewhere for some
449 # reason. We preserve it's state so as not to interfere.
450 if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then
460 [ ! -z "${OCC}" ] && export CC="${OCC}"
461 [ ! -z "${OCXX}" ] && export CXX="${OCXX}"
464 # Hardcoded bash lists are needed for backward compatibility with
465 # <portage-2.1.4 since they assume that a newly installed version
466 # of ebuild.sh will work for pkg_postinst, pkg_prerm, and pkg_postrm
467 # when portage is upgrading itself.
469 PORTAGE_READONLY_METADATA="DEFINED_PHASES DEPEND DESCRIPTION
470 EAPI HOMEPAGE INHERITED IUSE REQUIRED_USE KEYWORDS LICENSE
471 PDEPEND PROVIDE RDEPEND RESTRICT SLOT SRC_URI"
473 PORTAGE_READONLY_VARS="D EBUILD EBUILD_PHASE \
474 EBUILD_SH_ARGS ECLASSDIR EMERGE_FROM FILESDIR MERGE_TYPE \
476 PORTAGE_ACTUAL_DISTDIR PORTAGE_ARCHLIST PORTAGE_BASHRC \
477 PORTAGE_BINPKG_FILE PORTAGE_BINPKG_TAR_OPTS PORTAGE_BINPKG_TMPFILE \
478 PORTAGE_BIN_PATH PORTAGE_BUILDDIR PORTAGE_BUNZIP2_COMMAND \
479 PORTAGE_BZIP2_COMMAND PORTAGE_COLORMAP PORTAGE_CONFIGROOT \
480 PORTAGE_DEBUG PORTAGE_DEPCACHEDIR PORTAGE_EBUILD_EXIT_FILE \
481 PORTAGE_GID PORTAGE_GRPNAME PORTAGE_INST_GID PORTAGE_INST_UID \
482 PORTAGE_IPC_DAEMON PORTAGE_IUSE PORTAGE_LOG_FILE \
483 PORTAGE_MUTABLE_FILTERED_VARS PORTAGE_PYM_PATH PORTAGE_PYTHON \
484 PORTAGE_READONLY_METADATA PORTAGE_READONLY_VARS \
485 PORTAGE_REPO_NAME PORTAGE_RESTRICT PORTAGE_SANDBOX_COMPAT_LEVEL \
486 PORTAGE_SAVED_READONLY_VARS PORTAGE_SIGPIPE_STATUS \
487 PORTAGE_TMPDIR PORTAGE_UPDATE_ENV PORTAGE_USERNAME \
488 PORTAGE_VERBOSE PORTAGE_WORKDIR_MODE PORTDIR PORTDIR_OVERLAY \
489 PROFILE_PATHS REPLACING_VERSIONS REPLACED_BY_VERSION T WORKDIR"
491 PORTAGE_SAVED_READONLY_VARS="A CATEGORY P PF PN PR PV PVR"
493 # Variables that portage sets but doesn't mark readonly.
494 # In order to prevent changed values from causing unexpected
495 # interference, they are filtered out of the environment when
496 # it is saved or loaded (any mutations do not persist).
497 PORTAGE_MUTABLE_FILTERED_VARS="AA HOSTNAME"
499 # @FUNCTION: filter_readonly_variables
500 # @DESCRIPTION: [--filter-sandbox] [--allow-extra-vars]
501 # Read an environment from stdin and echo to stdout while filtering variables
502 # with names that are known to cause interference:
504 # * some specific variables for which bash does not allow assignment
505 # * some specific variables that affect portage or sandbox behavior
506 # * variable names that begin with a digit or that contain any
507 # non-alphanumeric characters that are not be supported by bash
509 # --filter-sandbox causes all SANDBOX_* variables to be filtered, which
510 # is only desired in certain cases, such as during preprocessing or when
511 # saving environment.bz2 for a binary or installed package.
513 # --filter-features causes the special FEATURES variable to be filtered.
514 # Generally, we want it to persist between phases since the user might
515 # want to modify it via bashrc to enable things like splitdebug and
516 # installsources for specific packages. They should be able to modify it
517 # in pre_pkg_setup() and have it persist all the way through the install
518 # phase. However, if FEATURES exist inside environment.bz2 then they
519 # should be overridden by current settings.
521 # --filter-locale causes locale related variables such as LANG and LC_*
522 # variables to be filtered. These variables should persist between phases,
523 # in case they are modified by the ebuild. However, the current user
524 # settings should be used when loading the environment from a binary or
527 # --filter-path causes the PATH variable to be filtered. This variable
528 # should persist between phases, in case it is modified by the ebuild.
529 # However, old settings should be overridden when loading the
530 # environment from a binary or installed package.
532 # ---allow-extra-vars causes some extra vars to be allowd through, such
533 # as ${PORTAGE_SAVED_READONLY_VARS} and ${PORTAGE_MUTABLE_FILTERED_VARS}.
535 # In bash-3.2_p20+ an attempt to assign BASH_*, FUNCNAME, GROUPS or any
536 # readonly variable cause the shell to exit while executing the "source"
537 # builtin command. To avoid this problem, this function filters those
538 # variables out and discards them. See bug #190128.
539 filter_readonly_variables() {
540 local x filtered_vars
541 local readonly_bash_vars="BASHOPTS BASHPID DIRSTACK EUID
542 FUNCNAME GROUPS PIPESTATUS PPID SHELLOPTS UID"
543 local bash_misc_vars="BASH BASH_.* COMP_WORDBREAKS HISTCMD
544 HISTFILE HOSTNAME HOSTTYPE IFS LINENO MACHTYPE OLDPWD
545 OPTERR OPTIND OSTYPE POSIXLY_CORRECT PS4 PWD RANDOM
547 local filtered_sandbox_vars="SANDBOX_ACTIVE SANDBOX_BASHRC
548 SANDBOX_DEBUG_LOG SANDBOX_DISABLED SANDBOX_LIB
549 SANDBOX_LOG SANDBOX_ON"
550 local misc_garbage_vars="_portage_filter_opts"
551 filtered_vars="$readonly_bash_vars $bash_misc_vars
552 $PORTAGE_READONLY_VARS $misc_garbage_vars"
554 # Don't filter/interfere with prefix variables unless they are
555 # supported by the current EAPI.
560 filtered_vars+=" ED EPREFIX EROOT"
564 if has --filter-sandbox $* ; then
565 filtered_vars="${filtered_vars} SANDBOX_.*"
567 filtered_vars="${filtered_vars} ${filtered_sandbox_vars}"
569 if has --filter-features $* ; then
570 filtered_vars="${filtered_vars} FEATURES PORTAGE_FEATURES"
572 if has --filter-path $* ; then
573 filtered_vars+=" PATH"
575 if has --filter-locale $* ; then
576 filtered_vars+=" LANG LC_ALL LC_COLLATE
577 LC_CTYPE LC_MESSAGES LC_MONETARY
578 LC_NUMERIC LC_PAPER LC_TIME"
580 if ! has --allow-extra-vars $* ; then
583 ${PORTAGE_SAVED_READONLY_VARS}
584 ${PORTAGE_MUTABLE_FILTERED_VARS}
588 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}" || die "filter-bash-environment.py failed"
591 # @FUNCTION: preprocess_ebuild_env
593 # Filter any readonly variables from ${T}/environment, source it, and then
594 # save it via save_ebuild_env(). This process should be sufficient to prevent
595 # any stale variables or functions from an arbitrary environment from
596 # interfering with the current environment. This is useful when an existing
597 # environment needs to be loaded from a binary or installed package.
598 preprocess_ebuild_env() {
599 local _portage_filter_opts="--filter-features --filter-locale --filter-path --filter-sandbox"
601 # If environment.raw is present, this is a signal from the python side,
602 # indicating that the environment may contain stale FEATURES and
603 # SANDBOX_{DENY,PREDICT,READ,WRITE} variables that should be filtered out.
604 # Otherwise, we don't need to filter the environment.
605 [ -f "${T}/environment.raw" ] || return 0
607 filter_readonly_variables $_portage_filter_opts < "${T}"/environment \
608 >> "$T/environment.filtered" || return $?
609 unset _portage_filter_opts
610 mv "${T}"/environment.filtered "${T}"/environment || return $?
611 rm -f "${T}/environment.success" || return $?
612 # WARNING: Code inside this subshell should avoid making assumptions
613 # about variables or functions after source "${T}"/environment has been
614 # called. Any variables that need to be relied upon should already be
615 # filtered out above.
618 source "${T}/environment" || exit $?
619 # We have to temporarily disable sandbox since the
620 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
621 # may be unusable (triggering in spurious sandbox violations)
622 # until we've merged them with our current values.
625 # It's remotely possible that save_ebuild_env() has been overridden
626 # by the above source command. To protect ourselves, we override it
627 # here with our own version. ${PORTAGE_BIN_PATH} is safe to use here
628 # because it's already filtered above.
629 source "${PORTAGE_BIN_PATH}/isolated-functions.sh" || exit $?
631 # Rely on save_ebuild_env() to filter out any remaining variables
632 # and functions that could interfere with the current environment.
633 save_ebuild_env || exit $?
634 >> "$T/environment.success" || exit $?
635 ) > "${T}/environment.filtered"
637 if [ -e "${T}/environment.success" ] ; then
638 filter_readonly_variables --filter-features < \
639 "${T}/environment.filtered" > "${T}/environment"
644 rm -f "${T}"/environment.{filtered,raw,success}
648 # === === === === === === === === === === === === === === === === === ===
649 # === === === === === functions end, main part begins === === === === ===
650 # === === === === === functions end, main part begins === === === === ===
651 # === === === === === functions end, main part begins === === === === ===
652 # === === === === === === === === === === === === === === === === === ===
654 export SANDBOX_ON="1"
655 export S=${WORKDIR}/${P}
657 unset E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND
659 # Turn of extended glob matching so that g++ doesn't get incorrectly matched.
662 if [[ ${EBUILD_PHASE} == depend ]] ; then
663 QA_INTERCEPTORS="awk bash cc egrep equery fgrep g++
664 gawk gcc grep javac java-config nawk perl
665 pkg-config python python-config sed"
666 elif [[ ${EBUILD_PHASE} == clean* ]] ; then
667 unset QA_INTERCEPTORS
669 QA_INTERCEPTORS="autoconf automake aclocal libtoolize"
671 # level the QA interceptors if we're in depend
672 if [[ -n ${QA_INTERCEPTORS} ]] ; then
673 for BIN in ${QA_INTERCEPTORS}; do
674 BIN_PATH=$(type -Pf ${BIN})
675 if [ "$?" != "0" ]; then
676 BODY="echo \"*** missing command: ${BIN}\" >&2; return 127"
678 BODY="${BIN_PATH} \"\$@\"; return \$?"
680 if [[ ${EBUILD_PHASE} == depend ]] ; then
682 if [ \$ECLASS_DEPTH -gt 0 ]; then
683 eqawarn \"QA Notice: '${BIN}' called in global scope: eclass \${ECLASS}\"
685 eqawarn \"QA Notice: '${BIN}' called in global scope: \${CATEGORY}/\${PF}\"
689 elif has ${BIN} autoconf automake aclocal libtoolize ; then
691 if ! has \${FUNCNAME[1]} eautoreconf eaclocal _elibtoolize \\
692 eautoheader eautoconf eautomake autotools_run_tool \\
693 autotools_check_macro autotools_get_subdirs \\
694 autotools_get_auxdir ; then
695 eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
696 eqawarn \"Use autotools.eclass instead of calling '${BIN}' directly.\"
702 eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
706 eval "$FUNC_SRC" || echo "error creating QA interceptor ${BIN}" >&2
708 unset BIN_PATH BIN BODY FUNC_SRC
711 # Subshell/helper die support (must export for the die helper).
712 export EBUILD_MASTER_PID=$BASHPID
713 trap 'exit 1' SIGTERM
715 if [[ $EBUILD_PHASE != depend ]] ; then
716 source "${PORTAGE_BIN_PATH}/phase-functions.sh"
717 source "${PORTAGE_BIN_PATH}/phase-helpers.sh"
719 # These dummy functions are for things that are likely to be called
720 # in global scope, even though they are completely useless during
721 # the "depend" phase.
722 for x in diropts docompress exeopts insopts \
723 keepdir libopts use useq usev use_with use_enable ; do
724 eval "${x}() { : ; }"
726 # These functions die because calls to them during the "depend" phase
727 # are considered to be severe QA violations.
728 for x in best_version has_version ; do
729 eval "${x}() { die \"\${FUNCNAME} calls are not allowed in global scope\"; }"
734 if ! has "$EBUILD_PHASE" clean cleanrm depend && \
735 [ -f "${T}"/environment ] ; then
736 # The environment may have been extracted from environment.bz2 or
737 # may have come from another version of ebuild.sh or something.
738 # In any case, preprocess it to prevent any potential interference.
739 preprocess_ebuild_env || \
740 die "error processing environment"
741 # Colon separated SANDBOX_* variables need to be cumulative.
742 for x in SANDBOX_DENY SANDBOX_READ SANDBOX_PREDICT SANDBOX_WRITE ; do
743 export PORTAGE_${x}=${!x}
745 PORTAGE_SANDBOX_ON=${SANDBOX_ON}
747 source "${T}"/environment || \
748 die "error sourcing environment"
749 # We have to temporarily disable sandbox since the
750 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
751 # may be unusable (triggering in spurious sandbox violations)
752 # until we've merged them with our current values.
754 for x in SANDBOX_DENY SANDBOX_PREDICT SANDBOX_READ SANDBOX_WRITE ; do
756 if [ -z "${!x}" ] ; then
758 elif [ -n "${!y}" ] && [ "${!y}" != "${!x}" ] ; then
760 export ${x}=$(printf "${!y}:${!x}" | tr ":" "\0" | \
761 sort -z -u | tr "\0" ":")
767 export SANDBOX_ON=${PORTAGE_SANDBOX_ON}
768 unset PORTAGE_SANDBOX_ON
769 [[ -n $EAPI ]] || EAPI=0
772 if ! has "$EBUILD_PHASE" clean cleanrm ; then
773 if [[ $EBUILD_PHASE = depend || ! -f $T/environment || \
774 -f $PORTAGE_BUILDDIR/.ebuild_changed ]] || \
775 has noauto $FEATURES ; then
776 # The bashrcs get an opportunity here to set aliases that will be expanded
777 # during sourcing of ebuilds and eclasses.
780 # When EBUILD_PHASE != depend, INHERITED comes pre-initialized
781 # from cache. In order to make INHERITED content independent of
782 # EBUILD_PHASE during inherit() calls, we unset INHERITED after
783 # we make a backup copy for QA checks.
784 __INHERITED_QA_CACHE=$INHERITED
786 # *DEPEND and IUSE will be set during the sourcing of the ebuild.
787 # In order to ensure correct interaction between ebuilds and
788 # eclasses, they need to be unset before this process of
789 # interaction begins.
790 unset DEPEND RDEPEND PDEPEND INHERITED IUSE REQUIRED_USE \
791 ECLASS E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND
793 if [[ $PORTAGE_DEBUG != 1 || ${-/x/} != $- ]] ; then
794 source "$EBUILD" || die "error sourcing ebuild"
797 source "$EBUILD" || die "error sourcing ebuild"
801 if [[ "${EBUILD_PHASE}" != "depend" ]] ; then
802 RESTRICT=${PORTAGE_RESTRICT}
803 [[ -e $PORTAGE_BUILDDIR/.ebuild_changed ]] && \
804 rm "$PORTAGE_BUILDDIR/.ebuild_changed"
807 [[ -n $EAPI ]] || EAPI=0
809 if has "$EAPI" 0 1 2 3 3_pre2 ; then
810 export RDEPEND=${RDEPEND-${DEPEND}}
811 debug-print "RDEPEND: not set... Setting to: ${DEPEND}"
814 # add in dependency info from eclasses
815 IUSE="${IUSE} ${E_IUSE}"
816 DEPEND="${DEPEND} ${E_DEPEND}"
817 RDEPEND="${RDEPEND} ${E_RDEPEND}"
818 PDEPEND="${PDEPEND} ${E_PDEPEND}"
819 REQUIRED_USE="${REQUIRED_USE} ${E_REQUIRED_USE}"
821 unset ECLASS E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND \
824 # alphabetically ordered by $EBUILD_PHASE value
827 _valid_phases="src_compile pkg_config pkg_info src_install
828 pkg_nofetch pkg_postinst pkg_postrm pkg_preinst pkg_prerm
829 pkg_setup src_test src_unpack"
832 _valid_phases="src_compile pkg_config src_configure pkg_info
833 src_install pkg_nofetch pkg_postinst pkg_postrm pkg_preinst
834 src_prepare pkg_prerm pkg_setup src_test src_unpack"
837 _valid_phases="src_compile pkg_config src_configure pkg_info
838 src_install pkg_nofetch pkg_postinst pkg_postrm pkg_preinst
839 src_prepare pkg_prerm pkg_pretend pkg_setup src_test src_unpack"
844 for _f in $_valid_phases ; do
845 if declare -F $_f >/dev/null ; then
847 DEFINED_PHASES+=" ${_f#src_}"
850 [[ -n $DEFINED_PHASES ]] || DEFINED_PHASES=-
852 unset _f _valid_phases
854 if [[ $EBUILD_PHASE != depend ]] ; then
858 _ebuild_helpers_path="$PORTAGE_BIN_PATH/ebuild-helpers"
861 _ebuild_helpers_path="$PORTAGE_BIN_PATH/ebuild-helpers/4:$PORTAGE_BIN_PATH/ebuild-helpers"
865 PATH=$_ebuild_helpers_path:$PREROOTPATH${PREROOTPATH:+:}/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin${ROOTPATH:+:}$ROOTPATH
866 unset _ebuild_helpers_path
868 # Use default ABI libdir in accordance with bug #355283.
869 x=LIBDIR_${DEFAULT_ABI}
870 [[ -n $DEFAULT_ABI && -n ${!x} ]] && x=${!x} || x=lib
872 if has distcc $FEATURES ; then
873 PATH="/usr/$x/distcc/bin:$PATH"
874 [[ -n $DISTCC_LOG ]] && addwrite "${DISTCC_LOG%/*}"
877 if has ccache $FEATURES ; then
878 PATH="/usr/$x/ccache/bin:$PATH"
880 if [[ -n $CCACHE_DIR ]] ; then
881 addread "$CCACHE_DIR"
882 addwrite "$CCACHE_DIR"
885 [[ -n $CCACHE_SIZE ]] && ccache -M $CCACHE_SIZE &> /dev/null
890 if [[ -n $QA_PREBUILT ]] ; then
892 # these ones support fnmatch patterns
893 QA_EXECSTACK+=" $QA_PREBUILT"
894 QA_TEXTRELS+=" $QA_PREBUILT"
895 QA_WX_LOAD+=" $QA_PREBUILT"
897 # these ones support regular expressions, so translate
898 # fnmatch patterns to regular expressions
899 for x in QA_DT_HASH QA_DT_NEEDED QA_PRESTRIPPED QA_SONAME ; do
900 if [[ $(declare -p $x 2>/dev/null) = declare\ -a* ]] ; then
901 eval "$x=(\"\${$x[@]}\" ${QA_PREBUILT//\*/.*})"
903 eval "$x+=\" ${QA_PREBUILT//\*/.*}\""
910 # This needs to be exported since prepstrip is a separate shell script.
911 [[ -n $QA_PRESTRIPPED ]] && export QA_PRESTRIPPED
912 eval "[[ -n \$QA_PRESTRIPPED_${ARCH/-/_} ]] && \
913 export QA_PRESTRIPPED_${ARCH/-/_}"
918 # unset USE_EXPAND variables that contain only the special "*" token
919 for x in ${USE_EXPAND} ; do
920 [ "${!x}" == "*" ] && unset ${x}
924 if has nostrip ${FEATURES} ${RESTRICT} || has strip ${RESTRICT}
929 if [[ $EBUILD_PHASE = depend ]] ; then
930 export SANDBOX_ON="0"
933 if [ -n "${dbkey}" ] ; then
934 if [ ! -d "${dbkey%/*}" ]; then
935 install -d -g ${PORTAGE_GID} -m2775 "${dbkey%/*}"
937 # Make it group writable. 666&~002==664
941 auxdbkeys="DEPEND RDEPEND SLOT SRC_URI RESTRICT HOMEPAGE LICENSE
942 DESCRIPTION KEYWORDS INHERITED IUSE REQUIRED_USE PDEPEND PROVIDE EAPI
943 PROPERTIES DEFINED_PHASES UNUSED_05 UNUSED_04
944 UNUSED_03 UNUSED_02 UNUSED_01"
946 #the extra $(echo) commands remove newlines
947 [ -n "${EAPI}" ] || EAPI=0
949 if [ -n "${dbkey}" ] ; then
951 for f in ${auxdbkeys} ; do
952 echo $(echo ${!f}) >> "${dbkey}" || exit $?
955 for f in ${auxdbkeys} ; do
956 echo $(echo ${!f}) 1>&9 || exit $?
962 # Note: readonly variables interfere with preprocess_ebuild_env(), so
963 # declare them only after it has already run.
964 declare -r $PORTAGE_READONLY_METADATA $PORTAGE_READONLY_VARS
969 declare -r ED EPREFIX EROOT
973 if [[ -n $EBUILD_SH_ARGS ]] ; then
975 # Don't allow subprocesses to inherit the pipe which
976 # emerge uses to monitor ebuild.sh.
978 ebuild_main ${EBUILD_SH_ARGS}
985 # Do not exit when ebuild.sh is sourced by other scripts.