* [gentoo-dev] How to pass list of paths to eclass?
@ 2007-12-11 8:17 Peter Volkov
2007-12-11 8:37 ` likewhoa
` (4 more replies)
0 siblings, 5 replies; 15+ messages in thread
From: Peter Volkov @ 2007-12-11 8:17 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 527 bytes --]
Hello.
Some eclasses (kernel-2, font) use variable to pass space separated PATH
to patch or fontconfig files from ebuild to eclass. In ebuild we use:
FONT_CONF="path1 path2"
Then eclasses use the variable:
for conffile in ${FONT_CONF}; do
...
done
The problem with this doesn't work if path{1,2} contain spaces. The
solution I'm thinking about is to you arrays:
FONT_CONF=("path1" "path2")
for conffile in "${FONT_CONF[@]}"; do
...
done
But is this good idea? Are there better?
--
Peter.
[-- Attachment #2: Эта часть сообщения подписана цифровой подписью --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-dev] How to pass list of paths to eclass?
2007-12-11 8:17 [gentoo-dev] How to pass list of paths to eclass? Peter Volkov
@ 2007-12-11 8:37 ` likewhoa
2007-12-11 8:44 ` Donnie Berkholz
` (3 subsequent siblings)
4 siblings, 0 replies; 15+ messages in thread
From: likewhoa @ 2007-12-11 8:37 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 890 bytes --]
On Dec 11, 2007 8:17 AM, Peter Volkov <pva@gentoo.org> wrote:
> Hello.
>
> Some eclasses (kernel-2, font) use variable to pass space separated PATH
> to patch or fontconfig files from ebuild to eclass. In ebuild we use:
>
> FONT_CONF="path1 path2"
>
> Then eclasses use the variable:
>
> for conffile in ${FONT_CONF}; do
> ...
> done
>
> The problem with this doesn't work if path{1,2} contain spaces. The
> solution I'm thinking about is to you arrays:
>
> FONT_CONF=("path1" "path2")
>
> for conffile in "${FONT_CONF[@]}"; do
> ...
> done
>
> But is this good idea? Are there better?
>
> --
> Peter.
>
I agree using arrays would be much better, you can also loop through the
arrays like.
for ((i=0;i<${#FONT_CONF[*]};i++)); do echo "${FONT_CONF[i]}"; done
this way you can avoid spacing because you'll just be calling each array
element in order using quotes.
Fernando
[-- Attachment #2: Type: text/html, Size: 1313 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-dev] How to pass list of paths to eclass?
2007-12-11 8:17 [gentoo-dev] How to pass list of paths to eclass? Peter Volkov
2007-12-11 8:37 ` likewhoa
@ 2007-12-11 8:44 ` Donnie Berkholz
2007-12-11 10:38 ` Roy Marples
2007-12-11 10:38 ` Roy Marples
` (2 subsequent siblings)
4 siblings, 1 reply; 15+ messages in thread
From: Donnie Berkholz @ 2007-12-11 8:44 UTC (permalink / raw
To: gentoo-dev
On 11:17 Tue 11 Dec , Peter Volkov wrote:
> FONT_CONF=("path1" "path2")
>
> for conffile in "${FONT_CONF[@]}"; do
> ...
> done
>
> But is this good idea? Are there better?
Roy solved a similar problem in baselayout-2 using hardcoded newlines,
although it had the additional constraint of sh compatibility. It's
worth considering code clarity between that and arrays.
Thanks,
Donnie
--
gentoo-dev@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-dev] How to pass list of paths to eclass?
2007-12-11 8:17 [gentoo-dev] How to pass list of paths to eclass? Peter Volkov
2007-12-11 8:37 ` likewhoa
2007-12-11 8:44 ` Donnie Berkholz
@ 2007-12-11 10:38 ` Roy Marples
2007-12-11 11:14 ` Peter Volkov
2007-12-12 2:31 ` [gentoo-dev] " Ryan Hill
2007-12-13 9:18 ` [gentoo-dev] " Peter Volkov
4 siblings, 1 reply; 15+ messages in thread
From: Roy Marples @ 2007-12-11 10:38 UTC (permalink / raw
To: gentoo-dev
On Tuesday 11 December 2007 08:17:12 Peter Volkov wrote:
> Some eclasses (kernel-2, font) use variable to pass space separated PATH
> to patch or fontconfig files from ebuild to eclass. In ebuild we use:
>
> FONT_CONF="path1 path2"
>
> Then eclasses use the variable:
>
> for conffile in ${FONT_CONF}; do
> ...
> done
>
> The problem with this doesn't work if path{1,2} contain spaces. The
> solution I'm thinking about is to you arrays:
>
> FONT_CONF=("path1" "path2")
>
> for conffile in "${FONT_CONF[@]}"; do
> ...
> done
>
> But is this good idea? Are there better?
FONT_CONF=path1:path2
IFS=.
for for conffile in ${FONT_CONF}; do
....
done
unset IFS
Or if you want to be really picky about preserving IFS if you can't make it
local in a function
SIFS=${IFS-y} OIFS=${IFS}
IFS=.
for for conffile in ${FONT_CONF}; do
....
done
if [ "${SIFS}" = "y" ]; then
unset IFS
else
IFS=${OIFS}
fi
That way you work the same way as the classic $PATH variable.
But of course no one cares as it's Just Not Bash (tm)
Thanks
Roy
--
gentoo-dev@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-dev] How to pass list of paths to eclass?
2007-12-11 8:44 ` Donnie Berkholz
@ 2007-12-11 10:38 ` Roy Marples
0 siblings, 0 replies; 15+ messages in thread
From: Roy Marples @ 2007-12-11 10:38 UTC (permalink / raw
To: gentoo-dev
On Tuesday 11 December 2007 08:44:51 Donnie Berkholz wrote:
> Roy solved a similar problem in baselayout-2 using hardcoded newlines,
> although it had the additional constraint of sh compatibility. It's
> worth considering code clarity between that and arrays.
Only because some commands could litterally have any character in then, making
things a little tricky.
Here I see no reason why it cannot behave like $PATH and operate under the
same constraints.
Thanks
Roy
--
gentoo-dev@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-dev] How to pass list of paths to eclass?
2007-12-11 10:38 ` Roy Marples
@ 2007-12-11 11:14 ` Peter Volkov
2007-12-11 11:33 ` Roy Marples
0 siblings, 1 reply; 15+ messages in thread
From: Peter Volkov @ 2007-12-11 11:14 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 451 bytes --]
В Втр, 11/12/2007 в 10:38 +0000, Roy Marples пишет:
> FONT_CONF=path1:path2
>
> IFS=.
IIUC should be IFS=:
> for for conffile in ${FONT_CONF}; do
> ....
> done
> unset IFS
>
> That way you work the same way as the classic $PATH variable.
But this seems to fail if we have ':' inside path{1,2}. Is that true?
For PATH the same question stands, but I think that ':' is used there
for historical reasons.
--
Peter.
[-- Attachment #2: Эта часть сообщения подписана цифровой подписью --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-dev] How to pass list of paths to eclass?
2007-12-11 11:14 ` Peter Volkov
@ 2007-12-11 11:33 ` Roy Marples
0 siblings, 0 replies; 15+ messages in thread
From: Roy Marples @ 2007-12-11 11:33 UTC (permalink / raw
To: gentoo-dev
On Tuesday 11 December 2007 11:14:49 Peter Volkov wrote:
> > That way you work the same way as the classic $PATH variable.
>
> But this seems to fail if we have ':' inside path{1,2}. Is that true?
> For PATH the same question stands, but I think that ':' is used there
> for historical reasons.
Yes, that does mean you cannot use : in PATH.
I don't actually know if shells allow it to be escaped, but I do know that
escaping does not work when IFS is concerned.
You could also use the embedded newline approach that Donnie mentioned
earlier, but you may or may not want to go there. It's it's fairly ugly code.
But the good news is you can now escape anything into an item, and remian
shell portable. Here's a code snippet
FONT_CONF="conf1
conf2"
SIFS="${IFS-y}" OIFS="${IFS}"
IFS="
"
for for conffile in ${FONT_CONF}; do
....
done
if [ "${SIFS}" = "y" ]; then
unset IFS
else
IFS="${OIFS}"
fi
Oddly enough, you do need to quote variable assignment now as in my test even
bash got it wrong. Probably a bug, but heh.
Thanks
Roy
--
gentoo-dev@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* [gentoo-dev] Re: How to pass list of paths to eclass?
2007-12-11 8:17 [gentoo-dev] How to pass list of paths to eclass? Peter Volkov
` (2 preceding siblings ...)
2007-12-11 10:38 ` Roy Marples
@ 2007-12-12 2:31 ` Ryan Hill
2007-12-13 9:18 ` [gentoo-dev] " Peter Volkov
4 siblings, 0 replies; 15+ messages in thread
From: Ryan Hill @ 2007-12-12 2:31 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 1298 bytes --]
Peter Volkov wrote:
> Some eclasses (kernel-2, font) use variable to pass space separated PATH
> to patch or fontconfig files from ebuild to eclass. In ebuild we use:
>
> FONT_CONF="path1 path2"
>
> Then eclasses use the variable:
>
> for conffile in ${FONT_CONF}; do
> ...
> done
>
> The problem with this doesn't work if path{1,2} contain spaces. The
> solution I'm thinking about is to you arrays:
>
> FONT_CONF=("path1" "path2")
>
> for conffile in "${FONT_CONF[@]}"; do
> ...
> done
>
> But is this good idea? Are there better?
I was also thinking about changing it to a function instead of a variable,
so ebuilds would do something like:
dofontconfig "${FILESDIR}"/50-myconfig "${FILESDIR}"/51-myotherconfig
dofontconfig() {
insinto /etc/fonts/conf.avail/
for conf in "$@"; do
[[ -e ${conf} ]] && doins "${conf}"
done
}
course this would require a bit of ebuild editing. not many ebuilds
use FONT_CONF though.
on the other hand, the nicety of the variable is that font ebuilds
rarely need to contain a src_install.
--
looks like christmas at fifty-five degrees
this latitude weakens my knees
EFFD 380E 047A 4B51 D2BD C64F 8AA8 8346 F9A4 0662 (0xF9A40662)
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-dev] How to pass list of paths to eclass?
2007-12-11 8:17 [gentoo-dev] How to pass list of paths to eclass? Peter Volkov
` (3 preceding siblings ...)
2007-12-12 2:31 ` [gentoo-dev] " Ryan Hill
@ 2007-12-13 9:18 ` Peter Volkov
2007-12-13 9:41 ` Roy Marples
2007-12-13 10:52 ` [gentoo-dev] " Steve Long
4 siblings, 2 replies; 15+ messages in thread
From: Peter Volkov @ 2007-12-13 9:18 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 547 bytes --]
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
--
Peter.
[-- Attachment #2: Эта часть сообщения подписана цифровой подписью --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-dev] How to pass list of paths to eclass?
2007-12-13 9:18 ` [gentoo-dev] " Peter Volkov
@ 2007-12-13 9:41 ` Roy Marples
2007-12-13 10:17 ` Peter Volkov
2007-12-13 10:52 ` [gentoo-dev] " Steve Long
1 sibling, 1 reply; 15+ messages in thread
From: Roy Marples @ 2007-12-13 9:41 UTC (permalink / raw
To: gentoo-dev
On Thursday 13 December 2007 09:18:45 Peter Volkov wrote:
> 2. Modify ebuilds to use arrays.
>
> -FONT_CONF="path1 path2"
> +FONT_CONF=( "path1" "path2" )
Why not use a function in pkg_setup as suggested earlier and pass each path
component as $1, $2, etc. Then the ebuild itself doesn't actually care about
the storage format of FONT_CONF, whether it's a bash array or a standard
string using IFS.
That gives you the luxury of changing it as you like without having to change
any ebuilds later.
pkg_setup() {
append_font_conf "path1" "path2"
}
Thanks
Roy
--
gentoo-dev@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-dev] How to pass list of paths to eclass?
2007-12-13 9:41 ` Roy Marples
@ 2007-12-13 10:17 ` Peter Volkov
2007-12-13 10:52 ` Roy Marples
0 siblings, 1 reply; 15+ messages in thread
From: Peter Volkov @ 2007-12-13 10:17 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 670 bytes --]
В Чтв, 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.
[-- Attachment #2: Эта часть сообщения подписана цифровой подписью --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-dev] How to pass list of paths to eclass?
2007-12-13 10:17 ` Peter Volkov
@ 2007-12-13 10:52 ` Roy Marples
0 siblings, 0 replies; 15+ messages in thread
From: Roy Marples @ 2007-12-13 10:52 UTC (permalink / raw
To: gentoo-dev
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
^ permalink raw reply [flat|nested] 15+ messages in thread
* [gentoo-dev] Re: How to pass list of paths to eclass?
2007-12-13 9:18 ` [gentoo-dev] " Peter Volkov
2007-12-13 9:41 ` Roy Marples
@ 2007-12-13 10:52 ` Steve Long
2007-12-13 11:34 ` Peter Volkov
1 sibling, 1 reply; 15+ messages in thread
From: Steve Long @ 2007-12-13 10:52 UTC (permalink / raw
To: gentoo-dev
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 $'foo\0bar' -- 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=$'\n'; 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=$'\t'
--
gentoo-dev@gentoo.org mailing list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [gentoo-dev] Re: How to pass list of paths to eclass?
2007-12-13 10:52 ` [gentoo-dev] " Steve Long
@ 2007-12-13 11:34 ` Peter Volkov
2007-12-13 16:08 ` [gentoo-dev] " Steve Long
0 siblings, 1 reply; 15+ messages in thread
From: Peter Volkov @ 2007-12-13 11:34 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 1068 bytes --]
В Чтв, 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.
[-- Attachment #2: Эта часть сообщения подписана цифровой подписью --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* [gentoo-dev] Re: Re: How to pass list of paths to eclass?
2007-12-13 11:34 ` Peter Volkov
@ 2007-12-13 16:08 ` Steve Long
0 siblings, 0 replies; 15+ messages in thread
From: Steve Long @ 2007-12-13 16:08 UTC (permalink / raw
To: gentoo-dev
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
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2007-12-13 16:26 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-11 8:17 [gentoo-dev] How to pass list of paths to eclass? Peter Volkov
2007-12-11 8:37 ` likewhoa
2007-12-11 8:44 ` Donnie Berkholz
2007-12-11 10:38 ` Roy Marples
2007-12-11 10:38 ` Roy Marples
2007-12-11 11:14 ` Peter Volkov
2007-12-11 11:33 ` Roy Marples
2007-12-12 2:31 ` [gentoo-dev] " Ryan Hill
2007-12-13 9:18 ` [gentoo-dev] " Peter Volkov
2007-12-13 9:41 ` Roy Marples
2007-12-13 10:17 ` Peter Volkov
2007-12-13 10:52 ` Roy Marples
2007-12-13 10:52 ` [gentoo-dev] " Steve Long
2007-12-13 11:34 ` Peter Volkov
2007-12-13 16:08 ` [gentoo-dev] " Steve Long
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox