[bbv2] newbie: how to get value of a feature inside a rule

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

[bbv2] newbie: how to get value of a feature inside a rule

Jaroslav Gresula
Could someone advise me how to retrieve value of a feature within a
rule? I followed an example from the docs which uses the toolset.flags
rule but with no luck.

Below is my attempt, but the TOOLSET variable expands to an empty string.

---
local rule this-module-rule ( ) { return [ CALLER_MODULE ] ; }
local this-module = [ this-module-rule ] ;

import toolset ;
toolset.flags $(this-module).print-toolset TOOLSET : <toolset> ;

rule print-toolset ( )
{
   ECHO $(TOOLSET) ;
}

alias main : : [ print-toolset ] ;



Thanks,
Jarda


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
Reply | Threaded
Open this post in threaded view
|

Re: [bbv2] newbie: how to get value of a feature inside a rule

Mark Evans-2
This should go in the FAQs because I had to figure this out myself just this week.  The toolset.flags rule sets your TOOLSET variable "on" $(targets) for the actions block.  The undocumented magic method to retrieve that value in a rule context is the following:

local toolset = [ on $(targets) return $(TOOLSET) ] ;

Voila! 

Jaroslav Gresula <[hidden email]> wrote:
Could someone advise me how to retrieve value of a feature within a
rule? I followed an example from the docs which uses the toolset.flags
rule but with no luck.


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
Reply | Threaded
Open this post in threaded view
|

Re: [bbv2] newbie: how to get value of a feature inside a rule

Vladimir Prus
In reply to this post by Jaroslav Gresula
On Sunday 05 February 2006 14:31, Jaroslav Gresula wrote:

> Could someone advise me how to retrieve value of a feature within a
> rule? I followed an example from the docs which uses the toolset.flags
> rule but with no luck.
>
> Below is my attempt, but the TOOLSET variable expands to an empty string.
>
> ---
> local rule this-module-rule ( ) { return [ CALLER_MODULE ] ; }
> local this-module = [ this-module-rule ] ;
>
> import toolset ;
> toolset.flags $(this-module).print-toolset TOOLSET : <toolset> ;
>
> rule print-toolset ( )
> {
>    ECHO $(TOOLSET) ;
> }
>
> alias main : : [ print-toolset ] ;

This code is executed during Jamfile parsing stage. It calls the rule
'print-toolset', that immediately executes "ECHO", but the value of
$(TOOLSET) is empty, because it's only set when bjam starts executing
actions, and only if 'print-toolset' is the updating action for some target.

Try this:

  import notfile ;
  import toolset ;
  import feature ;

  notfile test : @print-toolset ;

  rule print-toolset ( targets * : sources * : properties * )
  {
      ECHO "Toolset = " [ feature.get-values <toolset> : $(properties) ] ;
  }

Note that if you run "bjam" with two different toolsets, say:

    bjam gcc intel

you'll see two "Toolset = " lines, one for each time "test" is built.

You might also want to check the newly added FAQ item:

    http://boost.org/boost-build2/doc/html/bbv2/faq.html#id2577795

HTH,
Volodya





_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
Reply | Threaded
Open this post in threaded view
|

Re: [bbv2] newbie: how to get value of a featureinside a rule

Daniel Einspanjer
Ohh Ohh! I have been struggling with trying to learn how to do this.
This example allowed me to at least see the value of my <customer> feature.
The next step for me is finding a way to be able to make a <define> based on
the value of <customer>.
e.g. In my main project, I would like to have the following in my
requirements section:
<define>CUSTOMER=$(customer)

I can't find a syntax that would allow me to do that.

If someone could spare just a moment to point me at some documentation that
demonstrates anything like this I would greatly appreciate it.

Just in case, here is the relevant portion of my jamroot:

# Set up our customer variable as a variant that can be specified on the
command line e.g.
feature customer : internal foo bar : implicit composite propagated
symmetric ;
feature.set-default customer : internal ;

# customize the internal customer to set this extra define.
feature.compose <customer>internal: <define>_AN_INTERNAL_BUILD ;

import notfile ;
notfile test : @print-customer ;
rule print-customer ( targets * : sources * : properties * )
{
    ECHO "Customer = " [ feature.get-values <customer> : $(properties) ] ;
}

project testproject
    : requirements

#        <define>CUSTOMER=[ feature.get-values <customer> : $(properties) ]


Thanks,

Daniel

"Vladimir Prus" <[hidden email]> wrote in message
news:[hidden email]...

