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