How to pass list of paths to eclass?
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. |
How to pass list of paths to eclass?
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 |
How to pass list of paths to eclass?
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 |
How to pass list of paths to eclass?
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 |
How to pass list of paths to eclass?
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 |
How to pass list of paths to eclass?
В Втр, 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. |
How to pass list of paths to eclass?
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 |
How to pass list of paths to eclass?
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) |
How to pass list of paths to eclass?
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. |
How to pass list of paths to eclass?
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 |
| All times are GMT. The time now is 06:52 AM. |
VBulletin, Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.