public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] RFC: Update to elisp-common.eclass
@ 2014-05-18 18:13 Ulrich Mueller
  2014-05-19  0:08 ` Jeroen Roovers
  2014-05-19 10:28 ` Alex Xu
  0 siblings, 2 replies; 6+ messages in thread
From: Ulrich Mueller @ 2014-05-18 18:13 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 3829 bytes --]

The patch below will introduce two changes to function
elisp-site-regen (which is called in postinst and postrm phases):

1. Site-init files of Elisp packages will only be looked for in
   the site-gentoo.d subdirectory, but no longer in the main
   /usr/share/emacs/site-lisp dir. The elisp-site-file-install
   function installs them in the former location since 2007.

   I am not aware of any ebuild that would still install its site-init
   file in the top-level site-lisp dir (bypassing the proper eclass
   function). Also emacs-updater warns about this since a long time.
   However, if your ebuild does this, now is the time for changing it.

2. Some additional error checks added. Since callers usually don't
   test for the function's return status, die on errors, instead of
   returning bad exit status.

Please review. I intend to commit the changes in a few days from now.

Ulrich

--- a/eclass/elisp-common.eclass
+++ b/eclass/elisp-common.eclass
@@ -1,4 +1,4 @@
-# Copyright 1999-2013 Gentoo Foundation
+# Copyright 1999-2014 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 # $Header: $
 #
