Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
here-documents in ebuild
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
RealNC
Tux's lil' helper
Tux's lil' helper


Joined: 13 Apr 2008
Posts: 147

PostPosted: Sun Apr 13, 2008 2:55 am    Post subject: here-documents in ebuild Reply with quote

Ahoy.

I'm writing an ebuild that has a src_test() and one of the tests needs to be a here-document (command <<- EOF). But I need to do a 'die "Failed"' call if the test fails and I can't get the syntax right. Imagine this:

Code:
src_test() {
    ./frob <<- EOF || die "frob failed"
        foo
        bar
    EOF
}


It passes 'ebuild digest' but fails on emerge. What's the right syntax? Here's the error message:

Code:
[...]temp/environment: line 2329: syntax error near unexpected token `||'
[...]/temp/environment: line 2329: ` || die "frob failed";'
 *
 * Call stack:
 *               ebuild.sh, line 1641:  Called die
 * The specific snippet of code:
 *      preprocess_ebuild_env || \
 *              die "error processing environment"
 *  The die message:
 *   error processing environment
Back to top
View user's profile Send private message
Hu
Watchman
Watchman


Joined: 06 Mar 2007
Posts: 6828

PostPosted: Sun Apr 13, 2008 3:40 am    Post subject: Reply with quote

Would it be acceptable to call die separately afterward? This may confuse the automatic backtrace logic in die, but should produce the correct behavior:
Code:


./frob <<- EOF
    foo
    bar
EOF
[ $? -eq 0 ] || die "frob failed"
Back to top
View user's profile Send private message
RealNC
Tux's lil' helper
Tux's lil' helper


Joined: 13 Apr 2008
Posts: 147

PostPosted: Sun Apr 13, 2008 5:55 pm    Post subject: Reply with quote

It works OK that way. I was just wondering if it needs a syntax I'm missing. I can't find one, so I'll use your suggestion.
Back to top
View user's profile Send private message
RealNC
Tux's lil' helper
Tux's lil' helper


Joined: 13 Apr 2008
Posts: 147

PostPosted: Sun Apr 13, 2008 8:33 pm    Post subject: Reply with quote

Damn. More bugs. Example:

Code:

src_test() {
    ./frob <<- EOF
        foo
        bar
        baz
    EOF
}


only "foo" gets passed to ./frob. bar and baz (and everything else up to EOF) are totally ignored and have no effect.
Back to top
View user's profile Send private message
Hu
Watchman
Watchman


Joined: 06 Mar 2007
Posts: 6828

PostPosted: Sun Apr 13, 2008 8:35 pm    Post subject: Reply with quote

I tried the same with /usr/bin/cat instead of ./frob and I get the expected output. Are you sure frob is written to accept multiline input?
Back to top
View user's profile Send private message
RealNC
Tux's lil' helper
Tux's lil' helper


Joined: 13 Apr 2008
Posts: 147

PostPosted: Sun Apr 13, 2008 9:01 pm    Post subject: Reply with quote

Yes, it's no problem with frob. See, this normal script (call it tst.sh):

Code:
#! /bin/sh
/frob <<- EOF
        foo
        bar
        baz
EOF


Produces the correct results when run. The bugs appear only when trying to do this in an ebuild.
Back to top
View user's profile Send private message
RealNC
Tux's lil' helper
Tux's lil' helper


Joined: 13 Apr 2008
Posts: 147

PostPosted: Mon Apr 14, 2008 12:25 am    Post subject: Reply with quote

Oops, it turns out it WAS a problem with frob :oops:

Sorry for the confusion. It works OK.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum