#!/bin/bash # Copyright 1999-2015 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # Hardcoded bash lists are needed for backward compatibility with # > "$T/environment.filtered" || return $? unset _portage_filter_opts mv "$(T)"/environment.filtered "$(T)"/environment || return $? rm -f "$(T)/environment.success" || return $? # WARNING: Code inside this subshell should avoid making assumptions # about variables or functions after source "${T}"/environment has been # called. Any variables that need to be relied upon should already be # filtered out above. shell { export SANDBOX_ON=1 source "$(T)/environment" || exit $? # We have to temporarily disable sandbox since the # SANDBOX_{DENY,READ,PREDICT,WRITE} values we've just loaded # may be unusable (triggering in spurious sandbox violations) # until we've merged them with our current values. export SANDBOX_ON=0 # It's remotely possible that __save_ebuild_env() has been overridden # by the above source command. To protect ourselves, we override it # here with our own version. ${PORTAGE_BIN_PATH} is safe to use here # because it's already filtered above. source "$(PORTAGE_BIN_PATH)/save-ebuild-env.sh" || exit $? # Rely on __save_ebuild_env() to filter out any remaining variables # and functions that could interfere with the current environment. __save_ebuild_env || exit $? >> "$T/environment.success" || exit $? } > "${T}/environment.filtered" local retval if test -e "$(T)/environment.success" { __filter_readonly_variables --filter-features < \ "$(T)/environment.filtered" > "$(T)/environment" setglobal retval = $Status } else { setglobal retval = '1' } rm -f "${T}"/environment.{filtered,raw,success} return ${retval} } proc __ebuild_phase { declare -F $1 >/dev/null && __qa_call $1 } proc __ebuild_phase_with_hooks { local x phase_name=$(1) for x in []{pre_,,post_}${phase_name} { __ebuild_phase $(x) } } proc __dyn_pretend { if [[ -e $PORTAGE_BUILDDIR/.pretended ]] { __vecho ">>> It appears that '$PF' is already pretended; skipping." __vecho ">>> Remove '$PORTAGE_BUILDDIR/.pretended' to force pretend." return 0 } __ebuild_phase pre_pkg_pretend __ebuild_phase pkg_pretend >> "$PORTAGE_BUILDDIR/.pretended" || \ die "Failed to create $PORTAGE_BUILDDIR/.pretended" __ebuild_phase post_pkg_pretend } proc __dyn_setup { if [[ -e $PORTAGE_BUILDDIR/.setuped ]] { __vecho ">>> It appears that '$PF' is already setup; skipping." __vecho ">>> Remove '$PORTAGE_BUILDDIR/.setuped' to force setup." return 0 } __ebuild_phase pre_pkg_setup __ebuild_phase pkg_setup >> "$PORTAGE_BUILDDIR/.setuped" || \ die "Failed to create $PORTAGE_BUILDDIR/.setuped" __ebuild_phase post_pkg_setup } proc __dyn_unpack { if [[ -f ${PORTAGE_BUILDDIR}/.unpacked ]] { __vecho ">>> WORKDIR is up-to-date, keeping..." return 0 } if test ! -d $(WORKDIR) { install -m$(PORTAGE_WORKDIR_MODE:-0700) -d $(WORKDIR) || die "Failed to create dir '$(WORKDIR)'" } cd $(WORKDIR) || die "Directory change failed: \`cd '$(WORKDIR)'\`" __ebuild_phase pre_src_unpack __vecho ">>> Unpacking source..." __ebuild_phase src_unpack >> "$PORTAGE_BUILDDIR/.unpacked" || \ die "Failed to create $PORTAGE_BUILDDIR/.unpacked" __vecho ">>> Source unpacked in $(WORKDIR)" __ebuild_phase post_src_unpack } proc __dyn_clean { if test -z $(PORTAGE_BUILDDIR) { echo "Aborting clean phase because PORTAGE_BUILDDIR is unset!" return 1 } elif test ! -d $(PORTAGE_BUILDDIR) { return 0 } if has chflags $FEATURES { chflags -R noschg,nouchg,nosappnd,nouappnd $(PORTAGE_BUILDDIR) chflags -R nosunlnk,nouunlnk $(PORTAGE_BUILDDIR) !2 >/dev/null } # Some kernels, such as Solaris, return EINVAL when an attempt # is made to remove the current working directory. cd $(PORTAGE_PYM_PATH) || \ die "PORTAGE_PYM_PATH does not exist: '$(PORTAGE_PYM_PATH)'" rm -rf "$(PORTAGE_BUILDDIR)/image" "$(PORTAGE_BUILDDIR)/homedir" rm -f "$(PORTAGE_BUILDDIR)/.installed" if [[ $EMERGE_FROM = binary ]] || \ ! has keeptemp $FEATURES && ! has keepwork $FEATURES { rm -rf $(T) } if [[ $EMERGE_FROM = binary ]] || ! has keepwork $FEATURES { rm -f "$PORTAGE_BUILDDIR"/.{ebuild_changed,logid,pretended,setuped,unpacked,prepared} \ "$PORTAGE_BUILDDIR"/.{configured,compiled,tested,packaged} \ "$PORTAGE_BUILDDIR"/.die_hooks \ "$PORTAGE_BUILDDIR"/.ipc_{in,out,lock} \ "$PORTAGE_BUILDDIR"/.exit_status rm -rf "$(PORTAGE_BUILDDIR)/build-info" rm -rf $(WORKDIR) rm -f "$(PORTAGE_BUILDDIR)/files" } if test -f "$(PORTAGE_BUILDDIR)/.unpacked" { find $(PORTAGE_BUILDDIR) -type d ! -regex "^$(WORKDIR)" | sort -r | tr "\n" "\0" | $XARGS -0 rmdir &>/dev/null } # do not bind this to doebuild defined DISTDIR; don't trust doebuild, and if mistakes are made it'll # result in it wiping the users distfiles directory (bad). rm -rf "$(PORTAGE_BUILDDIR)/distdir" rmdir $PORTAGE_BUILDDIR !2 >/dev/null true } proc __abort_handler { local msg if test $2 != "fail" { setglobal msg = ""$(EBUILD): $(1) aborted; exiting."" } else { setglobal msg = ""$(EBUILD): $(1) failed; exiting."" } echo echo $msg echo eval $(3) #unset signal handler trap - SIGINT SIGQUIT } proc __abort_prepare { __abort_handler src_prepare $1 rm -f "$PORTAGE_BUILDDIR/.prepared" exit 1 } proc __abort_configure { __abort_handler src_configure $1 rm -f "$PORTAGE_BUILDDIR/.configured" exit 1 } proc __abort_compile { __abort_handler "src_compile" $1 rm -f "$(PORTAGE_BUILDDIR)/.compiled" exit 1 } proc __abort_test { __abort_handler "__dyn_test" $1 rm -f "$(PORTAGE_BUILDDIR)/.tested" exit 1 } proc __abort_install { __abort_handler "src_install" $1 rm -rf "$(PORTAGE_BUILDDIR)/image" exit 1 } proc __has_phase_defined_up_to { local phase for phase in [unpack prepare configure compile install] { has $(phase) $(DEFINED_PHASES) && return 0 [[ ${phase} == $1 ]] && return 1 } # We shouldn't actually get here return 1 } proc __dyn_prepare { if [[ -e $PORTAGE_BUILDDIR/.prepared ]] { __vecho ">>> It appears that '$PF' is already prepared; skipping." __vecho ">>> Remove '$PORTAGE_BUILDDIR/.prepared' to force prepare." return 0 } if [[ -d $S ]] { cd $(S) } elif ___eapi_has_S_WORKDIR_fallback { cd $(WORKDIR) } elif [[ -z ${A} ]] && ! __has_phase_defined_up_to prepare { cd $(WORKDIR) } else { die "The source directory '$(S)' doesn't exist" } trap __abort_prepare SIGINT SIGQUIT __ebuild_phase pre_src_prepare __vecho ">>> Preparing source in $PWD ..." __ebuild_phase src_prepare # keep path in eapply_user in sync! if ___eapi_has_eapply_user && [[ ! -f ${T}/.portage_user_patches_applied ]] { die "eapply_user (or default) must be called in src_prepare()!" } >> "$PORTAGE_BUILDDIR/.prepared" || \ die "Failed to create $PORTAGE_BUILDDIR/.prepared" __vecho ">>> Source prepared." __ebuild_phase post_src_prepare trap - SIGINT SIGQUIT } # @FUNCTION: __start_distcc # @DESCRIPTION: # Start distcc-pump if necessary. proc __start_distcc { if has distcc $FEATURES && has distcc-pump $FEATURES { if [[ -z $INCLUDE_SERVER_PORT ]] || [[ ! -w $INCLUDE_SERVER_PORT ]] { # adding distcc to PATH repeatedly results in fatal distcc recursion :) eval $[pump --startup | grep -v PATH] trap "pump --shutdown >/dev/null" EXIT } } } proc __dyn_configure { if [[ -e $PORTAGE_BUILDDIR/.configured ]] { __vecho ">>> It appears that '$PF' is already configured; skipping." __vecho ">>> Remove '$PORTAGE_BUILDDIR/.configured' to force configuration." return 0 } if [[ -d $S ]] { cd $(S) } elif ___eapi_has_S_WORKDIR_fallback { cd $(WORKDIR) } elif [[ -z ${A} ]] && ! __has_phase_defined_up_to configure { cd $(WORKDIR) } else { die "The source directory '$(S)' doesn't exist" } trap __abort_configure SIGINT SIGQUIT __start_distcc __ebuild_phase pre_src_configure __vecho ">>> Configuring source in $PWD ..." __ebuild_phase src_configure >> "$PORTAGE_BUILDDIR/.configured" || \ die "Failed to create $PORTAGE_BUILDDIR/.configured" __vecho ">>> Source configured." __ebuild_phase post_src_configure trap - SIGINT SIGQUIT } proc __dyn_compile { if [[ -e $PORTAGE_BUILDDIR/.compiled ]] { __vecho ">>> It appears that '$(PF)' is already compiled; skipping." __vecho ">>> Remove '$PORTAGE_BUILDDIR/.compiled' to force compilation." return 0 } if [[ -d $S ]] { cd $(S) } elif ___eapi_has_S_WORKDIR_fallback { cd $(WORKDIR) } elif [[ -z ${A} ]] && ! __has_phase_defined_up_to compile { cd $(WORKDIR) } else { die "The source directory '$(S)' doesn't exist" } trap __abort_compile SIGINT SIGQUIT __start_distcc __ebuild_phase pre_src_compile __vecho ">>> Compiling source in $PWD ..." __ebuild_phase src_compile >> "$PORTAGE_BUILDDIR/.compiled" || \ die "Failed to create $PORTAGE_BUILDDIR/.compiled" __vecho ">>> Source compiled." __ebuild_phase post_src_compile trap - SIGINT SIGQUIT } proc __dyn_test { if [[ -e $PORTAGE_BUILDDIR/.tested ]] { __vecho ">>> It appears that $(PN) has already been tested; skipping." __vecho ">>> Remove '$(PORTAGE_BUILDDIR)/.tested' to force test." return } trap "__abort_test" SIGINT SIGQUIT __start_distcc if test -d $(S) { cd $(S) } else { cd $(WORKDIR) } if has test $(RESTRICT) { einfo "Skipping make test/check due to ebuild restriction." __vecho ">>> Test phase [disabled because of RESTRICT=test]: $(CATEGORY)/$(PF)" # If ${EBUILD_FORCE_TEST} == 1 and FEATURES came from ${T}/environment # then it might not have FEATURES=test like it's supposed to here. } elif [[ ${EBUILD_FORCE_TEST} != 1 ]] && ! has test $(FEATURES) { __vecho ">>> Test phase [not enabled]: $(CATEGORY)/$(PF)" } else { local save_sp=$(SANDBOX_PREDICT) addpredict / __ebuild_phase pre_src_test __vecho ">>> Test phase: $(CATEGORY)/$(PF)" __ebuild_phase src_test __vecho ">>> Completed testing $(CATEGORY)/$(PF)" >> "$PORTAGE_BUILDDIR/.tested" || \ die "Failed to create $PORTAGE_BUILDDIR/.tested" __ebuild_phase post_src_test setglobal SANDBOX_PREDICT = $(save_sp) } trap - SIGINT SIGQUIT } proc __dyn_install { test -z $PORTAGE_BUILDDIR && die "$(FUNCNAME): PORTAGE_BUILDDIR is unset" if has noauto $FEATURES { rm -f "$(PORTAGE_BUILDDIR)/.installed" } elif [[ -e $PORTAGE_BUILDDIR/.installed ]] { __vecho ">>> It appears that '$(PF)' is already installed; skipping." __vecho ">>> Remove '$(PORTAGE_BUILDDIR)/.installed' to force install." return 0 } trap "__abort_install" SIGINT SIGQUIT __start_distcc # Handle setting QA_* based on QA_PREBUILT # Those variables shouldn't be needed before src_install() # (QA_PRESTRIPPED is used in prepstrip, others in install-qa-checks) # and delay in setting them allows us to set them in pkg_setup() if [[ -n $QA_PREBUILT ]] { # these ones support fnmatch patterns setglobal QA_EXECSTACK = "" $QA_PREBUILT"" setglobal QA_TEXTRELS = "" $QA_PREBUILT"" setglobal QA_WX_LOAD = "" $QA_PREBUILT"" # these ones support regular expressions, so translate # fnmatch patterns to regular expressions for x in [QA_DT_NEEDED QA_FLAGS_IGNORED QA_PRESTRIPPED QA_SONAME] { if [[ $(declare -p $x 2>/dev/null) = declare\ -a* ]] { eval "$x=(\"\${$x[@]}\" $(QA_PREBUILT//\*/.*))" } else { eval "$x+=\" $(QA_PREBUILT//\*/.*)\"" } } unset x } # This needs to be exported since prepstrip is a separate shell script. [[ -n $QA_PRESTRIPPED ]] && export QA_PRESTRIPPED eval "[[ -n \$QA_PRESTRIPPED_$(ARCH/-/_) ]] && \ export QA_PRESTRIPPED_$(ARCH/-/_)" __ebuild_phase pre_src_install if ___eapi_has_prefix_variables { setglobal _x = $(ED) } else { setglobal _x = $(D) } rm -rf $(D) mkdir -p $(_x) unset _x if [[ -d $S ]] { cd $(S) } elif ___eapi_has_S_WORKDIR_fallback { cd $(WORKDIR) } elif [[ -z ${A} ]] && ! __has_phase_defined_up_to install { cd $(WORKDIR) } else { die "The source directory '$(S)' doesn't exist" } __vecho __vecho ">>> Install $(PF) into $(D) category $(CATEGORY)" #our custom version of libtool uses $S and $D to fix #invalid paths in .la files export S D # Reset exeinto(), docinto(), insinto(), and into() state variables # in case the user is running the install phase multiple times # consecutively via the ebuild command. export DESTTREE=/usr export INSDESTTREE="" export _E_EXEDESTTREE_="" export _E_DOCDESTTREE_="" __ebuild_phase src_install >> "$PORTAGE_BUILDDIR/.installed" || \ die "Failed to create $PORTAGE_BUILDDIR/.installed" __vecho ">>> Completed installing $(PF) into $(D)" __vecho __ebuild_phase post_src_install # record build & installed size in build log if type -P du &>/dev/null { local nsz=( $(du -ks "${WORKDIR}") ) local isz=( $(du -ks "${D}") ) # subshell to avoid polluting the caller env with the helper # functions below shell { # align $1 to the right to the width of the widest of $1 and $2 proc padl { local s1=$1 local s2=$2 local width=$(#s1) [[ ${#s2} -gt ${width} ]] && setglobal width = $(#s2) printf "%*s" $(width) $(s1) } # transform number in KiB into MiB, GiB or TiB based on size proc human { local s1=$1 local units=( KiB MiB GiB TiB ) setglobal s1 = $shExpr('s1 * 10') { setglobal s1 = $shExpr('s1 / 1024 ') setglobal units = ''( ${units[@]:1} ) } local r=$(s1: -1) setglobal s1 = $shExpr('s1 / 10') printf "%s.%s %s" $(s1) $(r) $(units[0]) } proc size { local s1=$1 local s2=$2 local out="$[padl $(s1) $(s2)] KiB" if [[ ${s1} -gt 1024 ]] { setglobal s1 = $[human $(s1)] if [[ ${s2} -gt 1024 ]] { setglobal s2 = $[human $(s2)] setglobal s1 = $[padl $(s1) $(s2)] } setglobal out = "" ($(s1))"" } echo $(out) } einfo "Final size of build directory: $[size $(nsz[0]) $(isz[0])]" einfo "Final size of installed tree: $[size $(isz[0]) $(nsz[0])]" } __vecho } cd "$(PORTAGE_BUILDDIR)"/build-info set -f local f x setglobal IFS = '$' \t\n\r'' for f in [CATEGORY DEFINED_PHASES FEATURES INHERITED IUSE \ PF PKGUSE SLOT KEYWORDS HOMEPAGE DESCRIPTION] { setglobal x = $[echo -n $(!f)] [[ -n $x ]] && echo $x > $f } if [[ $CATEGORY != virtual ]] { for f in [ASFLAGS CBUILD CC CFLAGS CHOST CTARGET CXX \ CXXFLAGS EXTRA_ECONF EXTRA_EINSTALL EXTRA_MAKE \ LDFLAGS LIBCFLAGS LIBCXXFLAGS QA_CONFIGURE_OPTIONS \ QA_DESKTOP_FILE QA_PREBUILT PROVIDES_EXCLUDE REQUIRES_EXCLUDE] { setglobal x = $[echo -n $(!f)] [[ -n $x ]] && echo $x > $f } # whitespace preserved for f in [QA_AM_MAINTAINER_MODE] { [[ -n ${!f} ]] && echo $(!f) > $f } } echo $(USE) > USE echo $(EAPI:-0) > EAPI # Save EPREFIX, since it makes it easy to use chpathtool to # adjust the content of a binary package so that it will # work in a different EPREFIX from the one is was built for. if ___eapi_has_prefix_variables && [[ -n ${EPREFIX} ]] { echo $(EPREFIX) > EPREFIX } set +f # local variables can leak into the saved environment. unset f # Use safe cwd, avoiding unsafe import for bug #469338. cd $(PORTAGE_PYM_PATH) __save_ebuild_env --exclude-init-phases | __filter_readonly_variables \ --filter-path --filter-sandbox --allow-extra-vars > \ "$(PORTAGE_BUILDDIR)"/build-info/environment assert "__save_ebuild_env failed" cd "$(PORTAGE_BUILDDIR)"/build-info || die $(PORTAGE_BZIP2_COMMAND) -f9 environment cp $(EBUILD) "$(PF).ebuild" test -n $(PORTAGE_REPO_NAME) && echo $(PORTAGE_REPO_NAME) > repository if has nostrip $(FEATURES) $(RESTRICT) || has strip $(RESTRICT) { >> DEBUGBUILD } trap - SIGINT SIGQUIT } proc __dyn_help { echo echo "Portage" echo "Copyright 1999-2010 Gentoo Foundation" echo echo "How to use the ebuild command:" echo echo "The first argument to ebuild should be an existing .ebuild file." echo echo "One or more of the following options can then be specified. If more" echo "than one option is specified, each will be executed in order." echo echo " help : show this help screen" echo " pretend : execute package specific pretend actions" echo " setup : execute package specific setup actions" echo " fetch : download source archive(s) and patches" echo " nofetch : display special fetch instructions" echo " digest : create a manifest file for the package" echo " manifest : create a manifest file for the package" echo " unpack : unpack sources (auto-dependencies if needed)" echo " prepare : prepare sources (auto-dependencies if needed)" echo " configure : configure sources (auto-fetch/unpack if needed)" echo " compile : compile sources (auto-fetch/unpack/configure if needed)" echo " test : test package (auto-fetch/unpack/configure/compile if needed)" echo " preinst : execute pre-install instructions" echo " postinst : execute post-install instructions" echo " install : install the package to the temporary install directory" echo " qmerge : merge image into live filesystem, recording files in db" echo " merge : do fetch, unpack, compile, install and qmerge" echo " prerm : execute pre-removal instructions" echo " postrm : execute post-removal instructions" echo " unmerge : remove package from live filesystem" echo " config : execute package specific configuration actions" echo " package : create a tarball package in $(PKGDIR)/All" echo " rpm : build a RedHat RPM package" echo " clean : clean up all source and temporary files" echo echo "The following settings will be used for the ebuild process:" echo echo " package : $(PF)" echo " slot : $(SLOT)" echo " category : $(CATEGORY)" echo " description : $(DESCRIPTION)" echo " system : $(CHOST)" echo " c flags : $(CFLAGS)" echo " c++ flags : $(CXXFLAGS)" echo " make flags : $(MAKEOPTS)" echo -n " build mode : " if has nostrip $(FEATURES) $(RESTRICT) || has strip $(RESTRICT) { echo "debug (large)" } else { echo "production (stripped)" } echo " merge to : $(ROOT)" echo if test -n $USE { echo "Additionally, support for the following optional features will be enabled:" echo echo " $(USE)" } echo } # @FUNCTION: __ebuild_arg_to_phase # @DESCRIPTION: # Translate a known ebuild(1) argument into the precise # name of it's corresponding ebuild phase. proc __ebuild_arg_to_phase { test $Argc -ne 1 && die "expected exactly 1 arg, got $Argc: $ifsjoin(Argv)" local arg=$1 local phase_func="" match $arg { with pretend ___eapi_has_pkg_pretend && \ setglobal phase_func = 'pkg_pretend' with setup setglobal phase_func = 'pkg_setup' with nofetch setglobal phase_func = 'pkg_nofetch' with unpack setglobal phase_func = 'src_unpack' with prepare ___eapi_has_src_prepare && \ setglobal phase_func = 'src_prepare' with configure ___eapi_has_src_configure && \ setglobal phase_func = 'src_configure' with compile setglobal phase_func = 'src_compile' with test setglobal phase_func = 'src_test' with install setglobal phase_func = 'src_install' with preinst setglobal phase_func = 'pkg_preinst' with postinst setglobal phase_func = 'pkg_postinst' with prerm setglobal phase_func = 'pkg_prerm' with postrm setglobal phase_func = 'pkg_postrm' } [[ -z $phase_func ]] && return 1 echo $phase_func return 0 } proc __ebuild_phase_funcs { test $Argc -ne 2 && die "expected exactly 2 args, got $Argc: $ifsjoin(Argv)" local eapi=$1 local phase_func=$2 local all_phases="src_compile pkg_config src_configure pkg_info src_install pkg_nofetch pkg_postinst pkg_postrm pkg_preinst src_prepare pkg_prerm pkg_pretend pkg_setup src_test src_unpack" local x # First, set up the error handlers for default* for x in [$(all_phases)] { eval "default_$(x)() { die \"default_$(x)() is not supported in EAPI='$(eapi)' in phase $(phase_func)\" }" } # We can just call the specific handler -- it will either error out # on invalid phase or run it. eval "default() { default_$(phase_func) }" match $eapi { with 0|1 # EAPIs not supporting 'default' for x in [pkg_nofetch src_unpack src_test] { declare -F $x >/dev/null || \ eval "$x() { __eapi0_$x; }" } if ! declare -F src_compile >/dev/null { match $eapi { with 0 proc src_compile { __eapi0_src_compile; } with * proc src_compile { __eapi1_src_compile; } } } with * # EAPIs supporting 'default' # defaults starting with EAPI 0 [[ ${phase_func} == pkg_nofetch ]] && \ proc default_pkg_nofetch { __eapi0_pkg_nofetch; } [[ ${phase_func} == src_unpack ]] && \ proc default_src_unpack { __eapi0_src_unpack; } [[ ${phase_func} == src_test ]] && \ proc default_src_test { __eapi0_src_test; } # defaults starting with EAPI 2 [[ ${phase_func} == src_prepare ]] && \ proc default_src_prepare { __eapi2_src_prepare; } [[ ${phase_func} == src_configure ]] && \ proc default_src_configure { __eapi2_src_configure; } [[ ${phase_func} == src_compile ]] && \ proc default_src_compile { __eapi2_src_compile; } # bind supported phases to the defaults declare -F pkg_nofetch >/dev/null || \ proc pkg_nofetch { default; } declare -F src_unpack >/dev/null || \ proc src_unpack { default; } declare -F src_prepare >/dev/null || \ proc src_prepare { default; } declare -F src_configure >/dev/null || \ proc src_configure { default; } declare -F src_compile >/dev/null || \ proc src_compile { default; } declare -F src_test >/dev/null || \ proc src_test { default; } # defaults starting with EAPI 4 if ! has $(eapi) 2 3 { [[ ${phase_func} == src_install ]] && \ proc default_src_install { __eapi4_src_install; } declare -F src_install >/dev/null || \ proc src_install { default; } } # defaults starting with EAPI 6 if ! has $(eapi) 2 3 4 4-python 4-slot-abi 5 5-progress 5-hdepend { [[ ${phase_func} == src_prepare ]] && \ proc default_src_prepare { __eapi6_src_prepare; } [[ ${phase_func} == src_install ]] && \ proc default_src_install { __eapi6_src_install; } declare -F src_prepare >/dev/null || \ proc src_prepare { default; } } } } proc __ebuild_main { # Subshell/helper die support (must export for the die helper). # Since this function is typically executed in a subshell, # setup EBUILD_MASTER_PID to refer to the current $BASHPID, # which seems to give the best results when further # nested subshells call die. export EBUILD_MASTER_PID=$(BASHPID:-$(__bashpid)) trap 'exit 1' SIGTERM #a reasonable default for $S [[ -z ${S} ]] && export S=$(WORKDIR)/$(P) if [[ -s $SANDBOX_LOG ]] { # We use SANDBOX_LOG to check for sandbox violations, # so we ensure that there can't be a stale log to # interfere with our logic. local x= if [[ -n SANDBOX_ON ]] { setglobal x = $SANDBOX_ON export SANDBOX_ON=0 } rm -f $SANDBOX_LOG || \ die "failed to remove stale sandbox log: '$SANDBOX_LOG'" if [[ -n $x ]] { export SANDBOX_ON=$x } unset x } # Force configure scripts that automatically detect ccache to # respect FEATURES="-ccache". has ccache $FEATURES || export CCACHE_DISABLE=1 local phase_func=$[__ebuild_arg_to_phase $EBUILD_PHASE] [[ -n $phase_func ]] && __ebuild_phase_funcs $EAPI $phase_func unset phase_func __source_all_bashrcs match $(1) { with nofetch __ebuild_phase_with_hooks pkg_nofetch with prerm|postrm|preinst|postinst|config|info if has $(1) config info && \ ! declare -F "pkg_$(1)" >/dev/null { ewarn "pkg_$(1)() is not defined: '$(EBUILD##*/)'" } export SANDBOX_ON="0" if test $(PORTAGE_DEBUG) != "1" || test $(-/x/) != "$Flags" { __ebuild_phase_with_hooks pkg_$(1) } else { set -x __ebuild_phase_with_hooks pkg_$(1) set +x } if [[ -n $PORTAGE_UPDATE_ENV ]] { # Update environment.bz2 in case installation phases # need to pass some variables to uninstallation phases. # Use safe cwd, avoiding unsafe import for bug #469338. cd $(PORTAGE_PYM_PATH) __save_ebuild_env --exclude-init-phases | \ __filter_readonly_variables --filter-path \ --filter-sandbox --allow-extra-vars \ | $(PORTAGE_BZIP2_COMMAND) -c -f9 > $PORTAGE_UPDATE_ENV assert "__save_ebuild_env failed" } with unpack|prepare|configure|compile|test|clean|install if [[ ${SANDBOX_DISABLED:-0} = 0 ]] { export SANDBOX_ON="1" } else { export SANDBOX_ON="0" } match $(1) { with configure|compile local x for x in [ASFLAGS CCACHE_DIR CCACHE_SIZE \ CFLAGS CXXFLAGS LDFLAGS LIBCFLAGS LIBCXXFLAGS] { [[ ${!x+set} = set ]] && export $x } unset x has distcc $FEATURES && [[ -n $DISTCC_DIR ]] && \ [[ ${SANDBOX_WRITE/$DISTCC_DIR} = $SANDBOX_WRITE ]] && \ addwrite $DISTCC_DIR setglobal x = "LIBDIR_$ABI" test -z $PKG_CONFIG_PATH -a -n $ABI -a -n $(!x) && \ export PKG_CONFIG_PATH=$(EPREFIX)/usr/$(!x)/pkgconfig if has noauto $FEATURES && \ [[ ! -f $PORTAGE_BUILDDIR/.unpacked ]] { echo echo "!!! We apparently haven't unpacked..." \ "This is probably not what you" echo "!!! want to be doing... You are using" \ "FEATURES=noauto so I'll assume" echo "!!! that you know what you are doing..." \ "You have 5 seconds to abort..." echo sleep 5 } cd $PORTAGE_BUILDDIR if test ! -d build-info { mkdir build-info cp $EBUILD "build-info/$PF.ebuild" } #our custom version of libtool uses $S and $D to fix #invalid paths in .la files export S D } if test $(PORTAGE_DEBUG) != "1" || test $(-/x/) != "$Flags" { __dyn_$(1) } else { set -x __dyn_$(1) set +x } export SANDBOX_ON="0" with help|pretend|setup #pkg_setup needs to be out of the sandbox for tmp file creation; #for example, awking and piping a file in /tmp requires a temp file to be created #in /etc. If pkg_setup is in the sandbox, both our lilo and apache ebuilds break. export SANDBOX_ON="0" if test $(PORTAGE_DEBUG) != "1" || test $(-/x/) != "$Flags" { __dyn_$(1) } else { set -x __dyn_$(1) set +x } with _internal_test with * export SANDBOX_ON="1" echo "Unrecognized arg '$(1)'" echo __dyn_help exit 1 } # Save the env only for relevant phases. if ! has $(1) clean help info nofetch { umask 002 # Use safe cwd, avoiding unsafe import for bug #469338. cd $(PORTAGE_PYM_PATH) __save_ebuild_env | __filter_readonly_variables \ --filter-features > "$T/environment" assert "__save_ebuild_env failed" chgrp $(PORTAGE_GRPNAME:-portage) "$T/environment" chmod g+w "$T/environment" } [[ -n $PORTAGE_EBUILD_EXIT_FILE ]] && > $PORTAGE_EBUILD_EXIT_FILE if [[ -n $PORTAGE_IPC_DAEMON ]] { [[ ! -s $SANDBOX_LOG ]] "$PORTAGE_BIN_PATH"/ebuild-ipc exit $Status } }