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