> On Sunday 05 February 2006 14:31, Jaroslav Gresula wrote:
>> Could someone advise me how to retrieve value of a feature within a
>> rule? I followed an example from the docs which uses the toolset.flags
>> rule but with no luck.
>>
>> Below is my attempt, but the TOOLSET variable expands to an empty string.
>>
>> ---
>> local rule this-module-rule ( ) { return [ CALLER_MODULE ] ; }
>> local this-module = [ this-module-rule ] ;
>>
>> import toolset ;
>> toolset.flags $(this-module).print-toolset TOOLSET : <toolset> ;
>>
>> rule print-toolset ( )
>> {
>>    ECHO $(TOOLSET) ;
>> }
>>
>> alias main : : [ print-toolset ] ;
>
> This code is executed during Jamfile parsing stage. It calls the rule
> 'print-toolset', that immediately executes "ECHO", but the value of
> $(TOOLSET) is empty, because it's only set when bjam starts executing
> actions, and only if 'print-toolset' is the updating action for some
> target.
>
> Try this:
>
>  import notfile ;
>  import toolset ;
>  import feature ;
>
>  notfile test : @print-toolset ;
>
>  rule print-toolset ( targets * : sources * : properties * )
>  {
>      ECHO "Toolset = " [ feature.get-values <toolset> : $(properties) ] ;
>  }
>
> Note that if you run "bjam" with two different toolsets, say:
>
>    bjam gcc intel
>
> you'll see two "Toolset = " lines, one for each time "test" is built.
>
> You might also want to check the newly added FAQ item:
>
>    http://boost.org/boost-build2/doc/html/bbv2/faq.html#id2577795
>
> HTH,
> Volodya
>
>
>
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost-build
>


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
Reply | Threaded
Open this post in threaded view
|

Re: [bbv2] newbie: how to get value of afeatureinside a rule

Daniel Einspanjer
Hrm. I'm sorry, I should have read the new FAQ entry before I posted this.

The FAQ entry makes it sound like what I am wanting to do as a one liner is
not possible.
It sounds lie I would have to either create a feature.compose for every
customer I define or use conditional requirements for each customer I define
in the project section.

Does this sound correct that there is no one liner I can write that won't
require maintenance when adding customers?

If that is the case, should I do this as a feature.compose as I did the
extra <customer>internal define or should I do it as a conditional
requirement in the project?


"Daniel Einspanjer" <[hidden email]> wrote in message
news:dsaqkc$n5q$[hidden email]...

> Ohh Ohh! I have been struggling with trying to learn how to do this.
> This example allowed me to at least see the value of my <customer>
> feature.
> The next step for me is finding a way to be able to make a <define> based
> on
> the value of <customer>.
> e.g. In my main project, I would like to have the following in my
> requirements section:
> <define>CUSTOMER=$(customer)
>
> I can't find a syntax that would allow me to do that.
>
> If someone could spare just a moment to point me at some documentation
> that
> demonstrates anything like this I would greatly appreciate it.
>
> Just in case, here is the relevant portion of my jamroot:
>
> # Set up our customer variable as a variant that can be specified on the
> command line e.g.
> feature customer : internal foo bar : implicit composite propagated
> symmetric ;
> feature.set-default customer : internal ;
>
> # customize the internal customer to set this extra define.
> feature.compose <customer>internal: <define>_AN_INTERNAL_BUILD ;
>
> import notfile ;
> notfile test : @print-customer ;
> rule print-customer ( targets * : sources * : properties * )
> {
>    ECHO "Customer = " [ feature.get-values <customer> : $(properties) ] ;
> }
>
> project testproject
>    : requirements
>
> #        <define>CUSTOMER=[ feature.get-values <customer> :
> $(properties) ]
>
>
> Thanks,
>
> Daniel
>
> "Vladimir Prus" <[hidden email]> wrote in message
> news:[hidden email]...
>> On Sunday 05 February 2006 14:31, Jaroslav Gresula wrote:
>>> Could someone advise me how to retrieve value of a feature within a
>>> rule? I followed an example from the docs which uses the toolset.flags
>>> rule but with no luck.
>>>
>>> Below is my attempt, but the TOOLSET variable expands to an empty
>>> string.
>>>
>>> ---
>>> local rule this-module-rule ( ) { return [ CALLER_MODULE ] ; }
>>> local this-module = [ this-module-rule ] ;
>>>
>>> import toolset ;
>>> toolset.flags $(this-module).print-toolset TOOLSET : <toolset> ;
>>>
>>> rule print-toolset ( )
>>> {
>>>    ECHO $(TOOLSET) ;
>>> }
>>>
>>> alias main : : [ print-toolset ] ;
>>
>> This code is executed during Jamfile parsing stage. It calls the rule
>> 'print-toolset', that immediately executes "ECHO", but the value of
>> $(TOOLSET) is empty, because it's only set when bjam starts executing
>> actions, and only if 'print-toolset' is the updating action for some
>> target.
>>
>> Try this:
>>
>>  import notfile ;
>>  import toolset ;
>>  import feature ;
>>
>>  notfile test : @print-toolset ;
>>
>>  rule print-toolset ( targets * : sources * : properties * )
>>  {
>>      ECHO "Toolset = " [ feature.get-values <toolset> : $(properties) ] ;
>>  }
>>
>> Note that if you run "bjam" with two different toolsets, say:
>>
>>    bjam gcc intel
>>
>> you'll see two "Toolset = " lines, one for each time "test" is built.
>>
>> You might also want to check the newly added FAQ item:
>>
>>    http://boost.org/boost-build2/doc/html/bbv2/faq.html#id2577795
>>
>> HTH,
>> Volodya
>>
>>
>>
>>
>>
>> _______________________________________________
>> Unsubscribe & other changes:
>> http://lists.boost.org/mailman/listinfo.cgi/boost-build
>>
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost-build
>


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
Reply | Threaded
Open this post in threaded view
|

