summaryrefslogtreecommitdiff
blob: 9ccc1e5b186954da4e927dd2ba225ee8faec4dd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# HG changeset patch
# User Michael Haubenwallner <haubi@gentoo.org>
# Date 1330634734 -3600
# Node ID 6780ee2ddb337bbd8b4b2681615de7e78e6fb8c1
# Parent  04da3d4d44af4fd2096316f8e1bbb7a998011040
https://bugs.gentoo.org/155161

FEATURES=ebuildshell emerge xxxxx

results in an interactive shell for each function portage calls from the
ebuild, where all functionality is available as in the ebuild
(src_unpack, epatch, etc.).  This allows for convenient debugging of
ebuild issues.

diff -r 04da3d4d44af -r 6780ee2ddb33 bin/ebuild.sh
--- a/bin/ebuild.sh	Thu Mar 01 21:31:12 2012 +0100
+++ b/bin/ebuild.sh	Thu Mar 01 21:45:34 2012 +0100
@@ -82,7 +82,7 @@
 qa_call() {
 	local shopts=$(shopt) OLDIFS="$IFS"
 	local retval
-	"$@"
+	call-ebuildshell "$@"
 	retval=$?
 	set +e
 	[[ $shopts != $(shopt) ]] &&
@@ -453,6 +453,56 @@
 	unset BIN_PATH BIN BODY FUNC_SRC
 fi
 
+call-ebuildshell() {
+	if ! has ebuildshell ${FEATURES}; then
+		"$@"
+		return $?
+	fi
+	(
+		umask 002
+		(
+			(
+				set
+				declare -p
+				declare -fp
+				shopt -p
+				if [[ ${BASH_VERSINFO[0]} == 3 ]]; then
+					export
+				fi
+			) | filter_readonly_variables --filter-for-subshell
+			echo 'declare -r $PORTAGE_READONLY_METADATA $PORTAGE_READONLY_VARS'
+			echo "export PS1='EBUILD ${PN} $1 \$ '" 
+			echo 'unset ENV'
+			echo "type $1"
+			echo "echo WANTED: $@"
+			echo "trap '"
+			echo "umask 002"
+			echo "("
+			echo "	set"
+			echo "	declare -p"
+			echo "	declare -fp"
+			echo "	shopt -p"
+			if [[ ${BASH_VERSINFO[0]} == 3 ]]; then
+				echo "	export"
+			fi
+			echo -n ")"
+			echo -n " | filter_readonly_variables --filter-metadata"
+			echo " > ${T}/ebuildshell-environment-outcome' 0"
+		) > ${T}/ebuildshell-environment
+		chown ${PORTAGE_USER:-portage}:${PORTAGE_GROUP:-portage} "${T}/ebuildshell-environment" &>/dev/null
+		chmod g+w "${T}/ebuildshell-environment" &>/dev/null
+	)
+
+	rm -f "${T}/ebuildshell-environment-outcome" >&/dev/null
+
+	unset BASH_ENV
+	env -i ${BASH} --rcfile "${T}/ebuildshell-environment"  -i || die
+
+	chown ${PORTAGE_USER:-portage}:${PORTAGE_GROUP:-portage} "${T}/ebuildshell-environment-outcome" &>/dev/null
+	chmod g+w "${T}/ebuildshell-environment-outcome" &>/dev/null
+	source "${T}/ebuildshell-environment-outcome" &>/dev/null
+}
+
 # Subshell/helper die support (must export for the die helper).
 export EBUILD_MASTER_PID=$BASHPID
 trap 'exit 1' SIGTERM
diff -r 04da3d4d44af -r 6780ee2ddb33 bin/phase-functions.sh
--- a/bin/phase-functions.sh	Thu Mar 01 21:31:12 2012 +0100
+++ b/bin/phase-functions.sh	Thu Mar 01 21:45:34 2012 +0100
@@ -84,7 +84,7 @@
 filter_readonly_variables() {
 	local x filtered_vars
 	local readonly_bash_vars="BASHOPTS BASHPID DIRSTACK EUID
-		FUNCNAME GROUPS PIPESTATUS PPID SHELLOPTS UID"
+		FUNCNAME GROUPS PIPESTATUS PPID SHELLOPTS UID BASH_VERSINFO"
 	local bash_misc_vars="BASH BASH_.* COLUMNS COMP_WORDBREAKS HISTCMD
 		HISTFILE HOSTNAME HOSTTYPE IFS LINENO MACHTYPE OLDPWD
 		OPTERR OPTIND OSTYPE POSIXLY_CORRECT PS4 PWD RANDOM
@@ -95,8 +95,10 @@
 	# Untrusted due to possible application of package renames to binpkgs
 	local binpkg_untrusted_vars="CATEGORY P PF PN PR PV PVR"
 	local misc_garbage_vars="_portage_filter_opts"
-	filtered_vars="$readonly_bash_vars $bash_misc_vars
-		$PORTAGE_READONLY_VARS $misc_garbage_vars"
+	filtered_vars="$readonly_bash_vars"
+	if ! has --filter-for-subshell $* ; then
+		filtered_vars="$filtered_vars $bash_misc_vars $PORTAGE_READONLY_VARS $misc_garbage_vars"
+	fi
 
 	# Don't filter/interfere with prefix variables unless they are
 	# supported by the current EAPI.
@@ -126,7 +128,11 @@
 			LC_CTYPE LC_MESSAGES LC_MONETARY
 			LC_NUMERIC LC_PAPER LC_TIME"
 	fi
-	if ! has --allow-extra-vars $* ; then
+	if has --filter-metadata $* ; then
+		filtered_vars="$filtered_vars $PORTAGE_READONLY_METADATA"
+	fi
+	if ! has --allow-extra-vars $* &&
+	   ! has --filter-for-subshell $* ; then
 		if [ "${EMERGE_FROM}" = binary ] ; then
 			# preserve additional variables from build time,
 			# while excluding untrusted variables
diff -r 04da3d4d44af -r 6780ee2ddb33 man/make.conf.5
--- a/man/make.conf.5	Thu Mar 01 21:31:12 2012 +0100
+++ b/man/make.conf.5	Thu Mar 01 21:45:34 2012 +0100
@@ -297,6 +297,12 @@
 Use locks to ensure that unsandboxed ebuild phases never execute
 concurrently. Also see \fIparallel\-install\fR.
 .TP
+.B ebuildshell
+Drop into an interactive shell for each phase function, meant for
+debugging.  Because the shell would normally be used to execute the
+phase function, commands like src_unpack or epatch are available in the
+interactive shell.  Use `exit 1` to terminate the merge.
+.TP
 .B fakeroot
 Enable fakeroot for the install and package phases when a non-root user runs
 the \fBebuild\fR(1) command.
diff -r 04da3d4d44af -r 6780ee2ddb33 pym/_emerge/AbstractEbuildProcess.py
--- a/pym/_emerge/AbstractEbuildProcess.py	Thu Mar 01 21:31:12 2012 +0100
+++ b/pym/_emerge/AbstractEbuildProcess.py	Thu Mar 01 21:45:34 2012 +0100
@@ -97,6 +97,7 @@
 			self.fd_pipes = {}
 		null_fd = None
 		if 0 not in self.fd_pipes and \
+			"ebuildshell" not in self.settings.features and \
 			self.phase not in self._phases_interactive_whitelist and \
 			"interactive" not in self.settings.get("PROPERTIES", "").split():
 			null_fd = os.open('/dev/null', os.O_RDONLY)