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
125 # Custom version of esyslog() to take care of the "Red Star" bug.
126 # MUST follow functions.sh to override the "" parameter problem.
131 has $EBUILD_PHASE prerm postrm || eqawarn \
132 "QA Notice: The 'useq' function is deprecated (replaced by 'use')"
148 # if we got something like '!flag', then invert the return value
149 if [[ ${u:0:1} == "!" ]] ; then
154 if [[ $EBUILD_PHASE = depend ]] ; then
155 # TODO: Add a registration interface for eclasses to register
156 # any number of phase hooks, so that global scope eclass
157 # initialization can by migrated to phase hooks in new EAPIs.
158 # Example: add_phase_hook before pkg_setup $ECLASS_pre_pkg_setup
159 #if [[ -n $EAPI ]] && ! has "$EAPI" 0 1 2 3 ; then
160 # die "use() called during invalid phase: $EBUILD_PHASE"
164 # Make sure we have this USE flag in IUSE
165 elif [[ -n $PORTAGE_IUSE && -n $EBUILD_PHASE ]] ; then
166 [[ $u =~ $PORTAGE_IUSE ]] || \
167 eqawarn "QA Notice: USE Flag '${u}' not" \
168 "in IUSE for ${CATEGORY}/${PF}"
171 if has ${u} ${USE} ; then
178 # Return true if given package is installed. Otherwise return false.
179 # Takes single depend-type atoms.
181 if [ "${EBUILD_PHASE}" == "depend" ]; then
182 die "portageq calls (has_version calls portageq) are not allowed in the global scope"
185 if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
186 "$PORTAGE_BIN_PATH"/ebuild-ipc has_version "$ROOT" "$1"
188 PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
189 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" has_version "${ROOT}" "$1"
197 die "unexpected portageq exit code: ${retval}"
203 if [ "${EBUILD_PHASE}" == "depend" ]; then
204 die "portageq calls are not allowed in the global scope"
207 PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
208 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" "$@"
212 # ----------------------------------------------------------------------------
213 # ----------------------------------------------------------------------------
214 # ----------------------------------------------------------------------------
217 # Returns the best/most-current match.
218 # Takes single depend-type atoms.
220 if [ "${EBUILD_PHASE}" == "depend" ]; then
221 die "portageq calls (best_version calls portageq) are not allowed in the global scope"
224 if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
225 "$PORTAGE_BIN_PATH"/ebuild-ipc best_version "$ROOT" "$1"
227 PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
228 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" 'best_version' "${ROOT}" "$1"
236 die "unexpected portageq exit code: ${retval}"
243 echo "!!! use_with() called without a parameter." >&2
244 echo "!!! use_with <USEFLAG> [<flagname> [value]]" >&2
248 if ! has "${EAPI:-0}" 0 1 2 3 ; then
249 local UW_SUFFIX=${3+=$3}
251 local UW_SUFFIX=${3:+=$3}
256 echo "--with-${UWORD}${UW_SUFFIX}"
258 echo "--without-${UWORD}"
265 echo "!!! use_enable() called without a parameter." >&2
266 echo "!!! use_enable <USEFLAG> [<flagname> [value]]" >&2
270 if ! has "${EAPI:-0}" 0 1 2 3 ; then
271 local UE_SUFFIX=${3+=$3}
273 local UE_SUFFIX=${3:+=$3}
278 echo "--enable-${UWORD}${UE_SUFFIX}"
280 echo "--disable-${UWORD}"
285 register_die_hook() {
288 has $x $EBUILD_DEATH_HOOKS || \
289 export EBUILD_DEATH_HOOKS="$EBUILD_DEATH_HOOKS $x"
293 register_success_hook() {
296 has $x $EBUILD_SUCCESS_HOOKS || \
297 export EBUILD_SUCCESS_HOOKS="$EBUILD_SUCCESS_HOOKS $x"
301 # Ensure that $PWD is sane whenever possible, to protect against
302 # exploitation of insecure search path for python -c in ebuilds.
304 if ! has "$EBUILD_PHASE" clean cleanrm depend help ; then
305 cd "$PORTAGE_BUILDDIR" || \
306 die "PORTAGE_BUILDDIR does not exist: '$PORTAGE_BUILDDIR'"
309 #if no perms are specified, dirs/files will have decent defaults
310 #(not secretive, but not stupid)
313 export INSDESTTREE=""
314 export _E_EXEDESTTREE_=""
315 export _E_DOCDESTTREE_=""
316 export INSOPTIONS="-m0644"
317 export EXEOPTIONS="-m0755"
318 export LIBOPTIONS="-m0644"
319 export DIROPTIONS="-m0755"
320 export MOPREFIX=${PN}
321 declare -a PORTAGE_DOCOMPRESS=( /usr/share/{doc,info,man} )
322 declare -a PORTAGE_DOCOMPRESS_SKIP=( /usr/share/doc/${PF}/html )
324 # adds ".keep" files so that dirs aren't auto-cleaned
328 if [ "$1" == "-R" ] || [ "$1" == "-r" ]; then
330 find "$@" -type d -printf "${D}%p/.keep_${CATEGORY}_${PN}-${SLOT}\n" \
332 while read -r -d $'\0' ; do
334 die "Failed to recursively create .keep files"
338 >> "${D}${x}/.keep_${CATEGORY}_${PN}-${SLOT}" || \
339 die "Failed to create .keep in ${D}${x}"
349 local eapi=${EAPI:-0}
350 [ -z "$*" ] && die "Nothing passed to the 'unpack' command"
353 vecho ">>> Unpacking ${x} to ${PWD}"
357 if [[ ${x} == "./"* ]] ; then
359 elif [[ ${x} == ${DISTDIR%/}/* ]] ; then
360 die "Arguments to unpack() cannot begin with \${DISTDIR}."
361 elif [[ ${x} == "/"* ]] ; then
362 die "Arguments to unpack() cannot be absolute"
366 [[ ! -s ${srcdir}${x} ]] && die "${x} does not exist"
369 if [ "${y}" == "tar" ]; then
370 $1 -c -- "$srcdir$x" | tar xof -
371 assert_sigpipe_ok "$myfail"
373 local cwd_dest=${x##*/}
374 cwd_dest=${cwd_dest%.*}
375 $1 -c -- "${srcdir}${x}" > "${cwd_dest}" || die "$myfail"
379 myfail="failure unpacking ${x}"
382 tar xof "$srcdir$x" || die "$myfail"
385 tar xozf "$srcdir$x" || die "$myfail"
388 ${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- "$srcdir$x" | tar xof -
389 assert_sigpipe_ok "$myfail"
392 # unzip will interactively prompt under some error conditions,
393 # as reported in bug #336285
394 ( while true ; do echo n || break ; done ) | \
395 unzip -qo "${srcdir}${x}" || die "$myfail"
398 _unpack_tar "gzip -d"
401 _unpack_tar "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}"
405 my_output="$(7z x -y "${srcdir}${x}")"
406 if [ $? -ne 0 ]; then
407 echo "${my_output}" >&2
412 unrar x -idq -o+ "${srcdir}${x}" || die "$myfail"
415 lha xfq "${srcdir}${x}" || die "$myfail"
418 ar x "${srcdir}${x}" || die "$myfail"
421 # Unpacking .deb archives can not always be done with
422 # `ar`. For instance on AIX this doesn't work out. If
423 # we have `deb2targz` installed, prefer it over `ar` for
424 # that reason. We just make sure on AIX `deb2targz` is
426 if type -P deb2targz > /dev/null; then
428 local created_symlink=0
429 if [ ! "$srcdir$x" -ef "$y" ] ; then
430 # deb2targz always extracts into the same directory as
431 # the source file, so create a symlink in the current
432 # working directory if necessary.
433 ln -sf "$srcdir$x" "$y" || die "$myfail"
436 deb2targz "$y" || die "$myfail"
437 if [ $created_symlink = 1 ] ; then
438 # Clean up the symlink so the ebuild
439 # doesn't inadvertently install it.
442 mv -f "${y%.deb}".tar.gz data.tar.gz || die "$myfail"
444 ar x "$srcdir$x" || die "$myfail"
448 _unpack_tar "lzma -d"
451 if has $eapi 0 1 2 ; then
452 vecho "unpack ${x}: file format not recognized. Ignoring."
458 vecho "unpack ${x}: file format not recognized. Ignoring."
462 # Do not chmod '.' since it's probably ${WORKDIR} and PORTAGE_WORKDIR_MODE
463 # should be preserved.
464 find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \
465 ${XARGS} -0 chmod -fR a+rX,u+w,g-w,o-w
468 strip_duplicate_slashes() {
469 if [[ -n $1 ]] ; then
471 while [[ ${removed} == *//* ]] ; do
472 removed=${removed//\/\///}
481 for x ; do [[ ${x} == ${s} ]] && echo "${x}" && return 0 ; done
484 hasgq() { hasg "$@" >/dev/null ; }
488 local phase_func=$(_ebuild_arg_to_phase "$EAPI" "$EBUILD_PHASE")
489 if [[ -n $phase_func ]] ; then
490 if has "$EAPI" 0 1 ; then
491 [[ $phase_func != src_compile ]] && \
492 eqawarn "QA Notice: econf called in" \
493 "$phase_func instead of src_compile"
495 [[ $phase_func != src_configure ]] && \
496 eqawarn "QA Notice: econf called in" \
497 "$phase_func instead of src_configure"
502 if [ -x "${ECONF_SOURCE}/configure" ]; then
503 if [[ -n $CONFIG_SHELL && \
504 "$(head -n1 "$ECONF_SOURCE/configure")" =~ ^'#!'[[:space:]]*/bin/sh([[:space:]]|$) ]] ; then
505 sed -e "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" -i "$ECONF_SOURCE/configure" || \
506 die "Substition of shebang in '$ECONF_SOURCE/configure' failed"
508 if [ -e /usr/share/gnuconfig/ ]; then
509 find "${WORKDIR}" -type f '(' \
510 -name config.guess -o -name config.sub ')' -print0 | \
511 while read -r -d $'\0' x ; do
512 vecho " * econf: updating ${x/${WORKDIR}\/} with /usr/share/gnuconfig/${x##*/}"
513 cp -f /usr/share/gnuconfig/"${x##*/}" "${x}"
517 # EAPI=4 adds --disable-dependency-tracking to econf
518 if ! has "$EAPI" 0 1 2 3 3_pre2 && \
519 "${ECONF_SOURCE}/configure" --help 2>/dev/null | \
520 grep -q disable-dependency-tracking ; then
521 set -- --disable-dependency-tracking "$@"
524 # if the profile defines a location to install libs to aside from default, pass it on.
525 # if the ebuild passes in --libdir, they're responsible for the conf_libdir fun.
526 local CONF_LIBDIR LIBDIR_VAR="LIBDIR_${ABI}"
527 if [[ -n ${ABI} && -n ${!LIBDIR_VAR} ]] ; then
528 CONF_LIBDIR=${!LIBDIR_VAR}
530 if [[ -n ${CONF_LIBDIR} ]] && ! hasgq --libdir=\* "$@" ; then
531 export CONF_PREFIX=$(hasg --exec-prefix=\* "$@")
532 [[ -z ${CONF_PREFIX} ]] && CONF_PREFIX=$(hasg --prefix=\* "$@")
533 : ${CONF_PREFIX:=/usr}
534 CONF_PREFIX=${CONF_PREFIX#*=}
535 [[ ${CONF_PREFIX} != /* ]] && CONF_PREFIX="/${CONF_PREFIX}"
536 [[ ${CONF_LIBDIR} != /* ]] && CONF_LIBDIR="/${CONF_LIBDIR}"
537 set -- --libdir="$(strip_duplicate_slashes ${CONF_PREFIX}${CONF_LIBDIR})" "$@"
542 ${CBUILD:+--build=${CBUILD}} \
544 ${CTARGET:+--target=${CTARGET}} \
545 --mandir=/usr/share/man \
546 --infodir=/usr/share/info \
547 --datadir=/usr/share \
549 --localstatedir=/var/lib \
552 vecho "${ECONF_SOURCE}/configure" "$@"
554 if ! "${ECONF_SOURCE}/configure" "$@" ; then
556 if [ -s config.log ]; then
558 echo "!!! Please attach the following file when seeking support:"
559 echo "!!! ${PWD}/config.log"
563 elif [ -f "${ECONF_SOURCE}/configure" ]; then
564 die "configure is not executable"
566 die "no configure script found"
571 # CONF_PREFIX is only set if they didn't pass in libdir above.
572 local LOCAL_EXTRA_EINSTALL="${EXTRA_EINSTALL}"
573 LIBDIR_VAR="LIBDIR_${ABI}"
574 if [ -n "${ABI}" -a -n "${!LIBDIR_VAR}" ]; then
575 CONF_LIBDIR="${!LIBDIR_VAR}"
578 if [ -n "${CONF_LIBDIR}" ] && [ "${CONF_PREFIX:+set}" = set ]; then
579 EI_DESTLIBDIR="${D}/${CONF_PREFIX}/${CONF_LIBDIR}"
580 EI_DESTLIBDIR="$(strip_duplicate_slashes ${EI_DESTLIBDIR})"
581 LOCAL_EXTRA_EINSTALL="libdir=${EI_DESTLIBDIR} ${LOCAL_EXTRA_EINSTALL}"
585 if [ -f ./[mM]akefile -o -f ./GNUmakefile ] ; then
586 if [ "${PORTAGE_DEBUG}" == "1" ]; then
587 ${MAKE:-make} -n prefix="${D}usr" \
588 datadir="${D}usr/share" \
589 infodir="${D}usr/share/info" \
590 localstatedir="${D}var/lib" \
591 mandir="${D}usr/share/man" \
592 sysconfdir="${D}etc" \
593 ${LOCAL_EXTRA_EINSTALL} \
594 ${MAKEOPTS} ${EXTRA_EMAKE} -j1 \
597 ${MAKE:-make} prefix="${D}usr" \
598 datadir="${D}usr/share" \
599 infodir="${D}usr/share/info" \
600 localstatedir="${D}var/lib" \
601 mandir="${D}usr/share/man" \
602 sysconfdir="${D}etc" \
603 ${LOCAL_EXTRA_EINSTALL} \
604 ${MAKEOPTS} ${EXTRA_EMAKE} -j1 \
605 "$@" install || die "einstall failed"
607 die "no Makefile found"
611 _eapi0_pkg_nofetch() {
612 [ -z "${SRC_URI}" ] && return
614 elog "The following are listed in SRC_URI for ${PN}:"
616 for x in $(echo ${SRC_URI}); do
621 _eapi0_src_unpack() {
622 [[ -n ${A} ]] && unpack ${A}
625 _eapi0_src_compile() {
626 if [ -x ./configure ] ; then
633 # Since we don't want emake's automatic die
634 # support (EAPI 4 and later), and we also don't
635 # want the warning messages that it produces if
636 # we call it in 'nonfatal' mode, we use emake_cmd
637 # to emulate the desired parts of emake behavior.
638 local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}"
639 if $emake_cmd -j1 check -n &> /dev/null; then
640 vecho ">>> Test phase [check]: ${CATEGORY}/${PF}"
641 if ! $emake_cmd -j1 check; then
642 has test $FEATURES && die "Make check failed. See above for details."
643 has test $FEATURES || eerror "Make check failed. See above for details."
645 elif $emake_cmd -j1 test -n &> /dev/null; then
646 vecho ">>> Test phase [test]: ${CATEGORY}/${PF}"
647 if ! $emake_cmd -j1 test; then
648 has test $FEATURES && die "Make test failed. See above for details."
649 has test $FEATURES || eerror "Make test failed. See above for details."
652 vecho ">>> Test phase [none]: ${CATEGORY}/${PF}"
656 _eapi1_src_compile() {
661 _eapi2_src_configure() {
662 if [[ -x ${ECONF_SOURCE:-.}/configure ]] ; then
667 _eapi2_src_compile() {
668 if [ -f Makefile ] || [ -f GNUmakefile ] || [ -f makefile ]; then
669 emake || die "emake failed"
673 _eapi4_src_install() {
674 if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
675 emake DESTDIR="${D}" install
678 if ! declare -p DOCS &>/dev/null ; then
680 for d in README* ChangeLog AUTHORS NEWS TODO CHANGES \
681 THANKS BUGS FAQ CREDITS CHANGELOG ; do
682 [[ -s "${d}" ]] && dodoc "${d}"
684 elif [[ $(declare -p DOCS) == "declare -a "* ]] ; then
692 if [ "$1" == "/" ]; then
696 if [ ! -d "${D}${DESTTREE}" ]; then
697 install -d "${D}${DESTTREE}"
699 if [[ $ret -ne 0 ]] ; then
700 helpers_die "${FUNCNAME[0]} failed"
708 if [ "$1" == "/" ]; then
709 export INSDESTTREE=""
711 export INSDESTTREE=$1
712 if [ ! -d "${D}${INSDESTTREE}" ]; then
713 install -d "${D}${INSDESTTREE}"
715 if [[ $ret -ne 0 ]] ; then
716 helpers_die "${FUNCNAME[0]} failed"
724 if [ "$1" == "/" ]; then
725 export _E_EXEDESTTREE_=""
727 export _E_EXEDESTTREE_="$1"
728 if [ ! -d "${D}${_E_EXEDESTTREE_}" ]; then
729 install -d "${D}${_E_EXEDESTTREE_}"
731 if [[ $ret -ne 0 ]] ; then
732 helpers_die "${FUNCNAME[0]} failed"
740 if [ "$1" == "/" ]; then
741 export _E_DOCDESTTREE_=""
743 export _E_DOCDESTTREE_="$1"
744 if [ ! -d "${D}usr/share/doc/${PF}/${_E_DOCDESTTREE_}" ]; then
745 install -d "${D}usr/share/doc/${PF}/${_E_DOCDESTTREE_}"
747 if [[ $ret -ne 0 ]] ; then
748 helpers_die "${FUNCNAME[0]} failed"
756 export INSOPTIONS="$@"
758 # `install` should never be called with '-s' ...
759 has -s ${INSOPTIONS} && die "Never call insopts() with -s"
763 export DIROPTIONS="$@"
767 export EXEOPTIONS="$@"
769 # `install` should never be called with '-s' ...
770 has -s ${EXEOPTIONS} && die "Never call exeopts() with -s"
774 export LIBOPTIONS="$@"
776 # `install` should never be called with '-s' ...
777 has -s ${LIBOPTIONS} && die "Never call libopts() with -s"
781 has "${EAPI}" 0 1 2 3 && die "'docompress' not supported in this EAPI"
784 if [[ $1 = "-x" ]]; then
787 f=$(strip_duplicate_slashes "${f}"); f=${f%/}
788 [[ ${f:0:1} = / ]] || f="/${f}"
789 for g in "${PORTAGE_DOCOMPRESS_SKIP[@]}"; do
790 [[ ${f} = "${g}" ]] && continue 2
792 PORTAGE_DOCOMPRESS_SKIP[${#PORTAGE_DOCOMPRESS_SKIP[@]}]=${f}
796 f=$(strip_duplicate_slashes "${f}"); f=${f%/}
797 [[ ${f:0:1} = / ]] || f="/${f}"
798 for g in "${PORTAGE_DOCOMPRESS[@]}"; do
799 [[ ${f} = "${g}" ]] && continue 2
801 PORTAGE_DOCOMPRESS[${#PORTAGE_DOCOMPRESS[@]}]=${f}
806 # debug-print() gets called from many places with verbose status information useful
807 # for tracking down problems. The output is in $T/eclass-debug.log.
808 # You can set ECLASS_DEBUG_OUTPUT to redirect the output somewhere else as well.
809 # The special "on" setting echoes the information, mixing it with the rest of the
811 # You can override the setting by exporting a new one from the console, or you can
812 # set a new default in make.*. Here the default is "" or unset.
814 # in the future might use e* from /etc/init.d/functions.sh if i feel like it
816 # if $T isn't defined, we're in dep calculation mode and
817 # shouldn't do anything
818 [[ $EBUILD_PHASE = depend || ! -d ${T} || ${#} -eq 0 ]] && return 0
820 if [[ ${ECLASS_DEBUG_OUTPUT} == on ]]; then
821 printf 'debug: %s\n' "${@}" >&2
822 elif [[ -n ${ECLASS_DEBUG_OUTPUT} ]]; then
823 printf 'debug: %s\n' "${@}" >> "${ECLASS_DEBUG_OUTPUT}"
826 if [[ -w $T ]] ; then
828 printf '%s\n' "${@}" >> "${T}/eclass-debug.log"
829 # let the portage user own/write to this file
830 chgrp portage "${T}/eclass-debug.log" &>/dev/null
831 chmod g+w "${T}/eclass-debug.log" &>/dev/null
835 # The following 2 functions are debug-print() wrappers
837 debug-print-function() {
838 debug-print "${1}: entering function, parameters: ${*:2}"
841 debug-print-section() {
842 debug-print "now in section ${*}"
845 # Sources all eclasses in parameters
846 declare -ix ECLASS_DEPTH=0
848 ECLASS_DEPTH=$(($ECLASS_DEPTH + 1))
849 if [[ ${ECLASS_DEPTH} > 1 ]]; then
850 debug-print "*** Multiple Inheritence (Level: ${ECLASS_DEPTH})"
853 if [[ -n $ECLASS && -n ${!__export_funcs_var} ]] ; then
854 echo "QA Notice: EXPORT_FUNCTIONS is called before inherit in" \
855 "$ECLASS.eclass. For compatibility with <=portage-2.1.6.7," \
856 "only call EXPORT_FUNCTIONS after inherit(s)." \
857 | fmt -w 75 | while read -r ; do eqawarn "$REPLY" ; done
864 # These variables must be restored before returning.
865 local PECLASS=$ECLASS
866 local prev_export_funcs_var=$__export_funcs_var
874 location="${ECLASSDIR}/${1}.eclass"
878 __export_funcs_var=__export_functions_$ECLASS_DEPTH
879 unset $__export_funcs_var
881 if [ "${EBUILD_PHASE}" != "depend" ] && \
882 [[ ${EBUILD_PHASE} != *rm ]] && \
883 [[ ${EMERGE_FROM} != "binary" ]] ; then
884 # This is disabled in the *rm phases because they frequently give
885 # false alarms due to INHERITED in /var/db/pkg being outdated
886 # in comparison the the eclasses from the portage tree.
887 if ! has $ECLASS $INHERITED $__INHERITED_QA_CACHE ; then
888 eqawarn "QA Notice: ECLASS '$ECLASS' inherited illegally in $CATEGORY/$PF $EBUILD_PHASE"
892 # any future resolution code goes here
893 if [ -n "$PORTDIR_OVERLAY" ]; then
895 for overlay in ${PORTDIR_OVERLAY}; do
896 olocation="${overlay}/eclass/${1}.eclass"
897 if [ -e "$olocation" ]; then
898 location="${olocation}"
899 debug-print " eclass exists: ${location}"
903 debug-print "inherit: $1 -> $location"
904 [ ! -e "$location" ] && die "${1}.eclass could not be found by inherit()"
906 if [ "${location}" == "${olocation}" ] && \
907 ! has "${location}" ${EBUILD_OVERLAY_ECLASSES} ; then
908 EBUILD_OVERLAY_ECLASSES="${EBUILD_OVERLAY_ECLASSES} ${location}"
911 #We need to back up the value of DEPEND and RDEPEND to B_DEPEND and B_RDEPEND
912 #(if set).. and then restore them after the inherit call.
914 #turn off glob expansion
917 # Retain the old data and restore it later.
918 unset B_IUSE B_REQUIRED_USE B_DEPEND B_RDEPEND B_PDEPEND
919 [ "${IUSE+set}" = set ] && B_IUSE="${IUSE}"
920 [ "${REQUIRED_USE+set}" = set ] && B_REQUIRED_USE="${REQUIRED_USE}"
921 [ "${DEPEND+set}" = set ] && B_DEPEND="${DEPEND}"
922 [ "${RDEPEND+set}" = set ] && B_RDEPEND="${RDEPEND}"
923 [ "${PDEPEND+set}" = set ] && B_PDEPEND="${PDEPEND}"
924 unset IUSE REQUIRED_USE DEPEND RDEPEND PDEPEND
925 #turn on glob expansion
928 qa_source "$location" || die "died sourcing $location in inherit()"
930 #turn off glob expansion
933 # If each var has a value, append it to the global variable E_* to
934 # be applied after everything is finished. New incremental behavior.
935 [ "${IUSE+set}" = set ] && export E_IUSE="${E_IUSE} ${IUSE}"
936 [ "${REQUIRED_USE+set}" = set ] && export E_REQUIRED_USE="${E_REQUIRED_USE} ${REQUIRED_USE}"
937 [ "${DEPEND+set}" = set ] && export E_DEPEND="${E_DEPEND} ${DEPEND}"
938 [ "${RDEPEND+set}" = set ] && export E_RDEPEND="${E_RDEPEND} ${RDEPEND}"
939 [ "${PDEPEND+set}" = set ] && export E_PDEPEND="${E_PDEPEND} ${PDEPEND}"
941 [ "${B_IUSE+set}" = set ] && IUSE="${B_IUSE}"
942 [ "${B_IUSE+set}" = set ] || unset IUSE
944 [ "${B_REQUIRED_USE+set}" = set ] && REQUIRED_USE="${B_REQUIRED_USE}"
945 [ "${B_REQUIRED_USE+set}" = set ] || unset REQUIRED_USE
947 [ "${B_DEPEND+set}" = set ] && DEPEND="${B_DEPEND}"
948 [ "${B_DEPEND+set}" = set ] || unset DEPEND
950 [ "${B_RDEPEND+set}" = set ] && RDEPEND="${B_RDEPEND}"
951 [ "${B_RDEPEND+set}" = set ] || unset RDEPEND
953 [ "${B_PDEPEND+set}" = set ] && PDEPEND="${B_PDEPEND}"
954 [ "${B_PDEPEND+set}" = set ] || unset PDEPEND
956 #turn on glob expansion
959 if [[ -n ${!__export_funcs_var} ]] ; then
960 for x in ${!__export_funcs_var} ; do
961 debug-print "EXPORT_FUNCTIONS: $x -> ${ECLASS}_$x"
962 declare -F "${ECLASS}_$x" >/dev/null || \
963 die "EXPORT_FUNCTIONS: ${ECLASS}_$x is not defined"
964 eval "$x() { ${ECLASS}_$x \"\$@\" ; }" > /dev/null
967 unset $__export_funcs_var
969 has $1 $INHERITED || export INHERITED="$INHERITED $1"
973 ((--ECLASS_DEPTH)) # Returns 1 when ECLASS_DEPTH reaches 0.
974 if (( ECLASS_DEPTH > 0 )) ; then
975 export ECLASS=$PECLASS
976 __export_funcs_var=$prev_export_funcs_var
978 unset ECLASS __export_funcs_var
983 # Exports stub functions that call the eclass's functions, thereby making them default.
984 # For example, if ECLASS="base" and you call "EXPORT_FUNCTIONS src_unpack", the following
985 # code will be eval'd:
986 # src_unpack() { base_src_unpack; }
988 if [ -z "$ECLASS" ]; then
989 die "EXPORT_FUNCTIONS without a defined ECLASS"
991 eval $__export_funcs_var+=\" $*\"
994 # this is a function for removing any directory matching a passed in pattern from
996 remove_path_entry() {
999 stripped_path="${PATH}"
1000 while [ -n "$1" ]; do
1002 for p in ${stripped_path}; do
1003 if [ "${p/${1}}" == "${p}" ]; then
1004 cur_path="${cur_path}:${p}"
1007 stripped_path="${cur_path#:*}"
1011 PATH="${stripped_path}"
1014 # Set given variables unless these variable have been already set (e.g. during emerge
1015 # invocation) to values different than values set in make.conf.
1016 set_unless_changed() {
1017 if [[ $# -lt 1 ]]; then
1018 die "${FUNCNAME}() requires at least 1 argument: VARIABLE=VALUE"
1021 local argument value variable
1022 for argument in "$@"; do
1023 if [[ ${argument} != *=* ]]; then
1024 die "${FUNCNAME}(): Argument '${argument}' has incorrect syntax"
1026 variable="${argument%%=*}"
1027 value="${argument#*=}"
1028 if eval "[[ \${${variable}} == \$(env -u ${variable} portageq envvar ${variable}) ]]"; then
1029 eval "${variable}=\"\${value}\""
1034 # Unset given variables unless these variable have been set (e.g. during emerge
1035 # invocation) to values different than values set in make.conf.
1036 unset_unless_changed() {
1037 if [[ $# -lt 1 ]]; then
1038 die "${FUNCNAME}() requires at least 1 argument: VARIABLE"
1042 for variable in "$@"; do
1043 if eval "[[ \${${variable}} == \$(env -u ${variable} portageq envvar ${variable}) ]]"; then
1049 PORTAGE_BASHRCS_SOURCED=0
1051 # @FUNCTION: source_all_bashrcs
1053 # Source a relevant bashrc files and perform other miscellaneous
1054 # environment initialization when appropriate.
1056 # If EAPI is set then define functions provided by the current EAPI:
1058 # * default_* aliases for the current EAPI phase functions
1059 # * A "default" function which is an alias for the default phase
1060 # function for the current phase.
1062 source_all_bashrcs() {
1063 [[ $PORTAGE_BASHRCS_SOURCED = 1 ]] && return 0
1064 PORTAGE_BASHRCS_SOURCED=1
1067 local OCC="${CC}" OCXX="${CXX}"
1069 if [[ $EBUILD_PHASE != depend ]] ; then
1070 # source the existing profile.bashrcs.
1073 local path_array=($PROFILE_PATHS)
1075 for x in "${path_array[@]}" ; do
1076 [ -f "$x/profile.bashrc" ] && qa_source "$x/profile.bashrc"
1080 # We assume if people are changing shopts in their bashrc they do so at their
1081 # own peril. This is the ONLY non-portage bit of code that can change shopts
1082 # without a QA violation.
1083 for x in "${PORTAGE_BASHRC}" "${PM_EBUILD_HOOK_DIR}"/${CATEGORY}/{${PN},${PN}:${SLOT},${P},${PF}}; do
1084 if [ -r "${x}" ]; then
1085 # If $- contains x, then tracing has already enabled elsewhere for some
1086 # reason. We preserve it's state so as not to interfere.
1087 if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then
1097 [ ! -z "${OCC}" ] && export CC="${OCC}"
1098 [ ! -z "${OCXX}" ] && export CXX="${OCXX}"
1101 # Hardcoded bash lists are needed for backward compatibility with
1102 # <portage-2.1.4 since they assume that a newly installed version
1103 # of ebuild.sh will work for pkg_postinst, pkg_prerm, and pkg_postrm
1104 # when portage is upgrading itself.
1106 PORTAGE_READONLY_METADATA="DEFINED_PHASES DEPEND DESCRIPTION
1107 EAPI HOMEPAGE INHERITED IUSE REQUIRED_USE KEYWORDS LICENSE
1108 PDEPEND PROVIDE RDEPEND RESTRICT SLOT SRC_URI"
1110 PORTAGE_READONLY_VARS="D EBUILD EBUILD_PHASE \
1111 EBUILD_SH_ARGS ECLASSDIR EMERGE_FROM FILESDIR MERGE_TYPE \
1112 PM_EBUILD_HOOK_DIR \
1113 PORTAGE_ACTUAL_DISTDIR PORTAGE_ARCHLIST PORTAGE_BASHRC \
1114 PORTAGE_BINPKG_FILE PORTAGE_BINPKG_TAR_OPTS PORTAGE_BINPKG_TMPFILE \
1115 PORTAGE_BIN_PATH PORTAGE_BUILDDIR PORTAGE_BUNZIP2_COMMAND \
1116 PORTAGE_BZIP2_COMMAND PORTAGE_COLORMAP PORTAGE_CONFIGROOT \
1117 PORTAGE_DEBUG PORTAGE_DEPCACHEDIR PORTAGE_EBUILD_EXIT_FILE \
1118 PORTAGE_GID PORTAGE_GRPNAME PORTAGE_INST_GID PORTAGE_INST_UID \
1119 PORTAGE_IPC_DAEMON PORTAGE_IUSE PORTAGE_LOG_FILE \
1120 PORTAGE_MUTABLE_FILTERED_VARS PORTAGE_PYM_PATH PORTAGE_PYTHON \
1121 PORTAGE_READONLY_METADATA PORTAGE_READONLY_VARS \
1122 PORTAGE_REPO_NAME PORTAGE_RESTRICT PORTAGE_SANDBOX_COMPAT_LEVEL \
1123 PORTAGE_SAVED_READONLY_VARS PORTAGE_SIGPIPE_STATUS \
1124 PORTAGE_TMPDIR PORTAGE_UPDATE_ENV PORTAGE_USERNAME \
1125 PORTAGE_VERBOSE PORTAGE_WORKDIR_MODE PORTDIR PORTDIR_OVERLAY \
1126 PROFILE_PATHS REPLACING_VERSIONS REPLACED_BY_VERSION T WORKDIR"
1128 PORTAGE_SAVED_READONLY_VARS="A CATEGORY P PF PN PR PV PVR"
1130 # Variables that portage sets but doesn't mark readonly.
1131 # In order to prevent changed values from causing unexpected
1132 # interference, they are filtered out of the environment when
1133 # it is saved or loaded (any mutations do not persist).
1134 PORTAGE_MUTABLE_FILTERED_VARS="AA HOSTNAME"
1136 # @FUNCTION: filter_readonly_variables
1137 # @DESCRIPTION: [--filter-sandbox] [--allow-extra-vars]
1138 # Read an environment from stdin and echo to stdout while filtering variables
1139 # with names that are known to cause interference:
1141 # * some specific variables for which bash does not allow assignment
1142 # * some specific variables that affect portage or sandbox behavior
1143 # * variable names that begin with a digit or that contain any
1144 # non-alphanumeric characters that are not be supported by bash
1146 # --filter-sandbox causes all SANDBOX_* variables to be filtered, which
1147 # is only desired in certain cases, such as during preprocessing or when
1148 # saving environment.bz2 for a binary or installed package.
1150 # --filter-features causes the special FEATURES variable to be filtered.
1151 # Generally, we want it to persist between phases since the user might
1152 # want to modify it via bashrc to enable things like splitdebug and
1153 # installsources for specific packages. They should be able to modify it
1154 # in pre_pkg_setup() and have it persist all the way through the install
1155 # phase. However, if FEATURES exist inside environment.bz2 then they
1156 # should be overridden by current settings.
1158 # --filter-locale causes locale related variables such as LANG and LC_*
1159 # variables to be filtered. These variables should persist between phases,
1160 # in case they are modified by the ebuild. However, the current user
1161 # settings should be used when loading the environment from a binary or
1162 # installed package.
1164 # --filter-path causes the PATH variable to be filtered. This variable
1165 # should persist between phases, in case it is modified by the ebuild.
1166 # However, old settings should be overridden when loading the
1167 # environment from a binary or installed package.
1169 # ---allow-extra-vars causes some extra vars to be allowd through, such
1170 # as ${PORTAGE_SAVED_READONLY_VARS} and ${PORTAGE_MUTABLE_FILTERED_VARS}.
1172 # In bash-3.2_p20+ an attempt to assign BASH_*, FUNCNAME, GROUPS or any
1173 # readonly variable cause the shell to exit while executing the "source"
1174 # builtin command. To avoid this problem, this function filters those
1175 # variables out and discards them. See bug #190128.
1176 filter_readonly_variables() {
1177 local x filtered_vars
1178 local readonly_bash_vars="BASHOPTS BASHPID DIRSTACK EUID
1179 FUNCNAME GROUPS PIPESTATUS PPID SHELLOPTS UID"
1180 local bash_misc_vars="BASH BASH_.* COMP_WORDBREAKS HISTCMD
1181 HISTFILE HOSTNAME HOSTTYPE IFS LINENO MACHTYPE OLDPWD
1182 OPTERR OPTIND OSTYPE POSIXLY_CORRECT PS4 PWD RANDOM
1183 SECONDS SHELL SHLVL"
1184 local filtered_sandbox_vars="SANDBOX_ACTIVE SANDBOX_BASHRC
1185 SANDBOX_DEBUG_LOG SANDBOX_DISABLED SANDBOX_LIB
1186 SANDBOX_LOG SANDBOX_ON"
1187 local misc_garbage_vars="_portage_filter_opts"
1188 filtered_vars="$readonly_bash_vars $bash_misc_vars
1189 $PORTAGE_READONLY_VARS $misc_garbage_vars"
1191 # Don't filter/interfere with prefix variables unless they are
1192 # supported by the current EAPI.
1193 case "${EAPI:-0}" in
1197 filtered_vars+=" ED EPREFIX EROOT"
1201 if has --filter-sandbox $* ; then
1202 filtered_vars="${filtered_vars} SANDBOX_.*"
1204 filtered_vars="${filtered_vars} ${filtered_sandbox_vars}"
1206 if has --filter-features $* ; then
1207 filtered_vars="${filtered_vars} FEATURES PORTAGE_FEATURES"
1209 if has --filter-path $* ; then
1210 filtered_vars+=" PATH"
1212 if has --filter-locale $* ; then
1213 filtered_vars+=" LANG LC_ALL LC_COLLATE
1214 LC_CTYPE LC_MESSAGES LC_MONETARY
1215 LC_NUMERIC LC_PAPER LC_TIME"
1217 if ! has --allow-extra-vars $* ; then
1220 ${PORTAGE_SAVED_READONLY_VARS}
1221 ${PORTAGE_MUTABLE_FILTERED_VARS}
1225 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}" || die "filter-bash-environment.py failed"
1228 # @FUNCTION: preprocess_ebuild_env
1230 # Filter any readonly variables from ${T}/environment, source it, and then
1231 # save it via save_ebuild_env(). This process should be sufficient to prevent
1232 # any stale variables or functions from an arbitrary environment from
1233 # interfering with the current environment. This is useful when an existing
1234 # environment needs to be loaded from a binary or installed package.
1235 preprocess_ebuild_env() {
1236 local _portage_filter_opts="--filter-features --filter-locale --filter-path --filter-sandbox"
1238 # If environment.raw is present, this is a signal from the python side,
1239 # indicating that the environment may contain stale FEATURES and
1240 # SANDBOX_{DENY,PREDICT,READ,WRITE} variables that should be filtered out.
1241 # Otherwise, we don't need to filter the environment.
1242 [ -f "${T}/environment.raw" ] || return 0
1244 filter_readonly_variables $_portage_filter_opts < "${T}"/environment \
1245 >> "$T/environment.filtered" || return $?
1246 unset _portage_filter_opts
1247 mv "${T}"/environment.filtered "${T}"/environment || return $?
1248 rm -f "${T}/environment.success" || return $?
1249 # WARNING: Code inside this subshell should avoid making assumptions
1250 # about variables or functions after source "${T}"/environment has been
1251 # called. Any variables that need to be relied upon should already be
1252 # filtered out above.
1255 source "${T}/environment" || exit $?
1256 # We have to temporarily disable sandbox since the
1257 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
1258 # may be unusable (triggering in spurious sandbox violations)
1259 # until we've merged them with our current values.
1262 # It's remotely possible that save_ebuild_env() has been overridden
1263 # by the above source command. To protect ourselves, we override it
1264 # here with our own version. ${PORTAGE_BIN_PATH} is safe to use here
1265 # because it's already filtered above.
1266 source "${PORTAGE_BIN_PATH}/isolated-functions.sh" || exit $?
1268 # Rely on save_ebuild_env() to filter out any remaining variables
1269 # and functions that could interfere with the current environment.
1270 save_ebuild_env || exit $?
1271 >> "$T/environment.success" || exit $?
1272 ) > "${T}/environment.filtered"
1274 if [ -e "${T}/environment.success" ] ; then
1275 filter_readonly_variables --filter-features < \
1276 "${T}/environment.filtered" > "${T}/environment"
1281 rm -f "${T}"/environment.{filtered,raw,success}
1285 # === === === === === === === === === === === === === === === === === ===
1286 # === === === === === functions end, main part begins === === === === ===
1287 # === === === === === functions end, main part begins === === === === ===
1288 # === === === === === functions end, main part begins === === === === ===
1289 # === === === === === === === === === === === === === === === === === ===
1291 export SANDBOX_ON="1"
1292 export S=${WORKDIR}/${P}
1294 unset E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND
1296 # Turn of extended glob matching so that g++ doesn't get incorrectly matched.
1299 if [[ ${EBUILD_PHASE} == depend ]] ; then
1300 QA_INTERCEPTORS="awk bash cc egrep equery fgrep g++
1301 gawk gcc grep javac java-config nawk perl
1302 pkg-config python python-config sed"
1303 elif [[ ${EBUILD_PHASE} == clean* ]] ; then
1304 unset QA_INTERCEPTORS
1306 QA_INTERCEPTORS="autoconf automake aclocal libtoolize"
1308 # level the QA interceptors if we're in depend
1309 if [[ -n ${QA_INTERCEPTORS} ]] ; then
1310 for BIN in ${QA_INTERCEPTORS}; do
1311 BIN_PATH=$(type -Pf ${BIN})
1312 if [ "$?" != "0" ]; then
1313 BODY="echo \"*** missing command: ${BIN}\" >&2; return 127"
1315 BODY="${BIN_PATH} \"\$@\"; return \$?"
1317 if [[ ${EBUILD_PHASE} == depend ]] ; then
1318 FUNC_SRC="${BIN}() {
1319 if [ \$ECLASS_DEPTH -gt 0 ]; then
1320 eqawarn \"QA Notice: '${BIN}' called in global scope: eclass \${ECLASS}\"
1322 eqawarn \"QA Notice: '${BIN}' called in global scope: \${CATEGORY}/\${PF}\"
1326 elif has ${BIN} autoconf automake aclocal libtoolize ; then
1327 FUNC_SRC="${BIN}() {
1328 if ! has \${FUNCNAME[1]} eautoreconf eaclocal _elibtoolize \\
1329 eautoheader eautoconf eautomake autotools_run_tool \\
1330 autotools_check_macro autotools_get_subdirs \\
1331 autotools_get_auxdir ; then
1332 eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
1333 eqawarn \"Use autotools.eclass instead of calling '${BIN}' directly.\"
1338 FUNC_SRC="${BIN}() {
1339 eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
1343 eval "$FUNC_SRC" || echo "error creating QA interceptor ${BIN}" >&2
1345 unset BIN_PATH BIN BODY FUNC_SRC
1348 # Subshell/helper die support (must export for the die helper).
1349 export EBUILD_MASTER_PID=$BASHPID
1350 trap 'exit 1' SIGTERM
1352 [[ $EBUILD_PHASE == depend ]] || source "${PORTAGE_BIN_PATH}/phase-functions.sh"
1354 if ! has "$EBUILD_PHASE" clean cleanrm depend && \
1355 [ -f "${T}"/environment ] ; then
1356 # The environment may have been extracted from environment.bz2 or
1357 # may have come from another version of ebuild.sh or something.
1358 # In any case, preprocess it to prevent any potential interference.
1359 preprocess_ebuild_env || \
1360 die "error processing environment"
1361 # Colon separated SANDBOX_* variables need to be cumulative.
1362 for x in SANDBOX_DENY SANDBOX_READ SANDBOX_PREDICT SANDBOX_WRITE ; do
1363 export PORTAGE_${x}=${!x}
1365 PORTAGE_SANDBOX_ON=${SANDBOX_ON}
1367 source "${T}"/environment || \
1368 die "error sourcing environment"
1369 # We have to temporarily disable sandbox since the
1370 # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
1371 # may be unusable (triggering in spurious sandbox violations)
1372 # until we've merged them with our current values.
1374 for x in SANDBOX_DENY SANDBOX_PREDICT SANDBOX_READ SANDBOX_WRITE ; do
1376 if [ -z "${!x}" ] ; then
1378 elif [ -n "${!y}" ] && [ "${!y}" != "${!x}" ] ; then
1380 export ${x}=$(printf "${!y}:${!x}" | tr ":" "\0" | \
1381 sort -z -u | tr "\0" ":")
1387 export SANDBOX_ON=${PORTAGE_SANDBOX_ON}
1388 unset PORTAGE_SANDBOX_ON
1389 [[ -n $EAPI ]] || EAPI=0
1392 if ! has "$EBUILD_PHASE" clean cleanrm ; then
1393 if [[ $EBUILD_PHASE = depend || ! -f $T/environment || \
1394 -f $PORTAGE_BUILDDIR/.ebuild_changed ]] || \
1395 has noauto $FEATURES ; then
1396 # The bashrcs get an opportunity here to set aliases that will be expanded
1397 # during sourcing of ebuilds and eclasses.
1400 # When EBUILD_PHASE != depend, INHERITED comes pre-initialized
1401 # from cache. In order to make INHERITED content independent of
1402 # EBUILD_PHASE during inherit() calls, we unset INHERITED after
1403 # we make a backup copy for QA checks.
1404 __INHERITED_QA_CACHE=$INHERITED
1406 # *DEPEND and IUSE will be set during the sourcing of the ebuild.
1407 # In order to ensure correct interaction between ebuilds and
1408 # eclasses, they need to be unset before this process of
1409 # interaction begins.
1410 unset DEPEND RDEPEND PDEPEND INHERITED IUSE REQUIRED_USE \
1411 ECLASS E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND
1413 if [[ $PORTAGE_DEBUG != 1 || ${-/x/} != $- ]] ; then
1414 source "$EBUILD" || die "error sourcing ebuild"
1417 source "$EBUILD" || die "error sourcing ebuild"
1421 if [[ "${EBUILD_PHASE}" != "depend" ]] ; then
1422 RESTRICT=${PORTAGE_RESTRICT}
1423 [[ -e $PORTAGE_BUILDDIR/.ebuild_changed ]] && \
1424 rm "$PORTAGE_BUILDDIR/.ebuild_changed"
1427 [[ -n $EAPI ]] || EAPI=0
1429 if has "$EAPI" 0 1 2 3 3_pre2 ; then
1430 export RDEPEND=${RDEPEND-${DEPEND}}
1431 debug-print "RDEPEND: not set... Setting to: ${DEPEND}"
1434 # add in dependency info from eclasses
1435 IUSE="${IUSE} ${E_IUSE}"
1436 DEPEND="${DEPEND} ${E_DEPEND}"
1437 RDEPEND="${RDEPEND} ${E_RDEPEND}"
1438 PDEPEND="${PDEPEND} ${E_PDEPEND}"
1439 REQUIRED_USE="${REQUIRED_USE} ${E_REQUIRED_USE}"
1441 unset ECLASS E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND \
1442 __INHERITED_QA_CACHE
1444 # alphabetically ordered by $EBUILD_PHASE value
1447 _valid_phases="src_compile pkg_config pkg_info src_install
1448 pkg_nofetch pkg_postinst pkg_postrm pkg_preinst pkg_prerm
1449 pkg_setup src_test src_unpack"
1452 _valid_phases="src_compile pkg_config src_configure pkg_info
1453 src_install pkg_nofetch pkg_postinst pkg_postrm pkg_preinst
1454 src_prepare pkg_prerm pkg_setup src_test src_unpack"
1457 _valid_phases="src_compile pkg_config src_configure pkg_info
1458 src_install pkg_nofetch pkg_postinst pkg_postrm pkg_preinst
1459 src_prepare pkg_prerm pkg_pretend pkg_setup src_test src_unpack"
1464 for _f in $_valid_phases ; do
1465 if declare -F $_f >/dev/null ; then
1467 DEFINED_PHASES+=" ${_f#src_}"
1470 [[ -n $DEFINED_PHASES ]] || DEFINED_PHASES=-
1472 unset _f _valid_phases
1474 if [[ $EBUILD_PHASE != depend ]] ; then
1478 _ebuild_helpers_path="$PORTAGE_BIN_PATH/ebuild-helpers"
1481 _ebuild_helpers_path="$PORTAGE_BIN_PATH/ebuild-helpers/4:$PORTAGE_BIN_PATH/ebuild-helpers"
1485 PATH=$_ebuild_helpers_path:$PREROOTPATH${PREROOTPATH:+:}/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin${ROOTPATH:+:}$ROOTPATH
1486 unset _ebuild_helpers_path
1488 # Use default ABI libdir in accordance with bug #355283.
1489 x=LIBDIR_${DEFAULT_ABI}
1490 [[ -n $DEFAULT_ABI && -n ${!x} ]] && x=${!x} || x=lib
1492 if has distcc $FEATURES ; then
1493 PATH="/usr/$x/distcc/bin:$PATH"
1494 [[ -n $DISTCC_LOG ]] && addwrite "${DISTCC_LOG%/*}"
1497 if has ccache $FEATURES ; then
1498 PATH="/usr/$x/ccache/bin:$PATH"
1500 if [[ -n $CCACHE_DIR ]] ; then
1501 addread "$CCACHE_DIR"
1502 addwrite "$CCACHE_DIR"
1505 [[ -n $CCACHE_SIZE ]] && ccache -M $CCACHE_SIZE &> /dev/null
1510 if [[ -n $QA_PREBUILT ]] ; then
1512 # these ones support fnmatch patterns
1513 QA_EXECSTACK+=" $QA_PREBUILT"
1514 QA_TEXTRELS+=" $QA_PREBUILT"
1515 QA_WX_LOAD+=" $QA_PREBUILT"
1517 # these ones support regular expressions, so translate
1518 # fnmatch patterns to regular expressions
1519 for x in QA_DT_HASH QA_DT_NEEDED QA_PRESTRIPPED QA_SONAME ; do
1520 if [[ $(declare -p $x 2>/dev/null) = declare\ -a* ]] ; then
1521 eval "$x=(\"\${$x[@]}\" ${QA_PREBUILT//\*/.*})"
1523 eval "$x+=\" ${QA_PREBUILT//\*/.*}\""
1530 # This needs to be exported since prepstrip is a separate shell script.
1531 [[ -n $QA_PRESTRIPPED ]] && export QA_PRESTRIPPED
1532 eval "[[ -n \$QA_PRESTRIPPED_${ARCH/-/_} ]] && \
1533 export QA_PRESTRIPPED_${ARCH/-/_}"
1538 # unset USE_EXPAND variables that contain only the special "*" token
1539 for x in ${USE_EXPAND} ; do
1540 [ "${!x}" == "*" ] && unset ${x}
1544 if has nostrip ${FEATURES} ${RESTRICT} || has strip ${RESTRICT}
1549 #a reasonable default for $S
1550 [[ -z ${S} ]] && export S=${WORKDIR}/${P}
1552 # Note: readonly variables interfere with preprocess_ebuild_env(), so
1553 # declare them only after it has already run.
1554 if [ "${EBUILD_PHASE}" != "depend" ] ; then
1555 declare -r $PORTAGE_READONLY_METADATA $PORTAGE_READONLY_VARS
1560 declare -r ED EPREFIX EROOT
1567 # Subshell/helper die support (must export for the die helper).
1568 # Since this function is typically executed in a subshell,
1569 # setup EBUILD_MASTER_PID to refer to the current $BASHPID,
1570 # which seems to give the best results when further
1571 # nested subshells call die.
1572 export EBUILD_MASTER_PID=$BASHPID
1573 trap 'exit 1' SIGTERM
1575 if [[ $EBUILD_PHASE != depend ]] ; then
1576 # Force configure scripts that automatically detect ccache to
1577 # respect FEATURES="-ccache".
1578 has ccache $FEATURES || export CCACHE_DISABLE=1
1580 local phase_func=$(_ebuild_arg_to_phase "$EAPI" "$EBUILD_PHASE")
1581 [[ -n $phase_func ]] && _ebuild_phase_funcs "$EAPI" "$phase_func"
1587 case ${EBUILD_SH_ARGS} in
1589 ebuild_phase_with_hooks pkg_nofetch
1591 prerm|postrm|postinst|config|info)
1592 if has "$EBUILD_SH_ARGS" config info && \
1593 ! declare -F "pkg_$EBUILD_SH_ARGS" >/dev/null ; then
1594 ewarn "pkg_${EBUILD_SH_ARGS}() is not defined: '${EBUILD##*/}'"
1596 export SANDBOX_ON="0"
1597 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
1598 ebuild_phase_with_hooks pkg_${EBUILD_SH_ARGS}
1601 ebuild_phase_with_hooks pkg_${EBUILD_SH_ARGS}
1604 if [[ $EBUILD_PHASE == postinst ]] && [[ -n $PORTAGE_UPDATE_ENV ]]; then
1605 # Update environment.bz2 in case installation phases
1606 # need to pass some variables to uninstallation phases.
1607 save_ebuild_env --exclude-init-phases | \
1608 filter_readonly_variables --filter-path \
1609 --filter-sandbox --allow-extra-vars \
1610 | ${PORTAGE_BZIP2_COMMAND} -c -f9 > "$PORTAGE_UPDATE_ENV"
1611 assert "save_ebuild_env failed"
1614 unpack|prepare|configure|compile|test|clean|install)
1615 if [[ ${SANDBOX_DISABLED:-0} = 0 ]] ; then
1616 export SANDBOX_ON="1"
1618 export SANDBOX_ON="0"
1621 case "$EBUILD_SH_ARGS" in
1625 for x in ASFLAGS CCACHE_DIR CCACHE_SIZE \
1626 CFLAGS CXXFLAGS LDFLAGS LIBCFLAGS LIBCXXFLAGS ; do
1627 [[ ${!x+set} = set ]] && export $x
1631 has distcc $FEATURES && [[ -n $DISTCC_DIR ]] && \
1632 [[ ${SANDBOX_WRITE/$DISTCC_DIR} = $SANDBOX_WRITE ]] && \
1633 addwrite "$DISTCC_DIR"
1636 [ -z "$PKG_CONFIG_PATH" -a -n "$ABI" -a -n "${!x}" ] && \
1637 export PKG_CONFIG_PATH=/usr/${!x}/pkgconfig
1639 if has noauto $FEATURES && \
1640 [[ ! -f $PORTAGE_BUILDDIR/.unpacked ]] ; then
1642 echo "!!! We apparently haven't unpacked..." \
1643 "This is probably not what you"
1644 echo "!!! want to be doing... You are using" \
1645 "FEATURES=noauto so I'll assume"
1646 echo "!!! that you know what you are doing..." \
1647 "You have 5 seconds to abort..."
1651 for x in 1 2 3 4 5 6 7 8; do
1658 cd "$PORTAGE_BUILDDIR"
1659 if [ ! -d build-info ] ; then
1661 cp "$EBUILD" "build-info/$PF.ebuild"
1664 #our custom version of libtool uses $S and $D to fix
1665 #invalid paths in .la files
1671 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
1672 dyn_${EBUILD_SH_ARGS}
1675 dyn_${EBUILD_SH_ARGS}
1678 export SANDBOX_ON="0"
1680 help|pretend|setup|preinst)
1681 #pkg_setup needs to be out of the sandbox for tmp file creation;
1682 #for example, awking and piping a file in /tmp requires a temp file to be created
1683 #in /etc. If pkg_setup is in the sandbox, both our lilo and apache ebuilds break.
1684 export SANDBOX_ON="0"
1685 if [ "${PORTAGE_DEBUG}" != "1" ] || [ "${-/x/}" != "$-" ]; then
1686 dyn_${EBUILD_SH_ARGS}
1689 dyn_${EBUILD_SH_ARGS}
1694 export SANDBOX_ON="0"
1697 if [ -n "${dbkey}" ] ; then
1698 if [ ! -d "${dbkey%/*}" ]; then
1699 install -d -g ${PORTAGE_GID} -m2775 "${dbkey%/*}"
1701 # Make it group writable. 666&~002==664
1705 auxdbkeys="DEPEND RDEPEND SLOT SRC_URI RESTRICT HOMEPAGE LICENSE
1706 DESCRIPTION KEYWORDS INHERITED IUSE REQUIRED_USE PDEPEND PROVIDE EAPI
1707 PROPERTIES DEFINED_PHASES UNUSED_05 UNUSED_04
1708 UNUSED_03 UNUSED_02 UNUSED_01"
1710 #the extra $(echo) commands remove newlines
1711 [ -n "${EAPI}" ] || EAPI=0
1713 if [ -n "${dbkey}" ] ; then
1715 for f in ${auxdbkeys} ; do
1716 echo $(echo ${!f}) >> "${dbkey}" || exit $?
1719 for f in ${auxdbkeys} ; do
1720 echo $(echo ${!f}) 1>&9 || exit $?
1729 export SANDBOX_ON="1"
1730 echo "Unrecognized EBUILD_SH_ARGS: '${EBUILD_SH_ARGS}'"
1738 if [[ -s $SANDBOX_LOG ]] ; then
1739 # We use SANDBOX_LOG to check for sandbox violations,
1740 # so we ensure that there can't be a stale log to
1741 # interfere with our logic.
1743 if [[ -n SANDBOX_ON ]] ; then
1748 rm -f "$SANDBOX_LOG" || \
1749 die "failed to remove stale sandbox log: '$SANDBOX_LOG'"
1751 if [[ -n $x ]] ; then
1752 export SANDBOX_ON=$x
1757 if [[ $EBUILD_PHASE = depend ]] ; then
1759 elif [[ -n $EBUILD_SH_ARGS ]] ; then
1761 # Don't allow subprocesses to inherit the pipe which
1762 # emerge uses to monitor ebuild.sh.
1767 # Save the env only for relevant phases.
1768 if ! has "$EBUILD_SH_ARGS" clean help info nofetch ; then
1770 save_ebuild_env | filter_readonly_variables \
1771 --filter-features > "$T/environment"
1772 assert "save_ebuild_env failed"
1773 chown portage:portage "$T/environment" &>/dev/null
1774 chmod g+w "$T/environment" &>/dev/null
1776 [[ -n $PORTAGE_EBUILD_EXIT_FILE ]] && > "$PORTAGE_EBUILD_EXIT_FILE"
1777 if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
1778 [[ ! -s $SANDBOX_LOG ]]
1779 "$PORTAGE_BIN_PATH"/ebuild-ipc exit $?
1786 # Do not exit when ebuild.sh is sourced by other scripts.