Re: [bbv2] newbie: how to get value of afeatureinside a rule

Vladimir Prus
On Tuesday 07 February 2006 22:10, Daniel Einspanjer wrote:

> Hrm. I'm sorry, I should have read the new FAQ entry before I posted this.
>
> The FAQ entry makes it sound like what I am wanting to do as a one liner is
> not possible.
> It sounds lie I would have to either create a feature.compose for every
> customer I define or use conditional requirements for each customer I
> define in the project section.
>
> Does this sound correct that there is no one liner I can write that won't
> require maintenance when adding customers?
Hi Daniel,

until yesterday, you really had to use either feature.compose or conditional
requirements.

Today, using CVS state or nightly build, you can use the following in Jamroot:


  import feature ;

  feature.feature customer : first second : propagated ;


  project
     : requirements <conditional>@customer-define
     ;

  rule customer-define ( properties * )
  {
      local c = [ feature.get-values <customer> : $(properties) ] ;
      return <define>CUSTOMER=$(c) ;
  }


The 'CUSTOMER' define will be added to all targets in Jamroot and in all child
Jamfiles. For convenience, I attach the testcase I've used. Go to the "sub"
directory and run "bjam -n". You should see the -DCUSTOMER=first option in
the command line (if you're using gcc, with msvc the option goes to response
file, so you'd need #ifdef in the source to make sure everything works)

- Volodya

*****************************************************************************
**                                                                         **
** WARNING:  This email contains an attachment of a very suspicious type.  **
** You are urged NOT to open this attachment unless you are absolutely     **
** sure it is legitmate.  Opening this attachment may cause irreparable    **
** damage to your computer and your files.  If you have any questions      **
** about the validity of this message, PLEASE SEEK HELP BEFORE OPENING IT. **
**                                                                         **
** This warning was added by the IU Computer Science Dept. mail scanner.   **
*****************************************************************************


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build

indirect2.zip (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [bbv2] newbie: how to get value of afeatureinsidea rule

Daniel Einspanjer
Volodya,

Thank you so much for taking the time to teach me about how this new feature
can help me.  I sincerely appreciate it.
Is it likely that this feature will be in the next release of V2 (which I
believe is soon, right)?

Daniel

"Vladimir Prus" <[hidden email]> wrote in message
news:[hidden email]...

> On Tuesday 07 February 2006 22:10, Daniel Einspanjer wrote:
>> Hrm. I'm sorry, I should have read the new FAQ entry before I posted
>> this.
>>
>> The FAQ entry makes it sound like what I am wanting to do as a one liner
>> is
>> not possible.
>> It sounds lie I would have to either create a feature.compose for every
>> customer I define or use conditional requirements for each customer I
>> define in the project section.
>>
>> Does this sound correct that there is no one liner I can write that won't
>> require maintenance when adding customers?
>
> Hi Daniel,
>
> until yesterday, you really had to use either feature.compose or
> conditional
> requirements.
>
> Today, using CVS state or nightly build, you can use the following in
> Jamroot:
>
>
>  import feature ;
>
>  feature.feature customer : first second : propagated ;
>
>
>  project
>     : requirements <conditional>@customer-define
>     ;
>
>  rule customer-define ( properties * )
>  {
>      local c = [ feature.get-values <customer> : $(properties) ] ;
>      return <define>CUSTOMER=$(c) ;
>  }
>
>
> The 'CUSTOMER' define will be added to all targets in Jamroot and in all
> child
> Jamfiles. For convenience, I attach the testcase I've used. Go to the
> "sub"
> directory and run "bjam -n". You should see the -DCUSTOMER=first option in
> the command line (if you're using gcc, with msvc the option goes to
> response
> file, so you'd need #ifdef in the source to make sure everything works)
>
> - Volodya
>
> *****************************************************************************
> **
> **
> ** WARNING:  This email contains an attachment of a very suspicious type.
> **
> ** You are urged NOT to open this attachment unless you are absolutely
> **
> ** sure it is legitmate.  Opening this attachment may cause irreparable
> **
> ** damage to your computer and your files.  If you have any questions
> **
> ** about the validity of this message, PLEASE SEEK HELP BEFORE OPENING IT.
> **
> **
> **
> ** This warning was added by the IU Computer Science Dept. mail scanner.
> **
> *****************************************************************************
>
>


--------------------------------------------------------------------------------


> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost-build
>


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
Reply | Threaded
Open this post in threaded view
|

Re: [bbv2] newbie: how to get value of afeatureinsidea rule

Vladimir Prus
On Wednesday 08 February 2006 18:21, Daniel Einspanjer wrote:
> Volodya,
>
> Thank you so much for taking the time to teach me about how this new
> feature can help me.  I sincerely appreciate it.
> Is it likely that this feature will be in the next release of V2

It will be there, for sure.

> (which I
> believe is soon, right)?

Looking on

    http://zigzag.cs.msu.su/boost.build/roadmap

we have 1 issue for M11 already closed, 1 almost done (the --clean changes)
and 1 to go. I think pretty soon ;-)

- Volodya
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
Reply | Threaded
Open this post in threaded view
|

Re: [bbv2] newbie: how to get value ofafeatureinsidea rule

Daniel Einspanjer
Woot.  Now if I could just get the silly SourceForge anon CVS access to
allow me to update so I can test this...  It's been down for me all day. :/

Daniel

"Vladimir Prus" <[hidden email]> wrote in message
news:[hidden email]...

> On Wednesday 08 February 2006 18:21, Daniel Einspanjer wrote:
>> Volodya,
>>
>> Thank you so much for taking the time to teach me about how this new
>> feature can help me.  I sincerely appreciate it.
>> Is it likely that this feature will be in the next release of V2
>
> It will be there, for sure.
>
>> (which I
>> believe is soon, right)?
>
> Looking on
>
>    http://zigzag.cs.msu.su/boost.build/roadmap
>
> we have 1 issue for M11 already closed, 1 almost done (the --clean
> changes)
> and 1 to go. I think pretty soon ;-)
>
> - Volodya
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost-build
>


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
Reply | Threaded
Open this post in threaded view
|

Re: [bbv2] newbie: how to get value ofafeatureinsidea rule

Vladimir Prus
On Wednesday 08 February 2006 19:58, Daniel Einspanjer wrote:
> Woot.  Now if I could just get the silly SourceForge anon CVS access to
> allow me to update so I can test this...  It's been down for me all day. :/

If everything else fails, you can get today's nightly build from

   http://zigzag.cs.msu.su/~ghost/boost-build.zip

Let me know when you have the change to download the current code and test
your use cases.

And yes, SF web access is unbelievable slow for me too.

- Volodya
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
Reply | Threaded
Open this post in threaded view
|

Re: [bbv2] newbie: how to get value ofafeatureinsidearule

Daniel Einspanjer
I did eventually get access to the CVS update and the <conditional> method
did work fine for what I needed.
Thanks so much for your help.

Daniel

"Vladimir Prus" <[hidden email]> wrote in message
news:[hidden email]...

> On Wednesday 08 February 2006 19:58, Daniel Einspanjer wrote:
>> Woot.  Now if I could just get the silly SourceForge anon CVS access to
>> allow me to update so I can test this...  It's been down for me all day.
>> :/
>
> If everything else fails, you can get today's nightly build from
>
>   http://zigzag.cs.msu.su/~ghost/boost-build.zip
>
> Let me know when you have the change to download the current code and test
> your use cases.
>
> And yes, SF web access is unbelievable slow for me too.
>
> - Volodya
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost-build
>


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build