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

(-)a/bin/isolated-functions.sh (-13 / +66 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-117 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
#   # NB: if this were the last command in your helper function, you
148
#   # should "return 0" here, as $? is always nonzero at this point.
149
#
101
__helpers_die() {
150
__helpers_die() {
102
	if ___eapi_helpers_can_die; then
151
	local retcode=$?
152
	(( retcode == 0 )) && retcode=1
153
154
	if ___eapi_helpers_can_die && [[ "${PORTAGE_NONFATAL:-0}" != 1 ]]; then
103
		die "$@"
155
		die "$@"
104
	else
156
	else
105
		echo -e "$@" >&2
157
		local phase_str=
158
		[[ -n ${EBUILD_PHASE} ]] && phase_str=" (${EBUILD_PHASE} phase)"
159
		ewarn "WARNING: ${CATEGORY}/${PF}${phase_str}:"
160
		ewarn "  ${FUNCNAME}: ${*:-(no error message)}"
161
		ewarn
106
	fi
162
	fi
163
164
	return "${retcode}"
107
}
165
}
108
166
109
die() {
167
die() {
110
	if [[ $PORTAGE_NONFATAL -eq 1 ]]; then
111
		echo -e " $WARN*$NORMAL ${FUNCNAME[1]}: WARNING: $@" >&2
112
		return 1
113
	fi
114
115
	set +e
168
	set +e
116
	if [ -n "${QA_INTERCEPTORS}" ] ; then
169
	if [ -n "${QA_INTERCEPTORS}" ] ; then
117
		# die was called from inside inherit. We need to clean up
170
		# die was called from inside inherit. We need to clean up
(-)a/bin/phase-helpers.sh (-32 / +45 lines)
Lines 278-284 unpack() { Link Here
278
	local y
278
	local y
279
	local myfail
279
	local myfail
280
	local eapi=${EAPI:-0}
280
	local eapi=${EAPI:-0}
281
	[ -z "$*" ] && die "Nothing passed to the 'unpack' command"
281
	[ -z "$*" ] && { __helpers_die "Nothing passed to the 'unpack' command" ; return 1 ; }
282
282
283
	for x in "$@"; do
283
	for x in "$@"; do
284
		__vecho ">>> Unpacking ${x} to ${PWD}"
284
		__vecho ">>> Unpacking ${x} to ${PWD}"
Lines 288-352 unpack() { Link Here
288
		if [[ ${x} == "./"* ]] ; then
288
		if [[ ${x} == "./"* ]] ; then
289
			srcdir=""
289
			srcdir=""
290
		elif [[ ${x} == ${DISTDIR%/}/* ]] ; then
290
		elif [[ ${x} == ${DISTDIR%/}/* ]] ; then
291
			die "Arguments to unpack() cannot begin with \${DISTDIR}."
291
			__helpers_die "Arguments to unpack() cannot begin with \${DISTDIR}."
292
			return 1
292
		elif [[ ${x} == "/"* ]] ; then
293
		elif [[ ${x} == "/"* ]] ; then
293
			die "Arguments to unpack() cannot be absolute"
294
			__helpers_die "Arguments to unpack() cannot be absolute"
295
			return 1
294
		else
296
		else
295
			srcdir="${DISTDIR}/"
297
			srcdir="${DISTDIR}/"
296
		fi
298
		fi
297
		[[ ! -s ${srcdir}${x} ]] && die "${x} does not exist"
299
		[[ -s ${srcdir}${x} ]] || __helpers_die "${x} does not exist" || return 1
298
300
299
		__unpack_tar() {
301
		__unpack_tar() {
300
			if [ "${y}" == "tar" ]; then
302
			if [ "${y}" == "tar" ]; then
301
				$1 -c -- "$srcdir$x" | tar xof -
303
				$1 -c -- "$srcdir$x" | tar xof -
302
				__assert_sigpipe_ok "$myfail"
304
				__helpers_assert_sigpipe_ok "$myfail" || return $?
303
			else
305
			else
304
				local cwd_dest=${x##*/}
306
				local cwd_dest=${x##*/}
305
				cwd_dest=${cwd_dest%.*}
307
				cwd_dest=${cwd_dest%.*}
306
				$1 -c -- "${srcdir}${x}" > "${cwd_dest}" || die "$myfail"
308
				$1 -c -- "${srcdir}${x}" > "${cwd_dest}" || \
309
					__helpers_die "$myfail" || return $?
307
			fi
310
			fi
308
		}
311
		}
309
312
310
		myfail="failure unpacking ${x}"
313
		myfail="failure unpacking ${x}"
311
		case "${x##*.}" in
314
		case "${x##*.}" in
312
			tar)
315
			tar)
313
				tar xof "$srcdir$x" || die "$myfail"
316
				tar xof "$srcdir$x" || __helpers_die "$myfail" || return $?
314
				;;
317
				;;
315
			tgz)
318
			tgz)
316
				tar xozf "$srcdir$x" || die "$myfail"
319
				tar xozf "$srcdir$x" || __helpers_die "$myfail" || return $?
317
				;;
320
				;;
318
			tbz|tbz2)
