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