From 5067fa4c8c1067f99fdbddb02f66586febda6b07 Mon Sep 17 00:00:00 2001 From: Tim Harder Date: Wed, 18 Feb 2015 00:25:26 -0500 Subject: install bash files in /usr/lib/pkgcore instead of the python module We don't need to duplicate these for every version of python we install for especially once py3 support is re-added. Note that there is one python script in the bash directory for dohtml, but it's always had a generic shebang anyway. --- bash/dont_export_funcs.list | 120 +++++ bash/eapi/0.lib | 4 + bash/eapi/1.lib | 4 + bash/eapi/2.lib | 27 + bash/eapi/3.lib | 6 + bash/eapi/4.lib | 38 ++ bash/eapi/5.lib | 30 ++ bash/eapi/common.lib | 590 +++++++++++++++++++++ bash/eapi/depend.lib | 192 +++++++ bash/ebuild-daemon.bash | 453 ++++++++++++++++ bash/ebuild-daemon.lib | 62 +++ bash/ebuild-default-functions.lib | 309 +++++++++++ bash/ebuild-env-utils.lib | 201 +++++++ bash/ebuild.lib | 514 ++++++++++++++++++ bash/exit-handling.lib | 110 ++++ bash/generate_eapi_func_list.bash | 44 ++ bash/helpers/4/docompress | 5 + bash/helpers/4/dohard | 1 + bash/helpers/4/dosed | 1 + bash/helpers/5/doheader | 7 + bash/helpers/5/newheader | 1 + bash/helpers/common/dobin | 15 + bash/helpers/common/doconfd | 7 + bash/helpers/common/dodir | 7 + bash/helpers/common/dodoc | 35 ++ bash/helpers/common/doenvd | 7 + bash/helpers/common/doexe | 22 + bash/helpers/common/dohard | 19 + bash/helpers/common/dohtml | 7 + bash/helpers/common/doinfo | 12 + bash/helpers/common/doinitd | 7 + bash/helpers/common/doins | 50 ++ bash/helpers/common/dolib | 25 + bash/helpers/common/dolib.a | 1 + bash/helpers/common/dolib.so | 1 + bash/helpers/common/doman | 47 ++ bash/helpers/common/domo | 18 + bash/helpers/common/dosbin | 1 + bash/helpers/common/dosed | 24 + bash/helpers/common/dosym | 1 + bash/helpers/common/emake | 6 + bash/helpers/common/fowners | 9 + bash/helpers/common/fperms | 9 + bash/helpers/common/keepdir | 22 + bash/helpers/common/newbin | 1 + bash/helpers/common/newconfd | 1 + bash/helpers/common/newdoc | 1 + bash/helpers/common/newenvd | 1 + bash/helpers/common/newexe | 1 + bash/helpers/common/newinitd | 1 + bash/helpers/common/newins | 1 + bash/helpers/common/newlib.a | 1 + bash/helpers/common/newlib.so | 1 + bash/helpers/common/newman | 1 + bash/helpers/common/newsbin | 1 + bash/helpers/common/pkgcore-ebuild-helper | 126 +++++ bash/helpers/common/prepalldocs | 69 +++ bash/helpers/common/prepallstrip | 9 + bash/helpers/common/prepinfo | 69 +++ bash/helpers/common/prepman | 70 +++ bash/helpers/common/prepstrip | 75 +++ bash/helpers/internals/_generic_new | 22 + bash/helpers/internals/_raw_dohtml | 188 +++++++ bash/helpers/internals/banned | 3 + bash/helpers/internals/deprecated | 12 + bash/helpers/internals/prepall | 93 ++++ bash/helpers/internals/prepallman | 18 + bash/isolated-functions.lib | 229 ++++++++ bash/regenerate_dont_export_func_list.bash | 65 +++ bin/pwrapper | 2 + pkgcore/ebuild/const.py | 15 +- pkgcore/ebuild/eapi-bash/dont_export_funcs.list | 120 ----- pkgcore/ebuild/eapi-bash/eapi/0.lib | 4 - pkgcore/ebuild/eapi-bash/eapi/1.lib | 4 - pkgcore/ebuild/eapi-bash/eapi/2.lib | 27 - pkgcore/ebuild/eapi-bash/eapi/3.lib | 6 - pkgcore/ebuild/eapi-bash/eapi/4.lib | 38 -- pkgcore/ebuild/eapi-bash/eapi/5.lib | 30 -- pkgcore/ebuild/eapi-bash/eapi/common.lib | 590 --------------------- pkgcore/ebuild/eapi-bash/eapi/depend.lib | 192 ------- pkgcore/ebuild/eapi-bash/ebuild-daemon.bash | 453 ---------------- pkgcore/ebuild/eapi-bash/ebuild-daemon.lib | 62 --- .../ebuild/eapi-bash/ebuild-default-functions.lib | 309 ----------- pkgcore/ebuild/eapi-bash/ebuild-env-utils.lib | 201 ------- pkgcore/ebuild/eapi-bash/ebuild.lib | 514 ------------------ pkgcore/ebuild/eapi-bash/exit-handling.lib | 110 ---- .../ebuild/eapi-bash/generate_eapi_func_list.bash | 44 -- pkgcore/ebuild/eapi-bash/helpers/4/docompress | 5 - pkgcore/ebuild/eapi-bash/helpers/4/dohard | 1 - pkgcore/ebuild/eapi-bash/helpers/4/dosed | 1 - pkgcore/ebuild/eapi-bash/helpers/5/doheader | 7 - pkgcore/ebuild/eapi-bash/helpers/5/newheader | 1 - pkgcore/ebuild/eapi-bash/helpers/common/dobin | 15 - pkgcore/ebuild/eapi-bash/helpers/common/doconfd | 7 - pkgcore/ebuild/eapi-bash/helpers/common/dodir | 7 - pkgcore/ebuild/eapi-bash/helpers/common/dodoc | 35 -- pkgcore/ebuild/eapi-bash/helpers/common/doenvd | 7 - pkgcore/ebuild/eapi-bash/helpers/common/doexe | 22 - pkgcore/ebuild/eapi-bash/helpers/common/dohard | 19 - pkgcore/ebuild/eapi-bash/helpers/common/dohtml | 7 - pkgcore/ebuild/eapi-bash/helpers/common/doinfo | 12 - pkgcore/ebuild/eapi-bash/helpers/common/doinitd | 7 - pkgcore/ebuild/eapi-bash/helpers/common/doins | 50 -- pkgcore/ebuild/eapi-bash/helpers/common/dolib | 25 - pkgcore/ebuild/eapi-bash/helpers/common/dolib.a | 1 - pkgcore/ebuild/eapi-bash/helpers/common/dolib.so | 1 - pkgcore/ebuild/eapi-bash/helpers/common/doman | 47 -- pkgcore/ebuild/eapi-bash/helpers/common/domo | 18 - pkgcore/ebuild/eapi-bash/helpers/common/dosbin | 1 - pkgcore/ebuild/eapi-bash/helpers/common/dosed | 24 - pkgcore/ebuild/eapi-bash/helpers/common/dosym | 1 - pkgcore/ebuild/eapi-bash/helpers/common/emake | 6 - pkgcore/ebuild/eapi-bash/helpers/common/fowners | 9 - pkgcore/ebuild/eapi-bash/helpers/common/fperms | 9 - pkgcore/ebuild/eapi-bash/helpers/common/keepdir | 22 - pkgcore/ebuild/eapi-bash/helpers/common/newbin | 1 - pkgcore/ebuild/eapi-bash/helpers/common/newconfd | 1 - pkgcore/ebuild/eapi-bash/helpers/common/newdoc | 1 - pkgcore/ebuild/eapi-bash/helpers/common/newenvd | 1 - pkgcore/ebuild/eapi-bash/helpers/common/newexe | 1 - pkgcore/ebuild/eapi-bash/helpers/common/newinitd | 1 - pkgcore/ebuild/eapi-bash/helpers/common/newins | 1 - pkgcore/ebuild/eapi-bash/helpers/common/newlib.a | 1 - pkgcore/ebuild/eapi-bash/helpers/common/newlib.so | 1 - pkgcore/ebuild/eapi-bash/helpers/common/newman | 1 - pkgcore/ebuild/eapi-bash/helpers/common/newsbin | 1 - .../eapi-bash/helpers/common/pkgcore-ebuild-helper | 126 ----- .../ebuild/eapi-bash/helpers/common/prepalldocs | 69 --- .../ebuild/eapi-bash/helpers/common/prepallstrip | 9 - pkgcore/ebuild/eapi-bash/helpers/common/prepinfo | 69 --- pkgcore/ebuild/eapi-bash/helpers/common/prepman | 70 --- pkgcore/ebuild/eapi-bash/helpers/common/prepstrip | 75 --- .../eapi-bash/helpers/internals/_generic_new | 22 - .../ebuild/eapi-bash/helpers/internals/_raw_dohtml | 188 ------- pkgcore/ebuild/eapi-bash/helpers/internals/banned | 3 - .../ebuild/eapi-bash/helpers/internals/deprecated | 12 - pkgcore/ebuild/eapi-bash/helpers/internals/prepall | 93 ---- .../ebuild/eapi-bash/helpers/internals/prepallman | 18 - pkgcore/ebuild/eapi-bash/isolated-functions.lib | 229 -------- .../regenerate_dont_export_func_list.bash | 65 --- setup.py | 35 +- 141 files changed, 4146 insertions(+), 4166 deletions(-) create mode 100644 bash/dont_export_funcs.list create mode 100644 bash/eapi/0.lib create mode 100644 bash/eapi/1.lib create mode 100644 bash/eapi/2.lib create mode 100644 bash/eapi/3.lib create mode 100644 bash/eapi/4.lib create mode 100644 bash/eapi/5.lib create mode 100644 bash/eapi/common.lib create mode 100644 bash/eapi/depend.lib create mode 100755 bash/ebuild-daemon.bash create mode 100644 bash/ebuild-daemon.lib create mode 100644 bash/ebuild-default-functions.lib create mode 100644 bash/ebuild-env-utils.lib create mode 100644 bash/ebuild.lib create mode 100644 bash/exit-handling.lib create mode 100755 bash/generate_eapi_func_list.bash create mode 100755 bash/helpers/4/docompress create mode 120000 bash/helpers/4/dohard create mode 120000 bash/helpers/4/dosed create mode 100755 bash/helpers/5/doheader create mode 120000 bash/helpers/5/newheader create mode 100755 bash/helpers/common/dobin create mode 100755 bash/helpers/common/doconfd create mode 100755 bash/helpers/common/dodir create mode 100755 bash/helpers/common/dodoc create mode 100755 bash/helpers/common/doenvd create mode 100755 bash/helpers/common/doexe create mode 100755 bash/helpers/common/dohard create mode 100755 bash/helpers/common/dohtml create mode 100755 bash/helpers/common/doinfo create mode 100755 bash/helpers/common/doinitd create mode 100755 bash/helpers/common/doins create mode 100755 bash/helpers/common/dolib create mode 120000 bash/helpers/common/dolib.a create mode 120000 bash/helpers/common/dolib.so create mode 100755 bash/helpers/common/doman create mode 100755 bash/helpers/common/domo create mode 120000 bash/helpers/common/dosbin create mode 100755 bash/helpers/common/dosed create mode 120000 bash/helpers/common/dosym create mode 100755 bash/helpers/common/emake create mode 100755 bash/helpers/common/fowners create mode 100755 bash/helpers/common/fperms create mode 100755 bash/helpers/common/keepdir create mode 120000 bash/helpers/common/newbin create mode 120000 bash/helpers/common/newconfd create mode 120000 bash/helpers/common/newdoc create mode 120000 bash/helpers/common/newenvd create mode 120000 bash/helpers/common/newexe create mode 120000 bash/helpers/common/newinitd create mode 120000 bash/helpers/common/newins create mode 120000 bash/helpers/common/newlib.a create mode 120000 bash/helpers/common/newlib.so create mode 120000 bash/helpers/common/newman create mode 120000 bash/helpers/common/newsbin create mode 100755 bash/helpers/common/pkgcore-ebuild-helper create mode 100755 bash/helpers/common/prepalldocs create mode 100755 bash/helpers/common/prepallstrip create mode 100755 bash/helpers/common/prepinfo create mode 100755 bash/helpers/common/prepman create mode 100755 bash/helpers/common/prepstrip create mode 100755 bash/helpers/internals/_generic_new create mode 100755 bash/helpers/internals/_raw_dohtml create mode 100755 bash/helpers/internals/banned create mode 100755 bash/helpers/internals/deprecated create mode 100755 bash/helpers/internals/prepall create mode 100755 bash/helpers/internals/prepallman create mode 100644 bash/isolated-functions.lib create mode 100755 bash/regenerate_dont_export_func_list.bash delete mode 100644 pkgcore/ebuild/eapi-bash/dont_export_funcs.list delete mode 100644 pkgcore/ebuild/eapi-bash/eapi/0.lib delete mode 100644 pkgcore/ebuild/eapi-bash/eapi/1.lib delete mode 100644 pkgcore/ebuild/eapi-bash/eapi/2.lib delete mode 100644 pkgcore/ebuild/eapi-bash/eapi/3.lib delete mode 100644 pkgcore/ebuild/eapi-bash/eapi/4.lib delete mode 100644 pkgcore/ebuild/eapi-bash/eapi/5.lib delete mode 100644 pkgcore/ebuild/eapi-bash/eapi/common.lib delete mode 100644 pkgcore/ebuild/eapi-bash/eapi/depend.lib delete mode 100755 pkgcore/ebuild/eapi-bash/ebuild-daemon.bash delete mode 100644 pkgcore/ebuild/eapi-bash/ebuild-daemon.lib delete mode 100644 pkgcore/ebuild/eapi-bash/ebuild-default-functions.lib delete mode 100644 pkgcore/ebuild/eapi-bash/ebuild-env-utils.lib delete mode 100644 pkgcore/ebuild/eapi-bash/ebuild.lib delete mode 100644 pkgcore/ebuild/eapi-bash/exit-handling.lib delete mode 100755 pkgcore/ebuild/eapi-bash/generate_eapi_func_list.bash delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/4/docompress delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/4/dohard delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/4/dosed delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/5/doheader delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/5/newheader delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/dobin delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/doconfd delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/dodir delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/dodoc delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/doenvd delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/doexe delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/dohard delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/dohtml delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/doinfo delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/doinitd delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/doins delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/dolib delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/common/dolib.a delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/common/dolib.so delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/doman delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/domo delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/common/dosbin delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/dosed delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/common/dosym delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/emake delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/fowners delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/fperms delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/keepdir delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/common/newbin delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/common/newconfd delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/common/newdoc delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/common/newenvd delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/common/newexe delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/common/newinitd delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/common/newins delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/common/newlib.a delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/common/newlib.so delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/common/newman delete mode 120000 pkgcore/ebuild/eapi-bash/helpers/common/newsbin delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/pkgcore-ebuild-helper delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/prepalldocs delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/prepallstrip delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/prepinfo delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/prepman delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/common/prepstrip delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/internals/_generic_new delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/internals/_raw_dohtml delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/internals/banned delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/internals/deprecated delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/internals/prepall delete mode 100755 pkgcore/ebuild/eapi-bash/helpers/internals/prepallman delete mode 100644 pkgcore/ebuild/eapi-bash/isolated-functions.lib delete mode 100755 pkgcore/ebuild/eapi-bash/regenerate_dont_export_func_list.bash diff --git a/bash/dont_export_funcs.list b/bash/dont_export_funcs.list new file mode 100644 index 000000000..da5cb11da --- /dev/null +++ b/bash/dont_export_funcs.list @@ -0,0 +1,120 @@ +EXPORT_FUNCTIONS +KV_major +KV_micro +KV_minor +KV_to_int +adddeny +addpredict +addread +addwrite +assert +best_version +debug-print +debug-print-function +debug-print-section +die +diropts +docinto +ebegin +econf +eend +eerror +einfo +einfon +einstall +elog +eqawarn +ewarn +exeinto +exeopts +get_KV +has +has_version +hasq +hasv +inherit +insinto +insopts +into +libopts +portageq +unpack +use +use_enable +use_with +useq +usev +__IFS_pop +__IFS_push +__colored_output_disable +__colored_output_enable +__directory_is_empty +__dump_metadata_keys +__dump_trace +__dyn_pkg_preinst +__dyn_src_install +__ebd_exec_main +__ebd_main_loop +__ebd_process_ebuild_phases +__ebd_process_metadata +__ebd_process_sandbox_results +__ebd_read_cat_size +__ebd_read_line +__ebd_read_line_nonfatal +__ebd_read_size +__ebd_sigint_handler +__ebd_sigkill_handler +__ebd_write_line +__ebd_write_raw +__elog_base +__ensure_PATH +__environ_dump +__environ_list_funcs +__environ_list_vars +__environ_sanitize_saved_env +__environ_save_to_file +__escape_regex_array +__execute_phases +__feature_is_enabled +__filter_env +__generate_initial_ebuild_environ +__get_func_code +__get_libdir +__helper_check_exit +__helper_died +__helper_exit +__inject_common_phase_funcs +__inject_phase_funcs +__internal_inherit +__is_function +__load_eapi_libs +__load_ebuild +__make_preloaded_eclass_func +__phase_common_pkg_nofetch +__phase_common_pre_phase +__phase_common_src_compile +__phase_common_src_test +__phase_common_src_unpack +__phase_default_post_src_compile +__phase_default_pre_src_compile +__phase_default_pre_src_configure +__phase_default_pre_src_install +__phase_default_pre_src_prepare +__phase_default_pre_src_test +__phase_default_pre_src_unpack +__qa_interceptors_disable +__qa_interceptors_enable +__qa_invoke +__qa_run_function_if_exists +__regex_filter_input +__request_sandbox_summary +__reset_sandbox +__run_ebuild_phase +__run_function_if_exists +__safe_has +__set_perf_debug +__shopt_pop +__shopt_push +__source_bashrcs +__strip_duplicate_slashes +__timed_call diff --git a/bash/eapi/0.lib b/bash/eapi/0.lib new file mode 100644 index 000000000..35ef2ee73 --- /dev/null +++ b/bash/eapi/0.lib @@ -0,0 +1,4 @@ +# Copyright: 2012 Brian Harring +# license GPL2/BSD 3 + +__inject_common_phase_funcs diff --git a/bash/eapi/1.lib b/bash/eapi/1.lib new file mode 100644 index 000000000..35ef2ee73 --- /dev/null +++ b/bash/eapi/1.lib @@ -0,0 +1,4 @@ +# Copyright: 2012 Brian Harring +# license GPL2/BSD 3 + +__inject_common_phase_funcs diff --git a/bash/eapi/2.lib b/bash/eapi/2.lib new file mode 100644 index 000000000..1b63af89a --- /dev/null +++ b/bash/eapi/2.lib @@ -0,0 +1,27 @@ +# Copyright: 2011-2012 Brian Harring +# license GPL2/BSD 3 + +__phase_eapi2_src_configure() { + if [[ -x ${ECONF_SOURCE:-.}/configure ]]; then + econf + fi +} + +__phase_eapi2_src_prepare() { + : +} + +default() { + if __is_function default_pkg_${EBUILD_PHASE}; then + default_pkg_${EBUILD_PHASE} + elif __is_function default_src_${EBUILD_PHASE}; then + default_src_${EBUILD_PHASE} + else + die "default is not available in ebuild phase '${EBUILD_PHASE}'" + fi +} + +__inject_phase_funcs __phase_eapi2 src_{configure,prepare} +__inject_common_phase_funcs + +: diff --git a/bash/eapi/3.lib b/bash/eapi/3.lib new file mode 100644 index 000000000..7dbc85cc8 --- /dev/null +++ b/bash/eapi/3.lib @@ -0,0 +1,6 @@ +# Copyright: 2011-2012 Brian Harring +# license GPL2/BSD 3 + +source "${PKGCORE_BIN_PATH}"/eapi/2.lib + +: diff --git a/bash/eapi/4.lib b/bash/eapi/4.lib new file mode 100644 index 000000000..82e344fef --- /dev/null +++ b/bash/eapi/4.lib @@ -0,0 +1,38 @@ +# Copyright: 2011-2012 Brian Harring +# license GPL2/BSD 3 + +source "${PKGCORE_BIN_PATH}"/eapi/3.lib + +nonfatal() { + PKGCORE_NONFATAL_HELPER=true "$@" +} + +__phase_eapi4_src_install() { + if [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then + emake DESTDIR="${D}" install + fi + + # important; keep these as separate statements. we use the exit + # code after all. + local tmp_var + + if tmp_var=$(declare -p DOCS 2> /dev/null); then + # given declare -- x= || declare -a x=, isolate the --/-a + tmp_var=${tmp_var#declare -} + tmp_var=${tmp_var%% *} + if [[ ${tmp_var/a} != ${tmp_var} ]]; then + dodoc "${DOCS[@]}" + else + dodoc ${DOCS} + fi + else + for tmp_var in README* ChangeLog AUTHORS NEWS TODO CHANGES THANKS \ + BUGS FAQ CREDITS CHANGELOG; do + [[ -s ${tmp_var} ]] && dodoc "${tmp_var}" + done + fi +} + +__inject_phase_funcs __phase_eapi4 src_install + +: diff --git a/bash/eapi/5.lib b/bash/eapi/5.lib new file mode 100644 index 000000000..ca3cc35be --- /dev/null +++ b/bash/eapi/5.lib @@ -0,0 +1,30 @@ +# Copyright: 2012 Brian Harring +# license GPL2/BSD 3 + +source "${PKGCORE_BIN_PATH}"/eapi/4.lib + +has_version() { + local r=${ROOT:-/} + if [[ $1 == "--host-root" ]]; then + r=/ + shift + fi + PKGCORE_DISABLE_COMPAT=true portageq 'has_version' "$1" --domain-at-root "${r}" +} + +best_version() { + local r=${ROOT:-/} + if [[ $1 == "--host-root" ]]; then + r=/ + shift + fi + PKGCORE_DISABLE_COMPAT=true portageq 'best_version' "$1" --domain-at-root "${r}" + +} + +usex() { + use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" + return 0 +} + +: diff --git a/bash/eapi/common.lib b/bash/eapi/common.lib new file mode 100644 index 000000000..dd6369ad5 --- /dev/null +++ b/bash/eapi/common.lib @@ -0,0 +1,590 @@ +# Copyright: 2011-2012 Brian Harring +# license GPL2/BSD 3 + +use() { + # EAPI 5 and up + if ${PKGCORE_PROFILE_IUSE_INJECTION} && \ + [[ ! ${1#!} =~ ${PKGCORE_IUSE_EFFECTIVE} ]]; then + die "USE flag '${1#!}' not in IUSE for ${CATEGORY}/${PF}" + fi + + # Ensure USE is split on normal IFS. + local IFS=$' \t\n' + + if [[ ${1:0:1} == "!" ]]; then + ! __safe_has "${1#!}" ${USE} + else + __safe_has "$1" ${USE} + fi +} + +usev() { + if use "$1"; then + echo "${1#!}" + fi +} + +useq() { + use "$@" +} + +use_with() { + if [[ -z $1 ]]; then + echo "!!! use_with() called without a parameter." >&2 + echo "!!! use_with [ [value]]" >&2 + return + fi + + local uw_suffix="" + if __safe_has "${EAPI:-0}" 0 1 2 3; then + uw_suffix=${3:+=$3} + else + uw_suffix=${3+=$3} + fi + + local uword=$2 + if [[ -z ${uword} ]]; then + uword=$1 + fi + + if use $1; then + echo "--with-${uword}${uw_suffix}" + return 0 + fi + echo "--without-${uword}" + return 1 +} + +use_enable() { + if [[ -z $1 ]]; then + echo "!!! use_enable() called without a parameter." >&2 + echo "!!! use_enable [ [value]]" >&2 + return + fi + + local ue_suffix="" + if __safe_has "${EAPI:-0}" 0 1 2 3; then + ue_suffix=${3:+=$3} + else + ue_suffix=${3+=$3} + fi + + local uword=$2 + if [[ -z ${uword} ]]; then + uword=$1 + fi + + if use "$1"; then + echo "--enable-${uword}${ue_suffix}" + return 0 + fi + echo "--disable-${uword}" + return 1 +} + +econf() { + local ret + ECONF_SOURCE=${ECONF_SOURCE:-.} + if [[ ! -x ${ECONF_SOURCE}/configure ]]; then + [[ -f ${ECONF_SOURCE}/configure ]] && die "configure script isn't executable" + die "no configure script found" + fi + + if [[ -d /usr/share/gnuconfig ]]; then + local x + find "${WORKDIR}" -type f \( -name config.guess -o -name config.sub \) | \ + while read x; do + echo "econf: replacing ${x} with /usr/share/gnuconfig/${x##*/}" + cp -f "/usr/share/gnuconfig/${x##*/}" "${x}" + done + fi + + # if the profile defines a location to install libs to aside from default, pass it on. + # if the ebuild passes in --libdir, they're responsible for the conf_libdir fun. + local CONF_LIBDIR=$(__get_libdir) + if [[ -n ${CONF_LIBDIR} && $* != *"--libdir="* ]]; then + if [[ $* == *"--exec-prefix="* ]]; then + local args=$(echo $*) + local -a prefix=( $(echo ${args/*--exec-prefix[= ]}) ) + CONF_PREFIX=${prefix/--*} + [[ ${CONF_PREFIX} != /* ]] && CONF_PREFIX=/${CONF_PREFIX} + elif [[ $* == *"--prefix="* ]]; then + local args=$(echo $*) + local -a pref=( $(echo ${args/*--prefix[= ]}) ) + CONF_PREFIX=${prefix/--*} + [[ ${CONF_PREFIX} != /* ]] && CONF_PREFIX=/${CONF_PREFIX} + else + CONF_PREFIX=/usr + fi + export CONF_PREFIX + [[ ${CONF_LIBDIR} != /* ]] && CONF_LIBDIR=/${CONF_LIBDIR} + set -- --libdir="$(__strip_duplicate_slashes "${CONF_PREFIX}${CONF_LIBDIR}")" "$@" + fi + + if ${PKGCORE_ECONF_DISABLE_DEPENDENCY_TRACKING} || ${PKGCORE_ECONF_DISABLE_SILENT_RULES}; then + local help_text=$("${ECONF_SOURCE}/configure" --help 2> /dev/null) + local extra_args=() + + # EAPI 4 and up. + if ${PKGCORE_ECONF_DISABLE_DEPENDENCY_TRACKING} && \ + [[ ${help_text} =~ "--disable-dependency-tracking" ]]; then + extra_args+=( --disable-dependency-tracking ) + fi + + # EAPI 5 and up. + if ${PKGCORE_ECONF_DISABLE_SILENT_RULES} && \ + [[ ${help_text} =~ "--disable-silent-rules" ]]; then + extra_args+=( --disable-silent-rules ) + fi + set -- "${extra_args[@]}" "$@" + unset extra_args + unset help_text + fi + + # Reset IFS since we're interpretting user supplied EXTRA_ECONF. + local IFS=$' \t\n' + set -- "${ECONF_SOURCE}/configure" \ + --prefix=/usr \ + ${CBUILD:+--build="${CBUILD}"} \ + --host="${CHOST}" \ + ${CTARGET:+--target="${CTARGET}"} \ + --mandir=/usr/share/man \ + --infodir=/usr/share/info \ + --datadir=/usr/share \ + --sysconfdir=/etc \ + --localstatedir=/var/lib \ + "$@" \ + ${EXTRA_ECONF} + + echo "$@" + + if ! "$@"; then + if [[ -s config.log ]]; then + echo + echo "!!! Please attach the config.log to your bug report:" + echo "!!! ${PWD}/config.log" + fi + die "econf failed" + fi + return $? +} + +# debug-print() gets called from many places with verbose status information useful +# for tracking down problems. The output is in ${T}/eclass-debug.log. +# You can set ECLASS_DEBUG_OUTPUT to redirect the output somewhere else as well. +# The special "on" setting echoes the information, mixing it with the rest of the +# emerge output. +# You can override the setting by exporting a new one from the console, or you can +# set a new default in make.*. Here the default is "" or unset. + +# in the future might use e* from /etc/init.d/functions.sh if i feel like it +debug-print() { + if __safe_has ${EBUILD_PHASE} depend nofetch config info postinst; then + return + fi + # if ${T} isn't defined, we're in dep calculation mode and + # shouldn't do anything + [[ -z ${T} ]] && return 0 + + local _item + for _item in "$@"; do + # extra user-configurable targets + if [[ ${ECLASS_DEBUG_OUTPUT} == "on" ]]; then + echo "debug: ${_item}" + elif [[ -n ${ECLASS_DEBUG_OUTPUT} ]]; then + echo "debug: ${_item}" >> "${ECLASS_DEBUG_OUTPUT}" + fi + + # default target + echo "${_item}" >> "${T}"/eclass-debug.log + chmod g+w "${T}"/eclass-debug.log &> /dev/null + done + # let the portage user own/write to this file +} + +# The following 2 functions are debug-print() wrappers + +debug-print-function() { + str="$1: entering function" + shift + debug-print "${str}, parameters: $*" +} + +debug-print-section() { + debug-print "now in section $*" +} + +einstall() { + ${PKGCORE_PREFIX_SUPPORT} || local ED=${D} + # CONF_PREFIX is only set if they didn't pass in libdir above + local LOCAL_EXTRA_EINSTALL=( ${EXTRA_EINSTALL} ) + local CONF_LIBDIR=$(__get_libdir) + if [[ -n ${CONF_LIBDIR} && ${CONF_PREFIX:-unset} != "unset" ]]; then + EI_DESTLIBDIR=${ED%%/}/${CONF_PREFIX%%/}/${CONF_LIBDIR%%/}/ + LOCAL_EXTRA_EINSTALL+=( libdir=${EI_DESTLIBDIR} ) + unset EI_DESTLIBDIR + fi + + if ! [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then + die "no Makefile found" + fi + + # Reset IFS for LOCAL_EXTRA_EINSTALL, should users be up to something. + local IFS=$' \t\n' + set -- \ + ${MAKE:-make} \ + prefix="${ED}/usr" \ + datadir="${ED}/usr/share" \ + infodir="${ED}/usr/share/info" \ + localstatedir="${ED}/var/lib" \ + mandir="${ED}/usr/share/man" \ + sysconfdir="${ED}/etc" \ + ${LOCAL_EXTRA_EINSTALL[@]} \ + "$@" install + [[ ${PKGCORE_DEBUG} != 0 ]] && "$@" -n + "$@" || die "einstall failed" +} + +__get_libdir() { + local libdir=$1 libdir_var="LIBDIR_${ABI}" + [[ -n ${ABI} && -n ${!libdir_var} ]] && libdir=${!libdir_var} + echo "${libdir}" +} + +__phase_common_pkg_nofetch() { + [[ -z ${SRC_URI} ]] && return + + echo "!!! The following are listed in SRC_URI for ${PN}:" + local fp + __shopt_push -f + for fp in ${SRC_URI}; do + echo "!!! ${fp}" + done + __shopt_pop +} + +__phase_common_src_unpack() { + if [[ -n ${A} ]]; then + unpack ${A} + fi +} + +__phase_common_src_compile() { + # only eapi 0/1 invoke configure... + if __safe_has "${EAPI:-0}" 0 1; then + if [[ ${EAPI:-0} == 0 ]]; then + [[ -x ./configure ]] && econf + elif [[ -x ${ECONF_SOURCE:-.}/configure ]]; then + econf + fi + fi + if [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then + emake || die "emake failed" + fi +} + +__phase_common_src_test() { + addpredict / + local extra_args=( ${EXTRA_EMAKE} ) + ${PKGCORE_ALLOW_PARALLEL_SRC_TEST} || extra_args+=( -j1 ) + if make check -n &> /dev/null; then + echo ">>> Test phase [check]: ${CATEGORY}/${PF}" + emake "${extra_args[@]}" check || die "Make check failed. See above for details." + elif make test -n &> /dev/null; then + emake "${extra_args[@]}" test || die "Make test failed. See above for details." + else + echo ">>> Test phase [none]: ${CATEGORY}/${PF}" + fi + SANDBOX_PREDICT=${SANDBOX_PREDICT%:/} +} + +into() { + ${PKGCORE_PREFIX_SUPPORT} || local ED=${D} + if [[ $1 == "/" ]]; then + export DESTTREE="" + else + export DESTTREE=$1 + if [[ ! -d ${ED}${DESTTREE} ]]; then + install -d "${ED}${DESTTREE}" + fi + fi +} + +insinto() { + ${PKGCORE_PREFIX_SUPPORT} || local ED=${D} + if [[ $1 == "/" ]]; then + export INSDESTTREE="" + else + export INSDESTTREE=$1 + if [[ ! -d ${ED}${INSDESTTREE} ]]; then + install -d "${ED}${INSDESTTREE}" + fi + fi +} + +exeinto() { + ${PKGCORE_PREFIX_SUPPORT} || local ED=${D} + if [[ $1 == "/" ]]; then + export PKGCORE_EXEDESTTREE="" + else + export PKGCORE_EXEDESTTREE=$1 + if [[ ! -d ${ED}${PKGCORE_EXEDESTTREE} ]]; then + install -d "${ED}${PKGCORE_EXEDESTTREE}" + fi + fi +} + +docinto() { + ${PKGCORE_PREFIX_SUPPORT} || local ED=${D} + if [[ $1 == "/" ]]; then + export PKGCORE_DOCDESTTREE="" + else + export PKGCORE_DOCDESTTREE=$1 + if [[ ! -d ${ED}usr/share/doc/${PF}/${PKGCORE_DOCDESTTREE} ]]; then + install -d "${ED}usr/share/doc/${PF}/${PKGCORE_DOCDESTTREE}" + fi + fi +} + +__phase_common_pre_phase() { + if [[ -d ${S} ]]; then + cd "${S}" + elif __safe_has "${EAPI}" 0 1 2 3; then + cd "${WORKDIR}" + elif [[ -n ${A} ]]; then + die "source directory '${S}' doesn't exist, but \${A} isn't empty (see S-WORKDIR-FALLBACK in PMS)" + else + local phase + # eapi4 blatant idiocy... + for phase in unpack prepare configure compile install; do + [[ ${phase} == ${EBUILD_PHASE} ]] && break + __is_function src_${phase} || continue + # to reach here means that (for example), we're doing src_install, and src_compile was defined + # but S doesn't exist. + die "source directory '${S}' doesn't exist, \${A} is defined, and there was a defined " \ + "phase function '${phase}' prior to '${EBUILD_PHASE}'; please see S-WORKDIR-FALLBACK " \ + "in pms for the details of what is allowed for eapi4 and later" + done + cd "${WORKDIR}" + fi +} + +__phase_default_pre_src_unpack() { + export PORTAGE_GZIP_COMMAND=${PORTAGE_GZIP_COMMAND:-gzip} + export PORTAGE_BZIP2_COMMAND=${PORTAGE_BZIP2_COMMAND:-bzip2} + export PORTAGE_XZ_COMMAND=${PORTAGE_XZ_COMMAND:-xz} + export S + cd "${WORKDIR}" +} + +__phase_default_pre_src_prepare() { __phase_common_pre_phase; } +__phase_default_pre_src_test() { __phase_common_pre_phase; } + +__phase_default_pre_src_configure() { + local var + for var in C{BUILD,HOST,TARGET,C,XX} {AS,LD,{,LIB}C{,XX}}FLAGS; do + [[ -n ${!var+set} ]] && export ${var}="${!var}" + done + __phase_common_pre_phase +} + +__phase_default_pre_src_compile() { + # just reuse the default_pre_src_configure; this means we don't have to care + # if the eapi has configure or not. + __phase_default_pre_src_configure + + if __feature_is_enabled distcc; then + [[ -n ${DISTCC_DIR} ]] && addwrite "${DISTCC_DIR}" + if __feature_is_enabled distcc-pump; then + eval $(pump --startup) || echo "Warning: Failed starting pump" >&2 + trap 'pump --shutdown' EXIT + fi + fi +} + +__phase_default_post_src_compile() { + if __feature_is_enabled distcc && __feature_is_enabled distcc-pump; then + pump --shutdown + trap - EXIT + fi +} + +__phase_default_pre_src_install() { + export DESTTREE=/usr INSDESTTREE='' PKGCORE_EXEDESTTREE='' PKGCORE_DOCDESTTREE='' + export INSOPTIONS="-m0644" EXEOPTIONS="-m0755" + export LIBOPTIONS="-m0644" DIROPTIONS="-m0755" + export PORTAGE_COMPRESS=${PORTAGE_COMPRESS:-bzip2} + export PORTAGE_COMPRESS_FLAGS=${PORTAGE_COMPRESS_FLAGS:--9} + export MOPREFIX=${PN} + export D + rm -rf "${D}" + if ${PKGCORE_PREFIX_SUPPORT}; then + [[ -n ${ED+set} ]] || \ + die "variable ED is unset, but prefix mode is enabled. internal error?" + export ED=${ED} + mkdir -p "${ED}" + else + mkdir "${D}" + fi + __phase_common_pre_phase +} + +__inject_phase_funcs() { + local prefix=$1 func + shift + + for func in "$@"; do + if ! __is_function "${func}"; then + eval "__phase_default_${func}() { ${prefix}_${func}; }"; + fi + + # define default_${phase} funcs for EAPI 2 and up + if ! __safe_has "${EAPI:-0}" 0 1 ; then + eval "default_${func}() { ${prefix}_${func}; }"; + fi + done +} + +__inject_common_phase_funcs() { + __inject_phase_funcs __phase_common pkg_nofetch src_{unpack,compile,test} +} + +unpack() { + local file filename myfail srcdir taropts tar_subdir + taropts='--no-same-owner' + + [[ $# -eq 0 ]] && die "Nothing passed to the 'unpack' command" + + for file in "$@"; do + echo ">>> Unpacking ${file} to ${PWD}" + myfail="failure unpacking ${file}" + if [[ ${file} == "./"* ]]; then + srcdir="" + else + srcdir=${DISTDIR} + fi + + [[ ! -e ${srcdir}${file} ]] && die "${myfail}: file doesn't exist" + [[ ! -s ${srcdir}${file} ]] && die "${myfail}: empty file" + [[ ${file} == ${DISTDIR%%/}/* ]] && \ + die "Arguments to unpack() must not begin with \${DISTDIR}." + [[ ${file} == /* ]] && + die "Arguments to unpack() must not be absolute paths." + + filename=${file##*/} + + case ${file} in + *.tar) + tar xf "${srcdir}${file}" ${taropts} || die "${myfail}" + ;; + *.tar.gz|*.tgz|*.tar.Z) + tar xf "${srcdir}${file}" -I"${PORTAGE_GZIP_COMMAND}" ${taropts} || die "${myfail}" + ;; + *.tar.bz2|*.tbz2|*.tbz) + tar xf "${srcdir}${file}" -I"${PORTAGE_BZIP2_COMMAND}" ${taropts} || die "${myfail}" + ;; + *.tar.lzma) + tar xf "${srcdir}${file}" -Ilzma ${taropts} || die "${myfail}" + ;; + *.tar.xz) + if __safe_has "${EAPI}" 0 1 2; then + echo "xz is a supported extension in EAPI 3 and above only" >&2 + continue; + fi + tar xf "${srcdir}${file}" -I"${PORTAGE_XZ_COMMAND}" ${taropts} || die "${myfail}" + ;; + *.ZIP|*.zip|*.jar) + { set +x; while :; do echo n || break; done } | \ + unzip -qo "${srcdir}${file}" || die "${myfail}" + ;; + *.gz|*.Z|*.z) + ${PORTAGE_GUNZIP_COMMAND:-${PORTAGE_GZIP_COMMAND} -d} -c "${srcdir}${file}" > ${filename%.*} || die "${myfail}" + ;; + *.bz2|*.bz) + ${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c "${srcdir}${file}" > ${filename%.*} || die "${myfail}" + ;; + *.xz) + if __safe_has "${EAPI}" 0 1 2; then + echo "xz is a supported extension in EAPI 3 and above only" >&2 + continue; + fi + ${PORTAGE_UNXZ_COMMAND:-${PORTAGE_XZ_COMMAND} -d} < "${srcdir}${file}" > ${filename%.*} || die "${myfail}" + ;; + *.7Z|*.7z) + local my_output + my_output=$(7z x -y "${srcdir}${file}") + if [[ $? -ne 0 ]]; then + echo "${my_output}" >&2 + die "${myfail}" + fi + ;; + *.RAR|*.rar) + unrar x -idq -o+ "${srcdir}${file}" || die "${myfail}" + ;; + *.LHa|*.LHA|*.lha|*.lzh) + lha xfq "${srcdir}${file}" || die "${myfail}" + ;; + *.a|*.deb) + ar x "${srcdir}${file}" || die "${myfail}" + ;; + *.lzma) + lzma -dc "${srcdir}${file}" > ${filename%.*} || die "${myfail}" + ;; + *) + echo "unpack ${file}: file format not recognized. Ignoring." + ;; + esac + done + find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \ + ${XARGS} -0 chmod -fR a+rX,u+w,g-w,o-w +} + +diropts() { + export DIROPTIONS=$@ +} + +insopts() { + { has -s "$@" || has --strip "$@"; } && \ + ewarn "insopts shouldn't be given -s; stripping should be left to the manager." + export INSOPTIONS=$@ +} + +exeopts() { + { has -s "$@" || has --strip "$@"; } && \ + ewarn "exeopts shouldn't be given -s; stripping should be left to the manager." + export EXEOPTIONS=$@ +} + +libopts() { + { has -s "$@" || has --strip "$@"; } && \ + ewarn "libopts shouldn't be given -s; stripping should be left to the manager." + export LIBOPTIONS=$@ +} + +portageq() { + if [[ ${EBUILD_PHASE} == "depend" ]]; then + die "portageq calls in depends phase aren't allowed" + fi + local command=$1 + shift + # suppress sandbox for the invocation; do this to avoid things like .pyc generation + # being snagged by the sandbox + local portageq_str="portageq" + ${PKGCORE_DISABLE_COMPAT-false} && portageq_str="query" + SANDBOX_ON=0 PYTHONPATH="${PKGCORE_PYTHONPATH}" "${PKGCORE_PYTHON_BINARY}" \ + $(type -P pinspect) ${portageq_str} "${command}" \ + --eapi "${EAPI:--1}" --use "${USE}" "$@" + local ret=$? + [[ ${ret} == 127 ]] && die "pinspect couldn't be found; broken pkgcore installation?" + return $(( ret )) +} + +has_version() { + PKGCORE_DISABLE_COMPAT=true portageq 'has_version' "$1" +} + +best_version() { + PKGCORE_DISABLE_COMPAT=true portageq 'best_version' "$1" +} + +: diff --git a/bash/eapi/depend.lib b/bash/eapi/depend.lib new file mode 100644 index 000000000..f7870cb11 --- /dev/null +++ b/bash/eapi/depend.lib @@ -0,0 +1,192 @@ +# Copyright: 2011-2012 Brian Harring +# license GPL2/BSD 3 + +# while these echo statements are ugly, written this way to ensure bash does it as a single write- +# aka, keep it within the size of atomic writes for pipes. Relevant for threaded output straight to term +use() { + echo "WARNING: 'use' function invoked by ${CATEGORY}/${PF} during metadata regeneration."$'\nWARNING: Please ensure upstream is aware of it and working to remove it.\n' >&2 + return 1 +} + +usev() { + echo "WARNING: 'usev' function invoked by ${CATEGORY}/${PF} during metadata regeneration."$'\nWARNING: Please ensure upstream is aware of it and working to remove it.\n' >&2 + return 1 +} + +use_with() { + echo "WARNING: 'use_with' function invoked by ${CATEGORY}/${PF} during metadata regeneration."$'\nWARNING: Please ensure upstream is aware of it and working to remove it.\n' >&2 + return 1 +} + +use_enable() { + echo "WARNING: 'use_enable' function invoked by ${CATEGORY}/${PF} during metadata regeneration."$'\nWARNING: Please ensure upstream is aware of it and working to remove it.\n' >&2 + return 1 +} + +has() { + local needle=$1 + shift + + local IFS=$'\001' + + # try fast mode first; no IFS match is guaranteed that the needle isn't there. + [[ "${IFS}${*}${IFS}" != *"${IFS}${needle}${IFS}"* ]] && return 1 + + # If we have a match, ensure it's not due to $@ already having \001 in it. + # unlikely, but better safe than sorry. + IFS=' ' + [[ *$'\001'* != $* ]] && return 0 + + # \001 for some insane reason was in $@; fallback to the slow for loop. + # Suppress debug outut for this part however. + __shopt_push +x + local x + for x in "$@"; do + if [[ ${x} == ${needle} ]]; then + __shopt_pop + return 0 + fi + done + __shopt_pop + return 1 +} + +hasq() { + has ${EBUILD_PHASE} prerm postrm || eqawarn \ + "QA Notice: The 'hasq' function is deprecated (replaced by 'has')" + has "$@" +} + +hasv() { + if has "$@"; then + echo "$1" + fi +} + +debug-print() { + : +} + +debug-print-function() { + : +} + +debug-print-section() { + : +} + +eqawarn() { + __elog_base QA "$*" + echo -e " ${PKGCORE_RC_WARN}*${PKGCORE_RC_NORMAL} $*" >&2 + PKGCORE_RC_LAST_CMD="eqawarn" + return 0 +} + +elog() { + __elog_base LOG "$*" + echo -e " ${PKGCORE_RC_GOOD}*${PKGCORE_RC_NORMAL} $*" + PKGCORE_RC_LAST_CMD="elog" + return 0 +} + +einfo() { + einfon "$*\n" + PKGCORE_RC_LAST_CMD="einfo" + return 0 +} + +einfon() { + __elog_base INFO "$*" + echo -ne " ${PKGCORE_RC_GOOD}*${PKGCORE_RC_NORMAL} $*" + PKGCORE_RC_LAST_CMD="einfon" + return 0 +} + +ewarn() { + __elog_base WARN "$*" + echo -e " ${PKGCORE_RC_WARN}*${PKGCORE_RC_NORMAL} $*" >&2 + PKGCORE_RC_LAST_CMD="ewarn" + return 0 +} + +eerror() { + __elog_base ERROR "$*" + echo -e " ${PKGCORE_RC_BAD}*${PKGCORE_RC_NORMAL} $*" >&2 + PKGCORE_RC_LAST_CMD="eerror" + return 0 +} + +ebegin() { + local msg="$* ..." + einfon "${msg}" + echo + PKGCORE_RC_LAST_CMD="ebegin" + return 0 +} + +eend() { + local retval=${1:-0} + shift + + local msg + + if [[ ${retval} == 0 ]]; then + msg="${PKGCORE_RC_BRACKET}[ ${PKGCORE_RC_GOOD}ok${PKGCORE_RC_BRACKET} ]${PKGCORE_RC_NORMAL}" + else + if [[ $# -ne 0 ]]; then + eerror "$*" + fi + msg="${PKGCORE_RC_BRACKET}[ ${PKGCORE_RC_BAD}!!${PKGCORE_RC_BRACKET} ]${PKGCORE_RC_NORMAL}" + fi + + echo -e "${PKGCORE_RC_ENDCOL} ${msg}" + + return ${retval} +} + +KV_major() { + [[ -z $1 ]] && return 1 + + local KV=$@ + echo "${KV%%.*}" +} + +KV_minor() { + [[ -z $1 ]] && return 1 + + local KV=$@ + KV=${KV#*.} + echo "${KV%%.*}" +} + +KV_micro() { + [[ -z $1 ]] && return 1 + + local KV=$@ + KV=${KV#*.*.} + echo "${KV%%[^[:digit:]]*}" +} + +KV_to_int() { + [[ -z $1 ]] && return 1 + + local KV_MAJOR=$(KV_major "$1") + local KV_MINOR=$(KV_minor "$1") + local KV_MICRO=$(KV_micro "$1") + local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO )) + + # We make version 2.2.0 the minimum version we will handle as + # a sanity check ... if its less, we fail ... + if [[ ${KV_int} -ge 131584 ]]; then + echo "${KV_int}" + return 0 + fi + + return 1 +} + +get_KV() { + echo $(KV_to_int "$(uname -r)") +} + +: diff --git a/bash/ebuild-daemon.bash b/bash/ebuild-daemon.bash new file mode 100755 index 000000000..75e65f78b --- /dev/null +++ b/bash/ebuild-daemon.bash @@ -0,0 +1,453 @@ +#!/bin/bash +# ebuild-daemon.bash; core ebuild processor handling code +# Copyright 2004-2012 Brian Harring +# License: BSD/GPL2 + +# These are functions that shouldn't be marked readonly, since they're runtime +# switchable. +PKGCORE_RUNTIME_FUNCS=( '__timed_call' ) + +__set_perf_debug() { + if [[ ${PKGCORE_DEBUG} -ge 4 || -n ${PKGCORE_PERF_DEBUG} ]]; then + __timed_call() { + echo "timing $*" >&2 + time "$@" + local __ret=$? + echo "timed $*" >&2 + return ${__ret} + } + else + __timed_call() { + "$@" + } + fi +} + +__set_perf_debug + +die() { + # Temporary function used by the daemon, till proper die implementation is loaded. + echo "$@" >&2 + exit 1 +} + +STARTING_PID=${BASHPID} +# use ebd_read/ebd_write for talking to the running portage instance instead of echo'ing to the fd yourself. +# this allows us to move the open fd's w/out issues down the line. +__ebd_read_line_nonfatal() { + read -u ${PKGCORE_EBD_READ_FD} $1 +} + +__ebd_read_line() { + __ebd_read_line_nonfatal "$@" + local ret=$? + [[ ${ret} -ne 0 ]] && \ + die "coms error in ${STARTING_PID}, read_line $@ failed w/ ${ret}: backing out of daemon." +} + +# are we running a version of bash (4.1 or so) that does -N? +if echo 'y' | read -N 1 &> /dev/null; then + __ebd_read_size() + { + read -u ${PKGCORE_EBD_READ_FD} -r -N $1 $2 + local ret=$? + [[ ${ret} -ne 0 ]] && \ + die "coms error in ${STARTING_PID}, read_size $@ failed w/ ${ret}: backing out of daemon." + } +else + # fallback to a *icky icky* but working alternative. + __ebd_read_size() { + eval "${2}=\$(dd bs=1 count=$1 <&${PKGCORE_EBD_READ_FD} 2> /dev/null)" + local ret=$? + [[ ${ret} -ne 0 ]] && \ + die "coms error in ${STARTING_PID}, read_size $@ failed w/ ${ret}: backing out of daemon." + } +fi + +__ebd_read_cat_size() { + dd bs=$1 count=1 <&${PKGCORE_EBD_READ_FD} +} + +__ebd_write_line() { + echo "$*" >&${PKGCORE_EBD_WRITE_FD} + local ret=$? + [[ ${ret} -ne 0 ]] && \ + die "coms error, write failed w/ ${ret}: backing out of daemon." +} + +__ebd_write_raw() { + echo -n "$*" >&${PKGCORE_EBD_WRITE_FD} || die "coms error, __ebd_write_raw failed; Backing out." +} + +for x in ebd_read_{line,{cat_,}size} __ebd_write_line __set_perf_debug; do + declare -rf ${x} +done +unset x +declare -r PKGCORE_EBD_WRITE_FD PKGCORE_EBD_READ_FD + +__ebd_sigint_handler() { + EBD_DISABLE_DIEFUNC="yes" + # silence ourselves as everything shuts down. + exec 2>/dev/null + exec 1>/dev/null + # suppress sigpipe; if we can't tell the parent to die, + # it's already shutting us down. + trap "exit 2" SIGPIPE + __ebd_write_line "killed" + trap - SIGINT + # this relies on the python side to *not* discard the killed + exit 2 +} + +__ebd_sigkill_handler() { + EBD_DISABLE_DIEFUNC="yes" + # silence ourselves as everything shuts down. + exec 2>/dev/null + exec 1>/dev/null + # suppress sigpipe; if we can't tell the parent to die, + # it's already shutting us down. + trap "exit 9" SIGPIPE + __ebd_write_line "killed" + trap - SIGKILL + exit 9 +} + +__ebd_exec_main() { + # ensure the other side is still there. Well, this moreso is for the python side to ensure + # loading up the intermediate funcs succeeded. + __ebd_read_line com + if [[ ${com} != "dude?" ]]; then + echo "serv init coms failed, received ${com} when expecting 'dude?'" >&2 + exit 1 + fi + __ebd_write_line "dude!" + __ebd_read_line PKGCORE_BIN_PATH + [[ -z ${PKGCORE_BIN_PATH} ]] && { __ebd_write_line "empty PKGCORE_BIN_PATH;"; exit 1; } + + if ! source "${PKGCORE_BIN_PATH}"/exit-handling.lib; then + __ebd_write_line "failed sourcing exit handling functionality" + exit 2 + fi + + # get our die functionality now. + if ! source "${PKGCORE_BIN_PATH}"/isolated-functions.lib; then + __ebd_write_line "failed sourcing isolated-functions.lib" + exit 2 + fi + + __ebd_read_line PKGCORE_PYTHON_BINARY + [[ -z ${PKGCORE_PYTHON_BINARY} ]] && die "empty PKGCORE_PYTHON_BINARY, bailing" + __ebd_read_line PKGCORE_PYTHONPATH + [[ -z ${PKGCORE_PYTHONPATH} ]] && die "empty PKGCORE_PYTHONPATH, bailing" + + if ! source "${PKGCORE_BIN_PATH}"/ebuild.lib >&2; then + __ebd_write_line "failed" + die "failed sourcing ${PKGCORE_BIN_PATH}/ebuild.lib" + fi + + if [[ -n ${SANDBOX_LOG} ]]; then + __ebd_read_line com + if [[ ${com} != "sandbox_log?" ]]; then + echo "unknown com '${com}'" + exit 1 + fi + __ebd_write_line "${SANDBOX_LOG}" + declare -rx SANDBOX_LOG=${SANDBOX_LOG} + addwrite "${SANDBOX_LOG}" + fi + + re=$(readonly | cut -s -d '=' -f 1 | cut -s -d ' ' -f 3) + for x in ${re}; do + if ! __safe_has "${x}" "${DONT_EXPORT_VARS}"; then + DONT_EXPORT_VARS+=" ${x}" + fi + done + __ebd_write_line ${re} + unset x re + + # protect ourselves. + declare -rx PKGCORE_BIN_PATH=${PKGCORE_BIN_PATH} + declare -rx PKGCORE_PYTHON_BINARY=${PKGCORE_PYTHON_BINARY} + declare -rx PKGCORE_PYTHONPATH=${PKGCORE_PYTHONPATH} + + if ! source "${PKGCORE_BIN_PATH}"/ebuild-daemon.lib >&2; then + __ebd_write_line "failed" + die "failed sourcing ${PKGCORE_BIN_PATH}/ebuild-daemon.lib" + fi + + __colored_output_disable + declare -A PKGCORE_PRELOADED_ECLASSES + + trap __ebd_sigint_handler SIGINT + trap __ebd_sigkill_handler SIGKILL + + # finally, load the master list of pkgcore funcs. fallback to + # regenerating it if needed. + if [[ -e ${PKGCORE_BIN_PATH}/dont_export_funcs.list ]]; then + DONT_EXPORT_FUNCS+=" $(<"${PKGCORE_BIN_PATH}"/dont_export_funcs.list)" + else + DONT_EXPORT_FUNCS+=" $("${PKGCORE_BIN_PATH}"/regenerate_dont_export_func_list.bash 2> /dev/null)" + fi + + DONT_EXPORT_FUNCS+=" ${PORTAGE_PRELOADED_ECLASSES}" + for x in ${DONT_EXPORT_FUNCS}; do + __is_function "${x}" || continue + if ! __safe_has "${x}" "${PKGCORE_RUNTIME_FUNCS[@]}"; then + declare -fr ${x} &> /dev/null + fi + done + unset x + + # depend's speed up. turn on qa interceptors by default, instead of flipping them on for each depends; + # same for loading depends .lib + # important- this needs be loaded after the declare -fr so it doesn't get marked as readonly. + # call. + export QA_CONTROLLED_EXTERNALLY="yes" + __qa_interceptors_enable + + source "${PKGCORE_BIN_PATH}"/eapi/depend.lib >&2 || die "failed sourcing eapi/depend.lib" + __ebd_main_loop + exit 0 +} + +__ebd_process_sandbox_results() { + if [[ -z ${SANDBOX_LOG} || ! -e ${SANDBOX_LOG} ]]; then + return 0; + fi + echo "sandbox exists- ${SANDBOX_LOG}" >&2 + __request_sandbox_summary >&2 + echo "SANDBOX_ON:=${SANDBOX_ON:-unset}" >&2 + echo "SANDBOX_DISABLED:=${SANDBOX_DISABLED:-unset}" >&2 + echo "SANDBOX_READ:=${SANDBOX_READ:-unset}" >&2 + echo "SANDBOX_WRITE:=${SANDBOX_WRITE:-unset}" >&2 + echo "SANDBOX_PREDICT:=${SANDBOX_PREDICT:-unset}" >&2 + echo "SANDBOX_DEBUG:=${SANDBOX_DEBUG:-unset}" >&2 + echo "SANDBOX_DEBUG_LOG:=${SANDBOX_DEBUG_LOG:-unset}" >&2 + echo "SANDBOX_LOG:=${SANDBOX_LOG:-unset}" >&2 + echo "SANDBOX_ARMED:=${SANDBOX_ARMED:-unset}" >&2 + return 1 +} + +__ebd_process_ebuild_phases() { + # note that this is entirely subshelled; as such exit is used rather than returns + ( + declare -r PKGCORE_QA_SUPPRESSED=false + local phases=$@ + local is_depends=true + if [[ ${phases/depend} == ${phases} ]]; then + is_depends=false + __qa_interceptors_disable + fi + local cont=0 + + while [[ ${cont} == 0 ]]; do + local line='' + __ebd_read_line line + case ${line} in + start_receiving_env*) + line=${line#start_receiving_env } + case ${line} in + file*) + line=${line#file } + source "${line}" + cont=$? + ;; + bytes*) + line=${line#bytes } + __ebd_read_size "${line}" line + __IFS_push $'\0' + eval "${line}" + cont=$? + __IFS_pop + ;; + lines) + ;& + *) + while __ebd_read_line line && [[ ${line} != "end_receiving_env" ]]; do + __IFS_push $'\0' + eval "${line}" + cont=$? + __IFS_pop + if [[ ${cont} != 0 ]]; then + echo "err, env receiving threw an error for '${line}': $?" >&2 + break + fi + done + ;; + esac + if [[ ${cont} != 0 ]]; then + __ebd_write_line "env_receiving_failed" + exit 1 + fi + __set_perf_debug + __ebd_write_line "env_received" + ;; + logging*) + PORTAGE_LOGFILE=${line#logging } + __ebd_write_line "logging_ack" + ;; + set_sandbox_state*) + if [[ $(( ${line:18} )) -eq 0 ]]; then + export SANDBOX_DISABLED=1 + else + export SANDBOX_DISABLED=0 + export SANDBOX_VERBOSE="no" + fi + ;; + start_processing) + if ${is_depends} && [[ -n ${PKGCORE_METADATA_PATH} ]]; then + export PATH=${PKGCORE_METADATA_PATH} + fi + cont=2 + ;; + shutdown_daemon) + break + ;; + *) + echo "received unknown com during phase processing: ${line}" >&2 + exit 1 + ;; + esac + done + if [[ ${cont} != 2 ]]; then + exit ${cont} + fi + + [[ -n ${PORTAGE_LOGFILE} ]] && addwrite "$(readlink -f "${PORTAGE_LOGFILE}")" + + [[ -z ${RC_NOCOLOR} ]] && __colored_output_enable + + [[ -n ${PORTAGE_TMPDIR} ]] && { + addpredict "${PORTAGE_TMPDIR}" + addwrite "${PORTAGE_TMPDIR}" + addread "${PORTAGE_TMPDIR}" + } + + local ret + umask 0022 + + if [[ -z ${PORTAGE_LOGFILE} ]]; then + __execute_phases ${phases} + ret=$? + else + __execute_phases ${phases} &> >(umask 0002; tee -i -a "${PORTAGE_LOGFILE}") + ret=$? + fi + + if [[ ${ret} -ne 0 ]]; then + __ebd_process_sandbox_results + exit ${ret} + fi + exit 0 + ) +} + +__ebd_process_metadata() { + # protect the env. + # note the local usage is redundant in light of it, but prefer to write it this + # way so that if someone ever drops the (), it'll still not bleed out. + ( + # Heavy QA checks (IFS, shopt, etc) are suppressed for speed + declare -r PKGCORE_QA_SUPPRESSED=false + # Wipe __mode; it bleeds from our parent. + unset __mode + local __data + local __ret + __ebd_read_size "$1" __data + local IFS=$'\0' + eval "$__data" + __ret=$? + unset __data + [[ ${__ret} -ne 0 ]] && exit 1 + unset __ret + local IFS=$' \t\n' + + if [[ -n ${PKGCORE_METADATA_PATH} ]]; then + export PATH=${PKGCORE_METADATA_PATH} + fi + + PORTAGE_SANDBOX_PID=${PPID} + __execute_phases "${2:-depend}" && exit 0 + __ebd_process_sandbox_results + exit 1 + ) +} + +__make_preloaded_eclass_func() { + eval "__preloaded_eclass_$1() { + $2 + }" + PKGCORE_PRELOADED_ECLASSES[$1]=__preloaded_eclass_$1 +} + +__ebd_main_loop() { + DONT_EXPORT_VARS+=" com phases line cont DONT_EXPORT_FUNCS STARTING_PID" + SANDBOX_ON=1 + while :; do + local com='' + # If we don't manage to read, this means that the other end hung up. + # exit. + __ebd_read_line_nonfatal com || com="shutdown_daemon" + case ${com} in + process_ebuild*) + # cleanse whitespace. + local phases=$(echo ${com#process_ebuild}) + PORTAGE_SANDBOX_PID=${PPID} + __ebd_process_ebuild_phases ${phases} + # tell python if it succeeded or not. + if [[ $? -ne 0 ]]; then + __ebd_write_line "phases failed" + else + __ebd_write_line "phases succeeded" + fi + ;; + shutdown_daemon) + break + ;; + preload_eclass\ *) + success="succeeded" + com=${com#preload_eclass } + for e in ${com}; do + x=${e##*/} + x=${x%.eclass} + if ! $(type -P bash) -n "${e}"; then + echo "errors detected in '${e}'" >&2 + success='failed' + break + fi + __make_preloaded_eclass_func "${x}" "$(< "${e}")" + done + __ebd_write_line "preload_eclass ${success}" + unset e x success + ;; + clear_preloaded_eclasses) + unset PKGCORE_PRELOADED_ECLASSES + declare -A PKGCORE_PRELOADED_ECLASSES + __ebd_write_line "clear_preloaded_eclasses succeeded" + ;; + set_metadata_path\ *) + line=${com#set_metadata_path } + __ebd_read_size "${line}" PKGCORE_METADATA_PATH + __ebd_write_line "metadata_path_received" + ;; + gen_metadata\ *|gen_ebuild_env\ *) + local __mode="depend" + [[ ${com} == gen_ebuild_env* ]] && __mode="generate_env" + line=${com#* } + if __ebd_process_metadata "${line}" "${__mode}"; then + __ebd_write_line "phases succeeded" + else + __ebd_write_line "phases failed" + fi + ;; + *) + echo "received unknown com: ${com}" >&2 + exit 1 + ;; + esac + done +} + +[[ -z ${PKGCORE_SOURCING_FOR_REGEN_FUNCS_LIST} ]] && __ebd_exec_main + +: diff --git a/bash/ebuild-daemon.lib b/bash/ebuild-daemon.lib new file mode 100644 index 000000000..f0fa81233 --- /dev/null +++ b/bash/ebuild-daemon.lib @@ -0,0 +1,62 @@ +#!/bin/bash +# ebuild-daemon.lib; daemon lib code. +# Copyright 2005-2012 Brian Harring +# License BSD/GPL2 + +# ask the python side to display sandbox complaints. +__request_sandbox_summary() { + local line + __ebd_write_line "__request_sandbox_summary ${SANDBOX_LOG}" + __ebd_read_line line + while [[ ${line} != "end_sandbox_summary" ]]; do + echo "${line}" + __ebd_read_line line + done +} + +__internal_inherit() { + local line + if [[ $# -ne 1 ]]; then + die "internal_inherit accepts one arg, requested eclass location. $* is a bit much" + fi + if [[ -n ${PKGCORE_PRELOADED_ECLASSES[$1]} ]]; then + __qa_invoke "${PKGCORE_PRELOADED_ECLASSES[$1]}" + return + fi + __ebd_write_line "request_inherit $1" + __ebd_read_line line + if [[ ${line} == "path" ]]; then + __ebd_read_line line + __qa_invoke source "${line}" >&2 || die "failed sources inherit: ${line}" + elif [[ ${line} == "transfer" ]]; then + __ebd_read_line line + __qa_invoke eval "${line}" || die "failed evaluating eclass $1 on an inherit transfer" + elif [[ ${line} == "failed" ]]; then + die "inherit for $1 failed" + else + die "unknown inherit command from pythonic side, '${line}' for eclass $1" + fi +} + +__source_bashrcs() { + ${PKGCORE_SUPPRESS_BASHRCS:-false} && return + local line + __ebd_write_line "request_bashrcs" + __ebd_read_line line + while [[ ${line} != "end_request" ]]; do + if [[ ${line} == "path" ]]; then + __ebd_read_line line + source "${line}" >&2 + elif [[ ${line} == "transfer" ]]; then + __ebd_read_line line + eval "${line}" || die "failed evaluating profile bashrc: ${line}" + else + __ebd_write_line "failed" + die "unknown profile bashrc transfer mode from pythonic side, '${line}'" + fi + __ebd_write_line "next" + __ebd_read_line line + done +} + +: diff --git a/bash/ebuild-default-functions.lib b/bash/ebuild-default-functions.lib new file mode 100644 index 000000000..70a0f4735 --- /dev/null +++ b/bash/ebuild-default-functions.lib @@ -0,0 +1,309 @@ +#!/bin/bash +# ebuild-default-functions.sh; default functions for ebuild env that aren't saved- specific to the portage instance. +# Copyright 2005-2012 Brian Harring : BSD/GPL2 +# Copyright 2004-2006 Gentoo Foundation: GPL2 + +# sandbox support functions +addread() { + export SANDBOX_READ=${SANDBOX_READ}:$1 +} + +addwrite() { + export SANDBOX_WRITE=${SANDBOX_WRITE}:$1 +} + +adddeny() { + export SANDBOX_DENY=${SANDBOX_DENY}:$1 +} + +addpredict() { + export SANDBOX_PREDICT=${SANDBOX_PREDICT}:$1 +} + +__dyn_src_install() { + local f + echo + if ${PKGCORE_PREFIX_SUPPORT}; then + echo ">>> Install ${PF} into ${ED} category ${CATEGORY}" + else + echo ">>> Install ${PF} into ${D} category ${CATEGORY}" + fi + if __is_function src_install; then + __qa_invoke src_install + else + __qa_run_function_if_exists __phase_default_src_install + fi + + "${PKGCORE_BIN_PATH}"/helpers/internals/prepall + ${PKGCORE_PREFIX_SUPPORT} || local ED=${D} + cd "${ED}" + + if type -p scanelf > /dev/null; then + # Make sure we disallow insecure RUNPATH/RPATH's + # Don't want paths that point to the tree where the package was built + # (older, broken libtools would do this). Also check for null paths + # because the loader will search $PWD when it finds null paths. + f=$(scanelf -qyRF '%r %p' "${ED}" | grep -E "(${WORKDIR}|${ED}|: |::|^ )") + if [[ -n ${f} ]]; then + echo -ne '\a\n' + echo "QA Notice: the following files contain insecure RUNPATH's" + echo " Please file a bug about this at http://bugs.gentoo.org/" + echo " For more information on this issue, kindly review:" + echo " http://bugs.gentoo.org/81745" + echo "${f}" + echo -ne '\a\n' + __feature_is_enabled stricter && die "Insecure binaries detected" + echo "autofixing rpath..." + TMPDIR=${WORKDIR} scanelf -BXr ${f} -o /dev/null + fi + + # Check for setid binaries but are not built with BIND_NOW + f=$(scanelf -qyRF '%b %p' "${ED}") + if [[ -n ${f} ]]; then + echo -ne '\a\n' + echo "QA Notice: the following files are setXid, dyn linked, and using lazy bindings" + echo " This combination is generally discouraged. Try forcing via bashrc" + echo " LDFLAGS='-Wl,-z,now' for the pkg, or disable FEATURES=stricter" + echo "${f}" + echo -ne '\a\n' + __feature_is_enabled stricter && die "Aborting due to lazy bindings" + sleep 1 + fi + + # TEXTREL's are baaaaaaaad + f=$(scanelf -qyRF '%t %p' "${ED}") + if [[ -n ${f} ]]; then + echo -ne '\a\n' + echo "QA Notice: the following files contain runtime text relocations" + echo " Text relocations require a lot of extra work to be preformed by the" + echo " dynamic linker which will cause serious performance impact on IA-32" + echo " and might not function properly on other architectures hppa for example." + echo " If you are a programmer please take a closer look at this package and" + echo " consider writing a patch which addresses this problem." + echo "${f}" + echo -ne '\a\n' + __feature_is_enabled stricter && die "Aborting due to textrels" + sleep 1 + fi + + # Check for files with executable stacks + f=$(scanelf -qyRF '%e %p' "${ED}") + if [[ -n ${f} ]]; then + echo -ne '\a\n' + echo "QA Notice: the following files contain executable stacks" + echo " Files with executable stacks will not work properly (or at all!)" + echo " on some architectures/operating systems. A bug should be filed" + echo " at http://bugs.gentoo.org/ to make sure the file is fixed." + echo "${f}" + echo -ne '\a\n' + __feature_is_enabled stricter && die "Aborting due to +x stack" + sleep 1 + fi + + # Create NEEDED and NEEDED.ELF.2 files required for things like preserve-libs + # TODO: someday find a way to move this to the triggers implementation to allow + # for parallelization of the scanning- if useful. + scanelf -qyRF '%a;%p;%S;%r;%n' "${ED}" | { while IFS= read -r l; do + arch=${l%%;*}; l=${l#*;} + obj="/${l%%;*}"; l=${l#*;} + soname=${l%%;*}; l=${l#*;} + rpath=${l%%;*}; l=${l#*;}; [[ ${rpath} == " - " ]] && rpath="" + needed=${l%%;*}; l=${l#*;} + echo "${obj} ${needed}" >> "${T}"/NEEDED + echo "${arch:3};${obj};${soname};${rpath};${needed}" >> "${T}"/NEEDED.ELF.2 + done } + fi + + echo ">>> Completed installing ${PF} into ${ED}" + echo + unset dir +} + +__dyn_pkg_preinst() { + if __is_function pkg_preinst; then + __qa_invoke pkg_preinst + else + __qa_run_function_if_exists __phase_default_pkg_preinst + fi + + ${PKGCORE_PREFIX_SUPPORT} || local ED=${D} + + # total suid control. + if __feature_is_enabled suidctl > /dev/null; then + sfconf=/etc/portage/suidctl.conf + echo ">>> Preforming suid scan in ${ED}" + local i + for i in $(find "${ED}"/ -type f \( -perm -4000 -o -perm -2000 \) ); do + if [[ -s ${sfconf} ]]; then + suid=$(grep ^${i/${ED}/}$ "${sfconf}") + if [[ ${suid} == ${i/${ED}/} ]]; then + echo "- ${i/${ED}/} is an approved suid file" + else + echo ">>> Removing sbit on non registered ${i/${ED}/}" + chmod ugo-s "${i}" + grep ^#${i/${ED}/}$ ${sfconf} > /dev/null || { + # sandbox prevents us from writing directly + # to files outside of the sandbox, but this + # can easly be bypassed using the addwrite() function + addwrite "${sfconf}" + echo ">>> Appending commented out entry to ${sfconf} for ${PF}" + ls_ret=$(ls -ldh "${i}") + echo "## ${ls_ret%${ED}*}${ls_ret#*${ED}}" >> "${sfconf}" + echo "#${i/${ED}/}" >> "${sfconf}" + # no delwrite() eh? + # delwrite ${sconf} + } + fi + else + echo "suidctl feature set but you are lacking a ${sfconf}" + fi + done + fi + + # SELinux file labeling (needs to always be last in dyn_preinst) + if __feature_is_enabled selinux; then + # only attempt to label if setfiles is executable + # and 'context' is available on selinuxfs. + if [[ -f /selinux/context && -x /usr/sbin/setfiles ]]; then + echo ">>> Setting SELinux security labels" + if [[ -f ${POLICYDIR}/file_contexts/file_contexts ]]; then + cp -f "${POLICYDIR}"/file_contexts/file_contexts "${T}" + else + make -C "${POLICYDIR}" FC=${T}/file_contexts "${T}"/file_contexts + fi + + addwrite /selinux/context + /usr/sbin/setfiles -r "${ED}" "${T}"/file_contexts "${ED}" \ + || die "Failed to set SELinux security labels." + else + # nonfatal, since merging can happen outside a SE kernel + # like during a recovery situation + echo "!!! Unable to set SELinux security labels" + fi + fi +} + +__internal_inherit() { + # default, backwards compatible beast. + local location overlay + location=${ECLASSDIR}/${1}.eclass + + if [[ -n ${PORTDIR_OVERLAY} ]]; then + local overlay + for overlay in ${PORTDIR_OVERLAY}; do + if [[ -e ${overlay}/eclass/${1}.eclass ]]; then + location=${overlay}/eclass/${1}.eclass + debug-print " eclass exists: ${location}" + fi + done + fi + debug-print "inherit: $1 -> ${location}" + __qa_invoke source "${location}" >&2 || die "died sourcing ${location} in inherit()" + return 0 +} + +inherit() { + local ECLASS_DEPTH=$(( ${ECLASS_DEPTH-0} + 1 )) + + if [[ ${ECLASS_DEPTH} -gt 1 ]]; then + debug-print "*** Multiple Inheritence (Level: ${ECLASS_DEPTH})" + fi + + local location olocation + local ECLASS + + # note that this ensures any later unsets/mangling, the ebuilds original + # setting is protected. + local IUSE REQUIRED_USE DEPEND RDEPEND PDEPEND + + for ECLASS in "$@"; do + if [[ ${EBUILD_PHASE} != "depend" ]]; then + if ! __safe_has "${ECLASS}" ${INHERITED}; then + echo + echo "QA Notice: ECLASS '${ECLASS}' illegal conditional inherit in ${CATEGORY}/${PF}" >&2 + echo + fi + fi + + unset IUSE REQUIRED_USE DEPEND RDEPEND PDEPEND + + __internal_inherit "$1" || die "failed sourcing $1 in inherit()" + + # If each var has a value, append it to the global variable E_* to + # be applied after everything is finished. New incremental behavior. + [[ -n ${IUSE} ]] && E_IUSE+=${E_IUSE:+ }${IUSE} + [[ -n ${REQUIRED_USE} ]] && E_REQUIRED_USE+=${E_REQUIRED_USE:+ }${REQUIRED_USE} + [[ -n ${DEPEND} ]] && E_DEPEND+=${E_DEPEND:+ }${DEPEND} + [[ -n ${RDEPEND} ]] && E_RDEPEND+=${E_RDEPEND:+ }${RDEPEND} + [[ -n ${PDEPEND} ]] && E_PDEPEND+=${E_PDEPEND:+ }${PDEPEND} + + # while other PMs have checks to keep this unique, we don't; no need, + # further up the stack (python side) we uniquify this. + # if you try to do it in bash rather than python, it's ~10% slower regen + INHERITED+=" ${ECLASS}" + + shift + done +} + +# Exports stub functions that call the eclass's functions, thereby making them default. +# For example, if ECLASS="base" and you call "EXPORT_FUNCTIONS src_unpack", the following +# code will be eval'd: +# src_unpack() { base_src_unpack; } +EXPORT_FUNCTIONS() { + if [[ -z ${ECLASS} ]]; then + echo "EXPORT_FUNCTIONS without a defined ECLASS" >&2 + exit 1 + fi + while [[ -n $1 ]]; do + debug-print "EXPORT_FUNCTIONS: $1 -> ${ECLASS}_$1" + eval "$1() { ${ECLASS}_$1 "\$@" ; }" > /dev/null + shift + done +} + +PKGCORE_QA_INTERCEPTORS=( + javac java-config python python-config perl grep egrep fgrep sed + gcc "g++" cc bash awk nawk pkg-config +) +__QA_INTERCEPTORS_ACTIVE=false + +__qa_interceptors_enable() { + # Turn off extended glob matching so that g++ doesn't get incorrectly matched. + shopt -u extglob + + ${__QA_INTERCEPTORS_ACTIVE} && return + # QA INTERCEPTORS + local BIN BODY BIN_PATH + for BIN in "${PKGCORE_QA_INTERCEPTORS[@]}"; do + BIN_PATH=$(type -pf ${BIN}) + if [[ $? != 0 ]]; then + BODY="echo \"*** missing command: ${BIN}\" >&2; return 127" + else + BODY="${BIN_PATH} \"\$@\"; return \$?" + fi + eval "${BIN}() { + echo -n \"QA Notice: ${BIN} in global scope: \" >&2 + if [[ \${ECLASS_DEPTH} -gt 0 ]]; then + echo \"eclass \${ECLASS}\" >&2 + else + echo \"\${CATEGORY}/\${PF}\" >&2 + fi + ${BODY} + }" || echo "error creating QA interceptor ${BIN}" >&2 + done + __QA_INTERCEPTORS_ACTIVE=true +} &> /dev/null + +__qa_interceptors_disable() { + ${__QA_INTERCEPTORS_ACTIVE} || return + local x + for x in "${PKGCORE_QA_INTERCEPTORS[@]}"; do + unset -f ${x} + done + __QA_INTERCEPTORS_ACTIVE=false +} &> /dev/null + +DONT_EXPORT_VARS+=" ECLASS_DEPTH __QA_INTERCEPTORS_ACTIVE" + +: diff --git a/bash/ebuild-env-utils.lib b/bash/ebuild-env-utils.lib new file mode 100644 index 000000000..d064e1654 --- /dev/null +++ b/bash/ebuild-env-utils.lib @@ -0,0 +1,201 @@ +# Copyright 2005-2012 Brian Harring : BSD/GPL2 +# this functionality is all related to saving/loading environmental dumps for ebuilds + +__regex_filter_input() { + # We don't need to reset IFS in this context, thus skip the pop. + local IFS='|' + local regex="^(${*})$" + # use egrep if possible... tis faster. + local l + if l=$(type -P gsed || type -P sed); then + "${l}" -re "/${regex}/d" + local ret=$? + [[ ${ret} != 0 ]] && die "got failing return code (${ret}) invoking ${l} -e '/${regex}/d'" + elif l=$(type -P egrep); then + # use type -p; qa_interceptors may be active. + "${l}" -v "${regex}" + local ret=$? + [[ ${ret} -gt 1 ]] && die "got failing return code (${ret}) ${l} -v '${regex}'" + elif [[ -x ${PKGCORE_PYTHON_BINARY} ]]; then + # We check for the binary on the offchance an ebuild operation + # just removed it under our feet. + "${PKGCORE_PYTHON_BINARY}" -c \ + 'import sys;import re;r=re.compile(sys.argv[1]).match;sys.stdout.write("\n".join(x for x in sys.stdin.read().splitlines() if r(x) is None))' \ + "${regex}" + local ret=$? + [[ ${ret} != 0 ]] && die "got failing return code (${ret}) invoking ${PKGCORE_PYTHON_BINARY} for regex_filter" + else + while read l; do + [[ ${l} =~ ${regex} ]] || echo "${l}" + done + fi +} + +__escape_regex_array() { + local __tmp_array + # Need to get the content of the original array... + eval "__tmp_array=( \"\${$1[@]}\" )" + __tmp_array=( "${__tmp_array[@]//\+/\\+}" ) + __tmp_array=( "${__tmp_array[@]//\./\\.}" ) + __tmp_array=( "${__tmp_array[@]//\*/\\*}" ) + # Now transfer the content back. + eval $1='( "${__tmp_array[@]}" )' +} &> /dev/null + +__environ_list_funcs() { + # Grab the vars /before/ adding our custom declare function, else it'll + # show up in the list of functions. + local __content=$(builtin declare -F) + declare() { + echo "$2" + } + eval "${__content}" || die "__environ_list_funcs eval failed" >&2 + unset -f declare + : +} + +__environ_list_vars() { + declare() { + local __ret=${2%%=*} + [[ $2 != ${__ret} ]] && echo "${__ret}" + : + } + eval "$(builtin declare -p)" || die "__environ_list_vars eval failed" >&2 + unset -f declare + : +} + +__filter_env() { + local opts + [[ ${PKGCORE_DEBUG} -ge 3 ]] && opts="--debug" + PYTHONPATH="${PKGCORE_PYTHONPATH}" "${PKGCORE_PYTHON_BINARY}" \ + $(type -P filter-env) ${opts} "$@" || die "filter-env invocation failed" +} + +# selectively saves the environ- specifically removes things that have been marked to not be exported. +# dump the environ to stdout. +__environ_dump() { + __shopt_push -f + local __func_filters=( ${DONT_EXPORT_FUNCS} ${PKGCORE_EAPI_FUNCS} "${PKGCORE_PRELOADED_ECLASSES[@]}" ) + ${__QA_INTERCEPTORS_ACTIVE:-false} && __func_filters+=( "${PKGCORE_QA_INTERCEPTORS[@]}" ) + + # Punt any regex chars... + __escape_regex_array __func_filters + __PKGCORE_TARGETS=( $(__environ_list_funcs | __regex_filter_input "${__func_filters[@]}" ) ) + unset __func_filters + if [[ ${#__PKGCORE_TARGETS[@]} -ne 0 ]]; then + declare -f "${__PKGCORE_TARGETS[@]}" || die "failed outputting funcs ${__PKGCORE_TARGETS[@]}" >&2 + fi + + __PKGCORE_TARGETS=( $(__environ_list_vars | __regex_filter_input ${DONT_EXPORT_VARS} __PKGCORE_TARGETS) ) + if [[ ${#__PKGCORE_TARGETS[@]} -ne 0 ]]; then + declare -p "${__PKGCORE_TARGETS[@]}" || die "failed outputting env vars ${__PKGCORE_TARGETS[@]}" >&2 + fi + + __shopt_pop +} + +# dump environ to $1, optionally piping it through $2 and redirecting $2's output to $1. +__environ_save_to_file() { + if [[ $# -ne 1 && $# -ne 2 ]]; then + die "__environ_save_to_file requires at least one argument, two max; given $@" + fi + + # the spaces on both sides are important- otherwise, the later ${DONT_EXPORT_VARS/ temp_umask /} won't match. + # we use spaces on both sides, to ensure we don't remove part of a variable w/ the same name- + # ex: temp_umask_for_some_app == _for_some_app. + #Do it with spaces on both sides. + + DONT_EXPORT_VARS+=" temp_umask " + local temp_umask=$(umask) + umask 0002 + + if [[ $# -eq 1 ]]; then + __environ_dump > "$1" + else + __environ_dump | $2 > "$1" + fi + chown portage:portage "$1" &> /dev/null + chmod 0664 "$1" &> /dev/null + + DONT_EXPORT_VARS=${DONT_EXPORT_VARS/ temp_umask /} + + umask ${temp_umask} +} + +# reload a saved env, applying usual filters to the env prior to eval'ing it. +__environ_sanitize_saved_env() { + local src e ret EXISTING_PATH + # localize these so the reload doesn't have the ability to change them + + if [[ $# -ne 1 ]]; then + die "scrub_environ called with wrong args, only one can be given: $@" + fi + + [[ ! -f $1 ]] && die "__environ_sanitize_saved_env called with a nonexist env: $1" + + src=$1 + + # here's how this goes; we do an eval'd loadup of the target env w/in a subshell.. + # declares and such will slide past filter-env (so it goes). we then use our own + # __environ_dump from within to get a clean dump from that env, and load it into + # the parent eval. + ( + + # protect the core vars and functions needed to do a __environ_dump + # some of these are already readonly- we still are forcing it to be safe. + declare -r PKGCORE_PYTHONPATH=${PKGCORE_PYTHONPATH} &> /dev/null + declare -r PKGCORE_PYTHON_BINARY=${PKGCORE_PYTHON_BINARY} &> /dev/null + declare -r DONT_EXPORT_VARS=${DONT_EXPORT_VARS} &> /dev/null + declare -r DONT_EXPORT_FUNCS=${DONT_EXPORT_FUNCS} &> /dev/null + declare -r SANDBOX_ON=${SANDBOX_ON} &> /dev/null + declare -r T=${T} &> /dev/null +# declare -rx PATH=${PATH} &> /dev/null + + readonly -f __filter_env &> /dev/null + readonly -f __environ_dump &> /dev/null + readonly -f __regex_filter_input &> /dev/null + + __shopt_push -f + IFS=$' \t\n' + declare -a PKGCORE_FUNC_ARRAY=( ${DONT_EXPORT_FUNCS} ) + declare -a PKGCORE_VAR_ARRAY=( ${DONT_EXPORT_VARS} src x EXISTING_PATH ) + IFS=, + PKGCORE_FUNC_ARRAY=${PKGCORE_FUNC_ARRAY[*]} + PKGCORE_VAR_ARRAY=${PKGCORE_VAR_ARRAY[*]} + IFS=$' \t\n' + __shopt_pop + + rm -f "${T}"/.pre-scrubbed-env || die "failed rm'ing" + # run the filtered env. + __filter_env \ + -f "${PKGCORE_FUNC_ARRAY}" \ + -v "${PKGCORE_VAR_ARRAY}" \ + -i "${src}" \ + > "${T}"/.pre-scrubbed-env || die "failed first step of scrubbing the env to load" + + [[ -s ${T}/.pre-scrubbed-env ]] || die "empty pre-scrubbed-env file. pkgcore bug?" + source "${T}"/.pre-scrubbed-env >&2 || die "failed sourcing scrubbed env" + + + # if reinstate_loaded_env_attributes exists, run it to add to the vars. + # old pkgcore env saving approach, long before portage/paludis were around... + type reinstate_loaded_env_attributes &> /dev/null && \ + reinstate_loaded_env_attributes + unset -f reinstate_loaded_env_attributes + + # ok. it's loaded into this subshell... now we use our dump mechanism (which we trust) + # to output it- this mechanism is far more bulletproof then the load filtering (since + # declare and friends can set vars via many, many different ways), thus we use it + # as the final filtering. + + unset -v EXISTING_PATH old_phase + + rm -f "${T}"/.scrubbed-env + __environ_dump > "${T}"/.scrubbed-env || die "dumping environment failed" + ) && return + + echo "die 'failed parsing the env dump'" # yep, we're injecting code into the eval. + exit 1 + # note no die usage here... exit instead, since we don't want another tb thrown +} diff --git a/bash/ebuild.lib b/bash/ebuild.lib new file mode 100644 index 000000000..724729656 --- /dev/null +++ b/bash/ebuild.lib @@ -0,0 +1,514 @@ +#!/bin/bash +# ebuild.lib; ebuild phase processing, env handling +# Copyright 2005-2012 Brian Harring : BSD/GPL2 + +# general phase execution path- +# __execute_phases is called, which sets EBUILD_PHASE, and then depending on the phase, +# loads or initializes. Env is init'd for non src based stages if the env isn't found- otherwise +# it loads the environ via __load_environ call. In cases where env isn't found for phases setup -> merge, +# it bails (theres no way the env should be missing- exemption is setup phase). +# +# for env filtering for restoration and reloading, note the updates to DONT_EXPORT_(VARS|FUNCS). +# those vars are basically used to track what shouldn't be saved/restored. Whitespace separated, +# those vars can support posix (think egrep) regex. They should hold all vars/funcs that are internal +# ebuild.sh vars. Basically, filter all vars/funcs that are specific to ebuild.sh, not the ebuild. +# +# after loading the env, user defined pre hooks are executed, __dyn_${EBUILD_PHASE} is executed, +# and the post hooks are executed. If the env needs to be flushed to disk, MUST_EXPORT_ENV is set to +# "yes", and __execute_phases will dump it to ${T}/environment. +# +# few notes on general env stuff- if it's not ebuild specific or a user option, it's typically marked +# readonly. This limits users, but also helps to ensure that reloaded envs from older portages don't +# overwrite an internal ebd.sh function that has since changed. + +ORIG_VARS=$(declare | grep -E '^[^[:space:]{}()]+=' | cut -s -d '=' -f 1) +ORIG_FUNCS=$(declare -F | cut -s -d ' ' -f 3) + +DONT_EXPORT_VARS="ORIG_VARS GROUPS ORIG_FUNCS FUNCNAME CCACHE.* DISTCC.* SYNC +(TMP)?DIR FEATURES CONFIG_PROTECT.* WORKDIR RSYNC_.* GENTOO_MIRRORS +(DIST|FILES|RPM|ECLASS)DIR HOME MUST_EXPORT_ENV QA_CONTROLLED_EXTERNALLY HOSTNAME +myarg SANDBOX_ON SANDBOX_(DEBUG(_LOG)?|VERBOSE|BASHRC|PID|LIB) +BASH.* EUID PPID SHELLOPTS UID ACCEPT_(KEYWORDS|LICENSE) BUILD(_PREFIX|DIR) T DIRSTACK +(PKGCORE_)?EBUILD_PHASE PKGCORE_.* PORTAGE_.* SUDO_.* LD_PRELOAD ret line phases D IMAGE +PORT(_LOGDIR|DIR(_OVERLAY)?) ROOT _ done e PROFILE_.* EBUILD ECLASS LINENO +HILITE TMP HISTCMD OPTIND RANDOM (OLD)?PWD IFS PIPESTATUS LINENO FUNCNAME _pipestatus +SHELL SHLVL EMERGE_(WARNING_DELAY|FROM) MERGE_TYPE REPLACING_VERSIONS REPLACED_BY_VERSION (RESUME|FETCH)COMMAND(_.*)? +AUTOCLEAN CLEAN_DELAY USE_ORDER XARGS +COLORTERM LESS(OPEN)? DISPLAY EDITOR LS_COLORS PAGER TERM TERMCAP (ftp|http)_proxy USER(NAME)?" + + +if [[ -z ${PKGCORE_BIN_PATH} ]]; then + echo "PKGCORE_BIN_PATH is unset!" + exit 1 +fi + +# knock the sandbox vars back to the pkgs defaults. +__reset_sandbox() { + export SANDBOX_ON=1 + export SANDBOX_PREDICT=${SANDBOX_PREDICT:+${SANDBOX_PREDICT}:}/proc/self/maps:/dev/console:/dev/random:${PORTAGE_TMPDIR} + export SANDBOX_WRITE=${SANDBOX_WRITE:+${SANDBOX_WRITE}:}/dev/shm:${PORTAGE_TMPDIR} + export SANDBOX_READ=${SANDBOX_READ:+${SANDBOX_READ}:}/dev/shm:${PORTAGE_TMPDIR} + local var + for var in CCACHE_DIR DISTCC_DIR D WORKDIR T; do + if [[ -n ${!var} ]]; then + addread "${!var}" + addwrite "${!var}" + fi + done +} + +# Prevent aliases from causing portage to act inappropriately. +# Make sure it's before everything so we don't mess aliases that follow. +unalias -a + +# We need this next line for "die" and "assert". It expands +# It _must_ preceed all the calls to die and assert. +shopt -s expand_aliases + +# Unset some variables that break things. +unset GZIP BZIP BZIP2 CDPATH GREP_OPTIONS GREP_COLOR GLOB_IGNORE + +# gentoo bug 309369; nasty alias, but it exists due to portage using declare's in env dumping. declare statements are implicitly local. +# as such, the sourcing statement has to be in the same scope as the invoker of __load_environ for that scope to get the changes +alias __load_environ='{ + [[ -z ${PKGCORE_TARGET_ENV} ]] && die "__load_environ was invoked w/out PKGCORE_TARGET_ENV set"; + [[ -z ${T} ]] && die "__load_environ requires \$T to be set"; + EXISTING_PATH=${PATH}; + __timed_call __environ_sanitize_saved_env "${PKGCORE_TARGET_ENV}" + if [[ -n ${PKGCORE_PERF_DEBUG} ]]; then + echo "timing source ${PKGCORE_TARGET_ENV}" >&2 + time source "${PKGCORE_TARGET_ENV}" >&2 + echo "timed source ${PKGCORE_TARGET_ENV}" >&2 + else + source "${PKGCORE_TARGET_ENV}" >&2 + fi + [[ $? == 0 ]] || die "sourcing saved env failed"; + __ensure_PATH "${EXISTING_PATH}"; + export EAPI=${PKGCORE_EAPI-${EAPI}} + __timed_call __load_eapi_libs + __timed_call __source_bashrcs + unset -v EXISTING_PATH; +}' + +# Invoke this when we know that this version of pkgcore generated the env dump; this bypasses +# The safeties in loading. +alias __load_safe_environ='{ + [[ -z ${PKGCORE_TARGET_ENV} ]] && die "__load_safe_environ was invoked w/out PKGCORE_TARGET_ENV set"; + [[ -z ${T} ]] && die "__load_safe_environ requires \$T to be set"; + EXISTING_PATH=${PATH}; + if [[ -n ${PKGCORE_PERF_DEBUG} ]]; then + echo "timing source ${PKGCORE_TARGET_ENV}" >&2 + time source "${PKGCORE_TARGET_ENV}" >&2 + echo "timed source ${PKGCORE_TARGET_ENV}" >&2 + else + source "${PKGCORE_TARGET_ENV}" >&2 + fi + [[ $? == 0 ]] || die "sourcing saved env failed"; + __ensure_PATH "${EXISTING_PATH}"; + export EAPI=${PKGCORE_EAPI-${EAPI}} + __timed_call __load_eapi_libs + __timed_call __source_bashrcs + unset -v EXISTING_PATH; +}' + +alias __init_environ='{ + EXISTING_PATH=${PATH}; + __timed_call __load_eapi_libs + if [[ -n ${PKGCORE_PERF_DEBUG} ]]; then + echo "timing eval \$(__generate_initial_ebuild_environ)" >&2 + time eval "$(__timed_call __generate_initial_ebuild_environ)" >&2 + echo "timed eval \$(__generate_initial_ebuild_environ)" >&2 + else + eval "$(__generate_initial_ebuild_environ)" + fi + [[ $? == 0 ]] || die "failed loading initialized environment"; + __ensure_PATH "${EXISTING_PATH}"; + __timed_call __source_bashrcs + unset -v EXISTING_PATH; +}' + +shopt -s extdebug &> /dev/null + +# if no perms are specified, dirs/files will have decent defaults +# (not secretive, but not stupid) +umask 022 + +# the sandbox is disabled by default except when overridden in the relevant stages +export SANDBOX_ON=0 + +# ensure the passed in PATH has its components in $PATH +__ensure_PATH() { + local EXISTING_PATH=$1 + local adds + # note this isolates the adds in the same order they appear in + # the passed in path, maintaining that order. + if [[ ${EXISTING_PATH} != ${PATH} ]]; then + local IFS=: + local p + for p in ${EXISTING_PATH}; do + # keep in mind PATH=":foon" is a valid way to say "cwd" + [[ -z ${p} ]] && continue + if ! __safe_has "${p}" ${PATH} && ! __safe_has "${p}" ${adds}; then + adds=${adds:+${adds}:}${p} + fi + done + [[ -n ${adds} ]] && PATH=${PATH}${PATH:+:}${adds} + fi + export PATH +} + +__load_eapi_libs() { + local BANNED_FUNCS DEPRECATED_FUNCS funcname + + # reload depend; while it may've been loaded already, reload it so that callers can + # rely on this setting the env up as necessary + # finally, update the filters with functionality loaded from here- + # always, always, *always* use our own functionality + source "${PKGCORE_BIN_PATH}"/eapi/common.lib || die "failed sourcing eapi/common.lib" + source "${PKGCORE_BIN_PATH}/eapi/${PKGCORE_EAPI-${EAPI}}.lib" || \ + die "failed loading eapi/${PKGCORE_EAPI-${EAPI}}.lib" + + # Hijack deprecated and banned functions to make them show QA warnings + # or failure messages, respectively. + for funcname in "${DEPRECATED_FUNCS[@]}"; do + local func_src=( $(__get_func_code ${funcname}) ) + eval "${funcname}() { + eqawarn \"QA Notice: '${funcname}' is deprecated in EAPI ${EAPI:-0}\" + ${func_src[@]} + }" || die "failed evaluating deprecated function '${funcname}'" + done + for funcname in "${BANNED_FUNCS[@]}"; do + eval "${funcname}() { + die \"'${funcname}' is banned in EAPI ${EAPI:-0}\" + }" || die "failed evaluating banned function '${funcname}'" + done +} + +# do all profile, bashrc's, and ebuild sourcing. Should only be called in setup phase, unless the +# env is *completely* missing, as it is occasionally for ebuilds during prerm/postrm. +__generate_initial_ebuild_environ() { + local ORIG_CC=${CC} + local ORIG_CXX=${CXX} + local EXISTING_PATH=${PATH} + local T=${T} + + if [[ ${PKGCORE_EBUILD_PHASE} == "setup" ]]; then + # we specifically save the env so it's not stomped on by sourcing. + # bug 51552 + __timed_call __environ_save_to_file "${T}"/.temp_env + + if [[ ${USERLAND} == "GNU" ]]; then + local PORTAGE_SHIFTED_PATH=${PATH} + __timed_call __qa_invoke source /etc/profile.env + __ensure_PATH "${EXISTING_PATH}" + fi + + # restore the saved env vars. + PKGCORE_SUPPRESS_BASHRCS=true + PKGCORE_TARGET_ENV=${T}/.temp_env + if ! __load_environ; then + # this shouldn't happen. + die "failed to load '${T}/.temp_env' -- fs is readonly?" + fi + unset PKGCORE_SUPPRESS_BASHRCS + + rm "${T}"/.temp_env + fi + + [[ -n ${EBUILD} ]] && __timed_call __load_ebuild "${EBUILD}" + + if [[ ${PKGCORE_EBUILD_PHASE} != "depend" ]]; then + RESTRICT=${PKGCORE_FINALIZED_RESTRICT} + unset PKGCORE_FINALIZED_RESTRICT + unset CC CXX + [[ -n ${ORIG_CC} ]] && export CC=${ORIG_CC} + [[ -n ${ORIG_CXX} ]] && export CXX=${ORIG_CXX} + unset ORIG_CC ORIG_CXX + fi + + __ensure_PATH "${EXISTING_PATH}" + if [[ -n ${T} ]]; then + # use a file if possible; faster since bash does this lovely byte by byte reading if it's a pipe. + # having the file around is useful for debugging also. + __timed_call __environ_dump > "${T}"/.initial_environ || die "dump_environ > '${T}/.initial_environ' return non zero" + echo "source \"${T}\"/.initial_environ" + else + __timed_call __environ_dump || die "dump_environ returned non zero" + fi +} + +__load_ebuild() { + local EBUILD=$1 + shift + + SANDBOX_ON=1 + export S=${WORKDIR}/${P} + + unset IUSE REQUIRED_USE DEPEND RDEPEND PDEPEND + local E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND + + if [[ ! -f ${EBUILD} ]]; then + echo "bailing, ebuild not found at '${EBUILD}'" + die "EBUILD=${EBUILD}; problem is, it doesn't exist. bye." >&2 + fi + + __qa_invoke source "${EBUILD}" >&2 + + # a reasonable default for $S + if [[ -z ${S} ]]; then + export S=${WORKDIR}/${P} + fi + + # default to EAPI=0 if unset + EAPI=${EAPI-0} + + # some users have $TMP/$TMPDIR to a custom dir in their home ... + # this will cause sandbox errors with some ./configure + # scripts, so set it to $T. + export TMP=${T} + export TMPDIR=${T} + + # Note: this next line is not the same as export RDEPEND=${RDEPEND:-${DEPEND}} + # That will test for unset *or* NULL (""). We want just to set for unset... + + if __safe_has "${EAPI}" 0 1 2 3; then + if [[ ${RDEPEND-unset} == "unset" ]]; then + export RDEPEND=${DEPEND} + fi + fi + + # add in dependency info from eclasses + IUSE+=${IUSE:+ }${E_IUSE} + REQUIRED_USE+=${REQUIRED_USE:+ }${E_REQUIRED_USE} + DEPEND+=${DEPEND:+ }${E_DEPEND} + RDEPEND+=${RDEPEND:+ }${E_RDEPEND} + PDEPEND+=${PDEPEND:+ }${E_PDEPEND} +} + +# short version. think these should be sourced via at the daemons choice, rather then defacto. +# note that exit-handling loads the die functions, thus the custom failure there. +source "${PKGCORE_BIN_PATH}"/exit-handling.lib >&2 || { echo "ERROR: failed sourcing exit-handling.lib"; exit -1; } +source "${PKGCORE_BIN_PATH}"/ebuild-default-functions.lib >&2 || die "failed sourcing ebuild-default-functions.lib" +source "${PKGCORE_BIN_PATH}"/ebuild-env-utils.lib >&2 || die "failed sourcing ebuild-env-utils.lib" + +__run_ebuild_phase() { + [[ -n ${PKGCORE_DEBUG} ]] && set -x + __qa_run_function_if_exists __phase_default_pre_$1 + __qa_run_function_if_exists pre_$1 + + local EBUILD_PHASE_FUNC + if ${PKGCORE_EBUILD_PHASE_FUNC}; then + EBUILD_PHASE_FUNC=$1 + fi + if __is_function __dyn_$1; then + __dyn_$1 + elif __is_function $1; then + __qa_invoke $1 + else + __qa_run_function_if_exists __phase_default_$1 + fi + + __qa_run_function_if_exists post_$1 + __qa_run_function_if_exists __phase_default_post_$1 + [[ ${PKGCORE_DEBUG} -lt 2 ]] && set +x +} + +# general func to call for phase execution. this handles necessary env loading/dumping, and executing pre/post/dyn +# calls. +__execute_phases() { + local PKGCORE_SAVE_ENV + local PKGCORE_MUST_EXPORT_ENV=false + + # give us pretty tracebacks. + shopt -s extdebug + + trap "exit 2" SIGINT + trap "exit 9" SIGQUIT + trap "exit 1" SIGTERM + trap "die 'a helper failed, see above'" SIGUSR1 + declare -rx PKGCORE_EBUILD_PROCESS_PID=${BASHPID} + + if __safe_has "${EAPI:-0}" 0 1 2 3; then + declare -rx PKGCORE_NONFATAL_HELPER=true + fi + + # local scope; this keeps it from bleeding further, and keeps + # it from being exported- we use it to track if we're subshelled w/in the main + # ebd instance, or if we're in a literal child process. + local PKGCORE_IS_NOT_HELPER=1 + local myarg ret + for myarg in $*; do + PKGCORE_EBUILD_PHASE=${myarg} + EBUILD_PHASE=${myarg} + + local PKGCORE_SAVE_ENV=true + local PKGCORE_DIE_OUTPUT_DETAILS=true + local PKGCORE_SUPPRESS_BASHRCS=false + + case ${EBUILD_PHASE} in + nofetch|pretend) + PKGCORE_SUPPRESS_BASHRCS=true + __init_environ + + PKGCORE_DIE_OUTPUT_DETAILS=false + __run_ebuild_phase pkg_${EBUILD_PHASE} + PKGCORE_SAVE_ENV=false + ret=0 + ;; + postrm) + PKGCORE_SAVE_ENV=false + # this is a fall thru; think of it as a select chunk w/out a break + # we just snag these phases to turn off env saving. + ;& + prerm|preinst|postinst|config) + export SANDBOX_ON=0 + + PKGCORE_TARGET_ENV=${T}/environment + if ! __load_environ; then + # hokay. this sucks. + ewarn + ewarn "failed to load env" + ewarn "this installed pkg may not behave correctly" + ewarn + sleep 10 + fi + + __run_ebuild_phase pkg_${EBUILD_PHASE} + ret=0 + ;; + unpack|prepare|configure|compile|test|install) + if [[ ${SANDBOX_DISABLED=0} == 0 ]]; then + export SANDBOX_ON=1 + else + export SANDBOX_ON=0 + fi + + [[ ${PKGCORE_DEBUG} -ge 3 ]] && set -x + PKGCORE_TARGET_ENV=${T}/environment + if ! __load_safe_environ; then + ewarn + ewarn "failed to load env. This is bad, bailing." + die "unable to load saved env for phase ${EBUILD_PHASE}, unwilling to continue" + fi + + [[ -z ${S} ]] && die "S was null- ${S}, path=${PATH}" + + __run_ebuild_phase src_${EBUILD_PHASE} + ret=0 + ;; + setup|setup-binpkg) + # 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. + + EBUILD_PHASE="setup" + + # binpkgs don't need to reinitialize the env. + if [[ ${myarg} == "setup" ]]; then + [[ -n ${DISTCC_LOG} ]] && addwrite "$(dirname ${DISTCC_LOG})" + + # if they aren't set, then holy hell ensues. deal. + + if __feature_is_enabled ccache; then + [[ -z ${CCACHE_SIZE} ]] && export CCACHE_SIZE="500M" + ccache -M ${CCACHE_SIZE} &> /dev/null + fi + [[ ${PKGCORE_DEBUG} == 2 ]] && set -x + __init_environ + else + PKGCORE_TARGET_ENV=${T}/environment + if ! __load_environ; then + die "failed loading saved env from '${T}/environment'" + fi + fi + + export SANDBOX_ON=0 + __run_ebuild_phase pkg_${EBUILD_PHASE} + ret=0; + + ;; + depend|generate_env) + SANDBOX_ON=1 + PKGCORE_SAVE_ENV=false + + PKGCORE_DIE_OUTPUT_DETAILS=false + if [[ -z ${QA_CONTROLLED_EXTERNALLY} ]]; then + __qa_interceptors_enable + fi + + EBUILD_PHASE="depend" + __load_ebuild "${EBUILD}" + + if [[ -z ${QA_CONTROLLED_EXTERNALLY} ]]; then + __qa_interceptors_disable + fi + if [[ ${myarg} == depend ]]; then + __dump_metadata_keys + else + # Use gawk if at possible; it's a fair bit faster since bash likes to do byte by byte reading. + local __path=$(type -P gawk) + if [[ $? == 0 ]]; then + { unset __path; __environ_dump; } | \ + LC_ALL=C "${__path}" -F $'\0' 'BEGIN { content="";chars=0;RS="\0";ORS=""} {chars += length($0);content = content $0} END {printf("receive_env %i\n%s",chars, content)}' >&${PKGCORE_EBD_WRITE_FD} + else + local my_env=$(__environ_dump) + __ebd_write_line "receive_env ${#my_env}" + __ebd_write_raw "${my_env}" + unset my_env __path + fi + #__environ_dump | $(type -P gawk) -F $'\0' 'BEGIN { content="";chars=0;RS="\0";ORS=""} {chars += length($0);content = content $0} END {printf("receive_env %i\n%s",chars, content)}' >&${PKGCORE_EBD_WRITE_FD} + #__environ_dump | $(type -P python) -c 'import sys;data=sys.stdin.read();sys.stdout.write("receive_env %i\n%s" % (len(data), data))' >&${PKGCORE_EBD_WRITE_FD} + fi + ;; + *) + die "Please specify a valid command: ${EBUILD_PHASE} isn't valid." + ;; + esac + + ${PKGCORE_SAVE_ENV} && PKGCORE_MUST_EXPORT_ENV=true + [[ ${PKGCORE_DEBUG} -lt 4 ]] && set +x + done + + if ${PKGCORE_MUST_EXPORT_ENV}; then + __timed_call __environ_save_to_file "${T}"/environment + fi + return ${ret:-0} +} + +__dump_metadata_keys() { + # note this function does /not/ use shopt pushing/popping; it should only + # be invoked after ebuild code has done it's thing, as such we no longer care, + # and directly screw w/ it for speed reasons- about 5% speedup in metadata regen. + set -f + local key + for key in EAPI DEPEND RDEPEND SLOT SRC_URI RESTRICT HOMEPAGE LICENSE \ + DESCRIPTION KEYWORDS INHERITED IUSE PDEPEND PROVIDE PROPERTIES REQUIRED_USE; do + # deref the val, if it's not empty/unset, then spit a key command to EBD + # after using echo to normalize whitespace (specifically removal of newlines) + if [[ ${!key:-unset} != "unset" ]]; then + # note that we explicitly bypass the normal functions, and directly + # write to the FD. This is done since it's about 25% faster for our usage; + # if we used the functions, we'd have to subshell the 'echo ${!key}', which + # because of bash behaviour, means the content would be read byte by byte. + echo -n "key ${key}=" >&${PKGCORE_EBD_WRITE_FD} + echo ${!key} >&${PKGCORE_EBD_WRITE_FD} + fi + done + set +f + + # defined phases... fun one. + local phases + for key in pkg_{pretend,configure,info,{pre,post}{rm,inst},setup} \ + src_{unpack,prepare,configure,compile,test,install}; do + __is_function "${key}" && phases+=${phases:+ }${key} + done + __ebd_write_line "key DEFINED_PHASES=${phases:--}" +} + +DONT_EXPORT_VARS+=" $(declare | __filter_env --print-vars | __regex_filter_input ${ORIG_VARS} ${DONT_EXPORT_VARS})" + +set +f + +export XARGS +set +H -h +: diff --git a/bash/exit-handling.lib b/bash/exit-handling.lib new file mode 100644 index 000000000..e2a40fd3b --- /dev/null +++ b/bash/exit-handling.lib @@ -0,0 +1,110 @@ +# Copyright 2005-2012 Brian Harring : BSD/GPL2 +# Copyright 2004-2005 Gentoo Foundation: GPL2 + +assert() { + local pipestatus=${PIPESTATUS[*]} + [[ -z ${pipestatus//[ 0]/} ]] || die "$@ (pipestatus: ${pipestatus})" +} + +die() { + set +x + # if we were signaled to die... + if [[ -n ${EBD_DISABLE_DIEFUNC} ]]; then + return + fi + + local n filespacing=0 linespacing=0 sourcefile lineno + # setup spacing to make output easier to read + for (( n = ${#FUNCNAME[@]} - 1 ; n >= 0 ; --n )); do + sourcefile=${BASH_SOURCE[${n}]} sourcefile=${sourcefile##*/} + lineno=${BASH_LINENO[${n}]} + (( filespacing < ${#sourcefile} )) && filespacing=${#sourcefile} + (( linespacing < ${#lineno} )) && linespacing=${#lineno} + done + + echo >&2 + echo "!!! ERROR: ${CATEGORY}/${PF} failed." >&2 + echo "!!! die invoked from directory $(pwd)" >&2 + if [[ -z ${PKGCORE_IS_NOT_HELPER} ]]; then + echo "!!! was running helper: ${HELPER_ERROR_PREFIX}" + else + __dump_trace 2 ${filespacing} ${linespacing} >&2 + echo "!!! $(printf "%${filespacing}s" "${BASH_SOURCE[1]##*/}"), line $(printf "%${linespacing}s" "${BASH_LINENO[0]}"): Called die" >&2 + fi + echo "!!! The die message:" >&2 + echo "!!! ${*:-(no error message)}" >&2 + if ${PKGCORE_DIE_OUTPUT_DETAILS-true}; then + if [[ -n ${PKGCORE_IS_NOT_HELPER} ]]; then + echo "!!!" >&2 + echo "!!! If you need support, post the topmost build error, and the call stack if relevant." >&2 + fi + local hook + for hook in ${EBUILD_DEATH_HOOKS}; do + ${hook} >&2 1>&2 + done + fi + echo >&2 + if [[ -n ${PKGCORE_EBUILD_PROCESS_PID} ]]; then + if [[ -z ${PKGCORE_IS_NOT_HELPER} ]]; then + kill -10 ${PKGCORE_EBUILD_PROCESS_PID} + elif [[ ${BASHPID} != ${PKGCORE_EBUILD_PROCESS_PID} ]]; then + kill -s SIGTERM ${PKGCORE_EBUILD_PROCESS_PID} + fi + fi + exit 1 +} + +# usage- first arg is the number of funcs on the stack to ignore. +# defaults to 1 (ignoring __dump_trace) +# whitespacing for filenames +# whitespacing for line numbers +__dump_trace() { + declare -i strip=1 + + if [[ -n $1 ]]; then + strip=$(( $1 )) + fi + echo "!!! Call stack:" + local filespacing=$2 linespacing=$3 + local n p + for (( n = ${#FUNCNAME[@]} - 1, p = ${#BASH_ARGV[@]} ; n > ${strip} ; n-- )); do + local funcname=${FUNCNAME[${n} - 1]} + local sourcefile=$(basename ${BASH_SOURCE[${n}]}) + local lineno=${BASH_LINENO[${n} - 1]} + # Display function arguments + local args= newargs= + local j + if [[ -n ${BASH_ARGV[@]} ]]; then + for (( j = 0 ; j < ${BASH_ARGC[${n} - 1]} ; ++j )); do + newarg=${BASH_ARGV[$(( p - j - 1 ))]} + args="${args:+${args} }'${newarg}'" + done + (( p -= ${BASH_ARGC[${n} - 1]} )) + fi + echo "!!! $(printf "%${filespacing}s" "${sourcefile}"), line $(printf "%${linespacing}s" "${lineno}"): Called ${funcname}${args:+ ${args}}" + done +} + +__helper_exit() { + [[ $1 == 0 ]] && exit 0 + if ${PKGCORE_NONFATAL_HELPER}; then + echo "WARNING: exitcode $1 from ${HELPER_ERROR_PREFIX}" >&2 + exit $1 + fi + if [[ -z $2 ]]; then + die "returned error $1" + fi + die "exitcode $1: $2" +} + +__helper_died() { + die "got $*"; +} + +__helper_check_exit() { + [[ $1 == 0 ]] && return + shift + __helper_exit "$@" +} + +: diff --git a/bash/generate_eapi_func_list.bash b/bash/generate_eapi_func_list.bash new file mode 100755 index 000000000..a5342b5fe --- /dev/null +++ b/bash/generate_eapi_func_list.bash @@ -0,0 +1,44 @@ +#!/bin/bash +# +# Generates a list of EAPI specific functions to avoid exporting to the saved +# ebuild environment. This script is run dynamically on initialization of the +# build environment for each ebuild since different EAPIs require different +# lists of functions to be skipped. + +EAPI=$1 +export PKGCORE_BIN_PATH=$(dirname "$0") + +# without this var, parsing certain things can fail; force to true +# so any code that tried accessing it thinks it succeeded +export PKGCORE_PYTHON_BINARY=/bin/true + +# sourcing EAPI specific libs requires a couple functions from +# isolated-functions.lib, specifically __safe_has() and __is_function() are +# used in __inject_phase_funcs() from common.lib +source "${PKGCORE_BIN_PATH}/isolated-functions.lib" \ + || { echo "failed loading isolated-functions.lib" >&2; exit 1; } + +# pull in common.lib for various functions used in EAPI libs, currently +# __inject_common_phase_funcs() and __inject_phase_funcs() in particular +source "${PKGCORE_BIN_PATH}/eapi/common.lib" \ + || { echo "failed loading eapi/common.lib" >&2; exit 1; } + +# grab current function list, we'll need to unset them further on +__content=$(builtin declare -F) +declare() { echo "$2"; } +__common_funcs=$(eval "${__content}") +unset -f declare + +source "${PKGCORE_BIN_PATH}/eapi/${EAPI}.lib" \ + || { echo "failed loading eapi/${EAPI}.lib" >&2; exit 1; } + +# remove functions pulled in by EAPI lib deps, we're only interested in the +# ones set specifically in the EAPI libs +unset -f ${__common_funcs} + +# grab function list *before* adding our custom declare function, otherwise +# it'll show up in the list of functions +__content=$(builtin declare -F) +declare() { echo "$2"; } +eval "${__content}" || { echo "generate EAPI func list eval failed" >&2; exit 1; } +unset -f declare diff --git a/bash/helpers/4/docompress b/bash/helpers/4/docompress new file mode 100755 index 000000000..3cc710882 --- /dev/null +++ b/bash/helpers/4/docompress @@ -0,0 +1,5 @@ +#!/bin/bash + +# for the time being, we're ignoring controllable compression. + +exit 0 diff --git a/bash/helpers/4/dohard b/bash/helpers/4/dohard new file mode 120000 index 000000000..22465e004 --- /dev/null +++ b/bash/helpers/4/dohard @@ -0,0 +1 @@ +../internals/banned \ No newline at end of file diff --git a/bash/helpers/4/dosed b/bash/helpers/4/dosed new file mode 120000 index 000000000..22465e004 --- /dev/null +++ b/bash/helpers/4/dosed @@ -0,0 +1 @@ +../internals/banned \ No newline at end of file diff --git a/bash/helpers/5/doheader b/bash/helpers/5/doheader new file mode 100755 index 000000000..a344f34ff --- /dev/null +++ b/bash/helpers/5/doheader @@ -0,0 +1,7 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +check_args 1 - + +INSDESTTREE=/usr/include invoke_script doins "$@" diff --git a/bash/helpers/5/newheader b/bash/helpers/5/newheader new file mode 120000 index 000000000..221e3362d --- /dev/null +++ b/bash/helpers/5/newheader @@ -0,0 +1 @@ +../internals/_generic_new \ No newline at end of file diff --git a/bash/helpers/common/dobin b/bash/helpers/common/dobin new file mode 100755 index 000000000..4c974cbb2 --- /dev/null +++ b/bash/helpers/common/dobin @@ -0,0 +1,15 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +check_args 1 - + +# chunk off the 'do' prefix to get the subdir to use. +target=${HELPER_NAME:2} + +# may exist already, but that's fine. +check_command_or_stop install -d "${ED}${DESTTREE}/${target}" + +for x in "$@"; do + check_command install -m0755 -o "${PKGCORE_INST_UID:-0}" -g "${PKGCORE_INST_GID:-0}" -- "${x}" "${ED}${DESTTREE}/${target}" +done diff --git a/bash/helpers/common/doconfd b/bash/helpers/common/doconfd new file mode 100755 index 000000000..beca058f4 --- /dev/null +++ b/bash/helpers/common/doconfd @@ -0,0 +1,7 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +check_args 1 - + +INSDESTTREE=/etc/conf.d invoke_script doins "$@" diff --git a/bash/helpers/common/dodir b/bash/helpers/common/dodir new file mode 100755 index 000000000..6646bcdcc --- /dev/null +++ b/bash/helpers/common/dodir @@ -0,0 +1,7 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +check_args 1 - + +check_command install -d ${DIROPTIONS} "${@/#/${ED}/}" diff --git a/bash/helpers/common/dodoc b/bash/helpers/common/dodoc new file mode 100755 index 000000000..e64adda36 --- /dev/null +++ b/bash/helpers/common/dodoc @@ -0,0 +1,35 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2012 Brian Harring +# License: GPL2/BSD 3 clause + +recursive=false +if ${PKGCORE_DODOC_ALLOW_RECURSIVE} && [[ $1 == "-r" ]]; then + recursive=true + shift +fi + +check_args 1 - + +install_paths() { + local mydir=$1 + shift + check_command install -d -- "${mydir}" || return + + for x in "${@}"; do + if [[ ! -e ${x} ]]; then + error "file '${x}' doesn't exist" + elif [[ -d ${x} ]]; then + if ! ${recursive}; then + error "'${x}' is a directory$($PKGCORE_DODOC_ALLOW_RECURSIVE && echo ", perhaps you forgot -r?")" + continue + fi + __directory_is_empty "${x}" && continue + install_paths "${mydir}/${x##*/}" "${x}"/* + elif [[ -s ${x} ]]; then + check_command install -m0644 -- "${x}" "${mydir}" && \ + check_command "${PORTAGE_COMPRESS}" "${PORTAGE_COMPRESS_FLAGS}" -f "${mydir}/${x##*/}" + fi + done +} + +install_paths "${ED}usr/share/doc/${PF}/${PKGCORE_DOCDESTTREE}" "$@" diff --git a/bash/helpers/common/doenvd b/bash/helpers/common/doenvd new file mode 100755 index 000000000..ef7590551 --- /dev/null +++ b/bash/helpers/common/doenvd @@ -0,0 +1,7 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +check_args 1 - + +INSDESTTREE=/etc/env.d invoke_script doins "$@" diff --git a/bash/helpers/common/doexe b/bash/helpers/common/doexe new file mode 100755 index 000000000..7ea5ebff7 --- /dev/null +++ b/bash/helpers/common/doexe @@ -0,0 +1,22 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +check_args 1 - + +check_command_or_stop install -d "${ED}${PKGCORE_EXEDESTTREE}" + +for x in "$@"; do + if [[ -L ${x} ]]; then + check_command cp -- "${x}" "${T}" || continue + mysrc=${T}/${x##*/} + elif [[ -d ${x} ]]; then + warn "skipping directory ${x}" + continue + else + mysrc=${x} + fi + check_command install ${EXEOPTIONS} -- "${mysrc}" "${ED}${PKGCORE_EXEDESTTREE}" + # cleanup after ourselves... + [[ ${mysrc} != ${x} ]] && rm -f "${mysrc}" +done diff --git a/bash/helpers/common/dohard b/bash/helpers/common/dohard new file mode 100755 index 000000000..be567e3b6 --- /dev/null +++ b/bash/helpers/common/dohard @@ -0,0 +1,19 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +check_args 2 + +ln_option= +src_prefix= +if [[ ${HELPER_NAME} == "dosym" ]]; then + ln_option="sn" + if [[ $2 == */ ]] || [[ -d $2 && ! -L $2 ]]; then + echo "QA: dosym target '$2' omits the filename target; see bug 379899" >&2 + fi +else + src_prefix=${ED} +fi + +check_command_or_stop dodir "${2%/*}" +check_command ln -${ln_option}f "${src_prefix}$1" "${ED}$2" diff --git a/bash/helpers/common/dohtml b/bash/helpers/common/dohtml new file mode 100755 index 000000000..df8a7fc45 --- /dev/null +++ b/bash/helpers/common/dohtml @@ -0,0 +1,7 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +check_args 1 - + +check_command "${PKGCORE_PYTHON_BINARY}" "${PKGCORE_BIN_PATH}/helpers/internals/_raw_dohtml" "$@" diff --git a/bash/helpers/common/doinfo b/bash/helpers/common/doinfo new file mode 100755 index 000000000..ca4ac8d86 --- /dev/null +++ b/bash/helpers/common/doinfo @@ -0,0 +1,12 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +check_args 1 - + +check_command_or_stop install -d "${ED}usr/share/info" + +for x in "$@"; do + check_command install -m0644 -- "${x}" "${ED}usr/share/info" && \ + check_command "${PORTAGE_COMPRESS}" "${PORTAGE_COMPRESS_FLAGS}" -f "${ED}usr/share/info/${x##*/}" +done diff --git a/bash/helpers/common/doinitd b/bash/helpers/common/doinitd new file mode 100755 index 000000000..2e969ff03 --- /dev/null +++ b/bash/helpers/common/doinitd @@ -0,0 +1,7 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +check_args 1 - + +PKGCORE_EXEDESTTREE=/etc/init.d invoke_script doexe "$@" diff --git a/bash/helpers/common/doins b/bash/helpers/common/doins new file mode 100755 index 000000000..ef4894f11 --- /dev/null +++ b/bash/helpers/common/doins @@ -0,0 +1,50 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2012 Brian Harring +# License: GPL2/BSD 3 clause + +recursive=false +if [[ $1 == "-r" ]]; then + recursive=true + shift +fi + +check_args 1 - + +if [[ -n ${INSDESTTREE} && -z ${INSDESTTREE%${ED}*} ]]; then + __helper_exit 2 "do not give \${D} nor \${ED} as part of the pathways to doins" +fi + +install_paths() { + local mydir=$1 + shift + check_command invoke_script dodir "${mydir}" || return 1 + + __shopt_push -s extglob + # strip trailing slashes + local paths=( "${@%%+(/)}" ) + __shopt_pop + + for x in "${paths[@]}"; do + mysrc=${x} + if [[ -L ${x} ]]; then + if ! ${PKGCORE_DOINS_ALLOW_SYMLINKS}; then + check_command cp -- "${x}" "${T}" || continue + mysrc=${T}/${x##*/} + else + check_command cp -P -- "${x}" "${ED}${mydir}/${x##*/}" + continue + fi + elif [[ -d ${x} ]]; then + ${recursive} || continue + __shopt_push -s dotglob nullglob + install_paths "${mydir}/${x##*/}" "${x}"/* + __shopt_pop + continue + fi + check_command install ${INSOPTIONS} -- "${mysrc}" "${ED}${mydir}" + # cleanup the tempspace... + [[ ${mysrc} != ${x} ]] && rm -f "${mysrc}" + done +} + +install_paths "${INSDESTTREE}" "$@" diff --git a/bash/helpers/common/dolib b/bash/helpers/common/dolib new file mode 100755 index 000000000..c88e7429f --- /dev/null +++ b/bash/helpers/common/dolib @@ -0,0 +1,25 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +check_args 1 - + +libdir=${ED}${DESTTREE}/$(__get_libdir lib) + +if [[ ${HELPER_NAME} == "dolib.so" ]]; then + LIBOPTIONS="-m0755" +elif [[ ${HELPER_NAME} == "dolib.a" ]]; then + LIBOPTIONS="-m0644" +fi + +check_command_or_stop install -d "${libdir}" + +for x in "$@"; do + if [[ -L ${x} ]]; then + # yes we want readlink, not readlink -f; we want the symlink content, + # not the resolved symlink target. + check_command ln -s -- "$(readlink -- "${x}")" "${libdir}/${x##*/}" + else + check_command install ${LIBOPTIONS} -- "${x}" "${libdir}" + fi +done diff --git a/bash/helpers/common/dolib.a b/bash/helpers/common/dolib.a new file mode 120000 index 000000000..c013e45e8 --- /dev/null +++ b/bash/helpers/common/dolib.a @@ -0,0 +1 @@ +dolib \ No newline at end of file diff --git a/bash/helpers/common/dolib.so b/bash/helpers/common/dolib.so new file mode 120000 index 000000000..c013e45e8 --- /dev/null +++ b/bash/helpers/common/dolib.so @@ -0,0 +1 @@ +dolib \ No newline at end of file diff --git a/bash/helpers/common/doman b/bash/helpers/common/doman new file mode 100755 index 000000000..bc5e1ea26 --- /dev/null +++ b/bash/helpers/common/doman @@ -0,0 +1,47 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +check_args 1 - + +i18n="" + +for x in "$@"; do + if [[ ${x} == "-i18n="* ]]; then + i18n=${x:6}/ + continue + fi + if [[ ${x} == ".keep_"* || ${x} == ".keep" ]]; then + continue + fi + + # rewrite this suffix bits into regex. + suffix=${x##*.} + if __safe_has "${suffix}" Z gz bz2; then + uncompressed_name=${x%.*} + suffix=${uncompressed_name##*.} + fi + + if ${PKGCORE_DOMAN_LANGUAGE_OVERRIDE} && [[ -n ${i18n} ]]; then + name=${x##*/} + mandir=${i18n}man${suffix:0:1} + elif ${PKGCORE_DOMAN_LANGUAGE_DETECT} && + [[ ${x} =~ (.*)\.([a-z][a-z](_[A-Z][A-Z])?)\.(.*) ]]; then + name=${BASH_REMATCH[1]##*/}.${BASH_REMATCH[4]} + mandir=${BASH_REMATCH[2]}/man${suffix:0:1} + else + name=${x##*/} + mandir=${i18n}man${suffix:0:1} + fi + + if [[ ${mandir} =~ man[0-9n](f|p|pm)?$ ]]; then + if [[ -s ${x} ]]; then + check_command install -d "${ED}/usr/share/man/${mandir}" || continue + check_command install -m0644 -- "${x}" "${ED}/usr/share/man/${mandir}/${name}" + elif [[ ! -e ${x} ]]; then + error "'${x}' does not exist" + fi + else + error "'${x}' doesn't have a filename pattern that looks like a man page, not installing" + fi +done diff --git a/bash/helpers/common/domo b/bash/helpers/common/domo new file mode 100755 index 000000000..8f7fc66eb --- /dev/null +++ b/bash/helpers/common/domo @@ -0,0 +1,18 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +check_args 1 - + +check_command_or_stop install -d "${ED}${DESTTREE}/share/locale/" + +for x in "$@"; do + if [[ -e ${x} ]]; then + my_basename=${x##*/} + mydir="${ED}${DESTTREE}/share/locale/${my_basename%.*}/LC_MESSAGES" + check_command install -d "${mydir}" && \ + check_command install -m0644 -- "${x}" "${mydir}/${MOPREFIX}.mo" + else + error "'${x}' does not exist" + fi +done diff --git a/bash/helpers/common/dosbin b/bash/helpers/common/dosbin new file mode 120000 index 000000000..46bbe6165 --- /dev/null +++ b/bash/helpers/common/dosbin @@ -0,0 +1 @@ +dobin \ No newline at end of file diff --git a/bash/helpers/common/dosed b/bash/helpers/common/dosed new file mode 100755 index 000000000..6e4aaeb98 --- /dev/null +++ b/bash/helpers/common/dosed @@ -0,0 +1,24 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +check_args 1 - + +pattern="s:${ED}::g" + +for x in "$@"; do + trg=${ED}${x} + if [[ ! -e ${trg} ]]; then + pattern=${x} + continue + fi + if [[ ! -f ${trg} ]]; then + error "'${trg}' is not a regular file!"; + continue + fi + tmp_file=${T}/${trg##*/} + if check_command cp "${trg}" "${tmp_file}"; then + check_command sed -e "${pattern}" "${tmp_file}" > "${trg}" + rm -f "${tmp_file}" + fi +done diff --git a/bash/helpers/common/dosym b/bash/helpers/common/dosym new file mode 120000 index 000000000..dacdb2f13 --- /dev/null +++ b/bash/helpers/common/dosym @@ -0,0 +1 @@ +dohard \ No newline at end of file diff --git a/bash/helpers/common/emake b/bash/helpers/common/emake new file mode 100755 index 000000000..ccc568fdd --- /dev/null +++ b/bash/helpers/common/emake @@ -0,0 +1,6 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +info "${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE} $@" +check_command ${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE} "$@" diff --git a/bash/helpers/common/fowners b/bash/helpers/common/fowners new file mode 100755 index 000000000..011620369 --- /dev/null +++ b/bash/helpers/common/fowners @@ -0,0 +1,9 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +# at least two args are required- the owner/group chunk, and the target +check_args 2 - + +# pathway must be absolute. +check_command chown "${@/#\//${ED}/}" diff --git a/bash/helpers/common/fperms b/bash/helpers/common/fperms new file mode 100755 index 000000000..8883c9827 --- /dev/null +++ b/bash/helpers/common/fperms @@ -0,0 +1,9 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause + +# at least two args are required- the owner/group chunk, and the target +check_args 2 - + +# pathway must be absolute. +check_command chmod "${@/#\//${ED}/}" diff --git a/bash/helpers/common/keepdir b/bash/helpers/common/keepdir new file mode 100755 index 000000000..b1efedfc0 --- /dev/null +++ b/bash/helpers/common/keepdir @@ -0,0 +1,22 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2011 Brian Harring +# License: GPL2/BSD 3 clause +# +# adds ".keep" files so that dirs aren't auto-cleaned + +recursive=false +if [[ $1 == "-r" ]]; then + recursive=true + shift +fi + +check_args 1 - +dodir "$@" + +if ${recursive}; then + check_command_or_stop find "$@" -type d -printf "${ED}/%p/.keep_${CATEGORY}_${PN}-${SLOT%/*}\0" | ${XARGS} -0 -n100 touch +else + for x in "$@"; do + check_command_or_stop touch "${ED}/${x}/.keep_${CATEGORY}_${PN}-${SLOT%/*}" + done +fi diff --git a/bash/helpers/common/newbin b/bash/helpers/common/newbin new file mode 120000 index 000000000..221e3362d --- /dev/null +++ b/bash/helpers/common/newbin @@ -0,0 +1 @@ +../internals/_generic_new \ No newline at end of file diff --git a/bash/helpers/common/newconfd b/bash/helpers/common/newconfd new file mode 120000 index 000000000..221e3362d --- /dev/null +++ b/bash/helpers/common/newconfd @@ -0,0 +1 @@ +../internals/_generic_new \ No newline at end of file diff --git a/bash/helpers/common/newdoc b/bash/helpers/common/newdoc new file mode 120000 index 000000000..221e3362d --- /dev/null +++ b/bash/helpers/common/newdoc @@ -0,0 +1 @@ +../internals/_generic_new \ No newline at end of file diff --git a/bash/helpers/common/newenvd b/bash/helpers/common/newenvd new file mode 120000 index 000000000..221e3362d --- /dev/null +++ b/bash/helpers/common/newenvd @@ -0,0 +1 @@ +../internals/_generic_new \ No newline at end of file diff --git a/bash/helpers/common/newexe b/bash/helpers/common/newexe new file mode 120000 index 000000000..221e3362d --- /dev/null +++ b/bash/helpers/common/newexe @@ -0,0 +1 @@ +../internals/_generic_new \ No newline at end of file diff --git a/bash/helpers/common/newinitd b/bash/helpers/common/newinitd new file mode 120000 index 000000000..221e3362d --- /dev/null +++ b/bash/helpers/common/newinitd @@ -0,0 +1 @@ +../internals/_generic_new \ No newline at end of file diff --git a/bash/helpers/common/newins b/bash/helpers/common/newins new file mode 120000 index 000000000..221e3362d --- /dev/null +++ b/bash/helpers/common/newins @@ -0,0 +1 @@ +../internals/_generic_new \ No newline at end of file diff --git a/bash/helpers/common/newlib.a b/bash/helpers/common/newlib.a new file mode 120000 index 000000000..221e3362d --- /dev/null +++ b/bash/helpers/common/newlib.a @@ -0,0 +1 @@ +../internals/_generic_new \ No newline at end of file diff --git a/bash/helpers/common/newlib.so b/bash/helpers/common/newlib.so new file mode 120000 index 000000000..221e3362d --- /dev/null +++ b/bash/helpers/common/newlib.so @@ -0,0 +1 @@ +../internals/_generic_new \ No newline at end of file diff --git a/bash/helpers/common/newman b/bash/helpers/common/newman new file mode 120000 index 000000000..221e3362d --- /dev/null +++ b/bash/helpers/common/newman @@ -0,0 +1 @@ +../internals/_generic_new \ No newline at end of file diff --git a/bash/helpers/common/newsbin b/bash/helpers/common/newsbin new file mode 120000 index 000000000..221e3362d --- /dev/null +++ b/bash/helpers/common/newsbin @@ -0,0 +1 @@ +../internals/_generic_new \ No newline at end of file diff --git a/bash/helpers/common/pkgcore-ebuild-helper b/bash/helpers/common/pkgcore-ebuild-helper new file mode 100755 index 000000000..c0b1b0430 --- /dev/null +++ b/bash/helpers/common/pkgcore-ebuild-helper @@ -0,0 +1,126 @@ +#!/usr/bin/env bash +# Copyright: 2012 Brian Harring +# License: GPL2/BSD 3 clause + +# protect against env screwups. +if [[ -z ${PKGCORE_BIN_PATH} ]]; then + PKGCORE_BIN_PATH=$(readlink -f "${0}") + # and go up 3, out of helpers. + PKGCORE_BIN_PATH=${PKGCORE_BIN_PATH%/*} + PKGCORE_BIN_PATH=${PKGCORE_BIN_PATH%/*} + PKGCORE_BIN_PATH=${PKGCORE_BIN_PATH%/*} +fi +export PKGCORE_BIN_PATH + +source "${PKGCORE_BIN_PATH}"/exit-handling.lib || { + echo "failed to load exit-handling library: PKGCORE_BIN_PATH=${PKGCORE_BIN_PATH}" >&2 + exit -127 +} + +if [[ $# -lt 1 ]]; then + die "ebuild-helper invoked without a target helper; no args given." +fi + +source "${PKGCORE_BIN_PATH}"/isolated-functions.lib || \ + die "failed to load isolated-functions.lib" +source "${PKGCORE_BIN_PATH}"/eapi/depend.lib >&2 || \ + die "failed sourcing eapi/depend.lib" +source "${PKGCORE_BIN_PATH}"/eapi/common.lib >&2 || \ + die "failed sourcing eapi/common.lib" + +failed=false +_helper_issues=() +error() { + echo "${HELPER_ERROR_PREFIX}: ${@-no message given}" >&2 + _helper[${#_helper[@]}]=${*-no message given} + failed=true +} + +warn() { + echo "${HELPER_ERROR_PREFIX}: warning, ${@-no message given}" >&2 +} + +info() { + echo "${HELPER_ERROR_PREFIX}: $@" >&2 +} + +check_args() { + local tense="argument" + local min=$(( $1 )) + local max + [[ ${min} -gt 1 ]] && tense="arguments" + if [[ $2 == '-' ]]; then + max=${HELPER_ARG_COUNT} + elif [[ -z $2 ]]; then + max=$1 + fi + max=$(( max )) + + if [[ ${HELPER_ARG_COUNT} -ge ${min} && ${HELPER_ARG_COUNT} -le ${max} ]]; then + return 0 + fi + if [[ ${min} -eq ${max} ]]; then + die "${HELPER_ERROR_PREFIX}: requires exactly ${min} ${tense}, got ${HELPER_ARG_COUNT}" + elif [[ $2 == '-' ]]; then + die "${HELPER_ERROR_PREFIX}: requires at least ${min} ${tense}, got ${HELPER_ARG_COUNT}" + else: + die "${HELPER_ERROR_PREFIX}: requires at least ${min} ${tense}, and at most ${max} arguments, got ${HELPER_ARG_COUNT}" + fi +} + +check_command() { + local ret + "$@" + ret=$? + [[ ${ret} == 0 ]] && return 0 + error "exitcode ${ret} from $*" + return $(( ret )) +} + +check_command_or_stop() { + check_command "$@" + __helper_check_exit $? "$@ failed, cannot continue" + return 0 +} + +MASTER_HELPER_NAME=${1##*/} +HELPER_ERROR_PREFIX= + +if ! ${PKGCORE_PREFIX_SUPPORT:=false}; then + export ED=${D} +elif [[ ${ED:-unset} == "unset" ]]; then + error "The variable ED is missing from the environment, but is required for prefix mode; failing." + exit -1 +fi + +invoke_script() { + [[ $# -eq 0 ]] && die "internal error: invoke_script invoked incorrectly" + local HELPER_PATH=$1 + local HELPER_NAME=${1##*/} + local HELPER_EAPI=${1%/*} + HELPER_EAPI=${HELPER_EAPI##*/} + shift + local HELPER_ARG_COUNT=$# + if [[ ! -e ${HELPER_PATH} ]]; then + # note this can daftly go find a binary... + HELPER_PATH=$(type -p "${HELPER_NAME}") + [[ -z ${HELPER_PATH} ]] && die "couldn't find implementation of ${HELPER_NAME}!?" + fi + + local OLD_ERROR_PREFIX=${HELPER_ERROR_PREFIX} + local HELPER_ERROR_PREFIX=${OLD_ERROR_PREFIX:+${OLD_ERROR_PREFIX}: }${HELPER_NAME} + + source "${HELPER_PATH}" + + if ${failed}; then + if [[ -n ${PKGCORE_NONFATAL_HELPER} ]]; then + echo "WARNING: nonzero exitcode from ${HELPER_ERROR_PREFIX}" >&2 + # need to track the exit code here... + return 1 + fi + die "Failures encountered. See proceeding output for details" + fi + return 0 +} +invoke_script "$@" +exit $(( $? )) diff --git a/bash/helpers/common/prepalldocs b/bash/helpers/common/prepalldocs new file mode 100755 index 000000000..5547fd734 --- /dev/null +++ b/bash/helpers/common/prepalldocs @@ -0,0 +1,69 @@ +#!/bin/bash +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +shopt -s extdebug +source "${PKGCORE_BIN_PATH}"/exit-handling.lib || { echo "failed loading libs"; exit -127; } + +if ! ${PKGCORE_PREFIX_SUPPORT:=false}; then + ED=${D} +elif [[ ${ED:-unset} == "unset" ]]; then + echo "The variable ED is missing from the environment, but is required for prefix mode; failing." + exit -1 +fi + +dir=${ED}usr/share/doc + +[[ ! -d ${dir} ]] && exit 0 + +z=$(find "${dir}" -print \ + '(' -type f -or -type l ')' \ + -not -name '*.gz' \ + -not -name '*.bz2' \ + -not -name '*.xz' \ + -not -name '*.Z' \ + -not -name '*.js' \ + 2>/dev/null) + +[[ -z ${z} ]] && exit 0 + +if [[ -z ${PORTAGE_COMPRESS_SUFFIX} ]]; then + case ${PORTAGE_COMPRESS} in + gzip) suffix="gz";; + bzip2) suffix="bz2";; + xz) suffix="xz";; + *) echo "prepalldocs error: please set PORTAGE_COMPRESS_SUFFIX in make.conf" >&2 + exit 1;; + esac +fi + +IFS=$'\n' +echo "doc: ${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS}" +for y in ${z}; do + if [[ -L ${y} ]]; then + # Symlink ... + mylink=${y} + linkto=$(readlink "${y}") + + if [[ ${linkto##*.} != ${suffix} ]]; then + linkto=${linkto}.${suffix} + fi + if [[ ${mylink##*.} != ${suffix} ]]; then + mylink=${mylink}.${suffix} + fi + + echo " link fixed ${mylink##*/}" + ln -snf "${linkto}" "${mylink}" + if [[ ${y} != ${mylink} ]]; then + echo " link removed ${y##*/}" + rm -f "${y}" + fi + else + if [[ ${y##*.} != ${suffix} ]]; then + echo " compressing ${y##*/}" >&2 + "${PORTAGE_COMPRESS}" ${PORTAGE_COMPRESS_FLAGS} -f "${y}" + fi + fi +done + +: diff --git a/bash/helpers/common/prepallstrip b/bash/helpers/common/prepallstrip new file mode 100755 index 000000000..5a0f33535 --- /dev/null +++ b/bash/helpers/common/prepallstrip @@ -0,0 +1,9 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright 2012 Brian Harring +# Distributed under the terms of the GNU General Public License v2 + +check_args 0 0 + +if ! __feature_is_enabled prepstrip && ! __safe_has nostrip ${RESTRICT}; then + check_command_or_stop prepstrip "${ED}" +fi diff --git a/bash/helpers/common/prepinfo b/bash/helpers/common/prepinfo new file mode 100755 index 000000000..e9ee5802d --- /dev/null +++ b/bash/helpers/common/prepinfo @@ -0,0 +1,69 @@ +#!/bin/bash +# Copyright: 2011 Brian Harring +# Copyright: 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +shopt -s extdebug +source "${PKGCORE_BIN_PATH}"/exit-handling.lib || { echo "failed loading libs"; exit -127; } + +if ! ${PKGCORE_PREFIX_SUPPORT:=false}; then + ED=${D} +elif [[ ${ED:-unset} == "unset" ]]; then + echo "The variable ED is missing from the environment, but is required for prefix mode; failing." + exit -1 +fi + +if [[ -z $1 ]]; then + z=${ED}usr/share/info +else + if [[ -d ${ED}$1/share/info ]]; then + z=${ED}$1/share/info + else + z=${ED}$1/info + fi +fi + +[[ ! -d ${z} ]] && exit 0 + +rm -f "${z}"/dir{,.old}{,.info{,.gz,.bz2,.xz,.Z}} + +if [[ -z ${PORTAGE_COMPRESS_SUFFIX} ]]; then + case ${PORTAGE_COMPRESS} in + gzip) suffix="gz";; + bzip2) suffix="bz2";; + xz) suffix="xz";; + *) echo "prepinfo: error fixing links: please set PORTAGE_COMPRESS_SUFFIX in make.conf" >&2 + exit 1;; + esac +fi + +echo "info: ${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS}" + +for x in $(find "${z}"/ \( -type f -or -type l \) -maxdepth 1 -mindepth 1 2>/dev/null); do + if [[ -L ${x} ]]; then + # Symlink ... + mylink=${x} + linkto=$(readlink "${x}") + + if [[ ${linkto##*.} != ${suffix} ]]; then + linkto=${linkto}.${suffix} + fi + if [[ ${mylink##*.} != ${suffix} ]]; then + mylink=${mylink}.${suffix} + fi + + echo " fixing GNU info symlink: ${mylink##*/}" + ln -snf "${linkto}" "${mylink}" + if [[ ${x} != ${mylink} ]]; then + echo " removing old symlink: ${x##*/}" + rm -f "${x}" + fi + else + if [[ ${x##*.} != ${suffix} ]]; then + echo " compressing GNU info page: ${x##*/}" + "${PORTAGE_COMPRESS}" ${PORTAGE_COMPRESS_FLAGS} -f "${x}" + fi + fi +done + +: diff --git a/bash/helpers/common/prepman b/bash/helpers/common/prepman new file mode 100755 index 000000000..530ca6c22 --- /dev/null +++ b/bash/helpers/common/prepman @@ -0,0 +1,70 @@ +#!/bin/bash +# Copyright: 2011 Brian Harring +# Copyright: 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +shopt -s extdebug +source "${PKGCORE_BIN_PATH}"/exit-handling.lib || { echo "failed loading libs"; exit -127; } + +if ! ${PKGCORE_PREFIX_SUPPORT:=false}; then + ED=${D} +elif [[ ${ED:-unset} == "unset" ]]; then + echo "The variable ED is missing from the environment, but is required for prefix mode; failing." + exit -1 +fi + +if [[ -z $1 ]]; then + z=${ED}usr/share/man +else + z=${ED}$1/man +fi + +[[ ! -d ${z} ]] && exit 0 + +if [[ -z ${PORTAGE_COMPRESS_SUFFIX} ]]; then + case ${PORTAGE_COMPRESS} in + gzip) suffix="gz";; + bzip2) suffix="bz2";; + xz) suffix="xz";; + *) echo "prepman error: please set PORTAGE_COMPRESS_SUFFIX in make.conf" 1>&2 + exit 1;; + esac +fi + +if [[ -z ${prepallman_banner} ]]; then + echo "man: ${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS}" +fi + +for x in $(find "${z}"/ -type d 2>/dev/null); do + for y in $(find "${x}"/ \( -type f -or -type l \) ! -name '.keep*' -maxdepth 1 -mindepth 1 2>/dev/null); do + if [[ -L ${y} ]]; then + # Symlink ... + mylink=${y} + linkto=$(readlink "${y}") + + # Do NOT change links to directories + if [[ -d ${z}/${linkto} ]]; then + continue + fi + + if [[ ${linkto##*.} != ${suffix} ]]; then + linkto=${linkto}.${suffix} + fi + if [[ ${mylink##*.} != ${suffix} ]]; then + mylink=${mylink}.${suffix} + fi + + echo " link fixed ${mylink##*/}" + ln -snf "${linkto}" "${mylink}" + if [[ ${y} != ${mylink} ]]; then + echo " link removed ${y##*/}" + rm -f "${y}" + fi + else + if [[ ${y##*.} != ${suffix} && ! -d ${y} ]]; then + echo " compressing ${y##*/}" + "${PORTAGE_COMPRESS}" ${PORTAGE_COMPRESS_FLAGS} -f "${y}" + fi + fi + done +done diff --git a/bash/helpers/common/prepstrip b/bash/helpers/common/prepstrip new file mode 100755 index 000000000..0f31e80ed --- /dev/null +++ b/bash/helpers/common/prepstrip @@ -0,0 +1,75 @@ +#!/bin/bash +# Copyright 2008-2011 Brian Harring : BSD/GPL2 +# Copyright 1999-2007 Gentoo Foundation: GPL2 +# Distributed under the terms of the GNU General Public License v2 + +shopt -s extdebug +source "${PKGCORE_BIN_PATH}"/exit-handling.lib || { echo "failed loading libs"; exit -127; } + +source "${PKGCORE_BIN_PATH}"/isolated-functions.lib || { + echo "failed sourcing isolated-functions.lib" + exit -1 +} + +# exit if the feature isn't requested, or the restrict isn't there. +__feature_is_enabled installsources || exit 0 +__safe_has installsources ${RESTRICT} && exit 0 + +if ! ${PKGCORE_PREFIX_SUPPORT:=false}; then + ED=${D} +elif [[ ${ED:-unset} == "unset" ]]; then + echo "The variable ED is missing from the environment, but is required for prefix mode; failing." + exit -1 +fi + +for x in debugedit scanelf rsync sort; do + if ! type -P ${x} >/dev/null; then + ewarn "FEATURES=installsources is enabled but the ${x} binary could not" + ewarn "be found. This feature will not work unless debugedit is installed!" + exit 0 + fi +done + +save_elf_sources() { + local x=$1 + local sources_dir=/usr/src/debug/${CATEGORY}/${PF} + debugedit -b "${WORKDIR}" -d "${sources_dir}" \ + -l "${T}"/debug.sources "${x}" + if [[ -s ${T}/debug.sources ]]; then + [[ -d ${ED}${sources_dir} ]] || mkdir -p "${ED}${sources_dir}" + grep -zv '/$' "${T}"/debug.sources | \ + (cd "${WORKDIR}"; LANG=C sort -z -u | \ + rsync -rtL0 --files-from=- "${WORKDIR}/" "${ED}${sources_dir}/" ) + fi +} + +# The existence of the section .symtab tells us that a binary is stripped. +# We want to log already stripped binaries, as this may be a QA violation. +# They prevent us from getting the splitdebug data. +if ! __safe_has binchecks ${RESTRICT} && ! __safe_has strip ${RESTRICT}; then + f=$(scanelf -yqRBF '#k%F' -k '!.symtab' "$@") + if [[ -n ${f} ]]; then + echo -e "\a\n" + ewarn "QA Notice: Pre-stripped files found:" + ewarn "${f}" + echo "${f}" > "${T}"/scanelf-already-stripped.log + fi +fi + +# Now we look for unstripped binaries. +for x in $(scanelf -yqRBF '#k%F' -k '.symtab' "$@"); do + f=$(file "${x}") || continue + [[ -z ${f} ]] && continue + + # only split debug info for final linked objects + # or kernel modules as debuginfo for intermediatary + # files (think crt*.o from gcc/glibc) is useless and + # actually causes problems. install sources for all + # elf types though cause that stuff is good. + + if [[ ${f} == *"SB executable"* || ${f} == *"SB shared object"* ]]; then + save_elf_sources "${x}" + elif [[ ${f} == *"SB relocatable"* ]]; then + save_elf_sources "${x}" + fi +done diff --git a/bash/helpers/internals/_generic_new b/bash/helpers/internals/_generic_new new file mode 100755 index 000000000..8bc3aa6d0 --- /dev/null +++ b/bash/helpers/internals/_generic_new @@ -0,0 +1,22 @@ +#!/usr/bin/env pkgcore-ebuild-helper +# Copyright: 2012 Brian Harring +# License: GPLv2 or bsd-3 + +check_args 2 + +if [[ -z ${T} ]]; then + __helper_exit 2 "environment issue (ebuild commands somehow filtered the env for ${HELPER_NAME} call)- \${T} was empty" +fi + +rm -rf "${T}/$2" + +if ${PKGCORE_NEW_READS_STDIN} && [[ $1 == "-" ]]; then + if [[ -t 0 ]]; then + die "${HELPER_NAME#new} - $2 cannot be invoked with stdin as a tty" + fi + check_command_or_stop cat > "${T}/$2" +else + check_command_or_stop cp -- "$1" "${T}/$2" +fi +invoke_script "do${HELPER_NAME#new}" "${T}/$2" +rm -f "${T}/$2" diff --git a/bash/helpers/internals/_raw_dohtml b/bash/helpers/internals/_raw_dohtml new file mode 100755 index 000000000..1a1ec8ae0 --- /dev/null +++ b/bash/helpers/internals/_raw_dohtml @@ -0,0 +1,188 @@ +#!/usr/bin/env python +# Copyright 1999-2006 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ + +# +# Typical usage: +# dohtml -r docs/* +# - put all files and directories in docs into /usr/share/doc/${PF}/html +# dohtml foo.html +# - put foo.html into /usr/share/doc/${PF}/html +# +# +# Detailed usage: +# dohtml +# - will install the files in the list of files (space-separated list) into +# /usr/share/doc/${PF}/html, provided the file ends in .htm, .html, .css, +# .js, ,gif, .jpeg, .jpg, or .png. +# dohtml -r +# - will do as 'dohtml', but recurse into all directories, as long as the +# directory name is not CVS +# dohtml -A jpe,java [-r] +# - will do as 'dohtml' but add .jpe,.java (default filter list is +# added to your list) +# dohtml -a png,gif,html,htm [-r] +# - will do as 'dohtml' but filter on .png,.gif,.html,.htm (default filter +# list is ignored) +# dohtml -x CVS,SCCS,RCS -r +# - will do as 'dohtml -r', but ignore directories named CVS, SCCS, RCS + +from __future__ import print_function + +import os +import sys +import textwrap + +def dodir(path): + os.spawnlp(os.P_WAIT, "install", "install", "-d", path) + +def dofile(src,dst): + os.spawnlp(os.P_WAIT, "install", "install", "-m0644", src, dst) + +def install(basename, dirname, options, prefix=""): + fullpath = basename + if prefix: + fullpath = prefix + "/" + fullpath + if dirname: + fullpath = dirname + "/" + fullpath + + if options.DOCDESTTREE: + destdir = options.D + "usr/share/doc/" + options.PF + "/" + options.DOCDESTTREE + "/" + options.doc_prefix + "/" + prefix + else: + destdir = options.D + "usr/share/doc/" + options.PF + "/html/" + options.doc_prefix + "/" + prefix + + if os.path.isfile(fullpath): + ext = os.path.splitext(basename)[1] + if (len(ext) and ext[1:] in options.allowed_exts) or basename in options.allowed_files: + dodir(destdir) + dofile(fullpath, destdir + "/" + basename) + elif options.recurse and os.path.isdir(fullpath) and \ + basename not in options.disallowed_dirs: + for i in os.listdir(fullpath): + pfx = basename + if prefix: pfx = prefix + "/" + pfx + install(i, dirname, options, pfx) + else: + return False + return True + + +class OptionsClass: + def __init__(self): + self.PF = "" + self.D = "" + self.DOCDESTTREE = "" + + if os.environ.has_key("PF"): + self.PF = os.environ["PF"] + if os.environ.has_key("D"): + self.D = os.environ["D"] + if os.environ.get("PKGCORE_PREFIX_SUPPORT", "false") == "true": + if not "ED" in os.environ: + raise Exception("runtime error, or ebuild error: no ED variable found, but required") + self.D = os.environ["ED"] + if os.environ.has_key("_E_DOCDESTTREE_"): + self.DOCDESTTREE = os.environ["_E_DOCDESTTREE_"] + + self.allowed_exts = [ 'htm', 'html', 'css', 'js', + 'gif', 'jpeg', 'jpg', 'png' ] + self.allowed_files = [] + self.disallowed_dirs = [ 'CVS' ] + self.recurse = False + self.verbose = False + self.doc_prefix = "" + +def print_help(): + opts = OptionsClass() + + print(textwrap.dedent( + """ + dohtml [-a .foo,.bar] [-A .foo,.bar] [-f foo,bar] [-x foo,bar] + [-r] [-V] [file ...] + + -a Set the list of allowed to those that are specified. + Default: {} + -A Extend the list of allowed file types. + -f Set list of allowed extensionless file names. + -x Set directories to be excluded from recursion. + Default: {} + -r Install files and directories recursively. + -V Be verbose. + """.format(", ".join(opts.allowed_exts), ", ".join(opts.disallowed_dirs)) + )) + +def parse_args(): + options = OptionsClass() + args = [] + + x = 1 + while x < len(sys.argv): + arg = sys.argv[x] + if arg in ["-h","-r","-V"]: + if arg == "-h": + print_help() + sys.exit(0) + elif arg == "-r": + options.recurse = True + elif arg == "-V": + options.verbose = True + elif sys.argv[x] in ["-A","-a","-f","-x","-p"]: + x += 1 + if x == len(sys.argv): + print_help() + sys.exit(0) + elif arg == "-p": + options.doc_prefix = sys.argv[x] + else: + values = sys.argv[x].split(",") + if arg == "-A": + options.allowed_exts.extend(values) + elif arg == "-a": + options.allowed_exts = values + elif arg == "-f": + options.allowed_files = values + elif arg == "-x": + options.disallowed_dirs = values + else: + args.append(sys.argv[x]) + x += 1 + + return (options, args) + +def main(): + + (options, args) = parse_args() + + if isinstance(options.allowed_exts, basestring): + options.allowed_exts = options.allowed_exts.split(",") + + if options.verbose: + print(textwrap.dedent( + """ + Allowed extensions: {} + Document prefix: '{}' + Allowed files: {} + """.format( + ", ".join(options.allowed_exts), options.doc_prefix, + ", ".join(options.allowed_files) + ) + )) + + success = True + + for x in args: + basename = os.path.basename(x) + dirname = os.path.dirname(x) + if not install(basename, dirname, options): + success = False + + if success: + retcode = 0 + else: + retcode = 1 + + sys.exit(retcode) + +if __name__ == "__main__": + main() diff --git a/bash/helpers/internals/banned b/bash/helpers/internals/banned new file mode 100755 index 000000000..ddda11767 --- /dev/null +++ b/bash/helpers/internals/banned @@ -0,0 +1,3 @@ +#!/usr/bin/env pkgcore-ebuild-helper + +die "'${HELPER_NAME}' is explicitly banned from usage in EAPI '${HELPER_EAPI}'" diff --git a/bash/helpers/internals/deprecated b/bash/helpers/internals/deprecated new file mode 100755 index 000000000..dc89b0102 --- /dev/null +++ b/bash/helpers/internals/deprecated @@ -0,0 +1,12 @@ +#!/usr/bin/env pkgcore-ebuild-helper + +eqawarn "QA Notice: '${HELPER_NAME}' is deprecated in EAPI '${HELPER_EAPI}'" + +# find original, nondeprecated helper and execute it by removing the EAPI where +# it's deprecated from PATH and searching for the old implementation +ORIG_PATH=${PATH} +export PATH=${PATH/:${PKGCORE_BIN_PATH}\/helpers\/${HELPER_EAPI}/} +ORIG_HELPER=$(type -P ${HELPER_NAME}) +export PATH=${ORIG_PATH} + +"${ORIG_HELPER}" "$@" diff --git a/bash/helpers/internals/prepall b/bash/helpers/internals/prepall new file mode 100755 index 000000000..5e4e9f285 --- /dev/null +++ b/bash/helpers/internals/prepall @@ -0,0 +1,93 @@ +#!/bin/bash +# Copyright: 2011 Brian Harring +# Copyright: 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +source "${PKGCORE_BIN_PATH}"/exit-handling.lib || { echo "failed loading libs"; exit -127; } + +"${PKGCORE_BIN_PATH}"/helpers/internals/prepallman +prepinfo +prepallstrip + +if ! ${PKGCORE_PREFIX_SUPPORT:=false}; then + ED=${D} +elif [[ ${ED:-unset} == "unset" ]]; then + echo "The variable ED is missing from the environment, but is required for prefix mode; failing." + exit -1 +fi + +# this should help to ensure that all (most?) shared libraries are executable +# and that all libtool scripts / static libraries are not executable +for i in "${ED}"opt/*/lib{,32,64} \ + "${ED}"lib{,32,64} \ + "${ED}"usr/lib{,32,64} \ + "${ED}"usr/X11R6/lib{,32,64}; do + [[ ! -d ${i} ]] && continue + + for j in "${i}"/*.so.* "${i}"/*.so; do + [[ ! -e ${j} ]] && continue + [[ -L ${j} ]] && continue + [[ -x ${j} ]] && continue + echo "making executable: /${j/${ED}/}" + chmod +x "${j}" + done + + for j in "${i}"/*.a "${i}"/*.la; do + [[ ! -e ${j} ]] && continue + [[ -L ${j} ]] && continue + [[ ! -x ${j} ]] && continue + echo "removing executable bit: /${j/${ED}/}" + chmod -x "${j}" + done +done + +# When installing static libraries into /usr/lib and shared libraries into +# /lib, we have to make sure we have a linker script in /usr/lib along side +# the static library, or gcc will utilize the static lib when linking :(. +# http://bugs.gentoo.org/4411 +for a in "${ED}"usr/lib*/*.a; do + s=${a%.a}.so + if [[ ! -e ${s} ]]; then + s=${s%usr/*}${s##*/usr/} + if [[ -e ${s} ]]; then + echo -e "\aQA Notice: missing gen_usr_ldscript for ${s##*/}\a" + sleep 1 + fi + fi +done + +# Make sure people don't store libtool files or static libs in /lib +f=$(ls "${ED}"lib*/*.{a,la} 2>/dev/null) +if [[ -n ${f} ]]; then + echo -e "\n\aQA Notice: excessive files found in the / partition\a" + echo "${f}" + sleep 1 +fi + +# Verify that the libtool files don't contain bogus $ED entries. +for a in "${ED}"usr/lib*/*.la; do + s=${a##*/} + if grep -qs "${ED}" "${a}"; then + echo -e "\n\aQA Notice: ${s} appears to contain PORTAGE_TMPDIR paths\a" + sleep 1 + fi +done + +if type -p scanelf > /dev/null; then + # Run some sanity checks on shared libraries + for d in "${ED}"lib* "${ED}"usr/lib*; do + f=$(scanelf -ByF '%S %p' "${d}"/lib*.so* | gawk '$2 == "" { print }') + if [[ -n ${f} ]]; then + echo -e "\n\aQA Notice: the following shared libraries lack a SONAME\a" + echo "${f}" + sleep 1 + fi + + f=$(scanelf -ByF '%n %p' "${d}"/lib*.so* | gawk '$2 == "" { print }') + if [[ -n ${f} ]]; then + echo -e "\n\aQA Notice: the following shared libraries lack NEEDED entries\a" + echo "${f}" + sleep 1 + fi + done +fi diff --git a/bash/helpers/internals/prepallman b/bash/helpers/internals/prepallman new file mode 100755 index 000000000..257498f40 --- /dev/null +++ b/bash/helpers/internals/prepallman @@ -0,0 +1,18 @@ +#!/bin/bash +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +shopt -s extdebug +source "${PKGCORE_BIN_PATH}"/exit-handling.lib || { echo "failed loading libs"; exit -127; } + +if ! ${PKGCORE_PREFIX_SUPPORT:=false}; then + ED=${D} +elif [[ ${ED:-unset} == "unset" ]]; then + echo "The variable ED is missing from the environment, but is required for prefix mode; failing." + exit -1 +fi + +for x in $(find "${ED}" -name man -type d -printf '%P\n'); do + prepman ${x%/man} + export prepallman_banner="no" +done diff --git a/bash/isolated-functions.lib b/bash/isolated-functions.lib new file mode 100644 index 000000000..7e887851f --- /dev/null +++ b/bash/isolated-functions.lib @@ -0,0 +1,229 @@ +# Copyright 2006-2012 Brian Harring +# License GPL2/BSD3 + +# Internal logging function, don't use this in ebuilds +__elog_base() { + local messagetype + [[ -z $1 || -z ${T} || ! -d ${T}/logging ]] && return 1 + case $1 in + INFO|WARN|ERROR|LOG|QA) + messagetype=$1 + shift + ;; + *) + echo -e " ${PKGCORE_RC_BAD}*${PKGCORE_RC_NORMAL} Invalid use of internal function __elog_base(), next message will not be logged" >&2 + return 1 + ;; + esac + echo "$*" >> "${T}/logging/${EBUILD_PHASE}.${messagetype}" + return 0 +} + +__colored_output_disable() { + PKGCORE_RC_COLS="25 80" + PKGCORE_RC_ENDCOL= + PKGCORE_RC_GOOD= + PKGCORE_RC_WARN= + PKGCORE_RC_BAD= + PKGCORE_RC_NORMAL= + PKGCORE_RC_HILITE= + PKGCORE_RC_BRACKET= +} &> /dev/null + +__colored_output_enable() { + # try setting the column width to bash's internal COLUMNS variable, + # then try to get it via stty. no go? hardcode it to 80. + PKGCORE_RC_COLS=${COLUMNS:-0} + if (( PKGCORE_RC_COLS <= 0 )); then + PKGCORE_RC_COLS=$(set -- $(stty size 2>/dev/null) ; echo ${2:-0}) + if (( PKGCORE_RC_COLS <= 0 )); then + PKGCORE_RC_COLS=80 + fi + fi + export COLUMNS=${PKGCORE_RC_COLS} + PKGCORE_RC_COLS=$(( PKGCORE_RC_COLS - 8 )) # width of [ ok ] == 7 + + export PKGCORE_RC_ENDCOL=$'\e[A\e['${PKGCORE_RC_COLS}'C' + # Now, ${PKGCORE_RC_ENDCOL} will move us to the end of the + # column; irregardless of character width + + export PKGCORE_RC_GOOD=$'\e[32;01m' + export PKGCORE_RC_WARN=$'\e[33;01m' + export PKGCORE_RC_BAD=$'\e[31;01m' + export PKGCORE_RC_HILITE=$'\e[36;01m' + export PKGCORE_RC_BRACKET=$'\e[34;01m' + export PKGCORE_RC_NORMAL=$'\e[0m' +} &> /dev/null + +__safe_has() { + # Version of has, only to be used when the invoker knows that that + # the needle/targets will never have \001 in them + local needle=$1 + shift + local IFS=$'\001' + [[ "${IFS}${*}${IFS}" == *"${IFS}${needle}${IFS}"* ]] +} + +__feature_is_enabled() { + local IFS=$' \t\n' + __safe_has "$1" ${FEATURES} +} &> /dev/null + + +__is_function() { + declare -F "$1" &> /dev/null +} &> /dev/null + +__run_function_if_exists() { + __is_function "$1" || return 0 + "$@" +} + +__qa_run_function_if_exists() { + __is_function "$1" || return 0 + __qa_invoke "$@" +} + +__directory_is_empty() { + __shopt_push -s dotglob nullglob + local files=( ${1}/* ) + __shopt_pop + [[ ${#files[@]} -gt 0 ]] && return 1 + return 0 +} + +__strip_duplicate_slashes() { + if [[ -n $1 ]]; then + local removed=$1 + while [[ ${removed} == *//* ]]; do + removed=${removed//\/\///} + done + echo "${removed}" + fi +} + +__get_func_code() { + __IFS_push $'\n' + local code=( $(declare -f "$1") ) + __IFS_pop + + [[ -z ${code[@]} ]] && return + + # drop function name and surrounding brackets + code=( ${code[@]:2:${#code[@]}-3} ) + echo "${code[@]}" +} + +PKGCORE_SHOPT_STACK=() + +__shopt_push() { + PKGCORE_SHOPT_STACK[${#PKGCORE_SHOPT_STACK[@]}]=${BASHOPTS} + PKGCORE_SHOPT_STACK[${#PKGCORE_SHOPT_STACK[@]}]=$- + if [[ $1 == -[su] ]]; then + # shopt modification + shopt "$@" || die "bad shopt options: $@" + elif [[ -n $@ ]]; then + set "$@" || die "bad set invocation: $@" + fi + return 0 +} &> /dev/null + +__shopt_pop() { + [[ $# -ne 0 ]] && die "bad invocation of __shopt_pop; no args should be supplied, got $@" + local count=$(( ${#PKGCORE_SHOPT_STACK[@]} - 1 )) + [[ ${count} -le 0 ]] && die "bad __shopt_pop invocation; no matching push, stack was empty" + + local set_val=${PKGCORE_SHOPT_STACK[${count}]} + if [[ $- != ${set_val} ]]; then + set ${-:++${-}} ${set_val:+-${set_val}} || die "failed enforcing set state of ${set_val}" + fi + unset PKGCORE_SHOPT_STACK[${count}] + + count=$(( count - 1 )) + + local previous=${PKGCORE_SHOPT_STACK[${count}]} + unset PKGCORE_SHOPT_STACK[${count}] + [[ ${BASHOPTS} == ${previous} ]] && return 0 + + local IFS=' ' + local current=${BASHOPTS} + if [[ -n ${current} ]]; then + shopt -u ${current//:/ } >&2 || die "failed wiping current shopt settings of ${current}" + fi + if [[ -n ${previous} ]]; then + shopt -s ${previous//:/ } >&2 || die "failed forcing old shopt settings to ${previous}" + fi + return 0 +} &> /dev/null + +declare -a PKGCORE_SAVED_IFS + +__IFS_push() { + PKGCORE_SAVED_IFS[${#PKGCORE_SAVED_IFS[@]}]=${IFS-unset} + if [[ $1 == unset ]]; then + unset IFS + else + IFS=$1 + fi + : +} + +__IFS_pop() { + if [[ ${#PKGCORE_SAVED_IFS[@]} -eq 0 ]]; then + die "__IFS_pop invoked with nothing on the stack..." + fi + IFS=${PKGCORE_SAVED_IFS[$(( ${#PKGCORE_SAVED_IFS[@]} - 1 ))]} + [[ ${IFS} == unset ]] && unset IFS + unset PKGCORE_SAVED_IFS[$(( ${#PKGCORE_SAVED_IFS[@]} - 1 ))] + : +} + +__qa_invoke() { + if ${PKGCORE_QA_SUPPRESSED:-false}; then + "$@" + return $(( $? )) + fi + local pkgcore_should_fail=false + # save env and shopt settings. + # in addition, protect the stack from bad pkgcore calls, or bad consumers accessing internals + local PKGCORE_SAVED_IFS=() + local PKGCORE_SHOPT_STACK=() + + __IFS_push "${IFS}" + __shopt_push + + "$@" + local ret=$? + + if [[ ${#PKGCORE_SAVED_IFS[@]} -ne 1 ]]; then + echo "QA warning: unbalanced __IFS_push/__IFS_pop detected. internal error?" \ + " count was ${#PKGCORE_SAVED_IFS[@]}" + pkgcore_should_fail=true + fi + if [[ ${#PKGCORE_SHOPT_STACK[@]} -ne 2 ]]; then + echo "QA warning: unbalanced __shopt_push/__shopt_pop detected. internal error? count was ${#PKGCORE_SHOPT_STACK[@]}" + pkgcore_should_fail=true + fi + + if [[ ${PKGCORE_SAVED_IFS[0]} != ${IFS-unset} ]]; then + echo "QA WARNING: invocation $@ manipulated IFS to ${IFS}, but didn't restore it to its original value!" + fi + __IFS_pop + + # while these echo statements are ugly, written this way to ensure bash does it as a single write- + # aka, keep it within the size of atomic writes for pipes. + # relevant for threaded output straight to term + if [[ ${PKGCORE_SHOPT_STACK[0]} != ${BASHOPTS} ]]; then + echo "QA warning: shopt modification bled out of invocation $@"$'\n'" : was ${PKGCORE_SHOPT_STACK[0]}"$'\n'" : now ${BASHOPTS}" >&2 + fi + + if [[ ${PKGCORE_SHOPT_STACK[1]} != $- ]]; then + echo "QA warning: set modification bled out of invocation $@"$'\n'" : was ${PKGCORE_SHOPT_STACK[1]}"$'\n'" : now $-" >&2 + fi + __shopt_pop + + ${pkgcore_should_fail} && die "invocation $@ modified globals and didn't clean up" + return $(( ret )) +} + +: diff --git a/bash/regenerate_dont_export_func_list.bash b/bash/regenerate_dont_export_func_list.bash new file mode 100755 index 000000000..23a0db913 --- /dev/null +++ b/bash/regenerate_dont_export_func_list.bash @@ -0,0 +1,65 @@ +#!/bin/bash +# +# Generates a file (or list) of functions defined in the various bash support +# libs to avoid exporting to the saved ebuild environment. + +_FP=${1:-dont_export_funcs.list} + +export PKGCORE_BIN_PATH=$(dirname "$0") +if [[ -z ${PKGCORE_CLEAN_ENV} ]]; then + exec env -i PKGCORE_PYTHON_PATH=${PKGCORE_PYTHON_PATH} PKGCORE_CLEAN_ENV=1 /bin/bash "$0" "${_FP}" +fi + +export LC_ALL=C # avoid any potential issues of unicode sorting for whacked func names +# export this so that scripts will behave as libs +export PKGCORE_SOURCING_FOR_REGEN_FUNCS_LIST=1 +set -f # shell expansion can bite us in the ass during the echo below +cd "${PKGCORE_BIN_PATH}" || { echo "!!! failed cd'ing to ${PKGCORE_BIN_PATH}" >&2; exit 1; } + +# force some ordering. + +__source_was_seen() { + local x + for x in "${seen[@]}"; do + [[ ${x} == $1 ]] && return 0 + done + return 1 +} +declare -a seen +source() { + local fp=$(readlink -f "$1") + __source_was_seen "${fp}" && return 0 + # die relies on these vars; we reuse them. + local CATEGORY=${PKGCORE_BIN_PATH} + local PF=$1 + echo "sourcing ${x}" >&2 + . "$@" || { echo "!!! failed sourcing ${x}; exit $?" >&2; exit 3; } + seen[${#seen[@]}]=${fp} + return 0 +} + +# without this var, parsing certain things can fail; force to true +# so any code that tried accessing it thinks it succeeded +export PKGCORE_PYTHON_BINARY=/bin/true + +forced_order_source="isolated-functions.lib exit-handling.lib eapi/common.lib ebuild-daemon.lib ebuild-daemon.bash" + +# skip EAPI specific libs since those need be sourced on demand depending on an ebuild's EAPI +for x in ${forced_order_source} $(find . -name '*.lib' ! -regex ".*/[0-9]+\.lib" | sed -e 's:^\./::' | sort); do + source "${x}" +done + +# wipe our custom funcs +unset -f __source_was_seen +unset -f source + +# Sorting order; put PMS functionality first, then our internals. +result=$(__environ_list_funcs | sort) +result=$(echo "${result}" | grep -v "^__"; echo "${result}" | grep "^__") + +if [[ ${_FP} == '-' ]]; then + echo >&2 + echo "${result}" +else + echo "${result}" > dont_export_funcs.list +fi diff --git a/bin/pwrapper b/bin/pwrapper index ecbc3ce76..505611371 100755 --- a/bin/pwrapper +++ b/bin/pwrapper @@ -31,6 +31,8 @@ if __name__ == '__main__': os.environ.update({ 'PKGCORE_SCRIPT_PATH': os.path.dirname(os.path.abspath(__file__)), + 'PKGCORE_BASH_PATH': os.path.join( + os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'bash'), 'PKGCORE_CONFIG_PATH': os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'config'), }) diff --git a/pkgcore/ebuild/const.py b/pkgcore/ebuild/const.py index 8791ccb91..41d0ed18c 100644 --- a/pkgcore/ebuild/const.py +++ b/pkgcore/ebuild/const.py @@ -4,7 +4,10 @@ """ ebuild internal constants """ -from os import path + +import os +from os.path import join as pjoin +import sys incrementals = ( "ACCEPT_KEYWORDS", "ACCEPT_LICENSE", "CONFIG_PROTECT", @@ -21,10 +24,10 @@ metadata_keys = ( "RDEPEND", "REQUIRED_USE", "RESTRICT", "SLOT", "SRC_URI", "_eclasses_", ) -WORLD_FILE = '/var/lib/portage/world' +WORLD_FILE = '/var/lib/portage/world' -EAPI_BIN_PATH = path.join(path.dirname(path.abspath(__file__)), "eapi-bash") -EBUILD_DAEMON_PATH = path.join(EAPI_BIN_PATH, "ebuild-daemon.bash") -EBUILD_HELPERS_PATH = path.join(EAPI_BIN_PATH, "helpers") +EAPI_BIN_PATH = os.environ.get("PKGCORE_BASH_PATH", pjoin(sys.prefix, 'lib/pkgcore')) +EBUILD_DAEMON_PATH = pjoin(EAPI_BIN_PATH, "ebuild-daemon.bash") +EBUILD_HELPERS_PATH = pjoin(EAPI_BIN_PATH, "helpers") -PKGCORE_DEBUG_VARS = ("PKGCORE_DEBUG", "PKGCORE_PERF_DEBUG") +PKGCORE_DEBUG_VARS = ("PKGCORE_DEBUG", "PKGCORE_PERF_DEBUG") diff --git a/pkgcore/ebuild/eapi-bash/dont_export_funcs.list b/pkgcore/ebuild/eapi-bash/dont_export_funcs.list deleted file mode 100644 index da5cb11da..000000000 --- a/pkgcore/ebuild/eapi-bash/dont_export_funcs.list +++ /dev/null @@ -1,120 +0,0 @@ -EXPORT_FUNCTIONS -KV_major -KV_micro -KV_minor -KV_to_int -adddeny -addpredict -addread -addwrite -assert -best_version -debug-print -debug-print-function -debug-print-section -die -diropts -docinto -ebegin -econf -eend -eerror -einfo -einfon -einstall -elog -eqawarn -ewarn -exeinto -exeopts -get_KV -has -has_version -hasq -hasv -inherit -insinto -insopts -into -libopts -portageq -unpack -use -use_enable -use_with -useq -usev -__IFS_pop -__IFS_push -__colored_output_disable -__colored_output_enable -__directory_is_empty -__dump_metadata_keys -__dump_trace -__dyn_pkg_preinst -__dyn_src_install -__ebd_exec_main -__ebd_main_loop -__ebd_process_ebuild_phases -__ebd_process_metadata -__ebd_process_sandbox_results -__ebd_read_cat_size -__ebd_read_line -__ebd_read_line_nonfatal -__ebd_read_size -__ebd_sigint_handler -__ebd_sigkill_handler -__ebd_write_line -__ebd_write_raw -__elog_base -__ensure_PATH -__environ_dump -__environ_list_funcs -__environ_list_vars -__environ_sanitize_saved_env -__environ_save_to_file -__escape_regex_array -__execute_phases -__feature_is_enabled -__filter_env -__generate_initial_ebuild_environ -__get_func_code -__get_libdir -__helper_check_exit -__helper_died -__helper_exit -__inject_common_phase_funcs -__inject_phase_funcs -__internal_inherit -__is_function -__load_eapi_libs -__load_ebuild -__make_preloaded_eclass_func -__phase_common_pkg_nofetch -__phase_common_pre_phase -__phase_common_src_compile -__phase_common_src_test -__phase_common_src_unpack -__phase_default_post_src_compile -__phase_default_pre_src_compile -__phase_default_pre_src_configure -__phase_default_pre_src_install -__phase_default_pre_src_prepare -__phase_default_pre_src_test -__phase_default_pre_src_unpack -__qa_interceptors_disable -__qa_interceptors_enable -__qa_invoke -__qa_run_function_if_exists -__regex_filter_input -__request_sandbox_summary -__reset_sandbox -__run_ebuild_phase -__run_function_if_exists -__safe_has -__set_perf_debug -__shopt_pop -__shopt_push -__source_bashrcs -__strip_duplicate_slashes -__timed_call diff --git a/pkgcore/ebuild/eapi-bash/eapi/0.lib b/pkgcore/ebuild/eapi-bash/eapi/0.lib deleted file mode 100644 index 35ef2ee73..000000000 --- a/pkgcore/ebuild/eapi-bash/eapi/0.lib +++ /dev/null @@ -1,4 +0,0 @@ -# Copyright: 2012 Brian Harring -# license GPL2/BSD 3 - -__inject_common_phase_funcs diff --git a/pkgcore/ebuild/eapi-bash/eapi/1.lib b/pkgcore/ebuild/eapi-bash/eapi/1.lib deleted file mode 100644 index 35ef2ee73..000000000 --- a/pkgcore/ebuild/eapi-bash/eapi/1.lib +++ /dev/null @@ -1,4 +0,0 @@ -# Copyright: 2012 Brian Harring -# license GPL2/BSD 3 - -__inject_common_phase_funcs diff --git a/pkgcore/ebuild/eapi-bash/eapi/2.lib b/pkgcore/ebuild/eapi-bash/eapi/2.lib deleted file mode 100644 index 1b63af89a..000000000 --- a/pkgcore/ebuild/eapi-bash/eapi/2.lib +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright: 2011-2012 Brian Harring -# license GPL2/BSD 3 - -__phase_eapi2_src_configure() { - if [[ -x ${ECONF_SOURCE:-.}/configure ]]; then - econf - fi -} - -__phase_eapi2_src_prepare() { - : -} - -default() { - if __is_function default_pkg_${EBUILD_PHASE}; then - default_pkg_${EBUILD_PHASE} - elif __is_function default_src_${EBUILD_PHASE}; then - default_src_${EBUILD_PHASE} - else - die "default is not available in ebuild phase '${EBUILD_PHASE}'" - fi -} - -__inject_phase_funcs __phase_eapi2 src_{configure,prepare} -__inject_common_phase_funcs - -: diff --git a/pkgcore/ebuild/eapi-bash/eapi/3.lib b/pkgcore/ebuild/eapi-bash/eapi/3.lib deleted file mode 100644 index 7dbc85cc8..000000000 --- a/pkgcore/ebuild/eapi-bash/eapi/3.lib +++ /dev/null @@ -1,6 +0,0 @@ -# Copyright: 2011-2012 Brian Harring -# license GPL2/BSD 3 - -source "${PKGCORE_BIN_PATH}"/eapi/2.lib - -: diff --git a/pkgcore/ebuild/eapi-bash/eapi/4.lib b/pkgcore/ebuild/eapi-bash/eapi/4.lib deleted file mode 100644 index 82e344fef..000000000 --- a/pkgcore/ebuild/eapi-bash/eapi/4.lib +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright: 2011-2012 Brian Harring -# license GPL2/BSD 3 - -source "${PKGCORE_BIN_PATH}"/eapi/3.lib - -nonfatal() { - PKGCORE_NONFATAL_HELPER=true "$@" -} - -__phase_eapi4_src_install() { - if [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then - emake DESTDIR="${D}" install - fi - - # important; keep these as separate statements. we use the exit - # code after all. - local tmp_var - - if tmp_var=$(declare -p DOCS 2> /dev/null); then - # given declare -- x= || declare -a x=, isolate the --/-a - tmp_var=${tmp_var#declare -} - tmp_var=${tmp_var%% *} - if [[ ${tmp_var/a} != ${tmp_var} ]]; then - dodoc "${DOCS[@]}" - else - dodoc ${DOCS} - fi - else - for tmp_var in README* ChangeLog AUTHORS NEWS TODO CHANGES THANKS \ - BUGS FAQ CREDITS CHANGELOG; do - [[ -s ${tmp_var} ]] && dodoc "${tmp_var}" - done - fi -} - -__inject_phase_funcs __phase_eapi4 src_install - -: diff --git a/pkgcore/ebuild/eapi-bash/eapi/5.lib b/pkgcore/ebuild/eapi-bash/eapi/5.lib deleted file mode 100644 index ca3cc35be..000000000 --- a/pkgcore/ebuild/eapi-bash/eapi/5.lib +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright: 2012 Brian Harring -# license GPL2/BSD 3 - -source "${PKGCORE_BIN_PATH}"/eapi/4.lib - -has_version() { - local r=${ROOT:-/} - if [[ $1 == "--host-root" ]]; then - r=/ - shift - fi - PKGCORE_DISABLE_COMPAT=true portageq 'has_version' "$1" --domain-at-root "${r}" -} - -best_version() { - local r=${ROOT:-/} - if [[ $1 == "--host-root" ]]; then - r=/ - shift - fi - PKGCORE_DISABLE_COMPAT=true portageq 'best_version' "$1" --domain-at-root "${r}" - -} - -usex() { - use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" - return 0 -} - -: diff --git a/pkgcore/ebuild/eapi-bash/eapi/common.lib b/pkgcore/ebuild/eapi-bash/eapi/common.lib deleted file mode 100644 index dd6369ad5..000000000 --- a/pkgcore/ebuild/eapi-bash/eapi/common.lib +++ /dev/null @@ -1,590 +0,0 @@ -# Copyright: 2011-2012 Brian Harring -# license GPL2/BSD 3 - -use() { - # EAPI 5 and up - if ${PKGCORE_PROFILE_IUSE_INJECTION} && \ - [[ ! ${1#!} =~ ${PKGCORE_IUSE_EFFECTIVE} ]]; then - die "USE flag '${1#!}' not in IUSE for ${CATEGORY}/${PF}" - fi - - # Ensure USE is split on normal IFS. - local IFS=$' \t\n' - - if [[ ${1:0:1} == "!" ]]; then - ! __safe_has "${1#!}" ${USE} - else - __safe_has "$1" ${USE} - fi -} - -usev() { - if use "$1"; then - echo "${1#!}" - fi -} - -useq() { - use "$@" -} - -use_with() { - if [[ -z $1 ]]; then - echo "!!! use_with() called without a parameter." >&2 - echo "!!! use_with [ [value]]" >&2 - return - fi - - local uw_suffix="" - if __safe_has "${EAPI:-0}" 0 1 2 3; then - uw_suffix=${3:+=$3} - else - uw_suffix=${3+=$3} - fi - - local uword=$2 - if [[ -z ${uword} ]]; then - uword=$1 - fi - - if use $1; then - echo "--with-${uword}${uw_suffix}" - return 0 - fi - echo "--without-${uword}" - return 1 -} - -use_enable() { - if [[ -z $1 ]]; then - echo "!!! use_enable() called without a parameter." >&2 - echo "!!! use_enable [ [value]]" >&2 - return - fi - - local ue_suffix="" - if __safe_has "${EAPI:-0}" 0 1 2 3; then - ue_suffix=${3:+=$3} - else - ue_suffix=${3+=$3} - fi - - local uword=$2 - if [[ -z ${uword} ]]; then - uword=$1 - fi - - if use "$1"; then - echo "--enable-${uword}${ue_suffix}" - return 0 - fi - echo "--disable-${uword}" - return 1 -} - -econf() { - local ret - ECONF_SOURCE=${ECONF_SOURCE:-.} - if [[ ! -x ${ECONF_SOURCE}/configure ]]; then - [[ -f ${ECONF_SOURCE}/configure ]] && die "configure script isn't executable" - die "no configure script found" - fi - - if [[ -d /usr/share/gnuconfig ]]; then - local x - find "${WORKDIR}" -type f \( -name config.guess -o -name config.sub \) | \ - while read x; do - echo "econf: replacing ${x} with /usr/share/gnuconfig/${x##*/}" - cp -f "/usr/share/gnuconfig/${x##*/}" "${x}" - done - fi - - # if the profile defines a location to install libs to aside from default, pass it on. - # if the ebuild passes in --libdir, they're responsible for the conf_libdir fun. - local CONF_LIBDIR=$(__get_libdir) - if [[ -n ${CONF_LIBDIR} && $* != *"--libdir="* ]]; then - if [[ $* == *"--exec-prefix="* ]]; then - local args=$(echo $*) - local -a prefix=( $(echo ${args/*--exec-prefix[= ]}) ) - CONF_PREFIX=${prefix/--*} - [[ ${CONF_PREFIX} != /* ]] && CONF_PREFIX=/${CONF_PREFIX} - elif [[ $* == *"--prefix="* ]]; then - local args=$(echo $*) - local -a pref=( $(echo ${args/*--prefix[= ]}) ) - CONF_PREFIX=${prefix/--*} - [[ ${CONF_PREFIX} != /* ]] && CONF_PREFIX=/${CONF_PREFIX} - else - CONF_PREFIX=/usr - fi - export CONF_PREFIX - [[ ${CONF_LIBDIR} != /* ]] && CONF_LIBDIR=/${CONF_LIBDIR} - set -- --libdir="$(__strip_duplicate_slashes "${CONF_PREFIX}${CONF_LIBDIR}")" "$@" - fi - - if ${PKGCORE_ECONF_DISABLE_DEPENDENCY_TRACKING} || ${PKGCORE_ECONF_DISABLE_SILENT_RULES}; then - local help_text=$("${ECONF_SOURCE}/configure" --help 2> /dev/null) - local extra_args=() - - # EAPI 4 and up. - if ${PKGCORE_ECONF_DISABLE_DEPENDENCY_TRACKING} && \ - [[ ${help_text} =~ "--disable-dependency-tracking" ]]; then - extra_args+=( --disable-dependency-tracking ) - fi - - # EAPI 5 and up. - if ${PKGCORE_ECONF_DISABLE_SILENT_RULES} && \ - [[ ${help_text} =~ "--disable-silent-rules" ]]; then - extra_args+=( --disable-silent-rules ) - fi - set -- "${extra_args[@]}" "$@" - unset extra_args - unset help_text - fi - - # Reset IFS since we're interpretting user supplied EXTRA_ECONF. - local IFS=$' \t\n' - set -- "${ECONF_SOURCE}/configure" \ - --prefix=/usr \ - ${CBUILD:+--build="${CBUILD}"} \ - --host="${CHOST}" \ - ${CTARGET:+--target="${CTARGET}"} \ - --mandir=/usr/share/man \ - --infodir=/usr/share/info \ - --datadir=/usr/share \ - --sysconfdir=/etc \ - --localstatedir=/var/lib \ - "$@" \ - ${EXTRA_ECONF} - - echo "$@" - - if ! "$@"; then - if [[ -s config.log ]]; then - echo - echo "!!! Please attach the config.log to your bug report:" - echo "!!! ${PWD}/config.log" - fi - die "econf failed" - fi - return $? -} - -# debug-print() gets called from many places with verbose status information useful -# for tracking down problems. The output is in ${T}/eclass-debug.log. -# You can set ECLASS_DEBUG_OUTPUT to redirect the output somewhere else as well. -# The special "on" setting echoes the information, mixing it with the rest of the -# emerge output. -# You can override the setting by exporting a new one from the console, or you can -# set a new default in make.*. Here the default is "" or unset. - -# in the future might use e* from /etc/init.d/functions.sh if i feel like it -debug-print() { - if __safe_has ${EBUILD_PHASE} depend nofetch config info postinst; then - return - fi - # if ${T} isn't defined, we're in dep calculation mode and - # shouldn't do anything - [[ -z ${T} ]] && return 0 - - local _item - for _item in "$@"; do - # extra user-configurable targets - if [[ ${ECLASS_DEBUG_OUTPUT} == "on" ]]; then - echo "debug: ${_item}" - elif [[ -n ${ECLASS_DEBUG_OUTPUT} ]]; then - echo "debug: ${_item}" >> "${ECLASS_DEBUG_OUTPUT}" - fi - - # default target - echo "${_item}" >> "${T}"/eclass-debug.log - chmod g+w "${T}"/eclass-debug.log &> /dev/null - done - # let the portage user own/write to this file -} - -# The following 2 functions are debug-print() wrappers - -debug-print-function() { - str="$1: entering function" - shift - debug-print "${str}, parameters: $*" -} - -debug-print-section() { - debug-print "now in section $*" -} - -einstall() { - ${PKGCORE_PREFIX_SUPPORT} || local ED=${D} - # CONF_PREFIX is only set if they didn't pass in libdir above - local LOCAL_EXTRA_EINSTALL=( ${EXTRA_EINSTALL} ) - local CONF_LIBDIR=$(__get_libdir) - if [[ -n ${CONF_LIBDIR} && ${CONF_PREFIX:-unset} != "unset" ]]; then - EI_DESTLIBDIR=${ED%%/}/${CONF_PREFIX%%/}/${CONF_LIBDIR%%/}/ - LOCAL_EXTRA_EINSTALL+=( libdir=${EI_DESTLIBDIR} ) - unset EI_DESTLIBDIR - fi - - if ! [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then - die "no Makefile found" - fi - - # Reset IFS for LOCAL_EXTRA_EINSTALL, should users be up to something. - local IFS=$' \t\n' - set -- \ - ${MAKE:-make} \ - prefix="${ED}/usr" \ - datadir="${ED}/usr/share" \ - infodir="${ED}/usr/share/info" \ - localstatedir="${ED}/var/lib" \ - mandir="${ED}/usr/share/man" \ - sysconfdir="${ED}/etc" \ - ${LOCAL_EXTRA_EINSTALL[@]} \ - "$@" install - [[ ${PKGCORE_DEBUG} != 0 ]] && "$@" -n - "$@" || die "einstall failed" -} - -__get_libdir() { - local libdir=$1 libdir_var="LIBDIR_${ABI}" - [[ -n ${ABI} && -n ${!libdir_var} ]] && libdir=${!libdir_var} - echo "${libdir}" -} - -__phase_common_pkg_nofetch() { - [[ -z ${SRC_URI} ]] && return - - echo "!!! The following are listed in SRC_URI for ${PN}:" - local fp - __shopt_push -f - for fp in ${SRC_URI}; do - echo "!!! ${fp}" - done - __shopt_pop -} - -__phase_common_src_unpack() { - if [[ -n ${A} ]]; then - unpack ${A} - fi -} - -__phase_common_src_compile() { - # only eapi 0/1 invoke configure... - if __safe_has "${EAPI:-0}" 0 1; then - if [[ ${EAPI:-0} == 0 ]]; then - [[ -x ./configure ]] && econf - elif [[ -x ${ECONF_SOURCE:-.}/configure ]]; then - econf - fi - fi - if [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then - emake || die "emake failed" - fi -} - -__phase_common_src_test() { - addpredict / - local extra_args=( ${EXTRA_EMAKE} ) - ${PKGCORE_ALLOW_PARALLEL_SRC_TEST} || extra_args+=( -j1 ) - if make check -n &> /dev/null; then - echo ">>> Test phase [check]: ${CATEGORY}/${PF}" - emake "${extra_args[@]}" check || die "Make check failed. See above for details." - elif make test -n &> /dev/null; then - emake "${extra_args[@]}" test || die "Make test failed. See above for details." - else - echo ">>> Test phase [none]: ${CATEGORY}/${PF}" - fi - SANDBOX_PREDICT=${SANDBOX_PREDICT%:/} -} - -into() { - ${PKGCORE_PREFIX_SUPPORT} || local ED=${D} - if [[ $1 == "/" ]]; then - export DESTTREE="" - else - export DESTTREE=$1 - if [[ ! -d ${ED}${DESTTREE} ]]; then - install -d "${ED}${DESTTREE}" - fi - fi -} - -insinto() { - ${PKGCORE_PREFIX_SUPPORT} || local ED=${D} - if [[ $1 == "/" ]]; then - export INSDESTTREE="" - else - export INSDESTTREE=$1 - if [[ ! -d ${ED}${INSDESTTREE} ]]; then - install -d "${ED}${INSDESTTREE}" - fi - fi -} - -exeinto() { - ${PKGCORE_PREFIX_SUPPORT} || local ED=${D} - if [[ $1 == "/" ]]; then - export PKGCORE_EXEDESTTREE="" - else - export PKGCORE_EXEDESTTREE=$1 - if [[ ! -d ${ED}${PKGCORE_EXEDESTTREE} ]]; then - install -d "${ED}${PKGCORE_EXEDESTTREE}" - fi - fi -} - -docinto() { - ${PKGCORE_PREFIX_SUPPORT} || local ED=${D} - if [[ $1 == "/" ]]; then - export PKGCORE_DOCDESTTREE="" - else - export PKGCORE_DOCDESTTREE=$1 - if [[ ! -d ${ED}usr/share/doc/${PF}/${PKGCORE_DOCDESTTREE} ]]; then - install -d "${ED}usr/share/doc/${PF}/${PKGCORE_DOCDESTTREE}" - fi - fi -} - -__phase_common_pre_phase() { - if [[ -d ${S} ]]; then - cd "${S}" - elif __safe_has "${EAPI}" 0 1 2 3; then - cd "${WORKDIR}" - elif [[ -n ${A} ]]; then - die "source directory '${S}' doesn't exist, but \${A} isn't empty (see S-WORKDIR-FALLBACK in PMS)" - else - local phase - # eapi4 blatant idiocy... - for phase in unpack prepare configure compile install; do - [[ ${phase} == ${EBUILD_PHASE} ]] && break - __is_function src_${phase} || continue - # to reach here means that (for example), we're doing src_install, and src_compile was defined - # but S doesn't exist. - die "source directory '${S}' doesn't exist, \${A} is defined, and there was a defined " \ - "phase function '${phase}' prior to '${EBUILD_PHASE}'; please see S-WORKDIR-FALLBACK " \ - "in pms for the details of what is allowed for eapi4 and later" - done - cd "${WORKDIR}" - fi -} - -__phase_default_pre_src_unpack() { - export PORTAGE_GZIP_COMMAND=${PORTAGE_GZIP_COMMAND:-gzip} - export PORTAGE_BZIP2_COMMAND=${PORTAGE_BZIP2_COMMAND:-bzip2} - export PORTAGE_XZ_COMMAND=${PORTAGE_XZ_COMMAND:-xz} - export S - cd "${WORKDIR}" -} - -__phase_default_pre_src_prepare() { __phase_common_pre_phase; } -__phase_default_pre_src_test() { __phase_common_pre_phase; } - -__phase_default_pre_src_configure() { - local var - for var in C{BUILD,HOST,TARGET,C,XX} {AS,LD,{,LIB}C{,XX}}FLAGS; do - [[ -n ${!var+set} ]] && export ${var}="${!var}" - done - __phase_common_pre_phase -} - -__phase_default_pre_src_compile() { - # just reuse the default_pre_src_configure; this means we don't have to care - # if the eapi has configure or not. - __phase_default_pre_src_configure - - if __feature_is_enabled distcc; then - [[ -n ${DISTCC_DIR} ]] && addwrite "${DISTCC_DIR}" - if __feature_is_enabled distcc-pump; then - eval $(pump --startup) || echo "Warning: Failed starting pump" >&2 - trap 'pump --shutdown' EXIT - fi - fi -} - -__phase_default_post_src_compile() { - if __feature_is_enabled distcc && __feature_is_enabled distcc-pump; then - pump --shutdown - trap - EXIT - fi -} - -__phase_default_pre_src_install() { - export DESTTREE=/usr INSDESTTREE='' PKGCORE_EXEDESTTREE='' PKGCORE_DOCDESTTREE='' - export INSOPTIONS="-m0644" EXEOPTIONS="-m0755" - export LIBOPTIONS="-m0644" DIROPTIONS="-m0755" - export PORTAGE_COMPRESS=${PORTAGE_COMPRESS:-bzip2} - export PORTAGE_COMPRESS_FLAGS=${PORTAGE_COMPRESS_FLAGS:--9} - export MOPREFIX=${PN} - export D - rm -rf "${D}" - if ${PKGCORE_PREFIX_SUPPORT}; then - [[ -n ${ED+set} ]] || \ - die "variable ED is unset, but prefix mode is enabled. internal error?" - export ED=${ED} - mkdir -p "${ED}" - else - mkdir "${D}" - fi - __phase_common_pre_phase -} - -__inject_phase_funcs() { - local prefix=$1 func - shift - - for func in "$@"; do - if ! __is_function "${func}"; then - eval "__phase_default_${func}() { ${prefix}_${func}; }"; - fi - - # define default_${phase} funcs for EAPI 2 and up - if ! __safe_has "${EAPI:-0}" 0 1 ; then - eval "default_${func}() { ${prefix}_${func}; }"; - fi - done -} - -__inject_common_phase_funcs() { - __inject_phase_funcs __phase_common pkg_nofetch src_{unpack,compile,test} -} - -unpack() { - local file filename myfail srcdir taropts tar_subdir - taropts='--no-same-owner' - - [[ $# -eq 0 ]] && die "Nothing passed to the 'unpack' command" - - for file in "$@"; do - echo ">>> Unpacking ${file} to ${PWD}" - myfail="failure unpacking ${file}" - if [[ ${file} == "./"* ]]; then - srcdir="" - else - srcdir=${DISTDIR} - fi - - [[ ! -e ${srcdir}${file} ]] && die "${myfail}: file doesn't exist" - [[ ! -s ${srcdir}${file} ]] && die "${myfail}: empty file" - [[ ${file} == ${DISTDIR%%/}/* ]] && \ - die "Arguments to unpack() must not begin with \${DISTDIR}." - [[ ${file} == /* ]] && - die "Arguments to unpack() must not be absolute paths." - - filename=${file##*/} - - case ${file} in - *.tar) - tar xf "${srcdir}${file}" ${taropts} || die "${myfail}" - ;; - *.tar.gz|*.tgz|*.tar.Z) - tar xf "${srcdir}${file}" -I"${PORTAGE_GZIP_COMMAND}" ${taropts} || die "${myfail}" - ;; - *.tar.bz2|*.tbz2|*.tbz) - tar xf "${srcdir}${file}" -I"${PORTAGE_BZIP2_COMMAND}" ${taropts} || die "${myfail}" - ;; - *.tar.lzma) - tar xf "${srcdir}${file}" -Ilzma ${taropts} || die "${myfail}" - ;; - *.tar.xz) - if __safe_has "${EAPI}" 0 1 2; then - echo "xz is a supported extension in EAPI 3 and above only" >&2 - continue; - fi - tar xf "${srcdir}${file}" -I"${PORTAGE_XZ_COMMAND}" ${taropts} || die "${myfail}" - ;; - *.ZIP|*.zip|*.jar) - { set +x; while :; do echo n || break; done } | \ - unzip -qo "${srcdir}${file}" || die "${myfail}" - ;; - *.gz|*.Z|*.z) - ${PORTAGE_GUNZIP_COMMAND:-${PORTAGE_GZIP_COMMAND} -d} -c "${srcdir}${file}" > ${filename%.*} || die "${myfail}" - ;; - *.bz2|*.bz) - ${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c "${srcdir}${file}" > ${filename%.*} || die "${myfail}" - ;; - *.xz) - if __safe_has "${EAPI}" 0 1 2; then - echo "xz is a supported extension in EAPI 3 and above only" >&2 - continue; - fi - ${PORTAGE_UNXZ_COMMAND:-${PORTAGE_XZ_COMMAND} -d} < "${srcdir}${file}" > ${filename%.*} || die "${myfail}" - ;; - *.7Z|*.7z) - local my_output - my_output=$(7z x -y "${srcdir}${file}") - if [[ $? -ne 0 ]]; then - echo "${my_output}" >&2 - die "${myfail}" - fi - ;; - *.RAR|*.rar) - unrar x -idq -o+ "${srcdir}${file}" || die "${myfail}" - ;; - *.LHa|*.LHA|*.lha|*.lzh) - lha xfq "${srcdir}${file}" || die "${myfail}" - ;; - *.a|*.deb) - ar x "${srcdir}${file}" || die "${myfail}" - ;; - *.lzma) - lzma -dc "${srcdir}${file}" > ${filename%.*} || die "${myfail}" - ;; - *) - echo "unpack ${file}: file format not recognized. Ignoring." - ;; - esac - done - find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \ - ${XARGS} -0 chmod -fR a+rX,u+w,g-w,o-w -} - -diropts() { - export DIROPTIONS=$@ -} - -insopts() { - { has -s "$@" || has --strip "$@"; } && \ - ewarn "insopts shouldn't be given -s; stripping should be left to the manager." - export INSOPTIONS=$@ -} - -exeopts() { - { has -s "$@" || has --strip "$@"; } && \ - ewarn "exeopts shouldn't be given -s; stripping should be left to the manager." - export EXEOPTIONS=$@ -} - -libopts() { - { has -s "$@" || has --strip "$@"; } && \ - ewarn "libopts shouldn't be given -s; stripping should be left to the manager." - export LIBOPTIONS=$@ -} - -portageq() { - if [[ ${EBUILD_PHASE} == "depend" ]]; then - die "portageq calls in depends phase aren't allowed" - fi - local command=$1 - shift - # suppress sandbox for the invocation; do this to avoid things like .pyc generation - # being snagged by the sandbox - local portageq_str="portageq" - ${PKGCORE_DISABLE_COMPAT-false} && portageq_str="query" - SANDBOX_ON=0 PYTHONPATH="${PKGCORE_PYTHONPATH}" "${PKGCORE_PYTHON_BINARY}" \ - $(type -P pinspect) ${portageq_str} "${command}" \ - --eapi "${EAPI:--1}" --use "${USE}" "$@" - local ret=$? - [[ ${ret} == 127 ]] && die "pinspect couldn't be found; broken pkgcore installation?" - return $(( ret )) -} - -has_version() { - PKGCORE_DISABLE_COMPAT=true portageq 'has_version' "$1" -} - -best_version() { - PKGCORE_DISABLE_COMPAT=true portageq 'best_version' "$1" -} - -: diff --git a/pkgcore/ebuild/eapi-bash/eapi/depend.lib b/pkgcore/ebuild/eapi-bash/eapi/depend.lib deleted file mode 100644 index f7870cb11..000000000 --- a/pkgcore/ebuild/eapi-bash/eapi/depend.lib +++ /dev/null @@ -1,192 +0,0 @@ -# Copyright: 2011-2012 Brian Harring -# license GPL2/BSD 3 - -# while these echo statements are ugly, written this way to ensure bash does it as a single write- -# aka, keep it within the size of atomic writes for pipes. Relevant for threaded output straight to term -use() { - echo "WARNING: 'use' function invoked by ${CATEGORY}/${PF} during metadata regeneration."$'\nWARNING: Please ensure upstream is aware of it and working to remove it.\n' >&2 - return 1 -} - -usev() { - echo "WARNING: 'usev' function invoked by ${CATEGORY}/${PF} during metadata regeneration."$'\nWARNING: Please ensure upstream is aware of it and working to remove it.\n' >&2 - return 1 -} - -use_with() { - echo "WARNING: 'use_with' function invoked by ${CATEGORY}/${PF} during metadata regeneration."$'\nWARNING: Please ensure upstream is aware of it and working to remove it.\n' >&2 - return 1 -} - -use_enable() { - echo "WARNING: 'use_enable' function invoked by ${CATEGORY}/${PF} during metadata regeneration."$'\nWARNING: Please ensure upstream is aware of it and working to remove it.\n' >&2 - return 1 -} - -has() { - local needle=$1 - shift - - local IFS=$'\001' - - # try fast mode first; no IFS match is guaranteed that the needle isn't there. - [[ "${IFS}${*}${IFS}" != *"${IFS}${needle}${IFS}"* ]] && return 1 - - # If we have a match, ensure it's not due to $@ already having \001 in it. - # unlikely, but better safe than sorry. - IFS=' ' - [[ *$'\001'* != $* ]] && return 0 - - # \001 for some insane reason was in $@; fallback to the slow for loop. - # Suppress debug outut for this part however. - __shopt_push +x - local x - for x in "$@"; do - if [[ ${x} == ${needle} ]]; then - __shopt_pop - return 0 - fi - done - __shopt_pop - return 1 -} - -hasq() { - has ${EBUILD_PHASE} prerm postrm || eqawarn \ - "QA Notice: The 'hasq' function is deprecated (replaced by 'has')" - has "$@" -} - -hasv() { - if has "$@"; then - echo "$1" - fi -} - -debug-print() { - : -} - -debug-print-function() { - : -} - -debug-print-section() { - : -} - -eqawarn() { - __elog_base QA "$*" - echo -e " ${PKGCORE_RC_WARN}*${PKGCORE_RC_NORMAL} $*" >&2 - PKGCORE_RC_LAST_CMD="eqawarn" - return 0 -} - -elog() { - __elog_base LOG "$*" - echo -e " ${PKGCORE_RC_GOOD}*${PKGCORE_RC_NORMAL} $*" - PKGCORE_RC_LAST_CMD="elog" - return 0 -} - -einfo() { - einfon "$*\n" - PKGCORE_RC_LAST_CMD="einfo" - return 0 -} - -einfon() { - __elog_base INFO "$*" - echo -ne " ${PKGCORE_RC_GOOD}*${PKGCORE_RC_NORMAL} $*" - PKGCORE_RC_LAST_CMD="einfon" - return 0 -} - -ewarn() { - __elog_base WARN "$*" - echo -e " ${PKGCORE_RC_WARN}*${PKGCORE_RC_NORMAL} $*" >&2 - PKGCORE_RC_LAST_CMD="ewarn" - return 0 -} - -eerror() { - __elog_base ERROR "$*" - echo -e " ${PKGCORE_RC_BAD}*${PKGCORE_RC_NORMAL} $*" >&2 - PKGCORE_RC_LAST_CMD="eerror" - return 0 -} - -ebegin() { - local msg="$* ..." - einfon "${msg}" - echo - PKGCORE_RC_LAST_CMD="ebegin" - return 0 -} - -eend() { - local retval=${1:-0} - shift - - local msg - - if [[ ${retval} == 0 ]]; then - msg="${PKGCORE_RC_BRACKET}[ ${PKGCORE_RC_GOOD}ok${PKGCORE_RC_BRACKET} ]${PKGCORE_RC_NORMAL}" - else - if [[ $# -ne 0 ]]; then - eerror "$*" - fi - msg="${PKGCORE_RC_BRACKET}[ ${PKGCORE_RC_BAD}!!${PKGCORE_RC_BRACKET} ]${PKGCORE_RC_NORMAL}" - fi - - echo -e "${PKGCORE_RC_ENDCOL} ${msg}" - - return ${retval} -} - -KV_major() { - [[ -z $1 ]] && return 1 - - local KV=$@ - echo "${KV%%.*}" -} - -KV_minor() { - [[ -z $1 ]] && return 1 - - local KV=$@ - KV=${KV#*.} - echo "${KV%%.*}" -} - -KV_micro() { - [[ -z $1 ]] && return 1 - - local KV=$@ - KV=${KV#*.*.} - echo "${KV%%[^[:digit:]]*}" -} - -KV_to_int() { - [[ -z $1 ]] && return 1 - - local KV_MAJOR=$(KV_major "$1") - local KV_MINOR=$(KV_minor "$1") - local KV_MICRO=$(KV_micro "$1") - local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO )) - - # We make version 2.2.0 the minimum version we will handle as - # a sanity check ... if its less, we fail ... - if [[ ${KV_int} -ge 131584 ]]; then - echo "${KV_int}" - return 0 - fi - - return 1 -} - -get_KV() { - echo $(KV_to_int "$(uname -r)") -} - -: diff --git a/pkgcore/ebuild/eapi-bash/ebuild-daemon.bash b/pkgcore/ebuild/eapi-bash/ebuild-daemon.bash deleted file mode 100755 index 75e65f78b..000000000 --- a/pkgcore/ebuild/eapi-bash/ebuild-daemon.bash +++ /dev/null @@ -1,453 +0,0 @@ -#!/bin/bash -# ebuild-daemon.bash; core ebuild processor handling code -# Copyright 2004-2012 Brian Harring -# License: BSD/GPL2 - -# These are functions that shouldn't be marked readonly, since they're runtime -# switchable. -PKGCORE_RUNTIME_FUNCS=( '__timed_call' ) - -__set_perf_debug() { - if [[ ${PKGCORE_DEBUG} -ge 4 || -n ${PKGCORE_PERF_DEBUG} ]]; then - __timed_call() { - echo "timing $*" >&2 - time "$@" - local __ret=$? - echo "timed $*" >&2 - return ${__ret} - } - else - __timed_call() { - "$@" - } - fi -} - -__set_perf_debug - -die() { - # Temporary function used by the daemon, till proper die implementation is loaded. - echo "$@" >&2 - exit 1 -} - -STARTING_PID=${BASHPID} -# use ebd_read/ebd_write for talking to the running portage instance instead of echo'ing to the fd yourself. -# this allows us to move the open fd's w/out issues down the line. -__ebd_read_line_nonfatal() { - read -u ${PKGCORE_EBD_READ_FD} $1 -} - -__ebd_read_line() { - __ebd_read_line_nonfatal "$@" - local ret=$? - [[ ${ret} -ne 0 ]] && \ - die "coms error in ${STARTING_PID}, read_line $@ failed w/ ${ret}: backing out of daemon." -} - -# are we running a version of bash (4.1 or so) that does -N? -if echo 'y' | read -N 1 &> /dev/null; then - __ebd_read_size() - { - read -u ${PKGCORE_EBD_READ_FD} -r -N $1 $2 - local ret=$? - [[ ${ret} -ne 0 ]] && \ - die "coms error in ${STARTING_PID}, read_size $@ failed w/ ${ret}: backing out of daemon." - } -else - # fallback to a *icky icky* but working alternative. - __ebd_read_size() { - eval "${2}=\$(dd bs=1 count=$1 <&${PKGCORE_EBD_READ_FD} 2> /dev/null)" - local ret=$? - [[ ${ret} -ne 0 ]] && \ - die "coms error in ${STARTING_PID}, read_size $@ failed w/ ${ret}: backing out of daemon." - } -fi - -__ebd_read_cat_size() { - dd bs=$1 count=1 <&${PKGCORE_EBD_READ_FD} -} - -__ebd_write_line() { - echo "$*" >&${PKGCORE_EBD_WRITE_FD} - local ret=$? - [[ ${ret} -ne 0 ]] && \ - die "coms error, write failed w/ ${ret}: backing out of daemon." -} - -__ebd_write_raw() { - echo -n "$*" >&${PKGCORE_EBD_WRITE_FD} || die "coms error, __ebd_write_raw failed; Backing out." -} - -for x in ebd_read_{line,{cat_,}size} __ebd_write_line __set_perf_debug; do - declare -rf ${x} -done -unset x -declare -r PKGCORE_EBD_WRITE_FD PKGCORE_EBD_READ_FD - -__ebd_sigint_handler() { - EBD_DISABLE_DIEFUNC="yes" - # silence ourselves as everything shuts down. - exec 2>/dev/null - exec 1>/dev/null - # suppress sigpipe; if we can't tell the parent to die, - # it's already shutting us down. - trap "exit 2" SIGPIPE - __ebd_write_line "killed" - trap - SIGINT - # this relies on the python side to *not* discard the killed - exit 2 -} - -__ebd_sigkill_handler() { - EBD_DISABLE_DIEFUNC="yes" - # silence ourselves as everything shuts down. - exec 2>/dev/null - exec 1>/dev/null - # suppress sigpipe; if we can't tell the parent to die, - # it's already shutting us down. - trap "exit 9" SIGPIPE - __ebd_write_line "killed" - trap - SIGKILL - exit 9 -} - -__ebd_exec_main() { - # ensure the other side is still there. Well, this moreso is for the python side to ensure - # loading up the intermediate funcs succeeded. - __ebd_read_line com - if [[ ${com} != "dude?" ]]; then - echo "serv init coms failed, received ${com} when expecting 'dude?'" >&2 - exit 1 - fi - __ebd_write_line "dude!" - __ebd_read_line PKGCORE_BIN_PATH - [[ -z ${PKGCORE_BIN_PATH} ]] && { __ebd_write_line "empty PKGCORE_BIN_PATH;"; exit 1; } - - if ! source "${PKGCORE_BIN_PATH}"/exit-handling.lib; then - __ebd_write_line "failed sourcing exit handling functionality" - exit 2 - fi - - # get our die functionality now. - if ! source "${PKGCORE_BIN_PATH}"/isolated-functions.lib; then - __ebd_write_line "failed sourcing isolated-functions.lib" - exit 2 - fi - - __ebd_read_line PKGCORE_PYTHON_BINARY - [[ -z ${PKGCORE_PYTHON_BINARY} ]] && die "empty PKGCORE_PYTHON_BINARY, bailing" - __ebd_read_line PKGCORE_PYTHONPATH - [[ -z ${PKGCORE_PYTHONPATH} ]] && die "empty PKGCORE_PYTHONPATH, bailing" - - if ! source "${PKGCORE_BIN_PATH}"/ebuild.lib >&2; then - __ebd_write_line "failed" - die "failed sourcing ${PKGCORE_BIN_PATH}/ebuild.lib" - fi - - if [[ -n ${SANDBOX_LOG} ]]; then - __ebd_read_line com - if [[ ${com} != "sandbox_log?" ]]; then - echo "unknown com '${com}'" - exit 1 - fi - __ebd_write_line "${SANDBOX_LOG}" - declare -rx SANDBOX_LOG=${SANDBOX_LOG} - addwrite "${SANDBOX_LOG}" - fi - - re=$(readonly | cut -s -d '=' -f 1 | cut -s -d ' ' -f 3) - for x in ${re}; do - if ! __safe_has "${x}" "${DONT_EXPORT_VARS}"; then - DONT_EXPORT_VARS+=" ${x}" - fi - done - __ebd_write_line ${re} - unset x re - - # protect ourselves. - declare -rx PKGCORE_BIN_PATH=${PKGCORE_BIN_PATH} - declare -rx PKGCORE_PYTHON_BINARY=${PKGCORE_PYTHON_BINARY} - declare -rx PKGCORE_PYTHONPATH=${PKGCORE_PYTHONPATH} - - if ! source "${PKGCORE_BIN_PATH}"/ebuild-daemon.lib >&2; then - __ebd_write_line "failed" - die "failed sourcing ${PKGCORE_BIN_PATH}/ebuild-daemon.lib" - fi - - __colored_output_disable - declare -A PKGCORE_PRELOADED_ECLASSES - - trap __ebd_sigint_handler SIGINT - trap __ebd_sigkill_handler SIGKILL - - # finally, load the master list of pkgcore funcs. fallback to - # regenerating it if needed. - if [[ -e ${PKGCORE_BIN_PATH}/dont_export_funcs.list ]]; then - DONT_EXPORT_FUNCS+=" $(<"${PKGCORE_BIN_PATH}"/dont_export_funcs.list)" - else - DONT_EXPORT_FUNCS+=" $("${PKGCORE_BIN_PATH}"/regenerate_dont_export_func_list.bash 2> /dev/null)" - fi - - DONT_EXPORT_FUNCS+=" ${PORTAGE_PRELOADED_ECLASSES}" - for x in ${DONT_EXPORT_FUNCS}; do - __is_function "${x}" || continue - if ! __safe_has "${x}" "${PKGCORE_RUNTIME_FUNCS[@]}"; then - declare -fr ${x} &> /dev/null - fi - done - unset x - - # depend's speed up. turn on qa interceptors by default, instead of flipping them on for each depends; - # same for loading depends .lib - # important- this needs be loaded after the declare -fr so it doesn't get marked as readonly. - # call. - export QA_CONTROLLED_EXTERNALLY="yes" - __qa_interceptors_enable - - source "${PKGCORE_BIN_PATH}"/eapi/depend.lib >&2 || die "failed sourcing eapi/depend.lib" - __ebd_main_loop - exit 0 -} - -__ebd_process_sandbox_results() { - if [[ -z ${SANDBOX_LOG} || ! -e ${SANDBOX_LOG} ]]; then - return 0; - fi - echo "sandbox exists- ${SANDBOX_LOG}" >&2 - __request_sandbox_summary >&2 - echo "SANDBOX_ON:=${SANDBOX_ON:-unset}" >&2 - echo "SANDBOX_DISABLED:=${SANDBOX_DISABLED:-unset}" >&2 - echo "SANDBOX_READ:=${SANDBOX_READ:-unset}" >&2 - echo "SANDBOX_WRITE:=${SANDBOX_WRITE:-unset}" >&2 - echo "SANDBOX_PREDICT:=${SANDBOX_PREDICT:-unset}" >&2 - echo "SANDBOX_DEBUG:=${SANDBOX_DEBUG:-unset}" >&2 - echo "SANDBOX_DEBUG_LOG:=${SANDBOX_DEBUG_LOG:-unset}" >&2 - echo "SANDBOX_LOG:=${SANDBOX_LOG:-unset}" >&2 - echo "SANDBOX_ARMED:=${SANDBOX_ARMED:-unset}" >&2 - return 1 -} - -__ebd_process_ebuild_phases() { - # note that this is entirely subshelled; as such exit is used rather than returns - ( - declare -r PKGCORE_QA_SUPPRESSED=false - local phases=$@ - local is_depends=true - if [[ ${phases/depend} == ${phases} ]]; then - is_depends=false - __qa_interceptors_disable - fi - local cont=0 - - while [[ ${cont} == 0 ]]; do - local line='' - __ebd_read_line line - case ${line} in - start_receiving_env*) - line=${line#start_receiving_env } - case ${line} in - file*) - line=${line#file } - source "${line}" - cont=$? - ;; - bytes*) - line=${line#bytes } - __ebd_read_size "${line}" line - __IFS_push $'\0' - eval "${line}" - cont=$? - __IFS_pop - ;; - lines) - ;& - *) - while __ebd_read_line line && [[ ${line} != "end_receiving_env" ]]; do - __IFS_push $'\0' - eval "${line}" - cont=$? - __IFS_pop - if [[ ${cont} != 0 ]]; then - echo "err, env receiving threw an error for '${line}': $?" >&2 - break - fi - done - ;; - esac - if [[ ${cont} != 0 ]]; then - __ebd_write_line "env_receiving_failed" - exit 1 - fi - __set_perf_debug - __ebd_write_line "env_received" - ;; - logging*) - PORTAGE_LOGFILE=${line#logging } - __ebd_write_line "logging_ack" - ;; - set_sandbox_state*) - if [[ $(( ${line:18} )) -eq 0 ]]; then - export SANDBOX_DISABLED=1 - else - export SANDBOX_DISABLED=0 - export SANDBOX_VERBOSE="no" - fi - ;; - start_processing) - if ${is_depends} && [[ -n ${PKGCORE_METADATA_PATH} ]]; then - export PATH=${PKGCORE_METADATA_PATH} - fi - cont=2 - ;; - shutdown_daemon) - break - ;; - *) - echo "received unknown com during phase processing: ${line}" >&2 - exit 1 - ;; - esac - done - if [[ ${cont} != 2 ]]; then - exit ${cont} - fi - - [[ -n ${PORTAGE_LOGFILE} ]] && addwrite "$(readlink -f "${PORTAGE_LOGFILE}")" - - [[ -z ${RC_NOCOLOR} ]] && __colored_output_enable - - [[ -n ${PORTAGE_TMPDIR} ]] && { - addpredict "${PORTAGE_TMPDIR}" - addwrite "${PORTAGE_TMPDIR}" - addread "${PORTAGE_TMPDIR}" - } - - local ret - umask 0022 - - if [[ -z ${PORTAGE_LOGFILE} ]]; then - __execute_phases ${phases} - ret=$? - else - __execute_phases ${phases} &> >(umask 0002; tee -i -a "${PORTAGE_LOGFILE}") - ret=$? - fi - - if [[ ${ret} -ne 0 ]]; then - __ebd_process_sandbox_results - exit ${ret} - fi - exit 0 - ) -} - -__ebd_process_metadata() { - # protect the env. - # note the local usage is redundant in light of it, but prefer to write it this - # way so that if someone ever drops the (), it'll still not bleed out. - ( - # Heavy QA checks (IFS, shopt, etc) are suppressed for speed - declare -r PKGCORE_QA_SUPPRESSED=false - # Wipe __mode; it bleeds from our parent. - unset __mode - local __data - local __ret - __ebd_read_size "$1" __data - local IFS=$'\0' - eval "$__data" - __ret=$? - unset __data - [[ ${__ret} -ne 0 ]] && exit 1 - unset __ret - local IFS=$' \t\n' - - if [[ -n ${PKGCORE_METADATA_PATH} ]]; then - export PATH=${PKGCORE_METADATA_PATH} - fi - - PORTAGE_SANDBOX_PID=${PPID} - __execute_phases "${2:-depend}" && exit 0 - __ebd_process_sandbox_results - exit 1 - ) -} - -__make_preloaded_eclass_func() { - eval "__preloaded_eclass_$1() { - $2 - }" - PKGCORE_PRELOADED_ECLASSES[$1]=__preloaded_eclass_$1 -} - -__ebd_main_loop() { - DONT_EXPORT_VARS+=" com phases line cont DONT_EXPORT_FUNCS STARTING_PID" - SANDBOX_ON=1 - while :; do - local com='' - # If we don't manage to read, this means that the other end hung up. - # exit. - __ebd_read_line_nonfatal com || com="shutdown_daemon" - case ${com} in - process_ebuild*) - # cleanse whitespace. - local phases=$(echo ${com#process_ebuild}) - PORTAGE_SANDBOX_PID=${PPID} - __ebd_process_ebuild_phases ${phases} - # tell python if it succeeded or not. - if [[ $? -ne 0 ]]; then - __ebd_write_line "phases failed" - else - __ebd_write_line "phases succeeded" - fi - ;; - shutdown_daemon) - break - ;; - preload_eclass\ *) - success="succeeded" - com=${com#preload_eclass } - for e in ${com}; do - x=${e##*/} - x=${x%.eclass} - if ! $(type -P bash) -n "${e}"; then - echo "errors detected in '${e}'" >&2 - success='failed' - break - fi - __make_preloaded_eclass_func "${x}" "$(< "${e}")" - done - __ebd_write_line "preload_eclass ${success}" - unset e x success - ;; - clear_preloaded_eclasses) - unset PKGCORE_PRELOADED_ECLASSES - declare -A PKGCORE_PRELOADED_ECLASSES - __ebd_write_line "clear_preloaded_eclasses succeeded" - ;; - set_metadata_path\ *) - line=${com#set_metadata_path } - __ebd_read_size "${line}" PKGCORE_METADATA_PATH - __ebd_write_line "metadata_path_received" - ;; - gen_metadata\ *|gen_ebuild_env\ *) - local __mode="depend" - [[ ${com} == gen_ebuild_env* ]] && __mode="generate_env" - line=${com#* } - if __ebd_process_metadata "${line}" "${__mode}"; then - __ebd_write_line "phases succeeded" - else - __ebd_write_line "phases failed" - fi - ;; - *) - echo "received unknown com: ${com}" >&2 - exit 1 - ;; - esac - done -} - -[[ -z ${PKGCORE_SOURCING_FOR_REGEN_FUNCS_LIST} ]] && __ebd_exec_main - -: diff --git a/pkgcore/ebuild/eapi-bash/ebuild-daemon.lib b/pkgcore/ebuild/eapi-bash/ebuild-daemon.lib deleted file mode 100644 index f0fa81233..000000000 --- a/pkgcore/ebuild/eapi-bash/ebuild-daemon.lib +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash -# ebuild-daemon.lib; daemon lib code. -# Copyright 2005-2012 Brian Harring -# License BSD/GPL2 - -# ask the python side to display sandbox complaints. -__request_sandbox_summary() { - local line - __ebd_write_line "__request_sandbox_summary ${SANDBOX_LOG}" - __ebd_read_line line - while [[ ${line} != "end_sandbox_summary" ]]; do - echo "${line}" - __ebd_read_line line - done -} - -__internal_inherit() { - local line - if [[ $# -ne 1 ]]; then - die "internal_inherit accepts one arg, requested eclass location. $* is a bit much" - fi - if [[ -n ${PKGCORE_PRELOADED_ECLASSES[$1]} ]]; then - __qa_invoke "${PKGCORE_PRELOADED_ECLASSES[$1]}" - return - fi - __ebd_write_line "request_inherit $1" - __ebd_read_line line - if [[ ${line} == "path" ]]; then - __ebd_read_line line - __qa_invoke source "${line}" >&2 || die "failed sources inherit: ${line}" - elif [[ ${line} == "transfer" ]]; then - __ebd_read_line line - __qa_invoke eval "${line}" || die "failed evaluating eclass $1 on an inherit transfer" - elif [[ ${line} == "failed" ]]; then - die "inherit for $1 failed" - else - die "unknown inherit command from pythonic side, '${line}' for eclass $1" - fi -} - -__source_bashrcs() { - ${PKGCORE_SUPPRESS_BASHRCS:-false} && return - local line - __ebd_write_line "request_bashrcs" - __ebd_read_line line - while [[ ${line} != "end_request" ]]; do - if [[ ${line} == "path" ]]; then - __ebd_read_line line - source "${line}" >&2 - elif [[ ${line} == "transfer" ]]; then - __ebd_read_line line - eval "${line}" || die "failed evaluating profile bashrc: ${line}" - else - __ebd_write_line "failed" - die "unknown profile bashrc transfer mode from pythonic side, '${line}'" - fi - __ebd_write_line "next" - __ebd_read_line line - done -} - -: diff --git a/pkgcore/ebuild/eapi-bash/ebuild-default-functions.lib b/pkgcore/ebuild/eapi-bash/ebuild-default-functions.lib deleted file mode 100644 index 70a0f4735..000000000 --- a/pkgcore/ebuild/eapi-bash/ebuild-default-functions.lib +++ /dev/null @@ -1,309 +0,0 @@ -#!/bin/bash -# ebuild-default-functions.sh; default functions for ebuild env that aren't saved- specific to the portage instance. -# Copyright 2005-2012 Brian Harring : BSD/GPL2 -# Copyright 2004-2006 Gentoo Foundation: GPL2 - -# sandbox support functions -addread() { - export SANDBOX_READ=${SANDBOX_READ}:$1 -} - -addwrite() { - export SANDBOX_WRITE=${SANDBOX_WRITE}:$1 -} - -adddeny() { - export SANDBOX_DENY=${SANDBOX_DENY}:$1 -} - -addpredict() { - export SANDBOX_PREDICT=${SANDBOX_PREDICT}:$1 -} - -__dyn_src_install() { - local f - echo - if ${PKGCORE_PREFIX_SUPPORT}; then - echo ">>> Install ${PF} into ${ED} category ${CATEGORY}" - else - echo ">>> Install ${PF} into ${D} category ${CATEGORY}" - fi - if __is_function src_install; then - __qa_invoke src_install - else - __qa_run_function_if_exists __phase_default_src_install - fi - - "${PKGCORE_BIN_PATH}"/helpers/internals/prepall - ${PKGCORE_PREFIX_SUPPORT} || local ED=${D} - cd "${ED}" - - if type -p scanelf > /dev/null; then - # Make sure we disallow insecure RUNPATH/RPATH's - # Don't want paths that point to the tree where the package was built - # (older, broken libtools would do this). Also check for null paths - # because the loader will search $PWD when it finds null paths. - f=$(scanelf -qyRF '%r %p' "${ED}" | grep -E "(${WORKDIR}|${ED}|: |::|^ )") - if [[ -n ${f} ]]; then - echo -ne '\a\n' - echo "QA Notice: the following files contain insecure RUNPATH's" - echo " Please file a bug about this at http://bugs.gentoo.org/" - echo " For more information on this issue, kindly review:" - echo " http://bugs.gentoo.org/81745" - echo "${f}" - echo -ne '\a\n' - __feature_is_enabled stricter && die "Insecure binaries detected" - echo "autofixing rpath..." - TMPDIR=${WORKDIR} scanelf -BXr ${f} -o /dev/null - fi - - # Check for setid binaries but are not built with BIND_NOW - f=$(scanelf -qyRF '%b %p' "${ED}") - if [[ -n ${f} ]]; then - echo -ne '\a\n' - echo "QA Notice: the following files are setXid, dyn linked, and using lazy bindings" - echo " This combination is generally discouraged. Try forcing via bashrc" - echo " LDFLAGS='-Wl,-z,now' for the pkg, or disable FEATURES=stricter" - echo "${f}" - echo -ne '\a\n' - __feature_is_enabled stricter && die "Aborting due to lazy bindings" - sleep 1 - fi - - # TEXTREL's are baaaaaaaad - f=$(scanelf -qyRF '%t %p' "${ED}") - if [[ -n ${f} ]]; then - echo -ne '\a\n' - echo "QA Notice: the following files contain runtime text relocations" - echo " Text relocations require a lot of extra work to be preformed by the" - echo " dynamic linker which will cause serious performance impact on IA-32" - echo " and might not function properly on other architectures hppa for example." - echo " If you are a programmer please take a closer look at this package and" - echo " consider writing a patch which addresses this problem." - echo "${f}" - echo -ne '\a\n' - __feature_is_enabled stricter && die "Aborting due to textrels" - sleep 1 - fi - - # Check for files with executable stacks - f=$(scanelf -qyRF '%e %p' "${ED}") - if [[ -n ${f} ]]; then - echo -ne '\a\n' - echo "QA Notice: the following files contain executable stacks" - echo " Files with executable stacks will not work properly (or at all!)" - echo " on some architectures/operating systems. A bug should be filed" - echo " at http://bugs.gentoo.org/ to make sure the file is fixed." - echo "${f}" - echo -ne '\a\n' - __feature_is_enabled stricter && die "Aborting due to +x stack" - sleep 1 - fi - - # Create NEEDED and NEEDED.ELF.2 files required for things like preserve-libs - # TODO: someday find a way to move this to the triggers implementation to allow - # for parallelization of the scanning- if useful. - scanelf -qyRF '%a;%p;%S;%r;%n' "${ED}" | { while IFS= read -r l; do - arch=${l%%;*}; l=${l#*;} - obj="/${l%%;*}"; l=${l#*;} - soname=${l%%;*}; l=${l#*;} - rpath=${l%%;*}; l=${l#*;}; [[ ${rpath} == " - " ]] && rpath="" - needed=${l%%;*}; l=${l#*;} - echo "${obj} ${needed}" >> "${T}"/NEEDED - echo "${arch:3};${obj};${soname};${rpath};${needed}" >> "${T}"/NEEDED.ELF.2 - done } - fi - - echo ">>> Completed installing ${PF} into ${ED}" - echo - unset dir -} - -__dyn_pkg_preinst() { - if __is_function pkg_preinst; then - __qa_invoke pkg_preinst - else - __qa_run_function_if_exists __phase_default_pkg_preinst - fi - - ${PKGCORE_PREFIX_SUPPORT} || local ED=${D} - - # total suid control. - if __feature_is_enabled suidctl > /dev/null; then - sfconf=/etc/portage/suidctl.conf - echo ">>> Preforming suid scan in ${ED}" - local i - for i in $(find "${ED}"/ -type f \( -perm -4000 -o -perm -2000 \) ); do - if [[ -s ${sfconf} ]]; then - suid=$(grep ^${i/${ED}/}$ "${sfconf}") - if [[ ${suid} == ${i/${ED}/} ]]; then - echo "- ${i/${ED}/} is an approved suid file" - else - echo ">>> Removing sbit on non registered ${i/${ED}/}" - chmod ugo-s "${i}" - grep ^#${i/${ED}/}$ ${sfconf} > /dev/null || { - # sandbox prevents us from writing directly - # to files outside of the sandbox, but this - # can easly be bypassed using the addwrite() function - addwrite "${sfconf}" - echo ">>> Appending commented out entry to ${sfconf} for ${PF}" - ls_ret=$(ls -ldh "${i}") - echo "## ${ls_ret%${ED}*}${ls_ret#*${ED}}" >> "${sfconf}" - echo "#${i/${ED}/}" >> "${sfconf}" - # no delwrite() eh? - # delwrite ${sconf} - } - fi - else - echo "suidctl feature set but you are lacking a ${sfconf}" - fi - done - fi - - # SELinux file labeling (needs to always be last in dyn_preinst) - if __feature_is_enabled selinux; then - # only attempt to label if setfiles is executable - # and 'context' is available on selinuxfs. - if [[ -f /selinux/context && -x /usr/sbin/setfiles ]]; then - echo ">>> Setting SELinux security labels" - if [[ -f ${POLICYDIR}/file_contexts/file_contexts ]]; then - cp -f "${POLICYDIR}"/file_contexts/file_contexts "${T}" - else - make -C "${POLICYDIR}" FC=${T}/file_contexts "${T}"/file_contexts - fi - - addwrite /selinux/context - /usr/sbin/setfiles -r "${ED}" "${T}"/file_contexts "${ED}" \ - || die "Failed to set SELinux security labels." - else - # nonfatal, since merging can happen outside a SE kernel - # like during a recovery situation - echo "!!! Unable to set SELinux security labels" - fi - fi -} - -__internal_inherit() { - # default, backwards compatible beast. - local location overlay - location=${ECLASSDIR}/${1}.eclass - - if [[ -n ${PORTDIR_OVERLAY} ]]; then - local overlay - for overlay in ${PORTDIR_OVERLAY}; do - if [[ -e ${overlay}/eclass/${1}.eclass ]]; then - location=${overlay}/eclass/${1}.eclass - debug-print " eclass exists: ${location}" - fi - done - fi - debug-print "inherit: $1 -> ${location}" - __qa_invoke source "${location}" >&2 || die "died sourcing ${location} in inherit()" - return 0 -} - -inherit() { - local ECLASS_DEPTH=$(( ${ECLASS_DEPTH-0} + 1 )) - - if [[ ${ECLASS_DEPTH} -gt 1 ]]; then - debug-print "*** Multiple Inheritence (Level: ${ECLASS_DEPTH})" - fi - - local location olocation - local ECLASS - - # note that this ensures any later unsets/mangling, the ebuilds original - # setting is protected. - local IUSE REQUIRED_USE DEPEND RDEPEND PDEPEND - - for ECLASS in "$@"; do - if [[ ${EBUILD_PHASE} != "depend" ]]; then - if ! __safe_has "${ECLASS}" ${INHERITED}; then - echo - echo "QA Notice: ECLASS '${ECLASS}' illegal conditional inherit in ${CATEGORY}/${PF}" >&2 - echo - fi - fi - - unset IUSE REQUIRED_USE DEPEND RDEPEND PDEPEND - - __internal_inherit "$1" || die "failed sourcing $1 in inherit()" - - # If each var has a value, append it to the global variable E_* to - # be applied after everything is finished. New incremental behavior. - [[ -n ${IUSE} ]] && E_IUSE+=${E_IUSE:+ }${IUSE} - [[ -n ${REQUIRED_USE} ]] && E_REQUIRED_USE+=${E_REQUIRED_USE:+ }${REQUIRED_USE} - [[ -n ${DEPEND} ]] && E_DEPEND+=${E_DEPEND:+ }${DEPEND} - [[ -n ${RDEPEND} ]] && E_RDEPEND+=${E_RDEPEND:+ }${RDEPEND} - [[ -n ${PDEPEND} ]] && E_PDEPEND+=${E_PDEPEND:+ }${PDEPEND} - - # while other PMs have checks to keep this unique, we don't; no need, - # further up the stack (python side) we uniquify this. - # if you try to do it in bash rather than python, it's ~10% slower regen - INHERITED+=" ${ECLASS}" - - shift - done -} - -# Exports stub functions that call the eclass's functions, thereby making them default. -# For example, if ECLASS="base" and you call "EXPORT_FUNCTIONS src_unpack", the following -# code will be eval'd: -# src_unpack() { base_src_unpack; } -EXPORT_FUNCTIONS() { - if [[ -z ${ECLASS} ]]; then - echo "EXPORT_FUNCTIONS without a defined ECLASS" >&2 - exit 1 - fi - while [[ -n $1 ]]; do - debug-print "EXPORT_FUNCTIONS: $1 -> ${ECLASS}_$1" - eval "$1() { ${ECLASS}_$1 "\$@" ; }" > /dev/null - shift - done -} - -PKGCORE_QA_INTERCEPTORS=( - javac java-config python python-config perl grep egrep fgrep sed - gcc "g++" cc bash awk nawk pkg-config -) -__QA_INTERCEPTORS_ACTIVE=false - -__qa_interceptors_enable() { - # Turn off extended glob matching so that g++ doesn't get incorrectly matched. - shopt -u extglob - - ${__QA_INTERCEPTORS_ACTIVE} && return - # QA INTERCEPTORS - local BIN BODY BIN_PATH - for BIN in "${PKGCORE_QA_INTERCEPTORS[@]}"; do - BIN_PATH=$(type -pf ${BIN}) - if [[ $? != 0 ]]; then - BODY="echo \"*** missing command: ${BIN}\" >&2; return 127" - else - BODY="${BIN_PATH} \"\$@\"; return \$?" - fi - eval "${BIN}() { - echo -n \"QA Notice: ${BIN} in global scope: \" >&2 - if [[ \${ECLASS_DEPTH} -gt 0 ]]; then - echo \"eclass \${ECLASS}\" >&2 - else - echo \"\${CATEGORY}/\${PF}\" >&2 - fi - ${BODY} - }" || echo "error creating QA interceptor ${BIN}" >&2 - done - __QA_INTERCEPTORS_ACTIVE=true -} &> /dev/null - -__qa_interceptors_disable() { - ${__QA_INTERCEPTORS_ACTIVE} || return - local x - for x in "${PKGCORE_QA_INTERCEPTORS[@]}"; do - unset -f ${x} - done - __QA_INTERCEPTORS_ACTIVE=false -} &> /dev/null - -DONT_EXPORT_VARS+=" ECLASS_DEPTH __QA_INTERCEPTORS_ACTIVE" - -: diff --git a/pkgcore/ebuild/eapi-bash/ebuild-env-utils.lib b/pkgcore/ebuild/eapi-bash/ebuild-env-utils.lib deleted file mode 100644 index d064e1654..000000000 --- a/pkgcore/ebuild/eapi-bash/ebuild-env-utils.lib +++ /dev/null @@ -1,201 +0,0 @@ -# Copyright 2005-2012 Brian Harring : BSD/GPL2 -# this functionality is all related to saving/loading environmental dumps for ebuilds - -__regex_filter_input() { - # We don't need to reset IFS in this context, thus skip the pop. - local IFS='|' - local regex="^(${*})$" - # use egrep if possible... tis faster. - local l - if l=$(type -P gsed || type -P sed); then - "${l}" -re "/${regex}/d" - local ret=$? - [[ ${ret} != 0 ]] && die "got failing return code (${ret}) invoking ${l} -e '/${regex}/d'" - elif l=$(type -P egrep); then - # use type -p; qa_interceptors may be active. - "${l}" -v "${regex}" - local ret=$? - [[ ${ret} -gt 1 ]] && die "got failing return code (${ret}) ${l} -v '${regex}'" - elif [[ -x ${PKGCORE_PYTHON_BINARY} ]]; then - # We check for the binary on the offchance an ebuild operation - # just removed it under our feet. - "${PKGCORE_PYTHON_BINARY}" -c \ - 'import sys;import re;r=re.compile(sys.argv[1]).match;sys.stdout.write("\n".join(x for x in sys.stdin.read().splitlines() if r(x) is None))' \ - "${regex}" - local ret=$? - [[ ${ret} != 0 ]] && die "got failing return code (${ret}) invoking ${PKGCORE_PYTHON_BINARY} for regex_filter" - else - while read l; do - [[ ${l} =~ ${regex} ]] || echo "${l}" - done - fi -} - -__escape_regex_array() { - local __tmp_array - # Need to get the content of the original array... - eval "__tmp_array=( \"\${$1[@]}\" )" - __tmp_array=( "${__tmp_array[@]//\+/\\+}" ) - __tmp_array=( "${__tmp_array[@]//\./\\.}" ) - __tmp_array=( "${__tmp_array[@]//\*/\\*}" ) - # Now transfer the content back. - eval $1='( "${__tmp_array[@]}" )' -} &> /dev/null - -__environ_list_funcs() { - # Grab the vars /before/ adding our custom declare function, else it'll - # show up in the list of functions. - local __content=$(builtin declare -F) - declare() { - echo "$2" - } - eval "${__content}" || die "__environ_list_funcs eval failed" >&2 - unset -f declare - : -} - -__environ_list_vars() { - declare() { - local __ret=${2%%=*} - [[ $2 != ${__ret} ]] && echo "${__ret}" - : - } - eval "$(builtin declare -p)" || die "__environ_list_vars eval failed" >&2 - unset -f declare - : -} - -__filter_env() { - local opts - [[ ${PKGCORE_DEBUG} -ge 3 ]] && opts="--debug" - PYTHONPATH="${PKGCORE_PYTHONPATH}" "${PKGCORE_PYTHON_BINARY}" \ - $(type -P filter-env) ${opts} "$@" || die "filter-env invocation failed" -} - -# selectively saves the environ- specifically removes things that have been marked to not be exported. -# dump the environ to stdout. -__environ_dump() { - __shopt_push -f - local __func_filters=( ${DONT_EXPORT_FUNCS} ${PKGCORE_EAPI_FUNCS} "${PKGCORE_PRELOADED_ECLASSES[@]}" ) - ${__QA_INTERCEPTORS_ACTIVE:-false} && __func_filters+=( "${PKGCORE_QA_INTERCEPTORS[@]}" ) - - # Punt any regex chars... - __escape_regex_array __func_filters - __PKGCORE_TARGETS=( $(__environ_list_funcs | __regex_filter_input "${__func_filters[@]}" ) ) - unset __func_filters - if [[ ${#__PKGCORE_TARGETS[@]} -ne 0 ]]; then - declare -f "${__PKGCORE_TARGETS[@]}" || die "failed outputting funcs ${__PKGCORE_TARGETS[@]}" >&2 - fi - - __PKGCORE_TARGETS=( $(__environ_list_vars | __regex_filter_input ${DONT_EXPORT_VARS} __PKGCORE_TARGETS) ) - if [[ ${#__PKGCORE_TARGETS[@]} -ne 0 ]]; then - declare -p "${__PKGCORE_TARGETS[@]}" || die "failed outputting env vars ${__PKGCORE_TARGETS[@]}" >&2 - fi - - __shopt_pop -} - -# dump environ to $1, optionally piping it through $2 and redirecting $2's output to $1. -__environ_save_to_file() { - if [[ $# -ne 1 && $# -ne 2 ]]; then - die "__environ_save_to_file requires at least one argument, two max; given $@" - fi - - # the spaces on both sides are important- otherwise, the later ${DONT_EXPORT_VARS/ temp_umask /} won't match. - # we use spaces on both sides, to ensure we don't remove part of a variable w/ the same name- - # ex: temp_umask_for_some_app == _for_some_app. - #Do it with spaces on both sides. - - DONT_EXPORT_VARS+=" temp_umask " - local temp_umask=$(umask) - umask 0002 - - if [[ $# -eq 1 ]]; then - __environ_dump > "$1" - else - __environ_dump | $2 > "$1" - fi - chown portage:portage "$1" &> /dev/null - chmod 0664 "$1" &> /dev/null - - DONT_EXPORT_VARS=${DONT_EXPORT_VARS/ temp_umask /} - - umask ${temp_umask} -} - -# reload a saved env, applying usual filters to the env prior to eval'ing it. -__environ_sanitize_saved_env() { - local src e ret EXISTING_PATH - # localize these so the reload doesn't have the ability to change them - - if [[ $# -ne 1 ]]; then - die "scrub_environ called with wrong args, only one can be given: $@" - fi - - [[ ! -f $1 ]] && die "__environ_sanitize_saved_env called with a nonexist env: $1" - - src=$1 - - # here's how this goes; we do an eval'd loadup of the target env w/in a subshell.. - # declares and such will slide past filter-env (so it goes). we then use our own - # __environ_dump from within to get a clean dump from that env, and load it into - # the parent eval. - ( - - # protect the core vars and functions needed to do a __environ_dump - # some of these are already readonly- we still are forcing it to be safe. - declare -r PKGCORE_PYTHONPATH=${PKGCORE_PYTHONPATH} &> /dev/null - declare -r PKGCORE_PYTHON_BINARY=${PKGCORE_PYTHON_BINARY} &> /dev/null - declare -r DONT_EXPORT_VARS=${DONT_EXPORT_VARS} &> /dev/null - declare -r DONT_EXPORT_FUNCS=${DONT_EXPORT_FUNCS} &> /dev/null - declare -r SANDBOX_ON=${SANDBOX_ON} &> /dev/null - declare -r T=${T} &> /dev/null -# declare -rx PATH=${PATH} &> /dev/null - - readonly -f __filter_env &> /dev/null - readonly -f __environ_dump &> /dev/null - readonly -f __regex_filter_input &> /dev/null - - __shopt_push -f - IFS=$' \t\n' - declare -a PKGCORE_FUNC_ARRAY=( ${DONT_EXPORT_FUNCS} ) - declare -a PKGCORE_VAR_ARRAY=( ${DONT_EXPORT_VARS} src x EXISTING_PATH ) - IFS=, - PKGCORE_FUNC_ARRAY=${PKGCORE_FUNC_ARRAY[*]} - PKGCORE_VAR_ARRAY=${PKGCORE_VAR_ARRAY[*]} - IFS=$' \t\n' - __shopt_pop - - rm -f "${T}"/.pre-scrubbed-env || die "failed rm'ing" - # run the filtered env. - __filter_env \ - -f "${PKGCORE_FUNC_ARRAY}" \ - -v "${PKGCORE_VAR_ARRAY}" \ - -i "${src}" \ - > "${T}"/.pre-scrubbed-env || die "failed first step of scrubbing the env to load" - - [[ -s ${T}/.pre-scrubbed-env ]] || die "empty pre-scrubbed-env file. pkgcore bug?" - source "${T}"/.pre-scrubbed-env >&2 || die "failed sourcing scrubbed env" - - - # if reinstate_loaded_env_attributes exists, run it to add to the vars. - # old pkgcore env saving approach, long before portage/paludis were around... - type reinstate_loaded_env_attributes &> /dev/null && \ - reinstate_loaded_env_attributes - unset -f reinstate_loaded_env_attributes - - # ok. it's loaded into this subshell... now we use our dump mechanism (which we trust) - # to output it- this mechanism is far more bulletproof then the load filtering (since - # declare and friends can set vars via many, many different ways), thus we use it - # as the final filtering. - - unset -v EXISTING_PATH old_phase - - rm -f "${T}"/.scrubbed-env - __environ_dump > "${T}"/.scrubbed-env || die "dumping environment failed" - ) && return - - echo "die 'failed parsing the env dump'" # yep, we're injecting code into the eval. - exit 1 - # note no die usage here... exit instead, since we don't want another tb thrown -} diff --git a/pkgcore/ebuild/eapi-bash/ebuild.lib b/pkgcore/ebuild/eapi-bash/ebuild.lib deleted file mode 100644 index 724729656..000000000 --- a/pkgcore/ebuild/eapi-bash/ebuild.lib +++ /dev/null @@ -1,514 +0,0 @@ -#!/bin/bash -# ebuild.lib; ebuild phase processing, env handling -# Copyright 2005-2012 Brian Harring : BSD/GPL2 - -# general phase execution path- -# __execute_phases is called, which sets EBUILD_PHASE, and then depending on the phase, -# loads or initializes. Env is init'd for non src based stages if the env isn't found- otherwise -# it loads the environ via __load_environ call. In cases where env isn't found for phases setup -> merge, -# it bails (theres no way the env should be missing- exemption is setup phase). -# -# for env filtering for restoration and reloading, note the updates to DONT_EXPORT_(VARS|FUNCS). -# those vars are basically used to track what shouldn't be saved/restored. Whitespace separated, -# those vars can support posix (think egrep) regex. They should hold all vars/funcs that are internal -# ebuild.sh vars. Basically, filter all vars/funcs that are specific to ebuild.sh, not the ebuild. -# -# after loading the env, user defined pre hooks are executed, __dyn_${EBUILD_PHASE} is executed, -# and the post hooks are executed. If the env needs to be flushed to disk, MUST_EXPORT_ENV is set to -# "yes", and __execute_phases will dump it to ${T}/environment. -# -# few notes on general env stuff- if it's not ebuild specific or a user option, it's typically marked -# readonly. This limits users, but also helps to ensure that reloaded envs from older portages don't -# overwrite an internal ebd.sh function that has since changed. - -ORIG_VARS=$(declare | grep -E '^[^[:space:]{}()]+=' | cut -s -d '=' -f 1) -ORIG_FUNCS=$(declare -F | cut -s -d ' ' -f 3) - -DONT_EXPORT_VARS="ORIG_VARS GROUPS ORIG_FUNCS FUNCNAME CCACHE.* DISTCC.* SYNC -(TMP)?DIR FEATURES CONFIG_PROTECT.* WORKDIR RSYNC_.* GENTOO_MIRRORS -(DIST|FILES|RPM|ECLASS)DIR HOME MUST_EXPORT_ENV QA_CONTROLLED_EXTERNALLY HOSTNAME -myarg SANDBOX_ON SANDBOX_(DEBUG(_LOG)?|VERBOSE|BASHRC|PID|LIB) -BASH.* EUID PPID SHELLOPTS UID ACCEPT_(KEYWORDS|LICENSE) BUILD(_PREFIX|DIR) T DIRSTACK -(PKGCORE_)?EBUILD_PHASE PKGCORE_.* PORTAGE_.* SUDO_.* LD_PRELOAD ret line phases D IMAGE -PORT(_LOGDIR|DIR(_OVERLAY)?) ROOT _ done e PROFILE_.* EBUILD ECLASS LINENO -HILITE TMP HISTCMD OPTIND RANDOM (OLD)?PWD IFS PIPESTATUS LINENO FUNCNAME _pipestatus -SHELL SHLVL EMERGE_(WARNING_DELAY|FROM) MERGE_TYPE REPLACING_VERSIONS REPLACED_BY_VERSION (RESUME|FETCH)COMMAND(_.*)? -AUTOCLEAN CLEAN_DELAY USE_ORDER XARGS -COLORTERM LESS(OPEN)? DISPLAY EDITOR LS_COLORS PAGER TERM TERMCAP (ftp|http)_proxy USER(NAME)?" - - -if [[ -z ${PKGCORE_BIN_PATH} ]]; then - echo "PKGCORE_BIN_PATH is unset!" - exit 1 -fi - -# knock the sandbox vars back to the pkgs defaults. -__reset_sandbox() { - export SANDBOX_ON=1 - export SANDBOX_PREDICT=${SANDBOX_PREDICT:+${SANDBOX_PREDICT}:}/proc/self/maps:/dev/console:/dev/random:${PORTAGE_TMPDIR} - export SANDBOX_WRITE=${SANDBOX_WRITE:+${SANDBOX_WRITE}:}/dev/shm:${PORTAGE_TMPDIR} - export SANDBOX_READ=${SANDBOX_READ:+${SANDBOX_READ}:}/dev/shm:${PORTAGE_TMPDIR} - local var - for var in CCACHE_DIR DISTCC_DIR D WORKDIR T; do - if [[ -n ${!var} ]]; then - addread "${!var}" - addwrite "${!var}" - fi - done -} - -# Prevent aliases from causing portage to act inappropriately. -# Make sure it's before everything so we don't mess aliases that follow. -unalias -a - -# We need this next line for "die" and "assert". It expands -# It _must_ preceed all the calls to die and assert. -shopt -s expand_aliases - -# Unset some variables that break things. -unset GZIP BZIP BZIP2 CDPATH GREP_OPTIONS GREP_COLOR GLOB_IGNORE - -# gentoo bug 309369; nasty alias, but it exists due to portage using declare's in env dumping. declare statements are implicitly local. -# as such, the sourcing statement has to be in the same scope as the invoker of __load_environ for that scope to get the changes -alias __load_environ='{ - [[ -z ${PKGCORE_TARGET_ENV} ]] && die "__load_environ was invoked w/out PKGCORE_TARGET_ENV set"; - [[ -z ${T} ]] && die "__load_environ requires \$T to be set"; - EXISTING_PATH=${PATH}; - __timed_call __environ_sanitize_saved_env "${PKGCORE_TARGET_ENV}" - if [[ -n ${PKGCORE_PERF_DEBUG} ]]; then - echo "timing source ${PKGCORE_TARGET_ENV}" >&2 - time source "${PKGCORE_TARGET_ENV}" >&2 - echo "timed source ${PKGCORE_TARGET_ENV}" >&2 - else - source "${PKGCORE_TARGET_ENV}" >&2 - fi - [[ $? == 0 ]] || die "sourcing saved env failed"; - __ensure_PATH "${EXISTING_PATH}"; - export EAPI=${PKGCORE_EAPI-${EAPI}} - __timed_call __load_eapi_libs - __timed_call __source_bashrcs - unset -v EXISTING_PATH; -}' - -# Invoke this when we know that this version of pkgcore generated the env dump; this bypasses -# The safeties in loading. -alias __load_safe_environ='{ - [[ -z ${PKGCORE_TARGET_ENV} ]] && die "__load_safe_environ was invoked w/out PKGCORE_TARGET_ENV set"; - [[ -z ${T} ]] && die "__load_safe_environ requires \$T to be set"; - EXISTING_PATH=${PATH}; - if [[ -n ${PKGCORE_PERF_DEBUG} ]]; then - echo "timing source ${PKGCORE_TARGET_ENV}" >&2 - time source "${PKGCORE_TARGET_ENV}" >&2 - echo "timed source ${PKGCORE_TARGET_ENV}" >&2 - else - source "${PKGCORE_TARGET_ENV}" >&2 - fi - [[ $? == 0 ]] || die "sourcing saved env failed"; - __ensure_PATH "${EXISTING_PATH}"; - export EAPI=${PKGCORE_EAPI-${EAPI}} - __timed_call __load_eapi_libs - __timed_call __source_bashrcs - unset -v EXISTING_PATH; -}' - -alias __init_environ='{ - EXISTING_PATH=${PATH}; - __timed_call __load_eapi_libs - if [[ -n ${PKGCORE_PERF_DEBUG} ]]; then - echo "timing eval \$(__generate_initial_ebuild_environ)" >&2 - time eval "$(__timed_call __generate_initial_ebuild_environ)" >&2 - echo "timed eval \$(__generate_initial_ebuild_environ)" >&2 - else - eval "$(__generate_initial_ebuild_environ)" - fi - [[ $? == 0 ]] || die "failed loading initialized environment"; - __ensure_PATH "${EXISTING_PATH}"; - __timed_call __source_bashrcs - unset -v EXISTING_PATH; -}' - -shopt -s extdebug &> /dev/null - -# if no perms are specified, dirs/files will have decent defaults -# (not secretive, but not stupid) -umask 022 - -# the sandbox is disabled by default except when overridden in the relevant stages -export SANDBOX_ON=0 - -# ensure the passed in PATH has its components in $PATH -__ensure_PATH() { - local EXISTING_PATH=$1 - local adds - # note this isolates the adds in the same order they appear in - # the passed in path, maintaining that order. - if [[ ${EXISTING_PATH} != ${PATH} ]]; then - local IFS=: - local p - for p in ${EXISTING_PATH}; do - # keep in mind PATH=":foon" is a valid way to say "cwd" - [[ -z ${p} ]] && continue - if ! __safe_has "${p}" ${PATH} && ! __safe_has "${p}" ${adds}; then - adds=${adds:+${adds}:}${p} - fi - done - [[ -n ${adds} ]] && PATH=${PATH}${PATH:+:}${adds} - fi - export PATH -} - -__load_eapi_libs() { - local BANNED_FUNCS DEPRECATED_FUNCS funcname - - # reload depend; while it may've been loaded already, reload it so that callers can - # rely on this setting the env up as necessary - # finally, update the filters with functionality loaded from here- - # always, always, *always* use our own functionality - source "${PKGCORE_BIN_PATH}"/eapi/common.lib || die "failed sourcing eapi/common.lib" - source "${PKGCORE_BIN_PATH}/eapi/${PKGCORE_EAPI-${EAPI}}.lib" || \ - die "failed loading eapi/${PKGCORE_EAPI-${EAPI}}.lib" - - # Hijack deprecated and banned functions to make them show QA warnings - # or failure messages, respectively. - for funcname in "${DEPRECATED_FUNCS[@]}"; do - local func_src=( $(__get_func_code ${funcname}) ) - eval "${funcname}() { - eqawarn \"QA Notice: '${funcname}' is deprecated in EAPI ${EAPI:-0}\" - ${func_src[@]} - }" || die "failed evaluating deprecated function '${funcname}'" - done - for funcname in "${BANNED_FUNCS[@]}"; do - eval "${funcname}() { - die \"'${funcname}' is banned in EAPI ${EAPI:-0}\" - }" || die "failed evaluating banned function '${funcname}'" - done -} - -# do all profile, bashrc's, and ebuild sourcing. Should only be called in setup phase, unless the -# env is *completely* missing, as it is occasionally for ebuilds during prerm/postrm. -__generate_initial_ebuild_environ() { - local ORIG_CC=${CC} - local ORIG_CXX=${CXX} - local EXISTING_PATH=${PATH} - local T=${T} - - if [[ ${PKGCORE_EBUILD_PHASE} == "setup" ]]; then - # we specifically save the env so it's not stomped on by sourcing. - # bug 51552 - __timed_call __environ_save_to_file "${T}"/.temp_env - - if [[ ${USERLAND} == "GNU" ]]; then - local PORTAGE_SHIFTED_PATH=${PATH} - __timed_call __qa_invoke source /etc/profile.env - __ensure_PATH "${EXISTING_PATH}" - fi - - # restore the saved env vars. - PKGCORE_SUPPRESS_BASHRCS=true - PKGCORE_TARGET_ENV=${T}/.temp_env - if ! __load_environ; then - # this shouldn't happen. - die "failed to load '${T}/.temp_env' -- fs is readonly?" - fi - unset PKGCORE_SUPPRESS_BASHRCS - - rm "${T}"/.temp_env - fi - - [[ -n ${EBUILD} ]] && __timed_call __load_ebuild "${EBUILD}" - - if [[ ${PKGCORE_EBUILD_PHASE} != "depend" ]]; then - RESTRICT=${PKGCORE_FINALIZED_RESTRICT} - unset PKGCORE_FINALIZED_RESTRICT - unset CC CXX - [[ -n ${ORIG_CC} ]] && export CC=${ORIG_CC} - [[ -n ${ORIG_CXX} ]] && export CXX=${ORIG_CXX} - unset ORIG_CC ORIG_CXX - fi - - __ensure_PATH "${EXISTING_PATH}" - if [[ -n ${T} ]]; then - # use a file if possible; faster since bash does this lovely byte by byte reading if it's a pipe. - # having the file around is useful for debugging also. - __timed_call __environ_dump > "${T}"/.initial_environ || die "dump_environ > '${T}/.initial_environ' return non zero" - echo "source \"${T}\"/.initial_environ" - else - __timed_call __environ_dump || die "dump_environ returned non zero" - fi -} - -__load_ebuild() { - local EBUILD=$1 - shift - - SANDBOX_ON=1 - export S=${WORKDIR}/${P} - - unset IUSE REQUIRED_USE DEPEND RDEPEND PDEPEND - local E_IUSE E_REQUIRED_USE E_DEPEND E_RDEPEND E_PDEPEND - - if [[ ! -f ${EBUILD} ]]; then - echo "bailing, ebuild not found at '${EBUILD}'" - die "EBUILD=${EBUILD}; problem is, it doesn't exist. bye." >&2 - fi - - __qa_invoke source "${EBUILD}" >&2 - - # a reasonable default for $S - if [[ -z ${S} ]]; then - export S=${WORKDIR}/${P} - fi - - # default to EAPI=0 if unset - EAPI=${EAPI-0} - - # some users have $TMP/$TMPDIR to a custom dir in their home ... - # this will cause sandbox errors with some ./configure - # scripts, so set it to $T. - export TMP=${T} - export TMPDIR=${T} - - # Note: this next line is not the same as export RDEPEND=${RDEPEND:-${DEPEND}} - # That will test for unset *or* NULL (""). We want just to set for unset... - - if __safe_has "${EAPI}" 0 1 2 3; then - if [[ ${RDEPEND-unset} == "unset" ]]; then - export RDEPEND=${DEPEND} - fi - fi - - # add in dependency info from eclasses - IUSE+=${IUSE:+ }${E_IUSE} - REQUIRED_USE+=${REQUIRED_USE:+ }${E_REQUIRED_USE} - DEPEND+=${DEPEND:+ }${E_DEPEND} - RDEPEND+=${RDEPEND:+ }${E_RDEPEND} - PDEPEND+=${PDEPEND:+ }${E_PDEPEND} -} - -# short version. think these should be sourced via at the daemons choice, rather then defacto. -# note that exit-handling loads the die functions, thus the custom failure there. -source "${PKGCORE_BIN_PATH}"/exit-handling.lib >&2 || { echo "ERROR: failed sourcing exit-handling.lib"; exit -1; } -source "${PKGCORE_BIN_PATH}"/ebuild-default-functions.lib >&2 || die "failed sourcing ebuild-default-functions.lib" -source "${PKGCORE_BIN_PATH}"/ebuild-env-utils.lib >&2 || die "failed sourcing ebuild-env-utils.lib" - -__run_ebuild_phase() { - [[ -n ${PKGCORE_DEBUG} ]] && set -x - __qa_run_function_if_exists __phase_default_pre_$1 - __qa_run_function_if_exists pre_$1 - - local EBUILD_PHASE_FUNC - if ${PKGCORE_EBUILD_PHASE_FUNC}; then - EBUILD_PHASE_FUNC=$1 - fi - if __is_function __dyn_$1; then - __dyn_$1 - elif __is_function $1; then - __qa_invoke $1 - else - __qa_run_function_if_exists __phase_default_$1 - fi - - __qa_run_function_if_exists post_$1 - __qa_run_function_if_exists __phase_default_post_$1 - [[ ${PKGCORE_DEBUG} -lt 2 ]] && set +x -} - -# general func to call for phase execution. this handles necessary env loading/dumping, and executing pre/post/dyn -# calls. -__execute_phases() { - local PKGCORE_SAVE_ENV - local PKGCORE_MUST_EXPORT_ENV=false - - # give us pretty tracebacks. - shopt -s extdebug - - trap "exit 2" SIGINT - trap "exit 9" SIGQUIT - trap "exit 1" SIGTERM - trap "die 'a helper failed, see above'" SIGUSR1 - declare -rx PKGCORE_EBUILD_PROCESS_PID=${BASHPID} - - if __safe_has "${EAPI:-0}" 0 1 2 3; then - declare -rx PKGCORE_NONFATAL_HELPER=true - fi - - # local scope; this keeps it from bleeding further, and keeps - # it from being exported- we use it to track if we're subshelled w/in the main - # ebd instance, or if we're in a literal child process. - local PKGCORE_IS_NOT_HELPER=1 - local myarg ret - for myarg in $*; do - PKGCORE_EBUILD_PHASE=${myarg} - EBUILD_PHASE=${myarg} - - local PKGCORE_SAVE_ENV=true - local PKGCORE_DIE_OUTPUT_DETAILS=true - local PKGCORE_SUPPRESS_BASHRCS=false - - case ${EBUILD_PHASE} in - nofetch|pretend) - PKGCORE_SUPPRESS_BASHRCS=true - __init_environ - - PKGCORE_DIE_OUTPUT_DETAILS=false - __run_ebuild_phase pkg_${EBUILD_PHASE} - PKGCORE_SAVE_ENV=false - ret=0 - ;; - postrm) - PKGCORE_SAVE_ENV=false - # this is a fall thru; think of it as a select chunk w/out a break - # we just snag these phases to turn off env saving. - ;& - prerm|preinst|postinst|config) - export SANDBOX_ON=0 - - PKGCORE_TARGET_ENV=${T}/environment - if ! __load_environ; then - # hokay. this sucks. - ewarn - ewarn "failed to load env" - ewarn "this installed pkg may not behave correctly" - ewarn - sleep 10 - fi - - __run_ebuild_phase pkg_${EBUILD_PHASE} - ret=0 - ;; - unpack|prepare|configure|compile|test|install) - if [[ ${SANDBOX_DISABLED=0} == 0 ]]; then - export SANDBOX_ON=1 - else - export SANDBOX_ON=0 - fi - - [[ ${PKGCORE_DEBUG} -ge 3 ]] && set -x - PKGCORE_TARGET_ENV=${T}/environment - if ! __load_safe_environ; then - ewarn - ewarn "failed to load env. This is bad, bailing." - die "unable to load saved env for phase ${EBUILD_PHASE}, unwilling to continue" - fi - - [[ -z ${S} ]] && die "S was null- ${S}, path=${PATH}" - - __run_ebuild_phase src_${EBUILD_PHASE} - ret=0 - ;; - setup|setup-binpkg) - # 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. - - EBUILD_PHASE="setup" - - # binpkgs don't need to reinitialize the env. - if [[ ${myarg} == "setup" ]]; then - [[ -n ${DISTCC_LOG} ]] && addwrite "$(dirname ${DISTCC_LOG})" - - # if they aren't set, then holy hell ensues. deal. - - if __feature_is_enabled ccache; then - [[ -z ${CCACHE_SIZE} ]] && export CCACHE_SIZE="500M" - ccache -M ${CCACHE_SIZE} &> /dev/null - fi - [[ ${PKGCORE_DEBUG} == 2 ]] && set -x - __init_environ - else - PKGCORE_TARGET_ENV=${T}/environment - if ! __load_environ; then - die "failed loading saved env from '${T}/environment'" - fi - fi - - export SANDBOX_ON=0 - __run_ebuild_phase pkg_${EBUILD_PHASE} - ret=0; - - ;; - depend|generate_env) - SANDBOX_ON=1 - PKGCORE_SAVE_ENV=false - - PKGCORE_DIE_OUTPUT_DETAILS=false - if [[ -z ${QA_CONTROLLED_EXTERNALLY} ]]; then - __qa_interceptors_enable - fi - - EBUILD_PHASE="depend" - __load_ebuild "${EBUILD}" - - if [[ -z ${QA_CONTROLLED_EXTERNALLY} ]]; then - __qa_interceptors_disable - fi - if [[ ${myarg} == depend ]]; then - __dump_metadata_keys - else - # Use gawk if at possible; it's a fair bit faster since bash likes to do byte by byte reading. - local __path=$(type -P gawk) - if [[ $? == 0 ]]; then - { unset __path; __environ_dump; } | \ - LC_ALL=C "${__path}" -F $'\0' 'BEGIN { content="";chars=0;RS="\0";ORS=""} {chars += length($0);content = content $0} END {printf("receive_env %i\n%s",chars, content)}' >&${PKGCORE_EBD_WRITE_FD} - else - local my_env=$(__environ_dump) - __ebd_write_line "receive_env ${#my_env}" - __ebd_write_raw "${my_env}" - unset my_env __path - fi - #__environ_dump | $(type -P gawk) -F $'\0' 'BEGIN { content="";chars=0;RS="\0";ORS=""} {chars += length($0);content = content $0} END {printf("receive_env %i\n%s",chars, content)}' >&${PKGCORE_EBD_WRITE_FD} - #__environ_dump | $(type -P python) -c 'import sys;data=sys.stdin.read();sys.stdout.write("receive_env %i\n%s" % (len(data), data))' >&${PKGCORE_EBD_WRITE_FD} - fi - ;; - *) - die "Please specify a valid command: ${EBUILD_PHASE} isn't valid." - ;; - esac - - ${PKGCORE_SAVE_ENV} && PKGCORE_MUST_EXPORT_ENV=true - [[ ${PKGCORE_DEBUG} -lt 4 ]] && set +x - done - - if ${PKGCORE_MUST_EXPORT_ENV}; then - __timed_call __environ_save_to_file "${T}"/environment - fi - return ${ret:-0} -} - -__dump_metadata_keys() { - # note this function does /not/ use shopt pushing/popping; it should only - # be invoked after ebuild code has done it's thing, as such we no longer care, - # and directly screw w/ it for speed reasons- about 5% speedup in metadata regen. - set -f - local key - for key in EAPI DEPEND RDEPEND SLOT SRC_URI RESTRICT HOMEPAGE LICENSE \ - DESCRIPTION KEYWORDS INHERITED IUSE PDEPEND PROVIDE PROPERTIES REQUIRED_USE; do - # deref the val, if it's not empty/unset, then spit a key command to EBD - # after using echo to normalize whitespace (specifically removal of newlines) - if [[ ${!key:-unset} != "unset" ]]; then - # note that we explicitly bypass the normal functions, and directly - # write to the FD. This is done since it's about 25% faster for our usage; - # if we used the functions, we'd have to subshell the 'echo ${!key}', which - # because of bash behaviour, means the content would be read byte by byte. - echo -n "key ${key}=" >&${PKGCORE_EBD_WRITE_FD} - echo ${!key} >&${PKGCORE_EBD_WRITE_FD} - fi - done - set +f - - # defined phases... fun one. - local phases - for key in pkg_{pretend,configure,info,{pre,post}{rm,inst},setup} \ - src_{unpack,prepare,configure,compile,test,install}; do - __is_function "${key}" && phases+=${phases:+ }${key} - done - __ebd_write_line "key DEFINED_PHASES=${phases:--}" -} - -DONT_EXPORT_VARS+=" $(declare | __filter_env --print-vars | __regex_filter_input ${ORIG_VARS} ${DONT_EXPORT_VARS})" - -set +f - -export XARGS -set +H -h -: diff --git a/pkgcore/ebuild/eapi-bash/exit-handling.lib b/pkgcore/ebuild/eapi-bash/exit-handling.lib deleted file mode 100644 index e2a40fd3b..000000000 --- a/pkgcore/ebuild/eapi-bash/exit-handling.lib +++ /dev/null @@ -1,110 +0,0 @@ -# Copyright 2005-2012 Brian Harring : BSD/GPL2 -# Copyright 2004-2005 Gentoo Foundation: GPL2 - -assert() { - local pipestatus=${PIPESTATUS[*]} - [[ -z ${pipestatus//[ 0]/} ]] || die "$@ (pipestatus: ${pipestatus})" -} - -die() { - set +x - # if we were signaled to die... - if [[ -n ${EBD_DISABLE_DIEFUNC} ]]; then - return - fi - - local n filespacing=0 linespacing=0 sourcefile lineno - # setup spacing to make output easier to read - for (( n = ${#FUNCNAME[@]} - 1 ; n >= 0 ; --n )); do - sourcefile=${BASH_SOURCE[${n}]} sourcefile=${sourcefile##*/} - lineno=${BASH_LINENO[${n}]} - (( filespacing < ${#sourcefile} )) && filespacing=${#sourcefile} - (( linespacing < ${#lineno} )) && linespacing=${#lineno} - done - - echo >&2 - echo "!!! ERROR: ${CATEGORY}/${PF} failed." >&2 - echo "!!! die invoked from directory $(pwd)" >&2 - if [[ -z ${PKGCORE_IS_NOT_HELPER} ]]; then - echo "!!! was running helper: ${HELPER_ERROR_PREFIX}" - else - __dump_trace 2 ${filespacing} ${linespacing} >&2 - echo "!!! $(printf "%${filespacing}s" "${BASH_SOURCE[1]##*/}"), line $(printf "%${linespacing}s" "${BASH_LINENO[0]}"): Called die" >&2 - fi - echo "!!! The die message:" >&2 - echo "!!! ${*:-(no error message)}" >&2 - if ${PKGCORE_DIE_OUTPUT_DETAILS-true}; then - if [[ -n ${PKGCORE_IS_NOT_HELPER} ]]; then - echo "!!!" >&2 - echo "!!! If you need support, post the topmost build error, and the call stack if relevant." >&2 - fi - local hook - for hook in ${EBUILD_DEATH_HOOKS}; do - ${hook} >&2 1>&2 - done - fi - echo >&2 - if [[ -n ${PKGCORE_EBUILD_PROCESS_PID} ]]; then - if [[ -z ${PKGCORE_IS_NOT_HELPER} ]]; then - kill -10 ${PKGCORE_EBUILD_PROCESS_PID} - elif [[ ${BASHPID} != ${PKGCORE_EBUILD_PROCESS_PID} ]]; then - kill -s SIGTERM ${PKGCORE_EBUILD_PROCESS_PID} - fi - fi - exit 1 -} - -# usage- first arg is the number of funcs on the stack to ignore. -# defaults to 1 (ignoring __dump_trace) -# whitespacing for filenames -# whitespacing for line numbers -__dump_trace() { - declare -i strip=1 - - if [[ -n $1 ]]; then - strip=$(( $1 )) - fi - echo "!!! Call stack:" - local filespacing=$2 linespacing=$3 - local n p - for (( n = ${#FUNCNAME[@]} - 1, p = ${#BASH_ARGV[@]} ; n > ${strip} ; n-- )); do - local funcname=${FUNCNAME[${n} - 1]} - local sourcefile=$(basename ${BASH_SOURCE[${n}]}) - local lineno=${BASH_LINENO[${n} - 1]} - # Display function arguments - local args= newargs= - local j - if [[ -n ${BASH_ARGV[@]} ]]; then - for (( j = 0 ; j < ${BASH_ARGC[${n} - 1]} ; ++j )); do - newarg=${BASH_ARGV[$(( p - j - 1 ))]} - args="${args:+${args} }'${newarg}'" - done - (( p -= ${BASH_ARGC[${n} - 1]} )) - fi - echo "!!! $(printf "%${filespacing}s" "${sourcefile}"), line $(printf "%${linespacing}s" "${lineno}"): Called ${funcname}${args:+ ${args}}" - done -} - -__helper_exit() { - [[ $1 == 0 ]] && exit 0 - if ${PKGCORE_NONFATAL_HELPER}; then - echo "WARNING: exitcode $1 from ${HELPER_ERROR_PREFIX}" >&2 - exit $1 - fi - if [[ -z $2 ]]; then - die "returned error $1" - fi - die "exitcode $1: $2" -} - -__helper_died() { - die "got $*"; -} - -__helper_check_exit() { - [[ $1 == 0 ]] && return - shift - __helper_exit "$@" -} - -: diff --git a/pkgcore/ebuild/eapi-bash/generate_eapi_func_list.bash b/pkgcore/ebuild/eapi-bash/generate_eapi_func_list.bash deleted file mode 100755 index a5342b5fe..000000000 --- a/pkgcore/ebuild/eapi-bash/generate_eapi_func_list.bash +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash -# -# Generates a list of EAPI specific functions to avoid exporting to the saved -# ebuild environment. This script is run dynamically on initialization of the -# build environment for each ebuild since different EAPIs require different -# lists of functions to be skipped. - -EAPI=$1 -export PKGCORE_BIN_PATH=$(dirname "$0") - -# without this var, parsing certain things can fail; force to true -# so any code that tried accessing it thinks it succeeded -export PKGCORE_PYTHON_BINARY=/bin/true - -# sourcing EAPI specific libs requires a couple functions from -# isolated-functions.lib, specifically __safe_has() and __is_function() are -# used in __inject_phase_funcs() from common.lib -source "${PKGCORE_BIN_PATH}/isolated-functions.lib" \ - || { echo "failed loading isolated-functions.lib" >&2; exit 1; } - -# pull in common.lib for various functions used in EAPI libs, currently -# __inject_common_phase_funcs() and __inject_phase_funcs() in particular -source "${PKGCORE_BIN_PATH}/eapi/common.lib" \ - || { echo "failed loading eapi/common.lib" >&2; exit 1; } - -# grab current function list, we'll need to unset them further on -__content=$(builtin declare -F) -declare() { echo "$2"; } -__common_funcs=$(eval "${__content}") -unset -f declare - -source "${PKGCORE_BIN_PATH}/eapi/${EAPI}.lib" \ - || { echo "failed loading eapi/${EAPI}.lib" >&2; exit 1; } - -# remove functions pulled in by EAPI lib deps, we're only interested in the -# ones set specifically in the EAPI libs -unset -f ${__common_funcs} - -# grab function list *before* adding our custom declare function, otherwise -# it'll show up in the list of functions -__content=$(builtin declare -F) -declare() { echo "$2"; } -eval "${__content}" || { echo "generate EAPI func list eval failed" >&2; exit 1; } -unset -f declare diff --git a/pkgcore/ebuild/eapi-bash/helpers/4/docompress b/pkgcore/ebuild/eapi-bash/helpers/4/docompress deleted file mode 100755 index 3cc710882..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/4/docompress +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -# for the time being, we're ignoring controllable compression. - -exit 0 diff --git a/pkgcore/ebuild/eapi-bash/helpers/4/dohard b/pkgcore/ebuild/eapi-bash/helpers/4/dohard deleted file mode 120000 index 22465e004..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/4/dohard +++ /dev/null @@ -1 +0,0 @@ -../internals/banned \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/4/dosed b/pkgcore/ebuild/eapi-bash/helpers/4/dosed deleted file mode 120000 index 22465e004..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/4/dosed +++ /dev/null @@ -1 +0,0 @@ -../internals/banned \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/5/doheader b/pkgcore/ebuild/eapi-bash/helpers/5/doheader deleted file mode 100755 index a344f34ff..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/5/doheader +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -check_args 1 - - -INSDESTTREE=/usr/include invoke_script doins "$@" diff --git a/pkgcore/ebuild/eapi-bash/helpers/5/newheader b/pkgcore/ebuild/eapi-bash/helpers/5/newheader deleted file mode 120000 index 221e3362d..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/5/newheader +++ /dev/null @@ -1 +0,0 @@ -../internals/_generic_new \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/dobin b/pkgcore/ebuild/eapi-bash/helpers/common/dobin deleted file mode 100755 index 4c974cbb2..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/dobin +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -check_args 1 - - -# chunk off the 'do' prefix to get the subdir to use. -target=${HELPER_NAME:2} - -# may exist already, but that's fine. -check_command_or_stop install -d "${ED}${DESTTREE}/${target}" - -for x in "$@"; do - check_command install -m0755 -o "${PKGCORE_INST_UID:-0}" -g "${PKGCORE_INST_GID:-0}" -- "${x}" "${ED}${DESTTREE}/${target}" -done diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/doconfd b/pkgcore/ebuild/eapi-bash/helpers/common/doconfd deleted file mode 100755 index beca058f4..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/doconfd +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -check_args 1 - - -INSDESTTREE=/etc/conf.d invoke_script doins "$@" diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/dodir b/pkgcore/ebuild/eapi-bash/helpers/common/dodir deleted file mode 100755 index 6646bcdcc..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/dodir +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -check_args 1 - - -check_command install -d ${DIROPTIONS} "${@/#/${ED}/}" diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/dodoc b/pkgcore/ebuild/eapi-bash/helpers/common/dodoc deleted file mode 100755 index e64adda36..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/dodoc +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2012 Brian Harring -# License: GPL2/BSD 3 clause - -recursive=false -if ${PKGCORE_DODOC_ALLOW_RECURSIVE} && [[ $1 == "-r" ]]; then - recursive=true - shift -fi - -check_args 1 - - -install_paths() { - local mydir=$1 - shift - check_command install -d -- "${mydir}" || return - - for x in "${@}"; do - if [[ ! -e ${x} ]]; then - error "file '${x}' doesn't exist" - elif [[ -d ${x} ]]; then - if ! ${recursive}; then - error "'${x}' is a directory$($PKGCORE_DODOC_ALLOW_RECURSIVE && echo ", perhaps you forgot -r?")" - continue - fi - __directory_is_empty "${x}" && continue - install_paths "${mydir}/${x##*/}" "${x}"/* - elif [[ -s ${x} ]]; then - check_command install -m0644 -- "${x}" "${mydir}" && \ - check_command "${PORTAGE_COMPRESS}" "${PORTAGE_COMPRESS_FLAGS}" -f "${mydir}/${x##*/}" - fi - done -} - -install_paths "${ED}usr/share/doc/${PF}/${PKGCORE_DOCDESTTREE}" "$@" diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/doenvd b/pkgcore/ebuild/eapi-bash/helpers/common/doenvd deleted file mode 100755 index ef7590551..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/doenvd +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -check_args 1 - - -INSDESTTREE=/etc/env.d invoke_script doins "$@" diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/doexe b/pkgcore/ebuild/eapi-bash/helpers/common/doexe deleted file mode 100755 index 7ea5ebff7..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/doexe +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -check_args 1 - - -check_command_or_stop install -d "${ED}${PKGCORE_EXEDESTTREE}" - -for x in "$@"; do - if [[ -L ${x} ]]; then - check_command cp -- "${x}" "${T}" || continue - mysrc=${T}/${x##*/} - elif [[ -d ${x} ]]; then - warn "skipping directory ${x}" - continue - else - mysrc=${x} - fi - check_command install ${EXEOPTIONS} -- "${mysrc}" "${ED}${PKGCORE_EXEDESTTREE}" - # cleanup after ourselves... - [[ ${mysrc} != ${x} ]] && rm -f "${mysrc}" -done diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/dohard b/pkgcore/ebuild/eapi-bash/helpers/common/dohard deleted file mode 100755 index be567e3b6..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/dohard +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -check_args 2 - -ln_option= -src_prefix= -if [[ ${HELPER_NAME} == "dosym" ]]; then - ln_option="sn" - if [[ $2 == */ ]] || [[ -d $2 && ! -L $2 ]]; then - echo "QA: dosym target '$2' omits the filename target; see bug 379899" >&2 - fi -else - src_prefix=${ED} -fi - -check_command_or_stop dodir "${2%/*}" -check_command ln -${ln_option}f "${src_prefix}$1" "${ED}$2" diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/dohtml b/pkgcore/ebuild/eapi-bash/helpers/common/dohtml deleted file mode 100755 index df8a7fc45..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/dohtml +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -check_args 1 - - -check_command "${PKGCORE_PYTHON_BINARY}" "${PKGCORE_BIN_PATH}/helpers/internals/_raw_dohtml" "$@" diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/doinfo b/pkgcore/ebuild/eapi-bash/helpers/common/doinfo deleted file mode 100755 index ca4ac8d86..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/doinfo +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -check_args 1 - - -check_command_or_stop install -d "${ED}usr/share/info" - -for x in "$@"; do - check_command install -m0644 -- "${x}" "${ED}usr/share/info" && \ - check_command "${PORTAGE_COMPRESS}" "${PORTAGE_COMPRESS_FLAGS}" -f "${ED}usr/share/info/${x##*/}" -done diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/doinitd b/pkgcore/ebuild/eapi-bash/helpers/common/doinitd deleted file mode 100755 index 2e969ff03..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/doinitd +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -check_args 1 - - -PKGCORE_EXEDESTTREE=/etc/init.d invoke_script doexe "$@" diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/doins b/pkgcore/ebuild/eapi-bash/helpers/common/doins deleted file mode 100755 index ef4894f11..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/doins +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2012 Brian Harring -# License: GPL2/BSD 3 clause - -recursive=false -if [[ $1 == "-r" ]]; then - recursive=true - shift -fi - -check_args 1 - - -if [[ -n ${INSDESTTREE} && -z ${INSDESTTREE%${ED}*} ]]; then - __helper_exit 2 "do not give \${D} nor \${ED} as part of the pathways to doins" -fi - -install_paths() { - local mydir=$1 - shift - check_command invoke_script dodir "${mydir}" || return 1 - - __shopt_push -s extglob - # strip trailing slashes - local paths=( "${@%%+(/)}" ) - __shopt_pop - - for x in "${paths[@]}"; do - mysrc=${x} - if [[ -L ${x} ]]; then - if ! ${PKGCORE_DOINS_ALLOW_SYMLINKS}; then - check_command cp -- "${x}" "${T}" || continue - mysrc=${T}/${x##*/} - else - check_command cp -P -- "${x}" "${ED}${mydir}/${x##*/}" - continue - fi - elif [[ -d ${x} ]]; then - ${recursive} || continue - __shopt_push -s dotglob nullglob - install_paths "${mydir}/${x##*/}" "${x}"/* - __shopt_pop - continue - fi - check_command install ${INSOPTIONS} -- "${mysrc}" "${ED}${mydir}" - # cleanup the tempspace... - [[ ${mysrc} != ${x} ]] && rm -f "${mysrc}" - done -} - -install_paths "${INSDESTTREE}" "$@" diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/dolib b/pkgcore/ebuild/eapi-bash/helpers/common/dolib deleted file mode 100755 index c88e7429f..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/dolib +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -check_args 1 - - -libdir=${ED}${DESTTREE}/$(__get_libdir lib) - -if [[ ${HELPER_NAME} == "dolib.so" ]]; then - LIBOPTIONS="-m0755" -elif [[ ${HELPER_NAME} == "dolib.a" ]]; then - LIBOPTIONS="-m0644" -fi - -check_command_or_stop install -d "${libdir}" - -for x in "$@"; do - if [[ -L ${x} ]]; then - # yes we want readlink, not readlink -f; we want the symlink content, - # not the resolved symlink target. - check_command ln -s -- "$(readlink -- "${x}")" "${libdir}/${x##*/}" - else - check_command install ${LIBOPTIONS} -- "${x}" "${libdir}" - fi -done diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/dolib.a b/pkgcore/ebuild/eapi-bash/helpers/common/dolib.a deleted file mode 120000 index c013e45e8..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/dolib.a +++ /dev/null @@ -1 +0,0 @@ -dolib \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/dolib.so b/pkgcore/ebuild/eapi-bash/helpers/common/dolib.so deleted file mode 120000 index c013e45e8..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/dolib.so +++ /dev/null @@ -1 +0,0 @@ -dolib \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/doman b/pkgcore/ebuild/eapi-bash/helpers/common/doman deleted file mode 100755 index bc5e1ea26..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/doman +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -check_args 1 - - -i18n="" - -for x in "$@"; do - if [[ ${x} == "-i18n="* ]]; then - i18n=${x:6}/ - continue - fi - if [[ ${x} == ".keep_"* || ${x} == ".keep" ]]; then - continue - fi - - # rewrite this suffix bits into regex. - suffix=${x##*.} - if __safe_has "${suffix}" Z gz bz2; then - uncompressed_name=${x%.*} - suffix=${uncompressed_name##*.} - fi - - if ${PKGCORE_DOMAN_LANGUAGE_OVERRIDE} && [[ -n ${i18n} ]]; then - name=${x##*/} - mandir=${i18n}man${suffix:0:1} - elif ${PKGCORE_DOMAN_LANGUAGE_DETECT} && - [[ ${x} =~ (.*)\.([a-z][a-z](_[A-Z][A-Z])?)\.(.*) ]]; then - name=${BASH_REMATCH[1]##*/}.${BASH_REMATCH[4]} - mandir=${BASH_REMATCH[2]}/man${suffix:0:1} - else - name=${x##*/} - mandir=${i18n}man${suffix:0:1} - fi - - if [[ ${mandir} =~ man[0-9n](f|p|pm)?$ ]]; then - if [[ -s ${x} ]]; then - check_command install -d "${ED}/usr/share/man/${mandir}" || continue - check_command install -m0644 -- "${x}" "${ED}/usr/share/man/${mandir}/${name}" - elif [[ ! -e ${x} ]]; then - error "'${x}' does not exist" - fi - else - error "'${x}' doesn't have a filename pattern that looks like a man page, not installing" - fi -done diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/domo b/pkgcore/ebuild/eapi-bash/helpers/common/domo deleted file mode 100755 index 8f7fc66eb..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/domo +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -check_args 1 - - -check_command_or_stop install -d "${ED}${DESTTREE}/share/locale/" - -for x in "$@"; do - if [[ -e ${x} ]]; then - my_basename=${x##*/} - mydir="${ED}${DESTTREE}/share/locale/${my_basename%.*}/LC_MESSAGES" - check_command install -d "${mydir}" && \ - check_command install -m0644 -- "${x}" "${mydir}/${MOPREFIX}.mo" - else - error "'${x}' does not exist" - fi -done diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/dosbin b/pkgcore/ebuild/eapi-bash/helpers/common/dosbin deleted file mode 120000 index 46bbe6165..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/dosbin +++ /dev/null @@ -1 +0,0 @@ -dobin \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/dosed b/pkgcore/ebuild/eapi-bash/helpers/common/dosed deleted file mode 100755 index 6e4aaeb98..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/dosed +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -check_args 1 - - -pattern="s:${ED}::g" - -for x in "$@"; do - trg=${ED}${x} - if [[ ! -e ${trg} ]]; then - pattern=${x} - continue - fi - if [[ ! -f ${trg} ]]; then - error "'${trg}' is not a regular file!"; - continue - fi - tmp_file=${T}/${trg##*/} - if check_command cp "${trg}" "${tmp_file}"; then - check_command sed -e "${pattern}" "${tmp_file}" > "${trg}" - rm -f "${tmp_file}" - fi -done diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/dosym b/pkgcore/ebuild/eapi-bash/helpers/common/dosym deleted file mode 120000 index dacdb2f13..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/dosym +++ /dev/null @@ -1 +0,0 @@ -dohard \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/emake b/pkgcore/ebuild/eapi-bash/helpers/common/emake deleted file mode 100755 index ccc568fdd..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/emake +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -info "${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE} $@" -check_command ${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE} "$@" diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/fowners b/pkgcore/ebuild/eapi-bash/helpers/common/fowners deleted file mode 100755 index 011620369..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/fowners +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -# at least two args are required- the owner/group chunk, and the target -check_args 2 - - -# pathway must be absolute. -check_command chown "${@/#\//${ED}/}" diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/fperms b/pkgcore/ebuild/eapi-bash/helpers/common/fperms deleted file mode 100755 index 8883c9827..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/fperms +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause - -# at least two args are required- the owner/group chunk, and the target -check_args 2 - - -# pathway must be absolute. -check_command chmod "${@/#\//${ED}/}" diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/keepdir b/pkgcore/ebuild/eapi-bash/helpers/common/keepdir deleted file mode 100755 index b1efedfc0..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/keepdir +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2011 Brian Harring -# License: GPL2/BSD 3 clause -# -# adds ".keep" files so that dirs aren't auto-cleaned - -recursive=false -if [[ $1 == "-r" ]]; then - recursive=true - shift -fi - -check_args 1 - -dodir "$@" - -if ${recursive}; then - check_command_or_stop find "$@" -type d -printf "${ED}/%p/.keep_${CATEGORY}_${PN}-${SLOT%/*}\0" | ${XARGS} -0 -n100 touch -else - for x in "$@"; do - check_command_or_stop touch "${ED}/${x}/.keep_${CATEGORY}_${PN}-${SLOT%/*}" - done -fi diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/newbin b/pkgcore/ebuild/eapi-bash/helpers/common/newbin deleted file mode 120000 index 221e3362d..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/newbin +++ /dev/null @@ -1 +0,0 @@ -../internals/_generic_new \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/newconfd b/pkgcore/ebuild/eapi-bash/helpers/common/newconfd deleted file mode 120000 index 221e3362d..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/newconfd +++ /dev/null @@ -1 +0,0 @@ -../internals/_generic_new \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/newdoc b/pkgcore/ebuild/eapi-bash/helpers/common/newdoc deleted file mode 120000 index 221e3362d..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/newdoc +++ /dev/null @@ -1 +0,0 @@ -../internals/_generic_new \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/newenvd b/pkgcore/ebuild/eapi-bash/helpers/common/newenvd deleted file mode 120000 index 221e3362d..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/newenvd +++ /dev/null @@ -1 +0,0 @@ -../internals/_generic_new \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/newexe b/pkgcore/ebuild/eapi-bash/helpers/common/newexe deleted file mode 120000 index 221e3362d..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/newexe +++ /dev/null @@ -1 +0,0 @@ -../internals/_generic_new \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/newinitd b/pkgcore/ebuild/eapi-bash/helpers/common/newinitd deleted file mode 120000 index 221e3362d..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/newinitd +++ /dev/null @@ -1 +0,0 @@ -../internals/_generic_new \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/newins b/pkgcore/ebuild/eapi-bash/helpers/common/newins deleted file mode 120000 index 221e3362d..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/newins +++ /dev/null @@ -1 +0,0 @@ -../internals/_generic_new \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/newlib.a b/pkgcore/ebuild/eapi-bash/helpers/common/newlib.a deleted file mode 120000 index 221e3362d..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/newlib.a +++ /dev/null @@ -1 +0,0 @@ -../internals/_generic_new \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/newlib.so b/pkgcore/ebuild/eapi-bash/helpers/common/newlib.so deleted file mode 120000 index 221e3362d..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/newlib.so +++ /dev/null @@ -1 +0,0 @@ -../internals/_generic_new \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/newman b/pkgcore/ebuild/eapi-bash/helpers/common/newman deleted file mode 120000 index 221e3362d..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/newman +++ /dev/null @@ -1 +0,0 @@ -../internals/_generic_new \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/newsbin b/pkgcore/ebuild/eapi-bash/helpers/common/newsbin deleted file mode 120000 index 221e3362d..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/newsbin +++ /dev/null @@ -1 +0,0 @@ -../internals/_generic_new \ No newline at end of file diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/pkgcore-ebuild-helper b/pkgcore/ebuild/eapi-bash/helpers/common/pkgcore-ebuild-helper deleted file mode 100755 index c0b1b0430..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/pkgcore-ebuild-helper +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env bash -# Copyright: 2012 Brian Harring -# License: GPL2/BSD 3 clause - -# protect against env screwups. -if [[ -z ${PKGCORE_BIN_PATH} ]]; then - PKGCORE_BIN_PATH=$(readlink -f "${0}") - # and go up 3, out of helpers. - PKGCORE_BIN_PATH=${PKGCORE_BIN_PATH%/*} - PKGCORE_BIN_PATH=${PKGCORE_BIN_PATH%/*} - PKGCORE_BIN_PATH=${PKGCORE_BIN_PATH%/*} -fi -export PKGCORE_BIN_PATH - -source "${PKGCORE_BIN_PATH}"/exit-handling.lib || { - echo "failed to load exit-handling library: PKGCORE_BIN_PATH=${PKGCORE_BIN_PATH}" >&2 - exit -127 -} - -if [[ $# -lt 1 ]]; then - die "ebuild-helper invoked without a target helper; no args given." -fi - -source "${PKGCORE_BIN_PATH}"/isolated-functions.lib || \ - die "failed to load isolated-functions.lib" -source "${PKGCORE_BIN_PATH}"/eapi/depend.lib >&2 || \ - die "failed sourcing eapi/depend.lib" -source "${PKGCORE_BIN_PATH}"/eapi/common.lib >&2 || \ - die "failed sourcing eapi/common.lib" - -failed=false -_helper_issues=() -error() { - echo "${HELPER_ERROR_PREFIX}: ${@-no message given}" >&2 - _helper[${#_helper[@]}]=${*-no message given} - failed=true -} - -warn() { - echo "${HELPER_ERROR_PREFIX}: warning, ${@-no message given}" >&2 -} - -info() { - echo "${HELPER_ERROR_PREFIX}: $@" >&2 -} - -check_args() { - local tense="argument" - local min=$(( $1 )) - local max - [[ ${min} -gt 1 ]] && tense="arguments" - if [[ $2 == '-' ]]; then - max=${HELPER_ARG_COUNT} - elif [[ -z $2 ]]; then - max=$1 - fi - max=$(( max )) - - if [[ ${HELPER_ARG_COUNT} -ge ${min} && ${HELPER_ARG_COUNT} -le ${max} ]]; then - return 0 - fi - if [[ ${min} -eq ${max} ]]; then - die "${HELPER_ERROR_PREFIX}: requires exactly ${min} ${tense}, got ${HELPER_ARG_COUNT}" - elif [[ $2 == '-' ]]; then - die "${HELPER_ERROR_PREFIX}: requires at least ${min} ${tense}, got ${HELPER_ARG_COUNT}" - else: - die "${HELPER_ERROR_PREFIX}: requires at least ${min} ${tense}, and at most ${max} arguments, got ${HELPER_ARG_COUNT}" - fi -} - -check_command() { - local ret - "$@" - ret=$? - [[ ${ret} == 0 ]] && return 0 - error "exitcode ${ret} from $*" - return $(( ret )) -} - -check_command_or_stop() { - check_command "$@" - __helper_check_exit $? "$@ failed, cannot continue" - return 0 -} - -MASTER_HELPER_NAME=${1##*/} -HELPER_ERROR_PREFIX= - -if ! ${PKGCORE_PREFIX_SUPPORT:=false}; then - export ED=${D} -elif [[ ${ED:-unset} == "unset" ]]; then - error "The variable ED is missing from the environment, but is required for prefix mode; failing." - exit -1 -fi - -invoke_script() { - [[ $# -eq 0 ]] && die "internal error: invoke_script invoked incorrectly" - local HELPER_PATH=$1 - local HELPER_NAME=${1##*/} - local HELPER_EAPI=${1%/*} - HELPER_EAPI=${HELPER_EAPI##*/} - shift - local HELPER_ARG_COUNT=$# - if [[ ! -e ${HELPER_PATH} ]]; then - # note this can daftly go find a binary... - HELPER_PATH=$(type -p "${HELPER_NAME}") - [[ -z ${HELPER_PATH} ]] && die "couldn't find implementation of ${HELPER_NAME}!?" - fi - - local OLD_ERROR_PREFIX=${HELPER_ERROR_PREFIX} - local HELPER_ERROR_PREFIX=${OLD_ERROR_PREFIX:+${OLD_ERROR_PREFIX}: }${HELPER_NAME} - - source "${HELPER_PATH}" - - if ${failed}; then - if [[ -n ${PKGCORE_NONFATAL_HELPER} ]]; then - echo "WARNING: nonzero exitcode from ${HELPER_ERROR_PREFIX}" >&2 - # need to track the exit code here... - return 1 - fi - die "Failures encountered. See proceeding output for details" - fi - return 0 -} -invoke_script "$@" -exit $(( $? )) diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/prepalldocs b/pkgcore/ebuild/eapi-bash/helpers/common/prepalldocs deleted file mode 100755 index 5547fd734..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/prepalldocs +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash -# Copyright 1999-2005 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 - -shopt -s extdebug -source "${PKGCORE_BIN_PATH}"/exit-handling.lib || { echo "failed loading libs"; exit -127; } - -if ! ${PKGCORE_PREFIX_SUPPORT:=false}; then - ED=${D} -elif [[ ${ED:-unset} == "unset" ]]; then - echo "The variable ED is missing from the environment, but is required for prefix mode; failing." - exit -1 -fi - -dir=${ED}usr/share/doc - -[[ ! -d ${dir} ]] && exit 0 - -z=$(find "${dir}" -print \ - '(' -type f -or -type l ')' \ - -not -name '*.gz' \ - -not -name '*.bz2' \ - -not -name '*.xz' \ - -not -name '*.Z' \ - -not -name '*.js' \ - 2>/dev/null) - -[[ -z ${z} ]] && exit 0 - -if [[ -z ${PORTAGE_COMPRESS_SUFFIX} ]]; then - case ${PORTAGE_COMPRESS} in - gzip) suffix="gz";; - bzip2) suffix="bz2";; - xz) suffix="xz";; - *) echo "prepalldocs error: please set PORTAGE_COMPRESS_SUFFIX in make.conf" >&2 - exit 1;; - esac -fi - -IFS=$'\n' -echo "doc: ${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS}" -for y in ${z}; do - if [[ -L ${y} ]]; then - # Symlink ... - mylink=${y} - linkto=$(readlink "${y}") - - if [[ ${linkto##*.} != ${suffix} ]]; then - linkto=${linkto}.${suffix} - fi - if [[ ${mylink##*.} != ${suffix} ]]; then - mylink=${mylink}.${suffix} - fi - - echo " link fixed ${mylink##*/}" - ln -snf "${linkto}" "${mylink}" - if [[ ${y} != ${mylink} ]]; then - echo " link removed ${y##*/}" - rm -f "${y}" - fi - else - if [[ ${y##*.} != ${suffix} ]]; then - echo " compressing ${y##*/}" >&2 - "${PORTAGE_COMPRESS}" ${PORTAGE_COMPRESS_FLAGS} -f "${y}" - fi - fi -done - -: diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/prepallstrip b/pkgcore/ebuild/eapi-bash/helpers/common/prepallstrip deleted file mode 100755 index 5a0f33535..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/prepallstrip +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright 2012 Brian Harring -# Distributed under the terms of the GNU General Public License v2 - -check_args 0 0 - -if ! __feature_is_enabled prepstrip && ! __safe_has nostrip ${RESTRICT}; then - check_command_or_stop prepstrip "${ED}" -fi diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/prepinfo b/pkgcore/ebuild/eapi-bash/helpers/common/prepinfo deleted file mode 100755 index e9ee5802d..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/prepinfo +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash -# Copyright: 2011 Brian Harring -# Copyright: 1999-2005 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 - -shopt -s extdebug -source "${PKGCORE_BIN_PATH}"/exit-handling.lib || { echo "failed loading libs"; exit -127; } - -if ! ${PKGCORE_PREFIX_SUPPORT:=false}; then - ED=${D} -elif [[ ${ED:-unset} == "unset" ]]; then - echo "The variable ED is missing from the environment, but is required for prefix mode; failing." - exit -1 -fi - -if [[ -z $1 ]]; then - z=${ED}usr/share/info -else - if [[ -d ${ED}$1/share/info ]]; then - z=${ED}$1/share/info - else - z=${ED}$1/info - fi -fi - -[[ ! -d ${z} ]] && exit 0 - -rm -f "${z}"/dir{,.old}{,.info{,.gz,.bz2,.xz,.Z}} - -if [[ -z ${PORTAGE_COMPRESS_SUFFIX} ]]; then - case ${PORTAGE_COMPRESS} in - gzip) suffix="gz";; - bzip2) suffix="bz2";; - xz) suffix="xz";; - *) echo "prepinfo: error fixing links: please set PORTAGE_COMPRESS_SUFFIX in make.conf" >&2 - exit 1;; - esac -fi - -echo "info: ${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS}" - -for x in $(find "${z}"/ \( -type f -or -type l \) -maxdepth 1 -mindepth 1 2>/dev/null); do - if [[ -L ${x} ]]; then - # Symlink ... - mylink=${x} - linkto=$(readlink "${x}") - - if [[ ${linkto##*.} != ${suffix} ]]; then - linkto=${linkto}.${suffix} - fi - if [[ ${mylink##*.} != ${suffix} ]]; then - mylink=${mylink}.${suffix} - fi - - echo " fixing GNU info symlink: ${mylink##*/}" - ln -snf "${linkto}" "${mylink}" - if [[ ${x} != ${mylink} ]]; then - echo " removing old symlink: ${x##*/}" - rm -f "${x}" - fi - else - if [[ ${x##*.} != ${suffix} ]]; then - echo " compressing GNU info page: ${x##*/}" - "${PORTAGE_COMPRESS}" ${PORTAGE_COMPRESS_FLAGS} -f "${x}" - fi - fi -done - -: diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/prepman b/pkgcore/ebuild/eapi-bash/helpers/common/prepman deleted file mode 100755 index 530ca6c22..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/prepman +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/bash -# Copyright: 2011 Brian Harring -# Copyright: 1999-2005 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 - -shopt -s extdebug -source "${PKGCORE_BIN_PATH}"/exit-handling.lib || { echo "failed loading libs"; exit -127; } - -if ! ${PKGCORE_PREFIX_SUPPORT:=false}; then - ED=${D} -elif [[ ${ED:-unset} == "unset" ]]; then - echo "The variable ED is missing from the environment, but is required for prefix mode; failing." - exit -1 -fi - -if [[ -z $1 ]]; then - z=${ED}usr/share/man -else - z=${ED}$1/man -fi - -[[ ! -d ${z} ]] && exit 0 - -if [[ -z ${PORTAGE_COMPRESS_SUFFIX} ]]; then - case ${PORTAGE_COMPRESS} in - gzip) suffix="gz";; - bzip2) suffix="bz2";; - xz) suffix="xz";; - *) echo "prepman error: please set PORTAGE_COMPRESS_SUFFIX in make.conf" 1>&2 - exit 1;; - esac -fi - -if [[ -z ${prepallman_banner} ]]; then - echo "man: ${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS}" -fi - -for x in $(find "${z}"/ -type d 2>/dev/null); do - for y in $(find "${x}"/ \( -type f -or -type l \) ! -name '.keep*' -maxdepth 1 -mindepth 1 2>/dev/null); do - if [[ -L ${y} ]]; then - # Symlink ... - mylink=${y} - linkto=$(readlink "${y}") - - # Do NOT change links to directories - if [[ -d ${z}/${linkto} ]]; then - continue - fi - - if [[ ${linkto##*.} != ${suffix} ]]; then - linkto=${linkto}.${suffix} - fi - if [[ ${mylink##*.} != ${suffix} ]]; then - mylink=${mylink}.${suffix} - fi - - echo " link fixed ${mylink##*/}" - ln -snf "${linkto}" "${mylink}" - if [[ ${y} != ${mylink} ]]; then - echo " link removed ${y##*/}" - rm -f "${y}" - fi - else - if [[ ${y##*.} != ${suffix} && ! -d ${y} ]]; then - echo " compressing ${y##*/}" - "${PORTAGE_COMPRESS}" ${PORTAGE_COMPRESS_FLAGS} -f "${y}" - fi - fi - done -done diff --git a/pkgcore/ebuild/eapi-bash/helpers/common/prepstrip b/pkgcore/ebuild/eapi-bash/helpers/common/prepstrip deleted file mode 100755 index 0f31e80ed..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/common/prepstrip +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash -# Copyright 2008-2011 Brian Harring : BSD/GPL2 -# Copyright 1999-2007 Gentoo Foundation: GPL2 -# Distributed under the terms of the GNU General Public License v2 - -shopt -s extdebug -source "${PKGCORE_BIN_PATH}"/exit-handling.lib || { echo "failed loading libs"; exit -127; } - -source "${PKGCORE_BIN_PATH}"/isolated-functions.lib || { - echo "failed sourcing isolated-functions.lib" - exit -1 -} - -# exit if the feature isn't requested, or the restrict isn't there. -__feature_is_enabled installsources || exit 0 -__safe_has installsources ${RESTRICT} && exit 0 - -if ! ${PKGCORE_PREFIX_SUPPORT:=false}; then - ED=${D} -elif [[ ${ED:-unset} == "unset" ]]; then - echo "The variable ED is missing from the environment, but is required for prefix mode; failing." - exit -1 -fi - -for x in debugedit scanelf rsync sort; do - if ! type -P ${x} >/dev/null; then - ewarn "FEATURES=installsources is enabled but the ${x} binary could not" - ewarn "be found. This feature will not work unless debugedit is installed!" - exit 0 - fi -done - -save_elf_sources() { - local x=$1 - local sources_dir=/usr/src/debug/${CATEGORY}/${PF} - debugedit -b "${WORKDIR}" -d "${sources_dir}" \ - -l "${T}"/debug.sources "${x}" - if [[ -s ${T}/debug.sources ]]; then - [[ -d ${ED}${sources_dir} ]] || mkdir -p "${ED}${sources_dir}" - grep -zv '/$' "${T}"/debug.sources | \ - (cd "${WORKDIR}"; LANG=C sort -z -u | \ - rsync -rtL0 --files-from=- "${WORKDIR}/" "${ED}${sources_dir}/" ) - fi -} - -# The existence of the section .symtab tells us that a binary is stripped. -# We want to log already stripped binaries, as this may be a QA violation. -# They prevent us from getting the splitdebug data. -if ! __safe_has binchecks ${RESTRICT} && ! __safe_has strip ${RESTRICT}; then - f=$(scanelf -yqRBF '#k%F' -k '!.symtab' "$@") - if [[ -n ${f} ]]; then - echo -e "\a\n" - ewarn "QA Notice: Pre-stripped files found:" - ewarn "${f}" - echo "${f}" > "${T}"/scanelf-already-stripped.log - fi -fi - -# Now we look for unstripped binaries. -for x in $(scanelf -yqRBF '#k%F' -k '.symtab' "$@"); do - f=$(file "${x}") || continue - [[ -z ${f} ]] && continue - - # only split debug info for final linked objects - # or kernel modules as debuginfo for intermediatary - # files (think crt*.o from gcc/glibc) is useless and - # actually causes problems. install sources for all - # elf types though cause that stuff is good. - - if [[ ${f} == *"SB executable"* || ${f} == *"SB shared object"* ]]; then - save_elf_sources "${x}" - elif [[ ${f} == *"SB relocatable"* ]]; then - save_elf_sources "${x}" - fi -done diff --git a/pkgcore/ebuild/eapi-bash/helpers/internals/_generic_new b/pkgcore/ebuild/eapi-bash/helpers/internals/_generic_new deleted file mode 100755 index 8bc3aa6d0..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/internals/_generic_new +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper -# Copyright: 2012 Brian Harring -# License: GPLv2 or bsd-3 - -check_args 2 - -if [[ -z ${T} ]]; then - __helper_exit 2 "environment issue (ebuild commands somehow filtered the env for ${HELPER_NAME} call)- \${T} was empty" -fi - -rm -rf "${T}/$2" - -if ${PKGCORE_NEW_READS_STDIN} && [[ $1 == "-" ]]; then - if [[ -t 0 ]]; then - die "${HELPER_NAME#new} - $2 cannot be invoked with stdin as a tty" - fi - check_command_or_stop cat > "${T}/$2" -else - check_command_or_stop cp -- "$1" "${T}/$2" -fi -invoke_script "do${HELPER_NAME#new}" "${T}/$2" -rm -f "${T}/$2" diff --git a/pkgcore/ebuild/eapi-bash/helpers/internals/_raw_dohtml b/pkgcore/ebuild/eapi-bash/helpers/internals/_raw_dohtml deleted file mode 100755 index 1a1ec8ae0..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/internals/_raw_dohtml +++ /dev/null @@ -1,188 +0,0 @@ -#!/usr/bin/env python -# Copyright 1999-2006 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# $Id$ - -# -# Typical usage: -# dohtml -r docs/* -# - put all files and directories in docs into /usr/share/doc/${PF}/html -# dohtml foo.html -# - put foo.html into /usr/share/doc/${PF}/html -# -# -# Detailed usage: -# dohtml -# - will install the files in the list of files (space-separated list) into -# /usr/share/doc/${PF}/html, provided the file ends in .htm, .html, .css, -# .js, ,gif, .jpeg, .jpg, or .png. -# dohtml -r -# - will do as 'dohtml', but recurse into all directories, as long as the -# directory name is not CVS -# dohtml -A jpe,java [-r] -# - will do as 'dohtml' but add .jpe,.java (default filter list is -# added to your list) -# dohtml -a png,gif,html,htm [-r] -# - will do as 'dohtml' but filter on .png,.gif,.html,.htm (default filter -# list is ignored) -# dohtml -x CVS,SCCS,RCS -r -# - will do as 'dohtml -r', but ignore directories named CVS, SCCS, RCS - -from __future__ import print_function - -import os -import sys -import textwrap - -def dodir(path): - os.spawnlp(os.P_WAIT, "install", "install", "-d", path) - -def dofile(src,dst): - os.spawnlp(os.P_WAIT, "install", "install", "-m0644", src, dst) - -def install(basename, dirname, options, prefix=""): - fullpath = basename - if prefix: - fullpath = prefix + "/" + fullpath - if dirname: - fullpath = dirname + "/" + fullpath - - if options.DOCDESTTREE: - destdir = options.D + "usr/share/doc/" + options.PF + "/" + options.DOCDESTTREE + "/" + options.doc_prefix + "/" + prefix - else: - destdir = options.D + "usr/share/doc/" + options.PF + "/html/" + options.doc_prefix + "/" + prefix - - if os.path.isfile(fullpath): - ext = os.path.splitext(basename)[1] - if (len(ext) and ext[1:] in options.allowed_exts) or basename in options.allowed_files: - dodir(destdir) - dofile(fullpath, destdir + "/" + basename) - elif options.recurse and os.path.isdir(fullpath) and \ - basename not in options.disallowed_dirs: - for i in os.listdir(fullpath): - pfx = basename - if prefix: pfx = prefix + "/" + pfx - install(i, dirname, options, pfx) - else: - return False - return True - - -class OptionsClass: - def __init__(self): - self.PF = "" - self.D = "" - self.DOCDESTTREE = "" - - if os.environ.has_key("PF"): - self.PF = os.environ["PF"] - if os.environ.has_key("D"): - self.D = os.environ["D"] - if os.environ.get("PKGCORE_PREFIX_SUPPORT", "false") == "true": - if not "ED" in os.environ: - raise Exception("runtime error, or ebuild error: no ED variable found, but required") - self.D = os.environ["ED"] - if os.environ.has_key("_E_DOCDESTTREE_"): - self.DOCDESTTREE = os.environ["_E_DOCDESTTREE_"] - - self.allowed_exts = [ 'htm', 'html', 'css', 'js', - 'gif', 'jpeg', 'jpg', 'png' ] - self.allowed_files = [] - self.disallowed_dirs = [ 'CVS' ] - self.recurse = False - self.verbose = False - self.doc_prefix = "" - -def print_help(): - opts = OptionsClass() - - print(textwrap.dedent( - """ - dohtml [-a .foo,.bar] [-A .foo,.bar] [-f foo,bar] [-x foo,bar] - [-r] [-V] [file ...] - - -a Set the list of allowed to those that are specified. - Default: {} - -A Extend the list of allowed file types. - -f Set list of allowed extensionless file names. - -x Set directories to be excluded from recursion. - Default: {} - -r Install files and directories recursively. - -V Be verbose. - """.format(", ".join(opts.allowed_exts), ", ".join(opts.disallowed_dirs)) - )) - -def parse_args(): - options = OptionsClass() - args = [] - - x = 1 - while x < len(sys.argv): - arg = sys.argv[x] - if arg in ["-h","-r","-V"]: - if arg == "-h": - print_help() - sys.exit(0) - elif arg == "-r": - options.recurse = True - elif arg == "-V": - options.verbose = True - elif sys.argv[x] in ["-A","-a","-f","-x","-p"]: - x += 1 - if x == len(sys.argv): - print_help() - sys.exit(0) - elif arg == "-p": - options.doc_prefix = sys.argv[x] - else: - values = sys.argv[x].split(",") - if arg == "-A": - options.allowed_exts.extend(values) - elif arg == "-a": - options.allowed_exts = values - elif arg == "-f": - options.allowed_files = values - elif arg == "-x": - options.disallowed_dirs = values - else: - args.append(sys.argv[x]) - x += 1 - - return (options, args) - -def main(): - - (options, args) = parse_args() - - if isinstance(options.allowed_exts, basestring): - options.allowed_exts = options.allowed_exts.split(",") - - if options.verbose: - print(textwrap.dedent( - """ - Allowed extensions: {} - Document prefix: '{}' - Allowed files: {} - """.format( - ", ".join(options.allowed_exts), options.doc_prefix, - ", ".join(options.allowed_files) - ) - )) - - success = True - - for x in args: - basename = os.path.basename(x) - dirname = os.path.dirname(x) - if not install(basename, dirname, options): - success = False - - if success: - retcode = 0 - else: - retcode = 1 - - sys.exit(retcode) - -if __name__ == "__main__": - main() diff --git a/pkgcore/ebuild/eapi-bash/helpers/internals/banned b/pkgcore/ebuild/eapi-bash/helpers/internals/banned deleted file mode 100755 index ddda11767..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/internals/banned +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper - -die "'${HELPER_NAME}' is explicitly banned from usage in EAPI '${HELPER_EAPI}'" diff --git a/pkgcore/ebuild/eapi-bash/helpers/internals/deprecated b/pkgcore/ebuild/eapi-bash/helpers/internals/deprecated deleted file mode 100755 index dc89b0102..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/internals/deprecated +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env pkgcore-ebuild-helper - -eqawarn "QA Notice: '${HELPER_NAME}' is deprecated in EAPI '${HELPER_EAPI}'" - -# find original, nondeprecated helper and execute it by removing the EAPI where -# it's deprecated from PATH and searching for the old implementation -ORIG_PATH=${PATH} -export PATH=${PATH/:${PKGCORE_BIN_PATH}\/helpers\/${HELPER_EAPI}/} -ORIG_HELPER=$(type -P ${HELPER_NAME}) -export PATH=${ORIG_PATH} - -"${ORIG_HELPER}" "$@" diff --git a/pkgcore/ebuild/eapi-bash/helpers/internals/prepall b/pkgcore/ebuild/eapi-bash/helpers/internals/prepall deleted file mode 100755 index 5e4e9f285..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/internals/prepall +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/bash -# Copyright: 2011 Brian Harring -# Copyright: 1999-2005 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 - -source "${PKGCORE_BIN_PATH}"/exit-handling.lib || { echo "failed loading libs"; exit -127; } - -"${PKGCORE_BIN_PATH}"/helpers/internals/prepallman -prepinfo -prepallstrip - -if ! ${PKGCORE_PREFIX_SUPPORT:=false}; then - ED=${D} -elif [[ ${ED:-unset} == "unset" ]]; then - echo "The variable ED is missing from the environment, but is required for prefix mode; failing." - exit -1 -fi - -# this should help to ensure that all (most?) shared libraries are executable -# and that all libtool scripts / static libraries are not executable -for i in "${ED}"opt/*/lib{,32,64} \ - "${ED}"lib{,32,64} \ - "${ED}"usr/lib{,32,64} \ - "${ED}"usr/X11R6/lib{,32,64}; do - [[ ! -d ${i} ]] && continue - - for j in "${i}"/*.so.* "${i}"/*.so; do - [[ ! -e ${j} ]] && continue - [[ -L ${j} ]] && continue - [[ -x ${j} ]] && continue - echo "making executable: /${j/${ED}/}" - chmod +x "${j}" - done - - for j in "${i}"/*.a "${i}"/*.la; do - [[ ! -e ${j} ]] && continue - [[ -L ${j} ]] && continue - [[ ! -x ${j} ]] && continue - echo "removing executable bit: /${j/${ED}/}" - chmod -x "${j}" - done -done - -# When installing static libraries into /usr/lib and shared libraries into -# /lib, we have to make sure we have a linker script in /usr/lib along side -# the static library, or gcc will utilize the static lib when linking :(. -# http://bugs.gentoo.org/4411 -for a in "${ED}"usr/lib*/*.a; do - s=${a%.a}.so - if [[ ! -e ${s} ]]; then - s=${s%usr/*}${s##*/usr/} - if [[ -e ${s} ]]; then - echo -e "\aQA Notice: missing gen_usr_ldscript for ${s##*/}\a" - sleep 1 - fi - fi -done - -# Make sure people don't store libtool files or static libs in /lib -f=$(ls "${ED}"lib*/*.{a,la} 2>/dev/null) -if [[ -n ${f} ]]; then - echo -e "\n\aQA Notice: excessive files found in the / partition\a" - echo "${f}" - sleep 1 -fi - -# Verify that the libtool files don't contain bogus $ED entries. -for a in "${ED}"usr/lib*/*.la; do - s=${a##*/} - if grep -qs "${ED}" "${a}"; then - echo -e "\n\aQA Notice: ${s} appears to contain PORTAGE_TMPDIR paths\a" - sleep 1 - fi -done - -if type -p scanelf > /dev/null; then - # Run some sanity checks on shared libraries - for d in "${ED}"lib* "${ED}"usr/lib*; do - f=$(scanelf -ByF '%S %p' "${d}"/lib*.so* | gawk '$2 == "" { print }') - if [[ -n ${f} ]]; then - echo -e "\n\aQA Notice: the following shared libraries lack a SONAME\a" - echo "${f}" - sleep 1 - fi - - f=$(scanelf -ByF '%n %p' "${d}"/lib*.so* | gawk '$2 == "" { print }') - if [[ -n ${f} ]]; then - echo -e "\n\aQA Notice: the following shared libraries lack NEEDED entries\a" - echo "${f}" - sleep 1 - fi - done -fi diff --git a/pkgcore/ebuild/eapi-bash/helpers/internals/prepallman b/pkgcore/ebuild/eapi-bash/helpers/internals/prepallman deleted file mode 100755 index 257498f40..000000000 --- a/pkgcore/ebuild/eapi-bash/helpers/internals/prepallman +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# Copyright 1999-2005 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 - -shopt -s extdebug -source "${PKGCORE_BIN_PATH}"/exit-handling.lib || { echo "failed loading libs"; exit -127; } - -if ! ${PKGCORE_PREFIX_SUPPORT:=false}; then - ED=${D} -elif [[ ${ED:-unset} == "unset" ]]; then - echo "The variable ED is missing from the environment, but is required for prefix mode; failing." - exit -1 -fi - -for x in $(find "${ED}" -name man -type d -printf '%P\n'); do - prepman ${x%/man} - export prepallman_banner="no" -done diff --git a/pkgcore/ebuild/eapi-bash/isolated-functions.lib b/pkgcore/ebuild/eapi-bash/isolated-functions.lib deleted file mode 100644 index 7e887851f..000000000 --- a/pkgcore/ebuild/eapi-bash/isolated-functions.lib +++ /dev/null @@ -1,229 +0,0 @@ -# Copyright 2006-2012 Brian Harring -# License GPL2/BSD3 - -# Internal logging function, don't use this in ebuilds -__elog_base() { - local messagetype - [[ -z $1 || -z ${T} || ! -d ${T}/logging ]] && return 1 - case $1 in - INFO|WARN|ERROR|LOG|QA) - messagetype=$1 - shift - ;; - *) - echo -e " ${PKGCORE_RC_BAD}*${PKGCORE_RC_NORMAL} Invalid use of internal function __elog_base(), next message will not be logged" >&2 - return 1 - ;; - esac - echo "$*" >> "${T}/logging/${EBUILD_PHASE}.${messagetype}" - return 0 -} - -__colored_output_disable() { - PKGCORE_RC_COLS="25 80" - PKGCORE_RC_ENDCOL= - PKGCORE_RC_GOOD= - PKGCORE_RC_WARN= - PKGCORE_RC_BAD= - PKGCORE_RC_NORMAL= - PKGCORE_RC_HILITE= - PKGCORE_RC_BRACKET= -} &> /dev/null - -__colored_output_enable() { - # try setting the column width to bash's internal COLUMNS variable, - # then try to get it via stty. no go? hardcode it to 80. - PKGCORE_RC_COLS=${COLUMNS:-0} - if (( PKGCORE_RC_COLS <= 0 )); then - PKGCORE_RC_COLS=$(set -- $(stty size 2>/dev/null) ; echo ${2:-0}) - if (( PKGCORE_RC_COLS <= 0 )); then - PKGCORE_RC_COLS=80 - fi - fi - export COLUMNS=${PKGCORE_RC_COLS} - PKGCORE_RC_COLS=$(( PKGCORE_RC_COLS - 8 )) # width of [ ok ] == 7 - - export PKGCORE_RC_ENDCOL=$'\e[A\e['${PKGCORE_RC_COLS}'C' - # Now, ${PKGCORE_RC_ENDCOL} will move us to the end of the - # column; irregardless of character width - - export PKGCORE_RC_GOOD=$'\e[32;01m' - export PKGCORE_RC_WARN=$'\e[33;01m' - export PKGCORE_RC_BAD=$'\e[31;01m' - export PKGCORE_RC_HILITE=$'\e[36;01m' - export PKGCORE_RC_BRACKET=$'\e[34;01m' - export PKGCORE_RC_NORMAL=$'\e[0m' -} &> /dev/null - -__safe_has() { - # Version of has, only to be used when the invoker knows that that - # the needle/targets will never have \001 in them - local needle=$1 - shift - local IFS=$'\001' - [[ "${IFS}${*}${IFS}" == *"${IFS}${needle}${IFS}"* ]] -} - -__feature_is_enabled() { - local IFS=$' \t\n' - __safe_has "$1" ${FEATURES} -} &> /dev/null - - -__is_function() { - declare -F "$1" &> /dev/null -} &> /dev/null - -__run_function_if_exists() { - __is_function "$1" || return 0 - "$@" -} - -__qa_run_function_if_exists() { - __is_function "$1" || return 0 - __qa_invoke "$@" -} - -__directory_is_empty() { - __shopt_push -s dotglob nullglob - local files=( ${1}/* ) - __shopt_pop - [[ ${#files[@]} -gt 0 ]] && return 1 - return 0 -} - -__strip_duplicate_slashes() { - if [[ -n $1 ]]; then - local removed=$1 - while [[ ${removed} == *//* ]]; do - removed=${removed//\/\///} - done - echo "${removed}" - fi -} - -__get_func_code() { - __IFS_push $'\n' - local code=( $(declare -f "$1") ) - __IFS_pop - - [[ -z ${code[@]} ]] && return - - # drop function name and surrounding brackets - code=( ${code[@]:2:${#code[@]}-3} ) - echo "${code[@]}" -} - -PKGCORE_SHOPT_STACK=() - -__shopt_push() { - PKGCORE_SHOPT_STACK[${#PKGCORE_SHOPT_STACK[@]}]=${BASHOPTS} - PKGCORE_SHOPT_STACK[${#PKGCORE_SHOPT_STACK[@]}]=$- - if [[ $1 == -[su] ]]; then - # shopt modification - shopt "$@" || die "bad shopt options: $@" - elif [[ -n $@ ]]; then - set "$@" || die "bad set invocation: $@" - fi - return 0 -} &> /dev/null - -__shopt_pop() { - [[ $# -ne 0 ]] && die "bad invocation of __shopt_pop; no args should be supplied, got $@" - local count=$(( ${#PKGCORE_SHOPT_STACK[@]} - 1 )) - [[ ${count} -le 0 ]] && die "bad __shopt_pop invocation; no matching push, stack was empty" - - local set_val=${PKGCORE_SHOPT_STACK[${count}]} - if [[ $- != ${set_val} ]]; then - set ${-:++${-}} ${set_val:+-${set_val}} || die "failed enforcing set state of ${set_val}" - fi - unset PKGCORE_SHOPT_STACK[${count}] - - count=$(( count - 1 )) - - local previous=${PKGCORE_SHOPT_STACK[${count}]} - unset PKGCORE_SHOPT_STACK[${count}] - [[ ${BASHOPTS} == ${previous} ]] && return 0 - - local IFS=' ' - local current=${BASHOPTS} - if [[ -n ${current} ]]; then - shopt -u ${current//:/ } >&2 || die "failed wiping current shopt settings of ${current}" - fi - if [[ -n ${previous} ]]; then - shopt -s ${previous//:/ } >&2 || die "failed forcing old shopt settings to ${previous}" - fi - return 0 -} &> /dev/null - -declare -a PKGCORE_SAVED_IFS - -__IFS_push() { - PKGCORE_SAVED_IFS[${#PKGCORE_SAVED_IFS[@]}]=${IFS-unset} - if [[ $1 == unset ]]; then - unset IFS - else - IFS=$1 - fi - : -} - -__IFS_pop() { - if [[ ${#PKGCORE_SAVED_IFS[@]} -eq 0 ]]; then - die "__IFS_pop invoked with nothing on the stack..." - fi - IFS=${PKGCORE_SAVED_IFS[$(( ${#PKGCORE_SAVED_IFS[@]} - 1 ))]} - [[ ${IFS} == unset ]] && unset IFS - unset PKGCORE_SAVED_IFS[$(( ${#PKGCORE_SAVED_IFS[@]} - 1 ))] - : -} - -__qa_invoke() { - if ${PKGCORE_QA_SUPPRESSED:-false}; then - "$@" - return $(( $? )) - fi - local pkgcore_should_fail=false - # save env and shopt settings. - # in addition, protect the stack from bad pkgcore calls, or bad consumers accessing internals - local PKGCORE_SAVED_IFS=() - local PKGCORE_SHOPT_STACK=() - - __IFS_push "${IFS}" - __shopt_push - - "$@" - local ret=$? - - if [[ ${#PKGCORE_SAVED_IFS[@]} -ne 1 ]]; then - echo "QA warning: unbalanced __IFS_push/__IFS_pop detected. internal error?" \ - " count was ${#PKGCORE_SAVED_IFS[@]}" - pkgcore_should_fail=true - fi - if [[ ${#PKGCORE_SHOPT_STACK[@]} -ne 2 ]]; then - echo "QA warning: unbalanced __shopt_push/__shopt_pop detected. internal error? count was ${#PKGCORE_SHOPT_STACK[@]}" - pkgcore_should_fail=true - fi - - if [[ ${PKGCORE_SAVED_IFS[0]} != ${IFS-unset} ]]; then - echo "QA WARNING: invocation $@ manipulated IFS to ${IFS}, but didn't restore it to its original value!" - fi - __IFS_pop - - # while these echo statements are ugly, written this way to ensure bash does it as a single write- - # aka, keep it within the size of atomic writes for pipes. - # relevant for threaded output straight to term - if [[ ${PKGCORE_SHOPT_STACK[0]} != ${BASHOPTS} ]]; then - echo "QA warning: shopt modification bled out of invocation $@"$'\n'" : was ${PKGCORE_SHOPT_STACK[0]}"$'\n'" : now ${BASHOPTS}" >&2 - fi - - if [[ ${PKGCORE_SHOPT_STACK[1]} != $- ]]; then - echo "QA warning: set modification bled out of invocation $@"$'\n'" : was ${PKGCORE_SHOPT_STACK[1]}"$'\n'" : now $-" >&2 - fi - __shopt_pop - - ${pkgcore_should_fail} && die "invocation $@ modified globals and didn't clean up" - return $(( ret )) -} - -: diff --git a/pkgcore/ebuild/eapi-bash/regenerate_dont_export_func_list.bash b/pkgcore/ebuild/eapi-bash/regenerate_dont_export_func_list.bash deleted file mode 100755 index 23a0db913..000000000 --- a/pkgcore/ebuild/eapi-bash/regenerate_dont_export_func_list.bash +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash -# -# Generates a file (or list) of functions defined in the various bash support -# libs to avoid exporting to the saved ebuild environment. - -_FP=${1:-dont_export_funcs.list} - -export PKGCORE_BIN_PATH=$(dirname "$0") -if [[ -z ${PKGCORE_CLEAN_ENV} ]]; then - exec env -i PKGCORE_PYTHON_PATH=${PKGCORE_PYTHON_PATH} PKGCORE_CLEAN_ENV=1 /bin/bash "$0" "${_FP}" -fi - -export LC_ALL=C # avoid any potential issues of unicode sorting for whacked func names -# export this so that scripts will behave as libs -export PKGCORE_SOURCING_FOR_REGEN_FUNCS_LIST=1 -set -f # shell expansion can bite us in the ass during the echo below -cd "${PKGCORE_BIN_PATH}" || { echo "!!! failed cd'ing to ${PKGCORE_BIN_PATH}" >&2; exit 1; } - -# force some ordering. - -__source_was_seen() { - local x - for x in "${seen[@]}"; do - [[ ${x} == $1 ]] && return 0 - done - return 1 -} -declare -a seen -source() { - local fp=$(readlink -f "$1") - __source_was_seen "${fp}" && return 0 - # die relies on these vars; we reuse them. - local CATEGORY=${PKGCORE_BIN_PATH} - local PF=$1 - echo "sourcing ${x}" >&2 - . "$@" || { echo "!!! failed sourcing ${x}; exit $?" >&2; exit 3; } - seen[${#seen[@]}]=${fp} - return 0 -} - -# without this var, parsing certain things can fail; force to true -# so any code that tried accessing it thinks it succeeded -export PKGCORE_PYTHON_BINARY=/bin/true - -forced_order_source="isolated-functions.lib exit-handling.lib eapi/common.lib ebuild-daemon.lib ebuild-daemon.bash" - -# skip EAPI specific libs since those need be sourced on demand depending on an ebuild's EAPI -for x in ${forced_order_source} $(find . -name '*.lib' ! -regex ".*/[0-9]+\.lib" | sed -e 's:^\./::' | sort); do - source "${x}" -done - -# wipe our custom funcs -unset -f __source_was_seen -unset -f source - -# Sorting order; put PMS functionality first, then our internals. -result=$(__environ_list_funcs | sort) -result=$(echo "${result}" | grep -v "^__"; echo "${result}" | grep "^__") - -if [[ ${_FP} == '-' ]]; then - echo >&2 - echo "${result}" -else - echo "${result}" > dont_export_funcs.list -fi diff --git a/setup.py b/setup.py index 4b9b53879..9d7b35f4e 100644 --- a/setup.py +++ b/setup.py @@ -204,6 +204,10 @@ def _get_files(path): for f in files: yield os.path.join(root, f)[len(path):].lstrip('/') +def _get_data_mapping(host_path, path): + for x in os.walk(path): + yield (os.path.join(host_path, x[0].partition(path)[2].lstrip('/')), + map(lambda y: os.path.join(x[0], y), x[2])) class pkgcore_install_docs(core.Command): @@ -360,31 +364,6 @@ class pkgcore_build_py(snk_distutils.build_py): package_namespace = 'pkgcore' generate_verinfo = True - def _recursive_chmod_files(self, base): - for f in os.listdir(base): - fp = os.path.join(base, f) - if os.path.isdir(fp): - self._recursive_chmod_files(fp) - elif os.path.isfile(fp): - self.set_chmod(fp) - - def _inner_run(self, py3k_rebuilds): - base = os.path.join(self.build_lib, "pkgcore", "ebuild", "eapi-bash") - self._recursive_chmod_files(os.path.join(base, "helpers")) - self.set_chmod(os.path.join(base, "ebuild-daemon.bash")) - self.set_chmod(os.path.join(base, "generate_eapi_func_list.bash")) - self.set_chmod(os.path.join(base, "regenerate_dont_export_func_list.bash")) - - def set_chmod(self, path): - if self.dry_run: - log.info("changing mode of %s", path) - else: - # note, we use the int here for python3k compatibility. - # 365 == 0555, 4095 = 0777 - mode = ((os.stat(path)[ST_MODE]) | 365) & 4095 - log.debug("changing mode of %s to %o", path, mode) - os.chmod(path, mode) - class test(snk_distutils.test): @@ -460,12 +439,8 @@ core.setup( author='Brian Harring', author_email='ferringb@gmail.com', packages=packages, - package_data={ - 'pkgcore': ['ebuild/eapi-bash/%s' % (x,) for x in - _get_files('pkgcore/ebuild/eapi-bash')], - }, data_files=[ ('share/pkgcore/config', glob.glob('config/*')), - ], + ] + list(_get_data_mapping('lib/pkgcore', 'bash')), ext_modules=extensions, cmdclass=cmdclass, command_options=command_options, ) -- cgit v1.2.3-65-gdbad