Remove _SANDBOX_COMPAT_LEVEL.
[portage.git] / bin / ebuild.sh
1 #!/bin/bash
2 # Copyright 1999-2011 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 PORTAGE_BIN_PATH="${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"
6 PORTAGE_PYM_PATH="${PORTAGE_PYM_PATH:-/usr/lib/portage/pym}"
7
8 # Prevent aliases from causing portage to act inappropriately.
9 # Make sure it's before everything so we don't mess aliases that follow.
10 unalias -a
11
12 source "${PORTAGE_BIN_PATH}/isolated-functions.sh" || exit 1
13
14 if [[ $EBUILD_PHASE != depend ]] ; then
15         source "${PORTAGE_BIN_PATH}/phase-functions.sh" || die
16         source "${PORTAGE_BIN_PATH}/save-ebuild-env.sh" || die
17         source "${PORTAGE_BIN_PATH}/phase-helpers.sh" || die
18         source "${PORTAGE_BIN_PATH}/bashrc-functions.sh" || die
19 else
20         # These dummy functions are for things that are likely to be called
21         # in global scope, even though they are completely useless during
22         # the "depend" phase.
23         for x in diropts docompress exeopts get_KV insopts \
24                 keepdir KV_major KV_micro KV_minor KV_to_int \
25                 libopts register_die_hook register_success_hook \
26                 remove_path_entry set_unless_changed strip_duplicate_slashes \
27                 unset_unless_changed use_with use_enable ; do
28                 eval "${x}() { : ; }"
29         done
30         # These dummy functions return false, in order to ensure that
31         # `use multislot` is false for the "depend" phase.
32         for x in use useq usev ; do
33                 eval "${x}() { return 1; }"
34         done
35         # These functions die because calls to them during the "depend" phase
36         # are considered to be severe QA violations.
37         for x in best_version has_version portageq ; do
38                 eval "${x}() { die \"\${FUNCNAME} calls are not allowed in global scope\"; }"
39         done
40         unset x
41 fi
42
43 # Don't use sandbox's BASH_ENV for new shells because it does
44 # 'source /etc/profile' which can interfere with the build
45 # environment by modifying our PATH.
46 unset BASH_ENV
47
48 # This is just a temporary workaround for portage-9999 users since
49 # earlier portage versions do not detect a version change in this case
50 # (9999 to 9999) and therefore they try execute an incompatible version of
51 # ebuild.sh during the upgrade.
52 export PORTAGE_BZIP2_COMMAND=${PORTAGE_BZIP2_COMMAND:-bzip2} 
53
54 # These two functions wrap sourcing and calling respectively.  At present they
55 # perform a qa check to make sure eclasses and ebuilds and profiles don't mess
56 # with shell opts (shopts).  Ebuilds/eclasses changing shopts should reset them 
57 # when they are done.
58
59 qa_source() {
60         local shopts=$(shopt) OLDIFS="$IFS"
61         local retval
62         source "$@"
63         retval=$?
64         set +e
65         [[ $shopts != $(shopt) ]] &&
66                 eqawarn "QA Notice: Global shell options changed and were not restored while sourcing '$*'"
67         [[ "$IFS" != "$OLDIFS" ]] &&
68                 eqawarn "QA Notice: Global IFS changed and was not restored while sourcing '$*'"
69         return $retval
70 }
71
72 qa_call() {
73         local shopts=$(shopt) OLDIFS="$IFS"
74         local retval
75         "$@"
76         retval=$?
77         set +e
78         [[ $shopts != $(shopt) ]] &&
79                 eqawarn "QA Notice: Global shell options changed and were not restored while calling '$*'"
80         [[ "$IFS" != "$OLDIFS" ]] &&
81                 eqawarn "QA Notice: Global IFS changed and was not restored while calling '$*'"
82         return $retval
83 }
84
85 EBUILD_SH_ARGS="$*"
86
87 shift $#
88
89 # Unset some variables that break things.
90 unset GZIP BZIP BZIP2 CDPATH GREP_OPTIONS GREP_COLOR GLOBIGNORE
91
92 [[ $PORTAGE_QUIET != "" ]] && export PORTAGE_QUIET
93
94 # sandbox support functions; defined prior to profile.bashrc srcing, since the profile might need to add a default exception (/usr/lib64/conftest fex)
95 _sb_append_var() {
96         local _v=$1 ; shift
97         local var="SANDBOX_${_v}"
98         [[ -z $1 || -n $2 ]] && die "Usage: add$(echo ${_v} | \
99                 LC_ALL=C tr [:upper:] [:lower:]) <colon-delimited list of paths>"
100         export ${var}="${!var:+${!var}:}$1"
101 }
102 # bash-4 version:
103 # local var="SANDBOX_${1^^}"
104 # addread() { _sb_append_var ${0#add} "$@" ; }
105 addread()    { _sb_append_var READ    "$@" ; }
106 addwrite()   { _sb_append_var WRITE   "$@" ; }
107 adddeny()    { _sb_append_var DENY    "$@" ; }
108 addpredict() { _sb_append_var PREDICT "$@" ; }
109
110 addwrite "${PORTAGE_TMPDIR}"
111 addread "/:${PORTAGE_TMPDIR}"
112 [[ -n ${PORTAGE_GPG_DIR} ]] && addpredict "${PORTAGE_GPG_DIR}"
113
114 # Avoid sandbox violations in temporary directories.
115 if [[ -w $T ]] ; then
116         export TEMP=$T
117         export TMP=$T
118         export TMPDIR=$T
119 elif [[ $SANDBOX_ON = 1 ]] ; then
120         for x in TEMP TMP TMPDIR ; do
121                 [[ -n ${!x} ]] && addwrite "${!x}"
122         done
123         unset x
124 fi
125
126 # the sandbox is disabled by default except when overridden in the relevant stages
127 export SANDBOX_ON=0
128
129 esyslog() {
130         # Custom version of esyslog() to take care of the "Red Star" bug.
131         # MUST follow functions.sh to override the "" parameter problem.
132         return 0
133 }
134
135 # Ensure that $PWD is sane whenever possible, to protect against
136 # exploitation of insecure search path for python -c in ebuilds.
137 # See bug #239560.
138 if ! has "$EBUILD_PHASE" clean cleanrm depend help ; then
139         cd "$PORTAGE_BUILDDIR" || \
140                 die "PORTAGE_BUILDDIR does not exist: '$PORTAGE_BUILDDIR'"
141 fi
142
143 #if no perms are specified, dirs/files will have decent defaults
144 #(not secretive, but not stupid)
145 umask 022
146
147 # debug-print() gets called from many places with verbose status information useful
148 # for tracking down problems. The output is in $T/eclass-debug.log.
149 # You can set ECLASS_DEBUG_OUTPUT to redirect the output somewhere else as well.
150 # The special "on" setting echoes the information, mixing it with the rest of the
151 # emerge output.
152 # You can override the setting by exporting a new one from the console, or you can
153 # set a new default in make.*. Here the default is "" or unset.
154
155 # in the future might use e* from /etc/init.d/functions.sh if i feel like it
156 debug-print() {
157         # if $T isn't defined, we're in dep calculation mode and
158         # shouldn't do anything
159         [[ $EBUILD_PHASE = depend || ! -d ${T} || ${#} -eq 0 ]] && return 0
160
161         if [[ ${ECLASS_DEBUG_OUTPUT} == on ]]; then
162                 printf 'debug: %s\n' "${@}" >&2
163         elif [[ -n ${ECLASS_DEBUG_OUTPUT} ]]; then
164                 printf 'debug: %s\n' "${@}" >> "${ECLASS_DEBUG_OUTPUT}"
165         fi
166
167         if [[ -w $T ]] ; then
168                 # default target
169                 printf '%s\n' "${@}" >> "${T}/eclass-debug.log"
170                 # let the portage user own/write to this file
171                 chgrp portage "${T}/eclass-debug.log" &>/dev/null
172                 chmod g+w "${T}/eclass-debug.log" &>/dev/null
173         fi
174 }
175
176 # The following 2 functions are debug-print() wrappers
177
178 debug-print-function() {
179         debug-print "${1}: entering function, parameters: ${*:2}"
180 }
181
182 debug-print-section() {
183         debug-print "now in section ${*}"
184 }
185
186 # Sources all eclasses in parameters
187 declare -ix ECLASS_DEPTH=0
188 inherit() {
189         ECLASS_DEPTH=$(($ECLASS_DEPTH + 1))
190         if [[ ${ECLASS_DEPTH} > 1 ]]; then
191                 debug-print "*** Multiple Inheritence (Level: ${ECLASS_DEPTH})"
192         fi
193
194         if [[ -n $ECLASS && -n ${!__export_funcs_var} ]] ; then
195                 echo "QA Notice: EXPORT_FUNCTIONS is called before inherit in" \
196                         "$ECLASS.eclass. For compatibility with <=portage-2.1.6.7," \
197                         "only call EXPORT_FUNCTIONS after inherit(s)." \
198                         | fmt -w 75 | while read -r ; do eqawarn "$REPLY" ; done
199         fi
200
201         local location
202         local olocation
203         local x
204
205         # These variables must be restored before returning.
206         local PECLASS=$ECLASS
207         local prev_export_funcs_var=$__export_funcs_var
208
209         local B_IUSE
210         local B_REQUIRED_USE
211         local B_DEPEND
212         local B_RDEPEND
213         local B_PDEPEND
214         while [ "$1" ]; do
215                 location="${ECLASSDIR}/${1}.eclass"
216                 olocation=""
217
218                 export ECLASS="$1"
219                 __export_funcs_var=__export_functions_$ECLASS_DEPTH
220                 unset $__export_funcs_var
221
222                 if [ "${EBUILD_PHASE}" != "depend" ] && \
223                         [[ ${EBUILD_PHASE} != *rm ]] && \
224                         [[ ${EMERGE_FROM} != "binary" ]] ; then
225                         # This is disabled in the *rm phases because they frequently give
226                         # false alarms due to INHERITED in /var/db/pkg being outdated
227                         # in comparison the the eclasses from the portage tree.
228                         if ! has $ECLASS $INHERITED $__INHERITED_QA_CACHE ; then
229                                 eqawarn "QA Notice: ECLASS '$ECLASS' inherited illegally in $CATEGORY/$PF $EBUILD_PHASE"
230                         fi
231                 fi
232
233                 # any future resolution code goes here
234                 if [ -n "$PORTDIR_OVERLAY" ]; then
235                         local overlay
236                         for overlay in ${PORTDIR_OVERLAY}; do
237                                 olocation="${overlay}/eclass/${1}.eclass"
238                                 if [ -e "$olocation" ]; then
239                                         location="${olocation}"
240                                         debug-print "  eclass exists: ${location}"
241                                 fi
242                         done
243                 fi
244                 debug-print "inherit: $1 -> $location"
245                 [ ! -e "$location" ] && die "${1}.eclass could not be found by inherit()"
246
247                 if [ "${location}" == "${olocation}" ] && \
248                         ! has "${location}" ${EBUILD_OVERLAY_ECLASSES} ; then
249                                 EBUILD_OVERLAY_ECLASSES="${EBUILD_OVERLAY_ECLASSES} ${location}"
250                 fi
251
252                 #We need to back up the value of DEPEND and RDEPEND to B_DEPEND and B_RDEPEND
253                 #(if set).. and then restore them after the inherit call.
254
255                 #turn off glob expansion
256                 set -f
257
258                 # Retain the old data and restore it later.
259                 unset B_IUSE B_REQUIRED_USE B_DEPEND B_RDEPEND B_PDEPEND
260                 [ "${IUSE+set}"       = set ] && B_IUSE="${IUSE}"
261                 [ "${REQUIRED_USE+set}" = set ] && B_REQUIRED_USE="${REQUIRED_USE}"
262                 [ "${DEPEND+set}"     = set ] && B_DEPEND="${DEPEND}"
263                 [ "${RDEPEND+set}"    = set ] && B_RDEPEND="${RDEPEND}"
264                 [ "${PDEPEND+set}"    = set ] && B_PDEPEND="${PDEPEND}"
265                 unset IUSE REQUIRED_USE DEPEND RDEPEND PDEPEND
266                 #turn on glob expansion
267                 set +f
268
269                 qa_source "$location" || die "died sourcing $location in inherit()"
270                 
271                 #turn off glob expansion
272                 set -f
273
274                 # If each var has a value, append it to the global variable E_* to
275                 # be applied after everything is finished. New incremental behavior.
276                 [ "${IUSE+set}"         = set ] && E_IUSE+="${E_IUSE:+ }${IUSE}"
277                 [ "${REQUIRED_USE+set}" = set ] && E_REQUIRED_USE+="${E_REQUIRED_USE:+ }${REQUIRED_USE}"
278                 [ "${DEPEND+set}"       = set ] && E_DEPEND+="${E_DEPEND:+ }${DEPEND}"
279                 [ "${RDEPEND+set}"      = set ] && E_RDEPEND+="${E_RDEPEND:+ }${RDEPEND}"
280                 [ "${PDEPEND+set}"      = set ] && E_PDEPEND+="${E_PDEPEND:+ }${PDEPEND}"
281
282                 [ "${B_IUSE+set}"     = set ] && IUSE="${B_IUSE}"
283                 [ "${B_IUSE+set}"     = set ] || unset IUSE
284                 
285                 [ "${B_REQUIRED_USE+set}"     = set ] && REQUIRED_USE="${B_REQUIRED_USE}"
286                 [ "${B_REQUIRED_USE+set}"     = set ] || unset REQUIRED_USE
287
288                 [ "${B_DEPEND+set}"   = set ] && DEPEND="${B_DEPEND}"
289                 [ "${B_DEPEND+set}"   = set ] || unset DEPEND
290
291                 [ "${B_RDEPEND+set}"  = set ] && RDEPEND="${B_RDEPEND}"
292                 [ "${B_RDEPEND+set}"  = set ] || unset RDEPEND
293
294                 [ "${B_PDEPEND+set}"  = set ] && PDEPEND="${B_PDEPEND}"
295                 [ "${B_PDEPEND+set}"  = set ] || unset PDEPEND
296
297                 #turn on glob expansion
298                 set +f
299
300                 if [[ -n ${!__export_funcs_var} ]] ; then
301                         for x in ${!__export_funcs_var} ; do
302                                 debug-print "EXPORT_FUNCTIONS: $x -> ${ECLASS}_$x"
303                                 declare -F "${ECLASS}_$x" >/dev/null || \
304                                         die "EXPORT_FUNCTIONS: ${ECLASS}_$x is not defined"
305                                 eval "$x() { ${ECLASS}_$x \"\$@\" ; }" > /dev/null
306                         done
307                 fi
308                 unset $__export_funcs_var
309
310                 has $1 $INHERITED || export INHERITED="$INHERITED $1"
311
312                 shift
313         done
314         ((--ECLASS_DEPTH)) # Returns 1 when ECLASS_DEPTH reaches 0.
315         if (( ECLASS_DEPTH > 0 )) ; then
316                 export ECLASS=$PECLASS
317                 __export_funcs_var=$prev_export_funcs_var
318         else
319                 unset ECLASS __export_funcs_var
320         fi
321         return 0
322 }
323
324 # Exports stub functions that call the eclass's functions, thereby making them default.
325 # For example, if ECLASS="base" and you call "EXPORT_FUNCTIONS src_unpack", the following
326 # code will be eval'd:
327 # src_unpack() { base_src_unpack; }
328 EXPORT_FUNCTIONS() {
329         if [ -z "$ECLASS" ]; then
330                 die "EXPORT_FUNCTIONS without a defined ECLASS"
331         fi
332         eval $__export_funcs_var+=\" $*\"
333 }
334
335 PORTAGE_BASHRCS_SOURCED=0
336
337 # @FUNCTION: source_all_bashrcs
338 # @DESCRIPTION:
339 # Source a relevant bashrc files and perform other miscellaneous
340 # environment initialization when appropriate.
341 #
342 # If EAPI is set then define functions provided by the current EAPI:
343 #
344 #  * default_* aliases for the current EAPI phase functions
345 #  * A "default" function which is an alias for the default phase
346 #    function for the current phase.
347 #
348 source_all_bashrcs() {
349         [[ $PORTAGE_BASHRCS_SOURCED = 1 ]] && return 0
350         PORTAGE_BASHRCS_SOURCED=1
351         local x
352
353         local OCC="${CC}" OCXX="${CXX}"
354
355         if [[ $EBUILD_PHASE != depend ]] ; then
356                 # source the existing profile.bashrcs.
357                 save_IFS
358                 IFS=$'\n'
359                 local path_array=($PROFILE_PATHS)
360                 restore_IFS
361                 for x in "${path_array[@]}" ; do
362                         [ -f "$x/profile.bashrc" ] && qa_source "$x/profile.bashrc"
363                 done
364         fi
365
366         # We assume if people are changing shopts in their bashrc they do so at their
367         # own peril.  This is the ONLY non-portage bit of code that can change shopts
368         # without a QA violation.
369         for x in "${PORTAGE_BASHRC}" "${PM_EBUILD_HOOK_DIR}"/${CATEGORY}/{${PN},${PN}:${SLOT},${P},${PF}}; do
370                 if [ -r "${x}" ]; then
371                         # If $- contains x, then tracing has already enabled elsewhere for some
372                         # reason.  We preserve it's state so as not to interfere.
373                         if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then
374                                 source "${x}"
375                         else
376                                 set -x
377                                 source "${x}"
378                                 set +x
379                         fi
380                 fi
381         done
382
383         [ ! -z "${OCC}" ] && export CC="${OCC}"
384         [ ! -z "${OCXX}" ] && export CXX="${OCXX}"
385 }
386
387 # === === === === === === === === === === === === === === === === === ===
388 # === === === === === functions end, main part begins === === === === ===
389 # === === === === === === === === === === === === === === === === === ===
390
391 export SANDBOX_ON="1"
392 export S=${WORKDIR}/${P}
393
394 # Turn of extended glob matching so that g++ doesn't get incorrectly matched.
395 shopt -u extglob
396
397 if [[ ${EBUILD_PHASE} == depend ]] ; then
398         QA_INTERCEPTORS="awk bash cc egrep equery fgrep g++
399                 gawk gcc grep javac java-config nawk perl
400                 pkg-config python python-config sed"
401 elif [[ ${EBUILD_PHASE} == clean* ]] ; then
402         unset QA_INTERCEPTORS
403 else
404         QA_INTERCEPTORS="autoconf automake aclocal libtoolize"
405 fi
406 # level the QA interceptors if we're in depend
407 if [[ -n ${QA_INTERCEPTORS} ]] ; then
408         for BIN in ${QA_INTERCEPTORS}; do
409                 BIN_PATH=$(type -Pf ${BIN})
410                 if [ "$?" != "0" ]; then
411                         BODY="echo \"*** missing command: ${BIN}\" >&2; return 127"
412                 else
413                         BODY="${BIN_PATH} \"\$@\"; return \$?"
414                 fi
415                 if [[ ${EBUILD_PHASE} == depend ]] ; then
416                         FUNC_SRC="${BIN}() {
417                                 if [ \$ECLASS_DEPTH -gt 0 ]; then
418                                         eqawarn \"QA Notice: '${BIN}' called in global scope: eclass \${ECLASS}\"
419                                 else
420                                         eqawarn \"QA Notice: '${BIN}' called in global scope: \${CATEGORY}/\${PF}\"
421                                 fi
422                         ${BODY}
423                         }"
424                 elif has ${BIN} autoconf automake aclocal libtoolize ; then
425                         FUNC_SRC="${BIN}() {
426                                 if ! has \${FUNCNAME[1]} eautoreconf eaclocal _elibtoolize \\
427                                         eautoheader eautoconf eautomake autotools_run_tool \\
428                                         autotools_check_macro autotools_get_subdirs \\
429                                         autotools_get_auxdir ; then
430                                         eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
431                                         eqawarn \"Use autotools.eclass instead of calling '${BIN}' directly.\"
432                                 fi
433                         ${BODY}
434                         }"
435                 else
436                         FUNC_SRC="${BIN}() {
437                                 eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
438                         ${BODY}
439                         }"
440                 fi
441                 eval "$FUNC_SRC" || echo "error creating QA interceptor ${BIN}" >&2
442         done
443         unset BIN_PATH BIN BODY FUNC_SRC
444 fi
445
446 # Subshell/helper die support (must export for the die helper).
447 export EBUILD_MASTER_PID=$BASHPID
448 trap 'exit 1' SIGTERM
449
450 if ! has "$EBUILD_PHASE" clean cleanrm depend && \
451         [ -f "${T}"/environment ] ; then
452         # The environment may have been extracted from environment.bz2 or
453         # may have come from another version of ebuild.sh or something.
454         # In any case, preprocess it to prevent any potential interference.
455         # NOTE: export ${FOO}=... requires quoting, unlike normal exports
456         preprocess_ebuild_env || \
457                 die "error processing environment"
458         # Colon separated SANDBOX_* variables need to be cumulative.
459         for x in SANDBOX_DENY SANDBOX_READ SANDBOX_PREDICT SANDBOX_WRITE ; do
460                 export PORTAGE_${x}="${!x}"
461         done
462         PORTAGE_SANDBOX_ON=${SANDBOX_ON}
463         export SANDBOX_ON=1
464         source "${T}"/environment || \
465                 die "error sourcing environment"
466         # We have to temporarily disable sandbox since the
467         # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
468         # may be unusable (triggering in spurious sandbox violations)
469         # until we've merged them with our current values.
470         export SANDBOX_ON=0
471         for x in SANDBOX_DENY SANDBOX_PREDICT SANDBOX_READ SANDBOX_WRITE ; do
472                 y="PORTAGE_${x}"
473                 if [ -z "${!x}" ] ; then
474                         export ${x}="${!y}"
475                 elif [ -n "${!y}" ] && [ "${!y}" != "${!x}" ] ; then
476                         # filter out dupes
477                         export ${x}="$(printf "${!y}:${!x}" | tr ":" "\0" | \
478                                 sort -z -u | tr "\0" ":")"
479                 fi
480                 export ${x}="${!x%:}"
481                 unset PORTAGE_${x}
482         done
483         unset x y
484         export SANDBOX_ON=${PORTAGE_SANDBOX_ON}
485         unset PORTAGE_SANDBOX_ON
486         [[ -n $EAPI ]] || EAPI=0
487 fi
488
489 if ! has "$EBUILD_PHASE" clean cleanrm ; then
490         if [[ $EBUILD_PHASE = depend || ! -f $T/environment || \
491                 -f $PORTAGE_BUILDDIR/.ebuild_changed ]] || \
492                 has noauto $FEATURES ; then
493                 # The bashrcs get an opportunity here to set aliases that will be expanded
494                 # during sourcing of ebuilds and eclasses.
495                 source_all_bashrcs
496
497                 # When EBUILD_PHASE != depend, INHERITED comes pre-initialized
498                 # from cache. In order to make INHERITED content independent of
499                 # EBUILD_PHASE during inherit() calls, we unset INHERITED after
500                 # we make a backup copy for QA checks.
501                 __INHERITED_QA_CACHE=$INHERITED
502
503                 # *DEPEND and IUSE will be set during the sourcing of the ebuild.
504                 # In order to ensure correct interaction between ebuilds and
505                 # eclasses, they need to be unset before this process of
506                 # interaction begins.
507                 unset DEPEND RDEPEND PDEPEND INHERITED IUSE REQUIRED_USE \
508                         ECLASS E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND
509
510                 if [[ $PORTAGE_DEBUG != 1 || ${-/x/} != $- ]] ; then
511                         source "$EBUILD" || die "error sourcing ebuild"
512                 else
513                         set -x
514                         source "$EBUILD" || die "error sourcing ebuild"
515                         set +x
516                 fi
517
518                 if [[ "${EBUILD_PHASE}" != "depend" ]] ; then
519                         RESTRICT=${PORTAGE_RESTRICT}
520                         [[ -e $PORTAGE_BUILDDIR/.ebuild_changed ]] && \
521                         rm "$PORTAGE_BUILDDIR/.ebuild_changed"
522                 fi
523
524                 [[ -n $EAPI ]] || EAPI=0
525
526                 if has "$EAPI" 0 1 2 3 3_pre2 ; then
527                         export RDEPEND=${RDEPEND-${DEPEND}}
528                         debug-print "RDEPEND: not set... Setting to: ${DEPEND}"
529                 fi
530
531                 # add in dependency info from eclasses
532                 IUSE+="${IUSE:+ }${E_IUSE}"
533                 DEPEND+="${DEPEND:+ }${E_DEPEND}"
534                 RDEPEND+="${RDEPEND:+ }${E_RDEPEND}"
535                 PDEPEND+="${PDEPEND:+ }${E_PDEPEND}"
536                 REQUIRED_USE+="${REQUIRED_USE:+ }${E_REQUIRED_USE}"
537                 
538                 unset ECLASS E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND \
539                         __INHERITED_QA_CACHE
540
541                 # alphabetically ordered by $EBUILD_PHASE value
542                 case "$EAPI" in
543                         0|1)
544                                 _valid_phases="src_compile pkg_config pkg_info src_install
545                                         pkg_nofetch pkg_postinst pkg_postrm pkg_preinst pkg_prerm
546                                         pkg_setup src_test src_unpack"
547                                 ;;
548                         2|3|3_pre2)
549                                 _valid_phases="src_compile pkg_config src_configure pkg_info
550                                         src_install pkg_nofetch pkg_postinst pkg_postrm pkg_preinst
551                                         src_prepare pkg_prerm pkg_setup src_test src_unpack"
552                                 ;;
553                         *)
554                                 _valid_phases="src_compile pkg_config src_configure pkg_info
555                                         src_install pkg_nofetch pkg_postinst pkg_postrm pkg_preinst
556                                         src_prepare pkg_prerm pkg_pretend pkg_setup src_test src_unpack"
557                                 ;;
558                 esac
559
560                 DEFINED_PHASES=
561                 for _f in $_valid_phases ; do
562                         if declare -F $_f >/dev/null ; then
563                                 _f=${_f#pkg_}
564                                 DEFINED_PHASES+=" ${_f#src_}"
565                         fi
566                 done
567                 [[ -n $DEFINED_PHASES ]] || DEFINED_PHASES=-
568
569                 unset _f _valid_phases
570
571                 if [[ $EBUILD_PHASE != depend ]] ; then
572
573                         if has distcc $FEATURES ; then
574                                 [[ -n $DISTCC_LOG ]] && addwrite "${DISTCC_LOG%/*}"
575                         fi
576
577                         if has ccache $FEATURES ; then
578
579                                 if [[ -n $CCACHE_DIR ]] ; then
580                                         addread "$CCACHE_DIR"
581                                         addwrite "$CCACHE_DIR"
582                                 fi
583
584                                 [[ -n $CCACHE_SIZE ]] && ccache -M $CCACHE_SIZE &> /dev/null
585                         fi
586
587                         if [[ -n $QA_PREBUILT ]] ; then
588
589                                 # these ones support fnmatch patterns
590                                 QA_EXECSTACK+=" $QA_PREBUILT"
591                                 QA_TEXTRELS+=" $QA_PREBUILT"
592                                 QA_WX_LOAD+=" $QA_PREBUILT"
593
594                                 # these ones support regular expressions, so translate
595                                 # fnmatch patterns to regular expressions
596                                 for x in QA_DT_HASH QA_DT_NEEDED QA_PRESTRIPPED QA_SONAME ; do
597                                         if [[ $(declare -p $x 2>/dev/null) = declare\ -a* ]] ; then
598                                                 eval "$x=(\"\${$x[@]}\" ${QA_PREBUILT//\*/.*})"
599                                         else
600                                                 eval "$x+=\" ${QA_PREBUILT//\*/.*}\""
601                                         fi
602                                 done
603
604                                 unset x
605                         fi
606
607                         # This needs to be exported since prepstrip is a separate shell script.
608                         [[ -n $QA_PRESTRIPPED ]] && export QA_PRESTRIPPED
609                         eval "[[ -n \$QA_PRESTRIPPED_${ARCH/-/_} ]] && \
610                                 export QA_PRESTRIPPED_${ARCH/-/_}"
611                 fi
612         fi
613 fi
614
615 # unset USE_EXPAND variables that contain only the special "*" token
616 for x in ${USE_EXPAND} ; do
617         [ "${!x}" == "*" ] && unset ${x}
618 done
619 unset x
620
621 if has nostrip ${FEATURES} ${RESTRICT} || has strip ${RESTRICT}
622 then
623         export DEBUGBUILD=1
624 fi
625
626 if [[ $EBUILD_PHASE = depend ]] ; then
627         export SANDBOX_ON="0"
628         set -f
629
630         if [ -n "${dbkey}" ] ; then
631                 if [ ! -d "${dbkey%/*}" ]; then
632                         install -d -g ${PORTAGE_GID} -m2775 "${dbkey%/*}"
633                 fi
634                 # Make it group writable. 666&~002==664
635                 umask 002
636         fi
637
638         auxdbkeys="DEPEND RDEPEND SLOT SRC_URI RESTRICT HOMEPAGE LICENSE
639                 DESCRIPTION KEYWORDS INHERITED IUSE REQUIRED_USE PDEPEND PROVIDE EAPI
640                 PROPERTIES DEFINED_PHASES UNUSED_05 UNUSED_04
641                 UNUSED_03 UNUSED_02 UNUSED_01"
642
643         #the extra $(echo) commands remove newlines
644         [ -n "${EAPI}" ] || EAPI=0
645
646         if [ -n "${dbkey}" ] ; then
647                 > "${dbkey}"
648                 for f in ${auxdbkeys} ; do
649                         echo $(echo ${!f}) >> "${dbkey}" || exit $?
650                 done
651         else
652                 for f in ${auxdbkeys} ; do
653                         echo $(echo ${!f}) 1>&9 || exit $?
654                 done
655                 exec 9>&-
656         fi
657         set +f
658 else
659         # Note: readonly variables interfere with preprocess_ebuild_env(), so
660         # declare them only after it has already run.
661         declare -r $PORTAGE_READONLY_METADATA $PORTAGE_READONLY_VARS
662         case "$EAPI" in
663                 0|1|2)
664                         [[ " ${FEATURES} " == *" force-prefix "* ]] && \
665                                 declare -r ED EPREFIX EROOT
666                         ;;
667                 *)
668                         declare -r ED EPREFIX EROOT
669                         ;;
670         esac
671
672         if [[ -n $EBUILD_SH_ARGS ]] ; then
673                 (
674                         # Don't allow subprocesses to inherit the pipe which
675                         # emerge uses to monitor ebuild.sh.
676                         exec 9>&-
677                         ebuild_main ${EBUILD_SH_ARGS}
678                         exit 0
679                 )
680                 exit $?
681         fi
682 fi
683
684 # Do not exit when ebuild.sh is sourced by other scripts.
685 true