Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 439356 | Differences between
and this patch

Collapse All | Expand All

(-)portage-2.2.0_alpha150.orig/bin/isolated-functions.sh (-13 / +67 lines)
Lines 17-23 assert() { Link Here
17
	done
17
	done
18
}
18
}
19
19
20
__assert_sigpipe_ok() {
20
__helpers_assert_sigpipe_ok() {
21
	# When extracting a tar file like this:
21
	# When extracting a tar file like this:
22
	#
22
	#
23
	#     bzip2 -dc foo.tar.bz2 | tar xof -
23
	#     bzip2 -dc foo.tar.bz2 | tar xof -
Lines 32-46 __assert_sigpipe_ok() { Link Here
32
	# which says, "When a command terminates on a fatal
32
	# which says, "When a command terminates on a fatal
33
	# signal whose number is N, Bash uses the value 128+N
33
	# signal whose number is N, Bash uses the value 128+N
34
	# as the exit status."
34
	# as the exit status."
35
36
	local x pipestatus=${PIPESTATUS[*]}
35
	local x pipestatus=${PIPESTATUS[*]}
37
	for x in $pipestatus ; do
36
	for x in ${pipestatus} ; do
38
		# Allow SIGPIPE through (128 + 13)
37
		# Allow SIGPIPE through (128 + 13)
39
		[[ $x -ne 0 && $x -ne ${PORTAGE_SIGPIPE_STATUS:-141} ]] && die "$@"
38
		if [[ ${x} -ne 0 && ${x} -ne ${PORTAGE_SIGPIPE_STATUS:-141} ]] ; then
39
			__helpers_die "${FUNCNAME}: error ${x}: $*"
40
			return ${x}
41
		fi
40
	done
42
	done
41
43
42
	# Require normal success for the last process (tar).
44
	# Require normal success for the last process (tar).
43
	[[ $x -eq 0 ]] || die "$@"
45
	[[ ${x} -eq 0 ]] || __helpers_die "${FUNCNAME}: error ${x}: $*" || return ${x}
46
47
	return 0
44
}
48
}
45
49
46
shopt -s extdebug
50
shopt -s extdebug
Lines 92-119 nonfatal() { Link Here
92
		die "$FUNCNAME() not supported in this EAPI"
96
		die "$FUNCNAME() not supported in this EAPI"
93
	fi
97
	fi
94
	if [[ $# -lt 1 ]]; then
98
	if [[ $# -lt 1 ]]; then
95
		die "$FUNCNAME(): Missing argument"
99
		# Well they said nonfatal and forgot to finish their sentence.
100
		# Something ain't right, to be sure, but die()ing here seems a bit
101
		# pendantic and mean-spirited :)
102
		local phase_str=
103
		[[ -n ${EBUILD_PHASE} ]] && phase_str=" (${EBUILD_PHASE} phase)"
104
		eerror "ERROR: ${CATEGORY}/${PF}${phase_str}:"
105
		eerror "  ${FUNCNAME}: Missing argument"
106
		eerror
107
		return 1
96
	fi
108
	fi
97
109
98
	PORTAGE_NONFATAL=1 "$@"
110
	PORTAGE_NONFATAL=1 "$@"
99
}
111
}
100
112
113
# Memorizing the return-code at the beginning of __helpers_die()
114
# and returning it unchanged (unless it's 0) is intended as a
115
# courtesy to invokers who may use a bash sequence like:
116
#
117
#   failure_prone_action || \
118
#       __helpers_die "${FUNCNAME}: descriptive error message" || \
119
#           return $?
120
#
121
# as syntactic sugar for the following equivalent code:
122
#
123
#   failure_prone_action
124
#   ret=$?
125
#   if [[ ${ret} -ne 0 ]] ; then
126
#       __helpers_die "${FUNCNAME}: descriptive error message"
127
#       return ${ret}
128
#   fi
129
#
130
# However, beware: this trick will not work for positive
131
# conditionals because __helpers_die always returns a nonzero
132
# failure code (if it returns at all).  Neither
133
#
134
#   action_intended_to_fail && __helpers_die msg && return $?
135
#
136
# nor
137
#
138
#   action_intended_to_fail && __helpers_die msg || return $?
139
#
140
# will work as intended.  The following would be a clean, correct
141
# way to trigger __helpers_die() from a positive conditional:
142
#
143
#   action_intended_to_fail && {
144
#       __helpers_die "${FUNCNAME}: descriptive error message"
145
#       return 1
146
#   }
147
#
148
#   # NB: if this were the last command in your helper function, you
149
#   # should "return 0" here, as $? is always nonzero at this point.
150
#
101
__helpers_die() {
151
__helpers_die() {
102
	if ___eapi_helpers_can_die; then
152
	local retcode=$?
153
	(( retcode == 0 )) && retcode=1
154
155
	if ___eapi_helpers_can_die && [[ "${PORTAGE_NONFATAL:-0}" != 1 ]]; then
103
		die "$@"
156
		die "$@"
104
	else
157
	else
105
		echo -e "$@" >&2
158
		local phase_str=
159
		[[ -n ${EBUILD_PHASE} ]] && phase_str=" (${EBUILD_PHASE} phase)"
160
		ewarn "WARNING: ${CATEGORY}/${PF}${phase_str}:"
161
		ewarn "  ${FUNCNAME}: ${*:-(no error message)}"
162
		ewarn
106
	fi
163
	fi
164
165
	return "${retcode}"
107
}
166
}
108
167
109
die() {
168
die() {
110
	local IFS=$' \t\n'
169
	local IFS=$' \t\n'
111
170
112
	if [[ $PORTAGE_NONFATAL -eq 1 ]]; then
113
		echo -e " $WARN*$NORMAL ${FUNCNAME[1]}: WARNING: $@" >&2
114
		return 1
115
	fi
116
117
	set +e
171
	set +e
118
	if [ -n "${QA_INTERCEPTORS}" ] ; then
172
	if [ -n "${QA_INTERCEPTORS}" ] ; then
119
		# die was called from inside inherit. We need to clean up
173
		# die was called from inside inherit. We need to clean up
(-)portage-2.2.0_alpha150.orig/bin/phase-helpers.sh (-32 / +44 lines)
Lines 285-291 unpack() { Link Here
285
	local suffix
285
	local suffix
286
	local myfail
286
	local myfail
287
	local eapi=${EAPI:-0}
287
	local eapi=${EAPI:-0}
288
	[ -z "$*" ] && die "Nothing passed to the 'unpack' command"
288
	[ -z "$*" ] && { __helpers_die "Nothing passed to the 'unpack' command" ; return 1 ; }
289
289
290
	for x in "$@"; do
290
	for x in "$@"; do
291
		__vecho ">>> Unpacking ${x} to ${PWD}"
291
		__vecho ">>> Unpacking ${x} to ${PWD}"
Lines 298-362 unpack() { Link Here
298
		if [[ ${x} == "./"* ]] ; then
298
		if [[ ${x} == "./"* ]] ; then
299
			srcdir=""
299
			srcdir=""
300
		elif [[ ${x} == ${DISTDIR%/}/* ]] ; then
300
		elif [[ ${x} == ${DISTDIR%/}/* ]] ; then
301
			die "Arguments to unpack() cannot begin with \${DISTDIR}."
301
			__helpers_die "Arguments to unpack() cannot begin with \${DISTDIR}."
302
			return 1
302
		elif [[ ${x} == "/"* ]] ; then
303
		elif [[ ${x} == "/"* ]] ; then
303
			die "Arguments to unpack() cannot be absolute"
304
			__helpers_die "Arguments to unpack() cannot be absolute"
305
			return 1
304
		else
306
		else
305
			srcdir="${DISTDIR}/"
307
			srcdir="${DISTDIR}/"
306
		fi
308
		fi
307
		[[ ! -s ${srcdir}${x} ]] && die "${x} does not exist"
309
		[[ -s ${srcdir}${x} ]] || __helpers_die "${x} does not exist" || return 1
308
310
309
		__unpack_tar() {
311
		__unpack_tar() {
310
			if [ "${y}" == "tar" ]; then
312
			if [ "${y}" == "tar" ]; then
311
				$1 -c -- "$srcdir$x" | tar xof -
313
				$1 -c -- "$srcdir$x" | tar xof -
312
				__assert_sigpipe_ok "$myfail"
314
				__helpers_assert_sigpipe_ok "$myfail" || return $?
313
			else
315
			else
314
				local cwd_dest=${x##*/}
316
				local cwd_dest=${x##*/}
315
				cwd_dest=${cwd_dest%.*}
317
				cwd_dest=${cwd_dest%.*}
316
				$1 -c -- "${srcdir}${x}" > "${cwd_dest}" || die "$myfail"
318
				$1 -c -- "${srcdir}${x}" > "${cwd_dest}" || \
319
					__helpers_die "$myfail" || return $?
317
			fi
320
			fi
318
		}
321
		}
319
322
320
		myfail="failure unpacking ${x}"
323
		myfail="failure unpacking ${x}"
321
		case "${suffix}" in
324
		case "${suffix}" in
322
			tar)
325
			tar)
323
				tar xof "$srcdir$x" || die "$myfail"
326
				tar xof "$srcdir$x" || __helpers_die "$myfail" || return $?
324
				;;
327
				;;
325
			tgz)
328
			tgz)
326
				tar xozf "$srcdir$x" || die "$myfail"
329
				tar xozf "$srcdir$x" || __helpers_die "$myfail" || return $?
327
				;;
330
				;;
328
			tbz|tbz2)
331
			tbz|tbz2)
329
				${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- "$srcdir$x" | tar xof -
332
				${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- "$srcdir$x" | tar xof -
330
				__assert_sigpipe_ok "$myfail"
333
				__helpers_assert_sigpipe_ok "$myfail" || return $?
331
				;;
334
				;;
332
			zip|jar)
335
			zip|jar)
333
				# unzip will interactively prompt under some error conditions,
336
				# unzip will interactively prompt under some error conditions,
334
				# as reported in bug #336285
337
				# as reported in bug #336285
335
				( set +x ; while true ; do echo n || break ; done ) | \
338
				( set +x ; while true ; do echo n || break ; done ) | \
336
				unzip -qo "${srcdir}${x}" || die "$myfail"
339
					unzip -qo "${srcdir}${x}" || \
340
						{ __helpers_die "$myfail" || return 1 ; }
337
				;;
341
				;;
338
			gz|z)
342
			gz|z)
