Add experimental EAPI 5-hdepend support.
[portage.git] / bin / ebuild.sh
1 #!/bin/bash
2 # Copyright 1999-2012 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                 __strip_duplicate_slashes \
27                 use_with use_enable ; do
28                 eval "${x}() {
29                         if has \"\${EAPI:-0}\" 4-python 5-progress; 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 usex ; do
37                 eval "${x}() {
38                         if has \"\${EAPI:-0}\" 4-python 5-progress; 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 # Ensure that $PWD is sane whenever possible, to protect against
140 # exploitation of insecure search path for python -c in ebuilds.
141 # See bug #239560.
142 if ! has "$EBUILD_PHASE" clean cleanrm depend help ; then
143         cd "$PORTAGE_BUILDDIR" || \
144                 die "PORTAGE_BUILDDIR does not exist: '$PORTAGE_BUILDDIR'"
145 fi
146
147 #if no perms are specified, dirs/files will have decent defaults
148 #(not secretive, but not stupid)
149 umask 022
150
151 # debug-print() gets called from many places with verbose status information useful
152 # for tracking down problems. The output is in $T/eclass-debug.log.
153 # You can set ECLASS_DEBUG_OUTPUT to redirect the output somewhere else as well.
154 # The special "on" setting echoes the information, mixing it with the rest of the
155 # emerge output.
156 # You can override the setting by exporting a new one from the console, or you can
157 # set a new default in make.*. Here the default is "" or unset.
158
159 # in the future might use e* from /etc/init.d/functions.sh if i feel like it
160 debug-print() {
161         # if $T isn't defined, we're in dep calculation mode and
162         # shouldn't do anything
163         [[ $EBUILD_PHASE = depend || ! -d ${T} || ${#} -eq 0 ]] && return 0
164
165         if [[ ${ECLASS_DEBUG_OUTPUT} == on ]]; then
166                 printf 'debug: %s\n' "${@}" >&2
167         elif [[ -n ${ECLASS_DEBUG_OUTPUT} ]]; then
168                 printf 'debug: %s\n' "${@}" >> "${ECLASS_DEBUG_OUTPUT}"
169         fi
170
171         if [[ -w $T ]] ; then
172                 # default target
173                 printf '%s\n' "${@}" >> "${T}/eclass-debug.log"
174                 # let the portage user own/write to this file
175                 chgrp portage "${T}/eclass-debug.log" &>/dev/null
176                 chmod g+w "${T}/eclass-debug.log" &>/dev/null
177         fi
178 }
179
180 # The following 2 functions are debug-print() wrappers
181
182 debug-print-function() {
183         debug-print "${1}: entering function, parameters: ${*:2}"
184 }
185
186 debug-print-section() {
187         debug-print "now in section ${*}"
188 }
189
190 # Sources all eclasses in parameters
191 declare -ix ECLASS_DEPTH=0
192 inherit() {
193         ECLASS_DEPTH=$(($ECLASS_DEPTH + 1))
194         if [[ ${ECLASS_DEPTH} > 1 ]]; then
195                 debug-print "*** Multiple Inheritence (Level: ${ECLASS_DEPTH})"
196         fi
197
198         if [[ -n $ECLASS && -n ${!__export_funcs_var} ]] ; then
199                 echo "QA Notice: EXPORT_FUNCTIONS is called before inherit in" \
200                         "$ECLASS.eclass. For compatibility with <=portage-2.1.6.7," \
201                         "only call EXPORT_FUNCTIONS after inherit(s)." \
202                         | fmt -w 75 | while read -r ; do eqawarn "$REPLY" ; done
203         fi
204
205         local location
206         local olocation
207         local x
208
209         # These variables must be restored before returning.
210         local PECLASS=$ECLASS
211         local prev_export_funcs_var=$__export_funcs_var
212
213         local B_IUSE
214         local B_REQUIRED_USE
215         local B_DEPEND
216         local B_RDEPEND
217         local B_PDEPEND
218         local B_HDEPEND
219         while [ "$1" ]; do
220                 location="${ECLASSDIR}/${1}.eclass"
221                 olocation=""
222
223                 export ECLASS="$1"
224                 __export_funcs_var=__export_functions_$ECLASS_DEPTH
225                 unset $__export_funcs_var
226
227                 if [ "${EBUILD_PHASE}" != "depend" ] && \
228                         [ "${EBUILD_PHASE}" != "nofetch" ] && \
229                         [[ ${EBUILD_PHASE} != *rm ]] && \
230                         [[ ${EMERGE_FROM} != "binary" ]] ; then
231                         # This is disabled in the *rm phases because they frequently give
232                         # false alarms due to INHERITED in /var/db/pkg being outdated
233                         # in comparison the the eclasses from the portage tree. It's
234                         # disabled for nofetch, since that can be called by repoman and
235                         # that triggers bug #407449 due to repoman not exporting
236                         # non-essential variables such as INHERITED.
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 values of *DEPEND to B_*DEPEND
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 B_HDEPEND
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                 [ "${HDEPEND+set}"    = set ] && B_HDEPEND="${HDEPEND}"
275                 unset IUSE REQUIRED_USE DEPEND RDEPEND PDEPEND HDEPEND
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                 [ "${HDEPEND+set}"      = set ] && E_HDEPEND+="${E_HDEPEND:+ }${HDEPEND}"
292
293                 [ "${B_IUSE+set}"     = set ] && IUSE="${B_IUSE}"
294                 [ "${B_IUSE+set}"     = set ] || unset IUSE
295                 
296                 [ "${B_REQUIRED_USE+set}"     = set ] && REQUIRED_USE="${B_REQUIRED_USE}"
297                 [ "${B_REQUIRED_USE+set}"     = set ] || unset REQUIRED_USE
298
299                 [ "${B_DEPEND+set}"   = set ] && DEPEND="${B_DEPEND}"
300                 [ "${B_DEPEND+set}"   = set ] || unset DEPEND
301
302                 [ "${B_RDEPEND+set}"  = set ] && RDEPEND="${B_RDEPEND}"
303                 [ "${B_RDEPEND+set}"  = set ] || unset RDEPEND
304
305                 [ "${B_PDEPEND+set}"  = set ] && PDEPEND="${B_PDEPEND}"
306                 [ "${B_PDEPEND+set}"  = set ] || unset PDEPEND
307
308                 [ "${B_HDEPEND+set}"  = set ] && HDEPEND="${B_HDEPEND}"
309                 [ "${B_HDEPEND+set}"  = set ] || unset HDEPEND
310
311                 #turn on glob expansion
312                 set +f
313
314                 if [[ -n ${!__export_funcs_var} ]] ; then
315                         for x in ${!__export_funcs_var} ; do
316                                 debug-print "EXPORT_FUNCTIONS: $x -> ${ECLASS}_$x"
317                                 declare -F "${ECLASS}_$x" >/dev/null || \
318                                         die "EXPORT_FUNCTIONS: ${ECLASS}_$x is not defined"
319                                 eval "$x() { ${ECLASS}_$x \"\$@\" ; }" > /dev/null
320                         done
321                 fi
322                 unset $__export_funcs_var
323
324                 has $1 $INHERITED || export INHERITED="$INHERITED $1"
325
326                 shift
327         done
328         ((--ECLASS_DEPTH)) # Returns 1 when ECLASS_DEPTH reaches 0.
329         if (( ECLASS_DEPTH > 0 )) ; then
330                 export ECLASS=$PECLASS
331                 __export_funcs_var=$prev_export_funcs_var
332         else
333                 unset ECLASS __export_funcs_var
334         fi
335         return 0
336 }
337
338 # Exports stub functions that call the eclass's functions, thereby making them default.
339 # For example, if ECLASS="base" and you call "EXPORT_FUNCTIONS src_unpack", the following
340 # code will be eval'd:
341 # src_unpack() { base_src_unpack; }
342 EXPORT_FUNCTIONS() {
343         if [ -z "$ECLASS" ]; then
344                 die "EXPORT_FUNCTIONS without a defined ECLASS"
345         fi
346         eval $__export_funcs_var+=\" $*\"
347 }
348
349 PORTAGE_BASHRCS_SOURCED=0
350
351 # @FUNCTION: __source_all_bashrcs
352 # @DESCRIPTION:
353 # Source a relevant bashrc files and perform other miscellaneous
354 # environment initialization when appropriate.
355 #
356 # If EAPI is set then define functions provided by the current EAPI:
357 #
358 #  * default_* aliases for the current EAPI phase functions
359 #  * A "default" function which is an alias for the default phase
360 #    function for the current phase.
361 #
362 __source_all_bashrcs() {
363         [[ $PORTAGE_BASHRCS_SOURCED = 1 ]] && return 0
364         PORTAGE_BASHRCS_SOURCED=1
365         local x
366
367         local OCC="${CC}" OCXX="${CXX}"
368
369         if [[ $EBUILD_PHASE != depend ]] ; then
370                 # source the existing profile.bashrcs.
371                 save_IFS
372                 IFS=$'\n'
373                 local path_array=($PROFILE_PATHS)
374                 restore_IFS
375                 for x in "${path_array[@]}" ; do
376                         [ -f "$x/profile.bashrc" ] && __qa_source "$x/profile.bashrc"
377                 done
378         fi
379
380         if [ -r "${PORTAGE_BASHRC}" ] ; then
381                 if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then
382                         source "${PORTAGE_BASHRC}"
383                 else
384                         set -x
385                         source "${PORTAGE_BASHRC}"
386                         set +x
387                 fi
388         fi
389
390         if [[ $EBUILD_PHASE != depend ]] ; then
391                 # The user's bashrc is the ONLY non-portage bit of code that can
392                 # change shopts without a QA violation.
393                 for x in "${PM_EBUILD_HOOK_DIR}"/${CATEGORY}/{${PN},${PN}:${SLOT},${P},${PF}}; do
394                         if [ -r "${x}" ]; then
395                                 # If $- contains x, then tracing has already been enabled
396                                 # elsewhere for some reason. We preserve it's state so as
397                                 # not to interfere.
398                                 if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then
399                                         source "${x}"
400                                 else
401                                         set -x
402                                         source "${x}"
403                                         set +x
404                                 fi
405                         fi
406                 done
407         fi
408
409         [ ! -z "${OCC}" ] && export CC="${OCC}"
410         [ ! -z "${OCXX}" ] && export CXX="${OCXX}"
411 }
412
413 # === === === === === === === === === === === === === === === === === ===
414 # === === === === === functions end, main part begins === === === === ===
415 # === === === === === === === === === === === === === === === === === ===
416
417 export SANDBOX_ON="1"
418 export S=${WORKDIR}/${P}
419
420 # Turn of extended glob matching so that g++ doesn't get incorrectly matched.
421 shopt -u extglob
422
423 if [[ ${EBUILD_PHASE} == depend ]] ; then
424         QA_INTERCEPTORS="awk bash cc egrep equery fgrep g++
425                 gawk gcc grep javac java-config nawk perl
426                 pkg-config python python-config sed"
427 elif [[ ${EBUILD_PHASE} == clean* ]] ; then
428         unset QA_INTERCEPTORS
429 else
430         QA_INTERCEPTORS="autoconf automake aclocal libtoolize"
431 fi
432 # level the QA interceptors if we're in depend
433 if [[ -n ${QA_INTERCEPTORS} ]] ; then
434         for BIN in ${QA_INTERCEPTORS}; do
435                 BIN_PATH=$(type -Pf ${BIN})
436                 if [ "$?" != "0" ]; then
437                         BODY="echo \"*** missing command: ${BIN}\" >&2; return 127"
438                 else
439                         BODY="${BIN_PATH} \"\$@\"; return \$?"
440                 fi
441                 if [[ ${EBUILD_PHASE} == depend ]] ; then
442                         FUNC_SRC="${BIN}() {
443                                 if [ \$ECLASS_DEPTH -gt 0 ]; then
444                                         eqawarn \"QA Notice: '${BIN}' called in global scope: eclass \${ECLASS}\"
445                                 else
446                                         eqawarn \"QA Notice: '${BIN}' called in global scope: \${CATEGORY}/\${PF}\"
447                                 fi
448                         ${BODY}
449                         }"
450                 elif has ${BIN} autoconf automake aclocal libtoolize ; then
451                         FUNC_SRC="${BIN}() {
452                                 if ! has \${FUNCNAME[1]} eautoreconf eaclocal _elibtoolize \\
453                                         eautoheader eautoconf eautomake autotools_run_tool \\
454                                         autotools_check_macro autotools_get_subdirs \\
455                                         autotools_get_auxdir ; then
456                                         eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
457                                         eqawarn \"Use autotools.eclass instead of calling '${BIN}' directly.\"
458                                 fi
459                         ${BODY}
460                         }"
461                 else
462                         FUNC_SRC="${BIN}() {
463                                 eqawarn \"QA Notice: '${BIN}' called by \${FUNCNAME[1]}: \${CATEGORY}/\${PF}\"
464                         ${BODY}
465                         }"
466                 fi
467                 eval "$FUNC_SRC" || echo "error creating QA interceptor ${BIN}" >&2
468         done
469         unset BIN_PATH BIN BODY FUNC_SRC
470 fi
471
472 # Subshell/helper die support (must export for the die helper).
473 export EBUILD_MASTER_PID=$BASHPID
474 trap 'exit 1' SIGTERM
475
476 if ! has "$EBUILD_PHASE" clean cleanrm depend && \
477         [ -f "${T}"/environment ] ; then
478         # The environment may have been extracted from environment.bz2 or
479         # may have come from another version of ebuild.sh or something.
480         # In any case, preprocess it to prevent any potential interference.
481         # NOTE: export ${FOO}=... requires quoting, unlike normal exports
482         __preprocess_ebuild_env || \
483                 die "error processing environment"
484         # Colon separated SANDBOX_* variables need to be cumulative.
485         for x in SANDBOX_DENY SANDBOX_READ SANDBOX_PREDICT SANDBOX_WRITE ; do
486                 export PORTAGE_${x}="${!x}"
487         done
488         PORTAGE_SANDBOX_ON=${SANDBOX_ON}
489         export SANDBOX_ON=1
490         source "${T}"/environment || \
491                 die "error sourcing environment"
492         # We have to temporarily disable sandbox since the
493         # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded
494         # may be unusable (triggering in spurious sandbox violations)
495         # until we've merged them with our current values.
496         export SANDBOX_ON=0
497         for x in SANDBOX_DENY SANDBOX_PREDICT SANDBOX_READ SANDBOX_WRITE ; do
498                 y="PORTAGE_${x}"
499                 if [ -z "${!x}" ] ; then
500                         export ${x}="${!y}"
501                 elif [ -n "${!y}" ] && [ "${!y}" != "${!x}" ] ; then
502                         # filter out dupes
503                         export ${x}="$(printf "${!y}:${!x}" | tr ":" "\0" | \
504                                 sort -z -u | tr "\0" ":")"
505                 fi
506                 export ${x}="${!x%:}"
507                 unset PORTAGE_${x}
508         done
509         unset x y
510         export SANDBOX_ON=${PORTAGE_SANDBOX_ON}
511         unset PORTAGE_SANDBOX_ON
512         [[ -n $EAPI ]] || EAPI=0
513 fi
514
515 if has "${EAPI:-0}" 4-python 5-progress; then
516         shopt -s globstar
517 fi
518
519 if ! has "$EBUILD_PHASE" clean cleanrm ; then
520         if [[ $EBUILD_PHASE = depend || ! -f $T/environment || \
521                 -f $PORTAGE_BUILDDIR/.ebuild_changed ]] || \
522                 has noauto $FEATURES ; then
523                 # The bashrcs get an opportunity here to set aliases that will be expanded
524                 # during sourcing of ebuilds and eclasses.
525                 __source_all_bashrcs
526
527                 # When EBUILD_PHASE != depend, INHERITED comes pre-initialized
528                 # from cache. In order to make INHERITED content independent of
529                 # EBUILD_PHASE during inherit() calls, we unset INHERITED after
530                 # we make a backup copy for QA checks.
531                 __INHERITED_QA_CACHE=$INHERITED
532
533                 # *DEPEND and IUSE will be set during the sourcing of the ebuild.
534                 # In order to ensure correct interaction between ebuilds and
535                 # eclasses, they need to be unset before this process of
536                 # interaction begins.
537                 unset EAPI DEPEND RDEPEND PDEPEND HDEPEND INHERITED IUSE REQUIRED_USE \
538                         ECLASS E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND \
539                         E_HDEPEND
540
541                 if [[ $PORTAGE_DEBUG != 1 || ${-/x/} != $- ]] ; then
542                         source "$EBUILD" || die "error sourcing ebuild"
543                 else
544                         set -x
545                         source "$EBUILD" || die "error sourcing ebuild"
546                         set +x
547                 fi
548
549                 if [[ "${EBUILD_PHASE}" != "depend" ]] ; then
550                         RESTRICT=${PORTAGE_RESTRICT}
551                         [[ -e $PORTAGE_BUILDDIR/.ebuild_changed ]] && \
552                         rm "$PORTAGE_BUILDDIR/.ebuild_changed"
553                 fi
554
555                 [ "${EAPI+set}" = set ] || EAPI=0
556
557                 # export EAPI for helpers (especially since we unset it above)
558                 export EAPI
559
560                 if has "$EAPI" 0 1 2 3 ; then
561                         export RDEPEND=${RDEPEND-${DEPEND}}
562                         debug-print "RDEPEND: not set... Setting to: ${DEPEND}"
563                 fi
564
565                 # add in dependency info from eclasses
566                 IUSE+="${IUSE:+ }${E_IUSE}"
567                 DEPEND+="${DEPEND:+ }${E_DEPEND}"
568                 RDEPEND+="${RDEPEND:+ }${E_RDEPEND}"
569                 PDEPEND+="${PDEPEND:+ }${E_PDEPEND}"
570                 HDEPEND+="${HDEPEND:+ }${E_HDEPEND}"
571                 REQUIRED_USE+="${REQUIRED_USE:+ }${E_REQUIRED_USE}"
572                 
573                 unset ECLASS E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND E_HDEPEND \
574                         __INHERITED_QA_CACHE
575
576                 # alphabetically ordered by $EBUILD_PHASE value
577                 case ${EAPI} in
578                         0|1)
579                                 _valid_phases="src_compile pkg_config pkg_info src_install
580                                         pkg_nofetch pkg_postinst pkg_postrm pkg_preinst pkg_prerm
581                                         pkg_setup src_test src_unpack"
582                                 ;;
583                         2|3)
584                                 _valid_phases="src_compile pkg_config src_configure pkg_info
585                                         src_install pkg_nofetch pkg_postinst pkg_postrm pkg_preinst
586                                         src_prepare pkg_prerm pkg_setup src_test src_unpack"
587                                 ;;
588                         *)
589                                 _valid_phases="src_compile pkg_config src_configure pkg_info
590                                         src_install pkg_nofetch pkg_postinst pkg_postrm pkg_preinst
591                                         src_prepare pkg_prerm pkg_pretend pkg_setup src_test src_unpack"
592                                 ;;
593                 esac
594
595                 DEFINED_PHASES=
596                 for _f in $_valid_phases ; do
597                         if declare -F $_f >/dev/null ; then
598                                 _f=${_f#pkg_}
599                                 DEFINED_PHASES+=" ${_f#src_}"
600                         fi
601                 done
602                 [[ -n $DEFINED_PHASES ]] || DEFINED_PHASES=-
603
604                 unset _f _valid_phases
605
606                 if [[ $EBUILD_PHASE != depend ]] ; then
607
608                         if has distcc $FEATURES ; then
609                                 [[ -n $DISTCC_LOG ]] && addwrite "${DISTCC_LOG%/*}"
610                         fi
611
612                         if has ccache $FEATURES ; then
613
614                                 if [[ -n $CCACHE_DIR ]] ; then
615                                         addread "$CCACHE_DIR"
616                                         addwrite "$CCACHE_DIR"
617                                 fi
618
619                                 [[ -n $CCACHE_SIZE ]] && ccache -M $CCACHE_SIZE &> /dev/null
620                         fi
621
622                         if [[ -n $QA_PREBUILT ]] ; then
623
624                                 # these ones support fnmatch patterns
625                                 QA_EXECSTACK+=" $QA_PREBUILT"
626                                 QA_TEXTRELS+=" $QA_PREBUILT"
627                                 QA_WX_LOAD+=" $QA_PREBUILT"
628
629                                 # these ones support regular expressions, so translate
630                                 # fnmatch patterns to regular expressions
631                                 for x in QA_DT_NEEDED QA_FLAGS_IGNORED QA_PRESTRIPPED QA_SONAME ; do
632                                         if [[ $(declare -p $x 2>/dev/null) = declare\ -a* ]] ; then
633                                                 eval "$x=(\"\${$x[@]}\" ${QA_PREBUILT//\*/.*})"
634                                         else
635                                                 eval "$x+=\" ${QA_PREBUILT//\*/.*}\""
636                                         fi
637                                 done
638
639                                 unset x
640                         fi
641
642                         # This needs to be exported since prepstrip is a separate shell script.
643                         [[ -n $QA_PRESTRIPPED ]] && export QA_PRESTRIPPED
644                         eval "[[ -n \$QA_PRESTRIPPED_${ARCH/-/_} ]] && \
645                                 export QA_PRESTRIPPED_${ARCH/-/_}"
646                 fi
647         fi
648 fi
649
650 # unset USE_EXPAND variables that contain only the special "*" token
651 for x in ${USE_EXPAND} ; do
652         [ "${!x}" == "*" ] && unset ${x}
653 done
654 unset x
655
656 if has nostrip ${FEATURES} ${RESTRICT} || has strip ${RESTRICT}
657 then
658         export DEBUGBUILD=1
659 fi
660
661 if [[ $EBUILD_PHASE = depend ]] ; then
662         export SANDBOX_ON="0"
663         set -f
664
665         if [ -n "${dbkey}" ] ; then
666                 if [ ! -d "${dbkey%/*}" ]; then
667                         install -d -g ${PORTAGE_GID} -m2775 "${dbkey%/*}"
668                 fi
669                 # Make it group writable. 666&~002==664
670                 umask 002
671         fi
672
673         auxdbkeys="DEPEND RDEPEND SLOT SRC_URI RESTRICT HOMEPAGE LICENSE
674                 DESCRIPTION KEYWORDS INHERITED IUSE REQUIRED_USE PDEPEND PROVIDE EAPI
675                 PROPERTIES DEFINED_PHASES HDEPEND UNUSED_04
676                 UNUSED_03 UNUSED_02 UNUSED_01"
677
678         case ${EAPI} in
679                 5-hdepend)
680                         ;;
681                 *)
682                         unset HDEPEND
683                         ;;
684         esac
685
686         # The extra $(echo) commands remove newlines.
687         if [ -n "${dbkey}" ] ; then
688                 > "${dbkey}"
689                 for f in ${auxdbkeys} ; do
690                         echo $(echo ${!f}) >> "${dbkey}" || exit $?
691                 done
692         else
693                 for f in ${auxdbkeys} ; do
694                         echo $(echo ${!f}) 1>&9 || exit $?
695                 done
696                 exec 9>&-
697         fi
698         set +f
699 else
700         # Note: readonly variables interfere with __preprocess_ebuild_env(), so
701         # declare them only after it has already run.
702         declare -r $PORTAGE_READONLY_METADATA $PORTAGE_READONLY_VARS
703         case ${EAPI} in
704                 0|1|2)
705                         [[ " ${FEATURES} " == *" force-prefix "* ]] && \
706                                 declare -r ED EPREFIX EROOT
707                         ;;
708                 *)
709                         declare -r ED EPREFIX EROOT
710                         ;;
711         esac
712
713         if [[ -n $EBUILD_SH_ARGS ]] ; then
714                 (
715                         # Don't allow subprocesses to inherit the pipe which
716                         # emerge uses to monitor ebuild.sh.
717                         exec 9>&-
718                         __ebuild_main ${EBUILD_SH_ARGS}
719                         exit 0
720                 )
721                 exit $?
722         fi
723 fi
724
725 # Do not exit when ebuild.sh is sourced by other scripts.
726 true