@@ -349,39 +349,27 @@ elisp-site-file-install() {
 
 elisp-site-regen() {
 	local sitelisp=${ROOT}${EPREFIX}${SITELISP}
-	local sf i null="" page=$'\f'
+	local sf i ret=0 null="" page=$'\f'
 	local -a sflist
 
-	if [[ ! -d ${sitelisp} ]]; then
-		eerror "elisp-site-regen: Directory ${sitelisp} does not exist"
-		return 1
-	fi
-
-	if [[ ! -d ${T} ]]; then
-		eerror "elisp-site-regen: Temporary directory ${T} does not exist"
-		return 1
-	fi
-
 	if [[ ${EBUILD_PHASE} = *rm && ! -e ${sitelisp}/site-gentoo.el ]]; then
 		ewarn "Refusing to create site-gentoo.el in ${EBUILD_PHASE} phase."
 		return 0
 	fi
 
+	[[ -d ${sitelisp} ]] \
+		|| die "elisp-site-regen: Directory ${sitelisp} does not exist"
+
+	[[ -d ${T} ]] \
+		|| die "elisp-site-regen: Temporary directory ${T} does not exist"
+
 	ebegin "Regenerating site-gentoo.el for GNU Emacs (${EBUILD_PHASE})"
 
-	for sf in "${sitelisp}"/[0-9][0-9]*-gentoo.el \
-		"${sitelisp}"/site-gentoo.d/[0-9][0-9]*.el
-	do
-		[[ -r ${sf} ]] || continue
-		# sort files by their basename. straight insertion sort.
-		for ((i=${#sflist[@]}; i>0; i--)); do
-			[[ ${sf##*/} < ${sflist[i-1]##*/} ]] || break
-			sflist[i]=${sflist[i-1]}
-		done
-		sflist[i]=${sf}
+	for sf in "${sitelisp}"/site-gentoo.d/[0-9][0-9]*.el; do
+		[[ -r ${sf} ]] && sflist+=("${sf}")
 	done
 
-	cat <<-EOF >"${T}"/site-gentoo.el
+	cat <<-EOF >"${T}"/site-gentoo.el || ret=$?
 	;;; site-gentoo.el --- site initialisation for Gentoo-installed packages
 
 	;;; Commentary:
@@ -391,8 +379,8 @@ elisp-site-regen() {
 	;;; Code:
 	EOF
 	# Use sed instead of cat here, since files may miss a trailing newline.
-	sed '$q' "${sflist[@]}" </dev/null >>"${T}"/site-gentoo.el
-	cat <<-EOF >>"${T}"/site-gentoo.el
+	sed '$q' "${sflist[@]}" </dev/null >>"${T}"/site-gentoo.el || ret=$?
+	cat <<-EOF >>"${T}"/site-gentoo.el || ret=$?
 
 	${page}
 	(provide 'site-gentoo)
@@ -405,7 +393,10 @@ elisp-site-regen() {
 	;;; site-gentoo.el ends here
 	EOF
 
-	if cmp -s "${sitelisp}"/site-gentoo.el "${T}"/site-gentoo.el; then
+	if [[ ${ret} -ne 0 ]]; then
+		eend ${ret} "elisp-site-regen: Writing site-gentoo.el failed."
+		die
+	elif cmp -s "${sitelisp}"/site-gentoo.el "${T}"/site-gentoo.el; then
 		# This prevents outputting unnecessary text when there
 		# was actually no change.
 		# A case is a remerge where we have doubled output.
@@ -414,7 +405,7 @@ elisp-site-regen() {
 		einfo "... no changes."
 	else
 		mv "${T}"/site-gentoo.el "${sitelisp}"/site-gentoo.el
-		eend
+		eend $? "elisp-site-regen: Replacing site-gentoo.el failed" || die
 		case ${#sflist[@]} in
 			0) [[ ${PN} = emacs-common-gentoo ]] \
 				|| ewarn "... Huh? No site initialisation files found." ;;

[-- Attachment #2: Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-dev] RFC: Update to elisp-common.eclass
  2014-05-18 18:13 [gentoo-dev] RFC: Update to elisp-common.eclass Ulrich Mueller
@ 2014-05-19  0:08 ` Jeroen Roovers
  2014-05-19  5:03   ` Ulrich Mueller
  2014-05-19 10:28 ` Alex Xu
  1 sibling, 1 reply; 6+ messages in thread
From: Jeroen Roovers @ 2014-05-19  0:08 UTC (permalink / raw
  To: gentoo-dev

On Sun, 18 May 2014 20:13:07 +0200
Ulrich Mueller <ulm@gentoo.org> wrote:

Are you sure this is useful?

> --- a/eclass/elisp-common.eclass
> +++ b/eclass/elisp-common.eclass
> @@ -1,4 +1,4 @@
> -# Copyright 1999-2013 Gentoo Foundation
> +# Copyright 1999-2014 Gentoo Foundation
>  # Distributed under the terms of the GNU General Public License v2
>  # $Header: $
>  #
> @@ -349,39 +349,27 @@ elisp-site-file-install() {
>  
>  elisp-site-regen() {
[...]
> -	if [[ ! -d ${T} ]]; then
> -		eerror "elisp-site-regen: Temporary directory ${T}
> does not exist"
> -		return 1
> -	fi

"The package manager must define the following environment variables.

[...]

"T [...]The full path to a temporary directory for use by the
ebuild."[1]


Regards,
     jer


[1] http://dev.gentoo.org/~ulm/pms/5/pms.html#x1-11800011.1




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-dev] RFC: Update to elisp-common.eclass
  2014-05-19  0:08 ` Jeroen Roovers
@ 2014-05-19  5:03   ` Ulrich Mueller
  0 siblings, 0 replies; 6+ messages in thread
From: Ulrich Mueller @ 2014-05-19  5:03 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 771 bytes --]

>>>>> On Mon, 19 May 2014, Jeroen Roovers wrote:

> Are you sure this is useful?

>> elisp-site-regen() {
> [...]
>> -	if [[ ! -d ${T} ]]; then
>> -		eerror "elisp-site-regen: Temporary directory ${T} does not exist"
>> -		return 1
>> -	fi

> "The package manager must define the following environment variables.

> [...]

> "T [...]The full path to a temporary directory for use by the
> ebuild."[1]

So is the theory. The test exists because this wasn't always the case
in practice [2].

I'd rather leave it there, because if T is empty then files will be
written to / instead. There is no sandbox in post{inst,rm}, so being
extra careful won't harm.

Ulrich

> [1] http://dev.gentoo.org/~ulm/pms/5/pms.html#x1-11800011.1
[2] http://paludis.exherbo.org/trac/ticket/517

[-- Attachment #2: Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-dev] RFC: Update to elisp-common.eclass
  2014-05-18 18:13 [gentoo-dev] RFC: Update to elisp-common.eclass Ulrich Mueller
  2014-05-19  0:08 ` Jeroen Roovers
@ 2014-05-19 10:28 ` Alex Xu
  2014-05-19 11:17   ` Ulrich Mueller
  1 sibling, 1 reply; 6+ messages in thread
From: Alex Xu @ 2014-05-19 10:28 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 517 bytes --]

On 18/05/14 02:13 PM, Ulrich Mueller wrote:
>  	if [[ ${EBUILD_PHASE} = *rm && ! -e ${sitelisp}/site-gentoo.el ]]; then
>  		ewarn "Refusing to create site-gentoo.el in ${EBUILD_PHASE} phase."
>  		return 0
>  	fi
>  
> +	[[ -d ${sitelisp} ]] \
> +		|| die "elisp-site-regen: Directory ${sitelisp} does not exist"
> +
> +	[[ -d ${T} ]] \
> +		|| die "elisp-site-regen: Temporary directory ${T} does not exist"
> +
!qefs

if ROOT, EPREFIX, or SITELISP has whitespace, this will throw a syntax
error.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-dev] RFC: Update to elisp-common.eclass
  2014-05-19 10:28 ` Alex Xu
@ 2014-05-19 11:17   ` Ulrich Mueller
  2014-05-19 11:18     ` Alex Xu
  0 siblings, 1 reply; 6+ messages in thread
From: Ulrich Mueller @ 2014-05-19 11:17 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 790 bytes --]

>>>>> On Mon, 19 May 2014, Alex Xu wrote:

> On 18/05/14 02:13 PM, Ulrich Mueller wrote:
>> if [[ ${EBUILD_PHASE} = *rm && ! -e ${sitelisp}/site-gentoo.el ]]; then
>> ewarn "Refusing to create site-gentoo.el in ${EBUILD_PHASE} phase."
>> return 0
>> fi
>> 
>> +	[[ -d ${sitelisp} ]] \
>> +		|| die "elisp-site-regen: Directory ${sitelisp} does not exist"
>> +
>> +	[[ -d ${T} ]] \
>> +		|| die "elisp-site-regen: Temporary directory ${T} does not exist"
>> +
> !qefs

> if ROOT, EPREFIX, or SITELISP has whitespace, this will throw a syntax
> error.

Where? In the snippet you quoted, I don't see where whitespace in
${sitelisp} could cause any problems.

"Word splitting and filename expansion are not performed on the words
between the `[[' and `]]'" -- GNU Bash Reference Manual

Ulrich

[-- Attachment #2: Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-dev] RFC: Update to elisp-common.eclass
  2014-05-19 11:17   ` Ulrich Mueller
@ 2014-05-19 11:18     ` Alex Xu
  0 siblings, 0 replies; 6+ messages in thread
From: Alex Xu @ 2014-05-19 11:18 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 957 bytes --]

On 19/05/14 07:17 AM, Ulrich Mueller wrote:
>>>>>> On Mon, 19 May 2014, Alex Xu wrote:
> 
>> On 18/05/14 02:13 PM, Ulrich Mueller wrote:
>>> if [[ ${EBUILD_PHASE} = *rm && ! -e ${sitelisp}/site-gentoo.el ]]; then
>>> ewarn "Refusing to create site-gentoo.el in ${EBUILD_PHASE} phase."
>>> return 0
>>> fi
>>>
>>> +	[[ -d ${sitelisp} ]] \
>>> +		|| die "elisp-site-regen: Directory ${sitelisp} does not exist"
>>> +
>>> +	[[ -d ${T} ]] \
>>> +		|| die "elisp-site-regen: Temporary directory ${T} does not exist"
>>> +
>> !qefs
> 
>> if ROOT, EPREFIX, or SITELISP has whitespace, this will throw a syntax
>> error.
> 
> Where? In the snippet you quoted, I don't see where whitespace in
> ${sitelisp} could cause any problems.
> 
> "Word splitting and filename expansion are not performed on the words
> between the `[[' and `]]'" -- GNU Bash Reference Manual
> 
> Ulrich
> 

/me ponders

hm...

never mind, I was mistaken.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-05-19 11:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-18 18:13 [gentoo-dev] RFC: Update to elisp-common.eclass Ulrich Mueller
2014-05-19  0:08 ` Jeroen Roovers
2014-05-19  5:03   ` Ulrich Mueller
2014-05-19 10:28 ` Alex Xu
2014-05-19 11:17   ` Ulrich Mueller
2014-05-19 11:18     ` Alex Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox