Chris Stankevitz | 27 Feb 21:36 2007

Executing shell command, save results to variable

Hi group,

Is it possible to execute a shell command and save the results as a jam 
variable?  The command I want to execute and its output is:
   wx-config --libs

-pthread   -L/usr/X11R6/lib  -lwx_gtk2u_xrc-2.6 -lwx_gtk2u_qa-2.6 
-lwx_gtk2u_htm l-2.6 -lwx_gtk2u_adv-2.6 -lwx_gtk2u_core-2.6 
-lwx_baseu_xml-2.6 -lwx_baseu_net-2.6 -lwx_baseu-2.6

Thank you!

Chris
_______________________________________________
jamming mailing list  -  jamming <at> perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming

Brian Osman | 28 Feb 14:56 2007

Re: Executing shell command, save results to variable

To what end? Realize that if this happens during an action, it's too late to 
do anything really productive with it, because all of your rules have 
already executed.

Personally, when we have to solve similar problems in our (rather complex) 
jam rigs, we generally just move those types of steps outside the jam files. 
In order to make sure that environments and what not are configured 
correctly, we already have thin wrappers (batch files, shell scripts, 
whatever), so having a batch file that does that step (and stuffs the result 
in an environment variable) may be the best option.

-Brian

----- Original Message ----- 
From: "Chris Stankevitz" <cstankevitz <at> toyon.com>
To: <jamming <at> perforce.com>
Sent: Tuesday, February 27, 2007 3:36 PM
Subject: [jamming] Executing shell command, save results to variable

> Hi group,
>
> Is it possible to execute a shell command and save the results as a jam
> variable?  The command I want to execute and its output is:
>   wx-config --libs
>
> -pthread   -L/usr/X11R6/lib  -lwx_gtk2u_xrc-2.6 -lwx_gtk2u_qa-2.6
> -lwx_gtk2u_htm l-2.6 -lwx_gtk2u_adv-2.6 -lwx_gtk2u_core-2.6
> -lwx_baseu_xml-2.6 -lwx_baseu_net-2.6 -lwx_baseu-2.6
>
> Thank you!
(Continue reading)

Gary Gendel | 28 Feb 15:17 2007

Re: Executing shell command, save results to variable

Chris,

I accomplished a similar thing by rewriting the action for (in my case C++)
which performs the command at the native level in preparation for the command.

rule C++ {
    EXTRAFLAGS=`wx_config --includes`
    $(C++) $EXTRAFLAGS <blah> <blah> <blah>
}

You can get a bit more fancy and have the command(s) you wan put into a file
during setup and sourcing that file in the proper rule.

It's not as elegant as having Jam be able to do a shell `cmd` operation
directly, but I haven't had any luck when I asked for it.

That said, you can do a lot by wrapping the jam call in a script to do a lot of
this nonsense up front outside of Jam.

BTW, I actually don't use this rule-replacement approach in production, but it
worked in an experimental system.

Gary

Chris Stankevitz wrote:
> Hi group,
> 
> Is it possible to execute a shell command and save the results as a jam 
> variable?  The command I want to execute and its output is:
>    wx-config --libs
(Continue reading)

Diane Holt | 28 Feb 17:41 2007
Picon

Re: Executing shell command, save results to variable

I've done both. I pass back-ticked pkg-config commands on my compile and link lines -- ie., I add them to the flags for each (from a new rule, though, not an override on Cc/C++/Link -- although I do have overrides for those rules, but for other reasons). And I also modified Jam to be able to run a shell command from a rule (it bugged me that there was something Make could do that Jam couldn't :)

In your case, Chris, if all you need is to pass that wx-config in on the command line, adding it to the flags is the easiest way to go.

Diane

_______________________________________________
jamming mailing list  -  jamming <at> perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming
Gary Gendel | 28 Feb 17:51 2007

Re: Executing shell command, save results to variable

Diane,