339
				__unpack_tar "gzip -d"
343
				__unpack_tar "gzip -d" || return $?
340
				;;
344
				;;
341
			bz2|bz)
345
			bz2|bz)
342
				__unpack_tar "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}"
346
				__unpack_tar "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}" || \
347
					return $?
343
				;;
348
				;;
344
			7z)
349
			7z)
345
				local my_output
350
				local my_output
346
				my_output="$(7z x -y "${srcdir}${x}")"
351
				my_output="$(7z x -y "${srcdir}${x}")"
347
				if [ $? -ne 0 ]; then
352
				if [ $? -ne 0 ]; then
353
					local my_result=$?
348
					echo "${my_output}" >&2
354
					echo "${my_output}" >&2
349
					die "$myfail"
355
					__helpers_die "$myfail"
356
					return ${my_result}
350
				fi
357
				fi
351
				;;
358
				;;
352
			rar)
359
			rar)
353
				unrar x -idq -o+ "${srcdir}${x}" || die "$myfail"
360
				unrar x -idq -o+ "${srcdir}${x}" || __helpers_die "$myfail" || return $?
354
				;;
361
				;;
355
			lha|lzh)
362
			lha|lzh)
356
				lha xfq "${srcdir}${x}" || die "$myfail"
363
				lha xfq "${srcdir}${x}" || __helpers_die "$myfail" || return $?
357
				;;
364
				;;
358
			a)
365
			a)
359
				ar x "${srcdir}${x}" || die "$myfail"
366
				ar x "${srcdir}${x}" || __helpers_die "$myfail" || return $?
360
				;;
367
				;;
361
			deb)
368
			deb)
362
				# Unpacking .deb archives can not always be done with
369
				# Unpacking .deb archives can not always be done with
Lines 366-396 unpack() { Link Here
366
				# installed.
373
				# installed.
367
				if type -P deb2targz > /dev/null; then
374
				if type -P deb2targz > /dev/null; then
368
					y=${x##*/}
375
					y=${x##*/}
369
					local created_symlink=0
376
					if [ ! "${srcdir}${x}" -ef "${y}" ] ; then
370
					if [ ! "$srcdir$x" -ef "$y" ] ; then
371
						# deb2targz always extracts into the same directory as
377
						# deb2targz always extracts into the same directory as
372
						# the source file, so create a symlink in the current
378
						# the source file, so create a symlink in the current
373
						# working directory if necessary.
379
						# working directory if necessary.
374
						ln -sf "$srcdir$x" "$y" || die "$myfail"
380
						ln -sf "${srcdir}${x}" "${y}" || \
375
						created_symlink=1
381
							__helpers_die "${myfail}" || return $?
376
					fi
382
						deb2targz "${y}" || \
377
					deb2targz "$y" || die "$myfail"
383
							__helpers_die "${myfail}" || return $?
378
					if [ $created_symlink = 1 ] ; then
379
						# Clean up the symlink so the ebuild
384
						# Clean up the symlink so the ebuild
380
						# doesn't inadvertently install it.
385
						# doesn't inadvertently install it.
381
						rm -f "$y"
386
						rm -f "${y}" || \
387
							__helpers_die "${myfail}" || return $?
388
					else
389
						deb2targz "${y}" || \
390
							__helpers_die "${myfail}" || return $?
382
					fi
391
					fi
383
					mv -f "${y%.deb}".tar.gz data.tar.gz || die "$myfail"
392
					mv -f "${y%.deb}".tar.gz data.tar.gz || \
393
						__helpers_die "${myfail}" || return $?
384
				else
394
				else
385
					ar x "$srcdir$x" || die "$myfail"
395
					ar x "${srcdir}${x}" \
396
						|| __helpers_die "${myfail}" || return $?
386
				fi
397
				fi
387
				;;
398
				;;
388
			lzma)
399
			lzma)
389
				__unpack_tar "lzma -d"
400
				__unpack_tar "lzma -d" || return $?
390
				;;
401
				;;
391
			xz)
402
			xz)
392
				if ___eapi_unpack_supports_xz; then
403
				if ___eapi_unpack_supports_xz; then
393
					__unpack_tar "xz -d"
404
					__unpack_tar "xz -d" || return $?
394
				else
405
				else
395
					__vecho "unpack ${x}: file format not recognized. Ignoring."
406
					__vecho "unpack ${x}: file format not recognized. Ignoring."
396
				fi
407
				fi
Lines 402-409 unpack() { Link Here
402
	done
413
	done
403
	# Do not chmod '.' since it's probably ${WORKDIR} and PORTAGE_WORKDIR_MODE
414
	# Do not chmod '.' since it's probably ${WORKDIR} and PORTAGE_WORKDIR_MODE
404
	# should be preserved.
415
	# should be preserved.
405
	find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \
416
	find . -mindepth 1 -maxdepth 1 ! -type l -execdir chmod -fR a+rX,u+w,g-w,o-w '{}' + || \
406
		${XARGS} -0 chmod -fR a+rX,u+w,g-w,o-w
417
		__helpers_die "${myfail}" || return $?
407
}
418
}
408
419
409
econf() {
420
econf() {
Lines 414-420 econf() { Link Here
414
	fi
425
	fi
415
426
416
	__hasg() {
427
	__hasg() {
417
		local x s=$1
428
		local x s="$1"
418
		shift
429
		shift
419
		for x ; do [[ ${x} == ${s} ]] && echo "${x}" && return 0 ; done
430
		for x ; do [[ ${x} == ${s} ]] && echo "${x}" && return 0 ; done
420
		return 1
431
		return 1
Lines 440-446 econf() { Link Here
440
		if [[ -n $CONFIG_SHELL && \
451
		if [[ -n $CONFIG_SHELL && \
441
			"$(head -n1 "$ECONF_SOURCE/configure")" =~ ^'#!'[[:space:]]*/bin/sh([[:space:]]|$) ]] ; then
452
			"$(head -n1 "$ECONF_SOURCE/configure")" =~ ^'#!'[[:space:]]*/bin/sh([[:space:]]|$) ]] ; then
442
			sed -e "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" -i "$ECONF_SOURCE/configure" || \
453
			sed -e "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" -i "$ECONF_SOURCE/configure" || \
443
				die "Substition of shebang in '$ECONF_SOURCE/configure' failed"
454
				__helpers_die "Substition of shebang in '$ECONF_SOURCE/configure' failed" || \
455
					return $?
444
		fi
456
		fi
445
		if [ -e "${EPREFIX}"/usr/share/gnuconfig/ ]; then
457
		if [ -e "${EPREFIX}"/usr/share/gnuconfig/ ]; then
446
			find "${WORKDIR}" -type f '(' \
458
			find "${WORKDIR}" -type f '(' \
(-)portage-2.2.0_alpha150.orig/bin/save-ebuild-env.sh (-1 / +1 lines)
Lines 46-52 __save_ebuild_env() { Link Here
46
	done
46
	done
47
	unset x
47
	unset x
48
48
49
	unset -f assert __assert_sigpipe_ok \
49
	unset -f assert __helpers_assert_sigpipe_ok \
50
		__dump_trace die \
50
		__dump_trace die \
51
		__quiet_mode __vecho __elog_base eqawarn elog \
51
		__quiet_mode __vecho __elog_base eqawarn elog \
52
		einfo einfon ewarn eerror ebegin __eend eend KV_major \
52
		einfo einfon ewarn eerror ebegin __eend eend KV_major \
(-)portage-2.2.0_alpha150.orig/doc/package/ebuild/eapi/4.docbook (-3 / +8 lines)
Lines 11-19 The dohard and dosed helpers from previo Link Here
11
<section id='package-ebuild-eapi-4-helpers-die-nonfatal'>
11
<section id='package-ebuild-eapi-4-helpers-die-nonfatal'>
12
<title>All helpers die on failure</title>
12
<title>All helpers die on failure</title>
13
<para>
13
<para>
14
All helpers now die automatically whenever some sort of error occurs.
14
All helpers now die automatically whenever any meaningful error occurs.
15
Helper calls may be prefixed with the 'nonfatal' helper in order
15
The 'nonfatal' helper may be used to effect the error-handling behavior
16
to prevent errors from being fatal.
16
of EAPIs 0-3, in which recoverable errors emit a warning and return
17
nonzero exit-codes to invokees.  It is used by prepending 'nonfatal' to any helper
18
invocation; for example, by replacing 'dodoc /foo.txt' with 'nonfatal dodoc /foo.txt'.
19
The 'nonfatal' helper should not be applied to
20
statements other than helper invocations, and has no effect on the 'die'
21
and 'assert' helpers.
17
</para>
22
</para>
18
</section>
23
</section>
19
<section id='package-ebuild-eapi-4-helpers-docompress'>
24
<section id='package-ebuild-eapi-4-helpers-docompress'>

Return to bug 439356