Lines 130-136
__qa_source() {
Link Here
|
130 |
__qa_call() { |
130 |
__qa_call() { |
131 |
local shopts=$(shopt) OLDIFS="$IFS" |
131 |
local shopts=$(shopt) OLDIFS="$IFS" |
132 |
local retval |
132 |
local retval |
133 |
"$@" |
133 |
__call-ebuildshell "$@" |
134 |
retval=$? |
134 |
retval=$? |
135 |
set +e |
135 |
set +e |
136 |
[[ $shopts != $(shopt) ]] && |
136 |
[[ $shopts != $(shopt) ]] && |
Lines 537-542
if [[ -n ${QA_INTERCEPTORS} ]] ; then
Link Here
|
537 |
unset BIN_PATH BIN BODY FUNC_SRC |
537 |
unset BIN_PATH BIN BODY FUNC_SRC |
538 |
fi |
538 |
fi |
539 |
|
539 |
|
|
|
540 |
__call-ebuildshell() { |
541 |
if ! has ebuildshell ${FEATURES}; then |
542 |
"$@" |
543 |
return $? |
544 |
fi |
545 |
local __ebuildshell_args=( "$@" ) |
546 |
# These are the variables I have seen 'bash -i' maintaining the values for: |
547 |
local __ebuildshell_bash_i_vars="__ebuildshell_.* |
548 |
_ BASH_ARGC BASH_ARGV BASH_COMMAND BASH_LINENO BASH_SOURCE |
549 |
BASH_VERSINFO BASH_SUBSHELL BASHOPTS BASHPID COMP_WORDBREAKS |
550 |
DIRSTACK EUID FUNCNAME GROUPS HISTCMD HISTFILE LINENO PIPESTATUS |
551 |
PPID PS1 PS2 PS3 PS4 PWD RANDOM SECONDS SHELLOPTS UID" |
552 |
# Allow recursive ebuildshell, for use in multibuild.eclass and similar: |
553 |
local __ebuildshell_pid=${BASHPID:-$(__bashpid)} |
554 |
local __ebuildshell_tmpf="${T}/ebuildshell.${__ebuildshell_pid}" |
555 |
rm -f "${__ebuildshell_tmpf}."{ebuild,return}-{env,rovars} |
556 |
( |
557 |
cat <<-EOE |
558 |
# local variables of functions using recursive ebuildshell are |
559 |
# visible to the EXIT trap of that recursive ebuildshell. To |
560 |
# keep them local, we have to filter them from that recursive |
561 |
# ebuildshell's return-env. As 'declare -p' is unable to tell |
562 |
# local-ity of variables, we abuse the trace attribute for local |
563 |
# variables to filter them from the return-env. So we need the |
564 |
# local alias active before declaring any functions. |
565 |
# On a sidehand, this allows for copy&paste of function body |
566 |
# lines including the local keyword. |
567 |
alias local='declare -t' |
568 |
shopt -s expand_aliases |
569 |
EOE |
570 |
( |
571 |
declare -p |
572 |
declare -fp |
573 |
shopt -p |
574 |
[[ ${BASH_VERSINFO[0]} == 3 ]] && export |
575 |
) | |
576 |
( |
577 |
# we need everything but the bash vars after 'env -i' |
578 |
2>"${__ebuildshell_tmpf}.ebuild-rovars" \ |
579 |
"${PORTAGE_PYTHON:-/tools/haubi/gentoo/s01en24/usr/bin/python}" \ |
580 |
"${PORTAGE_BIN_PATH}"/filter-bash-environment.py \ |
581 |
--report-readonly-variables \ |
582 |
--preserve-readonly-attribute \ |
583 |
"${__ebuildshell_bash_i_vars}" \ |
584 |
|| die "filter-bash-environment.py failed" |
585 |
) |
586 |
# 'declare -g' is available since bash-4.2, |
587 |
# https://bugs.gentoo.org/show_bug.cgi?id=155161#c35 |
588 |
if (( ${BASH_VERSINFO[0]} > 4 )) || |
589 |
(( ${BASH_VERSINFO[0]} == 4 && ${BASH_VERSINFO[1]} >= 2 )) |
590 |
then |
591 |
__ebuildshell_bash42_true= |
592 |
__ebuildshell_bash42_false='#bash-4.2#' |
593 |
else |
594 |
__ebuildshell_bash42_true='#bash-4.2#' |
595 |
__ebuildshell_bash42_false= |
596 |
fi |
597 |
# The already readonly variables, without bash maintained ones: |
598 |
__ebuildshell_ro_ebuild_vars=$(<"${__ebuildshell_tmpf}.ebuild-rovars") |
599 |
cat <<-EOE |
600 |
# properly quote the function arguments |
601 |
$(declare -p __ebuildshell_args) |
602 |
set -- "\${__ebuildshell_args[@]}" |
603 |
unset __ebuildshell_args |
604 |
# be informative about what to do |
605 |
PS1="EBUILD ${PN} $1 \$ " |
606 |
type $1 |
607 |
${__ebuildshell_bash42_false}echo 'warning: preserving variables across phases requires bash-4.2' |
608 |
echo "WANTED: \$@" |
609 |
echo "or use: \"\\\$@\"" |
610 |
# use bash history, but not the 'user's real one |
611 |
HISTFILE=~/.bash_history |
612 |
# but do not use history-expansion with '!', |
613 |
# for copy&paste of function body lines containing: ! |
614 |
set +H |
615 |
# this is a debugging shell already |
616 |
shopt -u extdebug |
617 |
trap - DEBUG |
618 |
# at exit, dump the current environment |
619 |
trap " |
620 |
unalias local |
621 |
unset -f __call-ebuildshell |
622 |
rm -f '${__ebuildshell_tmpf}.return-'* |
623 |
( |
624 |
( |
625 |
# declare -p does not tell the -g flag, |
626 |
# so we add it by aliasing declare. |
627 |
${__ebuildshell_bash42_true}echo \"alias declare='declare -g'\" |
628 |
declare -p |
629 |
${__ebuildshell_bash42_true}echo \"unalias declare\" |
630 |
declare -fp |
631 |
shopt -p | grep -v '\\(expand_aliases\\|extdebug\\)$' |
632 |
$([[ ${BASH_VERSINFO[0]} == 3 ]] && echo export) |
633 |
) | |
634 |
( |
635 |
# We may have more readonly variables now, yet we |
636 |
# need to filter variables that were readonly before. |
637 |
# And filter local variables by their trace attribute. |
638 |
2>'${__ebuildshell_tmpf}.return-rovars' \\ |
639 |
'${PORTAGE_PYTHON:-/tools/haubi/gentoo/s01en24/usr/bin/python}' \\ |
640 |
'${PORTAGE_BIN_PATH}'/filter-bash-environment.py \\ |
641 |
--report-readonly-variables \\ |
642 |
--preserve-readonly-attribute \\ |
643 |
--filter-traced-variables \\ |
644 |
'${__ebuildshell_bash_i_vars} \ |
645 |
${__ebuildshell_ro_ebuild_vars}' \\ |
646 |
|| die 'filter-bash-environment.py failed' |
647 |
) |
648 |
) > '${__ebuildshell_tmpf}.return-env' |
649 |
" EXIT |
650 |
# can do some cleanup right now |
651 |
rm -f '${__ebuildshell_tmpf}.ebuild-'* |
652 |
EOE |
653 |
) > "${__ebuildshell_tmpf}.ebuild-env" |
654 |
|
655 |
# pre-fill the history with "$@" |
656 |
echo '"$@"' >> ~/.bash_history |
657 |
|
658 |
env -i ${BASH} --rcfile "${__ebuildshell_tmpf}.ebuild-env" -i |
659 |
|
660 |
# The environment- and exit-status handling after leaving the ebuildshell |
661 |
# prompt is expected to be identical as without the ebuildshell prompt. |
662 |
local __ebuildshell_status=$? |
663 |
|
664 |
# We might be in a recursive ebuildshell, but do not want |
665 |
# any aliases being active while sourcing the return-env. |
666 |
local __ebuildshell_orig_aliases=$(alias) |
667 |
unalias -a |
668 |
source "${__ebuildshell_tmpf}.return-env" |
669 |
unalias -a |
670 |
eval "${__ebuildshell_orig_aliases}" |
671 |
|
672 |
# Portage does whitelist readonly variables. If an ebuild defines |
673 |
# more readonly variables, their readonly attribute is removed. |
674 |
# If we ever want to preserve additional readonly variables across |
675 |
# phases, their names are in "${__ebuildshell_tmpf}.return-rovars". |
676 |
rm -f "${__ebuildshell_tmpf}."{ebuild,return}-{env,rovars} |
677 |
|
678 |
return ${__ebuildshell_status} |
679 |
} |
680 |
|
540 |
# Subshell/helper die support (must export for the die helper). |
681 |
# Subshell/helper die support (must export for the die helper). |
541 |
export EBUILD_MASTER_PID=${BASHPID:-$(__bashpid)} |
682 |
export EBUILD_MASTER_PID=${BASHPID:-$(__bashpid)} |
542 |
trap 'exit 1' SIGTERM |
683 |
trap 'exit 1' SIGTERM |