Any chance of sharing your vision and some of your enhancements with us? I would
love to see a back-tick capability for Jam.

Gary

Diane Holt wrote:
> I've done both. I pass back-ticked pkg-config commands on my compile and
> link lines -- ie., I add them to the flags for each (from a new rule,
> though, not an override on Cc/C++/Link -- although I do have overrides
> for those rules, but for other reasons). And I also modified Jam to be
> able to run a shell command from a rule (it bugged me that there was
> something Make could do that Jam couldn't :)
> 
> In your case, Chris, if all you need is to pass that wx-config in on the
> command line, adding it to the flags is the easiest way to go.
> 
> Diane
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> jamming mailing list  -  jamming <at> perforce.com
> http://maillist.perforce.com/mailman/listinfo/jamming

Attachment (gary.vcf): text/x-vcard, 295 bytes
_______________________________________________
jamming mailing list  -  jamming <at> perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming
Diane Holt | 28 Feb 18:19 2007
Picon

Re: Executing shell command, save results to variable

I didn't do it as a back-tick, but as a new built-in rule, which I call Command. It's used inside square brackets.

For example, this just captures the return code (note: the square brackets passed in the Command itself is the shell's 'test', not Jam's brackets):

RT_OK = [ Command "[ -e /lib/libc.so -o -e /usr/lib/libc.so ] ; echo $?" ] ;
if $(RT_OK) != 0 { Exit "Error: You must install the C runtime before building." ; }

(P.S. So you don't think I'm crazy, testing for something like that -- that's being run inside a chroot'd environment :)

This one captures the actual output:

local libname = [ Command "echo $(shared_lib) | sed -e 's:\\(.*\\)\\.so\\..*$:\\1.so:'" ] ;

If you're still interested, I can send the diff of builtins.c.

Diane

On 2/28/07, Gary Gendel <gary <at> icmanage.com> wrote:
Diane,

Any chance of sharing your vision and some of your enhancements with us? I would
love to see a back-tick capability for Jam.

Gary

Diane Holt wrote:
> I've done both. I pass back-ticked pkg-config commands on my compile and
> link lines -- ie., I add them to the flags for each (from a new rule,
> though, not an override on Cc/C++/Link -- although I do have overrides
> for those rules, but for other reasons). And I also modified Jam to be
> able to run a shell command from a rule (it bugged me that there was
> something Make could do that Jam couldn't :)
>
> In your case, Chris, if all you need is to pass that wx-config in on the
> command line, adding it to the flags is the easiest way to go.
>
> Diane
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> jamming mailing list  -  jamming <at> perforce.com
> http://maillist.perforce.com/mailman/listinfo/jamming



_______________________________________________
jamming mailing list  -  jamming <at> perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming
Joshua ChaitinPollak | 1 Mar 21:41 2007

Multiple directories question

I'm sure this is a FAQ, but I can't seem to find an answer... I have  
a project with static libraries and executables, and I'm having  
trouble having the executables build the libraries.

Specifically, I have a directory myProj, which contains:

Jambase
Jamfile
myLib/
myExec/

Inside myLib, there is myLib.cpp and Jamfile, which contains:

SubDir TOP myLib ;

Library myLib : myLib.cpp ;

Inside myExec, there is main.cpp and Jamfile, which contains:

SubDir TOP myExec ;

Main myExec : main.cpp ;
LinkLibraries myExec : myLib ;

When I do the following, I get an error:

cd myExec
jam

don't know how to make myLib.a
<snip>
...skipped myExec for lack of myLib.a...

How do I tell myExec where to find myLib.a, and better yet, how to  
rebuild it if needed?

Thanks,

Josh

--

-- 
Joshua ChaitinPollak
Software Engineer
Kiva Systems

_______________________________________________
jamming mailing list  -  jamming <at> perforce.com
http://maillist.perforce.com/mailman/listinfo/jamming


Gmane