FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo Development

 
 
LinkBack Thread Tools
 
Old 12-13-2007, 09:17 AM
Peter Volkov
 
Default How to pass list of paths to eclass?

В Чтв, 13/12/2007 в 09:41 +0000, Roy Marples пишет:
> On Thursday 13 December 2007 09:18:45 Peter Volkov wrote:
> > use arrays.

> Why not use a function in pkg_setup as suggested earlier

Because this is more code for the same functionality. Also if at one
point somebody decides to add eclass_pkg_setup function to eclass he/she
will have to touch all ebuild and put this function into pkg_setup
there. BTW. Speaking about font.eclass we already have font_pkg_setup
there. So correct code will be:

pkg_setup() {
font_pkg_setup
append_font_conf "path1" "path2"
}

instead of on line

FONT_CONF=( "path1" "path2" )

--
Peter.
 
Old 12-13-2007, 09:52 AM
Roy Marples
 
Default How to pass list of paths to eclass?

On Thursday 13 December 2007 10:17:07 Peter Volkov wrote:
> В Чтв, 13/12/2007 в 09:41 +0000, Roy Marples пишет:
> > On Thursday 13 December 2007 09:18:45 Peter Volkov wrote:
> > > use arrays.
> >
> > Why not use a function in pkg_setup as suggested earlier
>
> Because this is more code for the same functionality. Also if at one
> point somebody decides to add eclass_pkg_setup function to eclass he/she
> will have to touch all ebuild and put this function into pkg_setup
> there. BTW. Speaking about font.eclass we already have font_pkg_setup
> there. So correct code will be:
>
> pkg_setup() {
> font_pkg_setup
> append_font_conf "path1" "path2"
> }
>
> instead of on line
>
> FONT_CONF=( "path1" "path2" )

You could do the append_font_conf in any function I think. So there's only
more code if there are no functions already.

Thanks

Roy
--
gentoo-dev@gentoo.org mailing list
 
Old 12-13-2007, 09:52 AM
Steve Long
 
Default How to pass list of paths to eclass?

Peter Volkov wrote:

> Thank you all, for your responds.
>
> Currently I see that the best approach is arrays. They provide required
> functionality, clear syntax and easy upgrade path.
++

> Speaking about the
> latter it is:
>
> 1. Modify eclass to use arrays:
>
> for conffile in ${FONT_CONF[@]}; do
> ...
> done
>
> 2. Modify ebuilds to use arrays.
>
> -FONT_CONF="path1 path2"
> +FONT_CONF=( "path1" "path2" )
>
> 3. Modify eclass, so that it works with path containing spaces inside:
>
> -for conffile in ${FONT_CONF[@]}; do
> +for conffile in "${FONT_CONF[@]}"; do
>
That looks right, although step 1 should *always* be to use the code from
step 3.

<greybot> The difference between $@ and $*: without double quotes, none at
all: both equal $1 $2 .... With double quotes, "$@" is "$1" "$2" ...,
while "$*" is expanded as the single argument "$1c$2c..." (where c is the
first character of $IFS). You almost always want "$@".

The same applies to the expansion of normal arrays. So for most cases, we
use "${arr[@]}" to deal with each element separately, irrespective of its
content. The *only* content BASH can't handle is a NUL byte, which is
treated as end of string, eg: echo $'foobar' -- pipes between commands
are ofc binary safe; you just can't hold raw binary data in shell vars.

${arr[*]} is used for display, eg die "Bad params to $FUNCNAME: $*"
or: oIFS=$IFS; IFS=$'
'; echo "These are the options$IFS${options[*]}"
IFS=$oIFS # [1]
echo ${#IFS} # to check IFS has been restored correctly

[1] works fine here, Roy func $TAB # needs quotes though, where TAB=$' '


--
gentoo-dev@gentoo.org mailing list
 
Old 12-13-2007, 10:34 AM
Peter Volkov
 
Default How to pass list of paths to eclass?

В Чтв, 13/12/2007 в 10:52 +0000, Steve Long пишет:
> Peter Volkov wrote:
> > Speaking about the
> > latter it is:
> >
> > 1. Modify eclass to use arrays:
> >
> > for conffile in ${FONT_CONF[@]}; do
> > ...
> > done
> >
> > 2. Modify ebuilds to use arrays.
> >
> > -FONT_CONF="path1 path2"
> > +FONT_CONF=( "path1" "path2" )
> >
> > 3. Modify eclass, so that it works with path containing spaces inside:
> >
> > -for conffile in ${FONT_CONF[@]}; do
> > +for conffile in "${FONT_CONF[@]}"; do

> That looks right, although step 1 should *always* be to use the code from
> step 3.

No. The idea is to have after first step some kind of "backward
compatibility". So while we have

FONT_CONF="path1 path2"

definitions in the tree, when I use them as array bash will expand
${FONT_CONF[@]} in the same way as array with exactly 1 element. And I
do not it to be qouted as for cycle should iterate through path{1,2}. I
know this does not work with spaces, but current implementations has the
same limitation.

--
Peter.
 
Old 12-13-2007, 03:08 PM
Steve Long
 
Default How to pass list of paths to eclass?

Peter Volkov wrote:

> ? ???, 13/12/2007 ? 10:52 +0000, Steve Long ?????:
>> Peter Volkov wrote:
>> > Speaking about the
>> > latter it is:
>> >
>> > 1. Modify eclass to use arrays:
>> >
>> > for conffile in ${FONT_CONF[@]}; do
>> > ...
>> > done
>> >
>> > 2. Modify ebuilds to use arrays.
>> >
>> > -FONT_CONF="path1 path2"
>> > +FONT_CONF=( "path1" "path2" )
>> >
>> > 3. Modify eclass, so that it works with path containing spaces inside:
>> >
>> > -for conffile in ${FONT_CONF[@]}; do
>> > +for conffile in "${FONT_CONF[@]}"; do
>
>> That looks right, although step 1 should *always* be to use the code from
>> step 3.
>
> No. The idea is to have after first step some kind of "backward
> compatibility". So while we have
>
> FONT_CONF="path1 path2"
>
> definitions in the tree, when I use them as array bash will expand
> ${FONT_CONF[@]} in the same way as array with exactly 1 element. And I
> do not it to be qouted as for cycle should iterate through path{1,2}. I
> know this does not work with spaces, but current implementations has the
> same limitation.
>
OIC. You could use this:
isArr() [[ $(declare -p "$1" 2>/dev/null) = 'declare -a'* ]]
with a function to carry out the actual task:
foo () { local conffile; for conffile; do .."$conffile".. ; done; }
if isArr FONT_CONF; then
foo "${FONT_CONF[@]}"
else foo $FONT_CONF
fi || die "Unable to foo ${FONT_CONF[*]}"

- if you want to support both types of config variable. But yeah, your
migration path makes sense; sorry for missing that and thanks for your
patience.


--
gentoo-dev@gentoo.org mailing list
 

Thread Tools




All times are GMT. The time now is 01:40 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org