321
			tbz|tbz2)
319
				${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- "$srcdir$x" | tar xof -
322
				${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- "$srcdir$x" | tar xof -
320
				__assert_sigpipe_ok "$myfail"
323
				__helpers_assert_sigpipe_ok "$myfail" || return $?
321
				;;
324
				;;
322
			ZIP|zip|jar)
325
			ZIP|zip|jar)
323
				# unzip will interactively prompt under some error conditions,
326
				# unzip will interactively prompt under some error conditions,
324
				# as reported in bug #336285
327
				# as reported in bug #336285
325
				( set +x ; while true ; do echo n || break ; done ) | \
328
				( set +x ; while true ; do echo n || break ; done ) | \
326
				unzip -qo "${srcdir}${x}" || die "$myfail"
329
				unzip -qo "${srcdir}${x}"
330
				__helpers_assert_sigpipe_ok "$myfail" || return $?
327
				;;
331
				;;
328
			gz|Z|z)
332
			gz|Z|z)
329
				__unpack_tar "gzip -d"
333
				__unpack_tar "gzip -d" || return $?
330
				;;
334
				;;
331
			bz2|bz)
335
			bz2|bz)
332
				__unpack_tar "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}"
336
				__unpack_tar "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}" || \
337
					return $?
333
				;;
338
				;;
334
			7Z|7z)
339
			7Z|7z)
335
				local my_output
340
				local my_output
336
				my_output="$(7z x -y "${srcdir}${x}")"
341
				my_output="$(7z x -y "${srcdir}${x}")"
337
				if [ $? -ne 0 ]; then
342
				if [ $? -ne 0 ]; then
338
					echo "${my_output}" >&2
343
					echo "${my_output}" >&2
339
					die "$myfail"
344
					__helpers_die "${myfail}" || return $?
340
				fi
345
				fi
341
				;;
346
				;;
342
			RAR|rar)
347
			RAR|rar)
343
				unrar x -idq -o+ "${srcdir}${x}" || die "$myfail"
348
				unrar x -idq -o+ "${srcdir}${x}" || \
349
					__helpers_die "${myfail}" || return $?
344
				;;
350
				;;
345
			LHa|LHA|lha|lzh)
351
			LHa|LHA|lha|lzh)
346
				lha xfq "${srcdir}${x}" || die "$myfail"
352
				lha xfq "${srcdir}${x}" || \
353
					__helpers_die "${myfail}" || return $?
347
				;;
354
				;;
348
			a)
355
			a)
349
				ar x "${srcdir}${x}" || die "$myfail"
356
				ar x "${srcdir}${x}" || \
357
					__helpers_die "${myfail}" || return $?
350
				;;
358
				;;
351
			deb)
359
			deb)
352
				# Unpacking .deb archives can not always be done with
360
				# Unpacking .deb archives can not always be done with
Lines 356-386 unpack() { Link Here
356
				# installed.
364
				# installed.
357
				if type -P deb2targz > /dev/null; then
365
				if type -P deb2targz > /dev/null; then
358
					y=${x##*/}
366
					y=${x##*/}
359
					local created_symlink=0
367
					if [ ! "${srcdir}${x}" -ef "${y}" ] ; then
360
					if [ ! "$srcdir$x" -ef "$y" ] ; then
361
						# deb2targz always extracts into the same directory as
368
						# deb2targz always extracts into the same directory as
362
						# the source file, so create a symlink in the current
369
						# the source file, so create a symlink in the current
363
						# working directory if necessary.
370
						# working directory if necessary.
364
						ln -sf "$srcdir$x" "$y" || die "$myfail"
371
						ln -sf "${srcdir}${x}" "${y}" || \
365
						created_symlink=1
372
							__helpers_die "${myfail}" || return $?
366
					fi
373
						deb2targz "${y}" || \
367
					deb2targz "$y" || die "$myfail"
374
							__helpers_die "${myfail}" || return $?
368
					if [ $created_symlink = 1 ] ; then
369
						# Clean up the symlink so the ebuild
375
						# Clean up the symlink so the ebuild
370
						# doesn't inadvertently install it.
376
						# doesn't inadvertently install it.
371
						rm -f "$y"
377
						rm -f "${y}" || \
378
							__helpers_die "${myfail}" || return $?
379
					else
380
						deb2targz "${y}" || \
381
							__helpers_die "${myfail}" || return $?
372
					fi
382
					fi
373
					mv -f "${y%.deb}".tar.gz data.tar.gz || die "$myfail"
383
					mv -f "${y%.deb}".tar.gz data.tar.gz || \
384
						__helpers_die "${myfail}" || return $?
374
				else
385
				else
375
					ar x "$srcdir$x" || die "$myfail"
386
					ar x "${srcdir}${x}" \
387
						|| __helpers_die "${myfail}" || return $?
376
				fi
388
				fi
377
				;;
389
				;;
378
			lzma)
390
			lzma)
379
				__unpack_tar "lzma -d"
391
				__unpack_tar "lzma -d" || return $?
380
				;;
392
				;;
381
			xz)
393
			xz)
382
				if ___eapi_unpack_supports_xz; then
394
				if ___eapi_unpack_supports_xz; then
383
					__unpack_tar "xz -d"
395
					__unpack_tar "xz -d" || return $?
384
				else
396
				else
385
					__vecho "unpack ${x}: file format not recognized. Ignoring."
397
					__vecho "unpack ${x}: file format not recognized. Ignoring."
386
				fi
398
				fi
Lines 392-399 unpack() { Link Here
392
	done
404
	done
393
	# Do not chmod '.' since it's probably ${WORKDIR} and PORTAGE_WORKDIR_MODE
405
	# Do not chmod '.' since it's probably ${WORKDIR} and PORTAGE_WORKDIR_MODE
394
	# should be preserved.
406
	# should be preserved.
395
	find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \
407
	find . -mindepth 1 -maxdepth 1 ! -type l -execdir chmod -fR a+rX,u+w,g-w,o-w '{}' + || \
396
		${XARGS} -0 chmod -fR a+rX,u+w,g-w,o-w
408
		__helpers_die "${myfail}" || return $?
397
}
409
}
398
410
399
econf() {
411
econf() {
Lines 404-410 econf() { Link Here
404
	fi
416
	fi
405
417
406
	__hasg() {
418
	__hasg() {
407
		local x s=$1
419
		local x s="$1"
408
		shift
420
		shift
409
		for x ; do [[ ${x} == ${s} ]] && echo "${x}" && return 0 ; done
421
		for x ; do [[ ${x} == ${s} ]] && echo "${x}" && return 0 ; done
410
		return 1
422
		return 1
Lines 430-436 econf() { Link Here
430
		if [[ -n $CONFIG_SHELL && \
442
		if [[ -n $CONFIG_SHELL && \
431
			"$(head -n1 "$ECONF_SOURCE/configure")" =~ ^'#!'[[:space:]]*/bin/sh([[:space:]]|$) ]] ; then
443
			"$(head -n1 "$ECONF_SOURCE/configure")" =~ ^'#!'[[:space:]]*/bin/sh([[:space:]]|$) ]] ; then
432
			sed -e "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" -i "$ECONF_SOURCE/configure" || \
444
			sed -e "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" -i "$ECONF_SOURCE/configure" || \
433
				die "Substition of shebang in '$ECONF_SOURCE/configure' failed"
445
				__helpers_die "Substition of shebang in '$ECONF_SOURCE/configure' failed" || \
446
					return $?
434
		fi
447
		fi
435
		if [ -e "${EPREFIX}"/usr/share/gnuconfig/ ]; then
448
		if [ -e "${EPREFIX}"/usr/share/gnuconfig/ ]; then
436
			find "${WORKDIR}" -type f '(' \
449
			find "${WORKDIR}" -type f '(' \
(-)a/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 \
(-)a/doc/package/ebuild/eapi/4.docbook (-3 / +8 lines)
Lines 11-19 The dohard and dosed helpers from previous EAPIs are no longer available. 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