0

I have an action defined that generates coverage files, it takes some options.

actions coverage {
    echo coverage $(OPTIONS) >> $(<)
}

I need a rule to set the $(OPTIONS) variable:

rule coverage ( targets * : sources * : properties * ) {
    OPTIONS on $(targets) = ...  # Get from environment variables
}

Once I have done that, I can use the rule to generate coverage files:

make cov.xml : : @coverage ;

What I want is a second rule (that computes the $(OPTIONS) variable in a different way), that uses the same actions. Is that possible without duplicating the action itself? In other words, is it possible to associate two rules with the same action?

What I want is something like this:

actions coverage-from-features {
    # AVOID HAVING TO REPEAT THIS
    echo coverage $(OPTIONS) >> $(<)
}
rule coverage-from-features ( targets * : sources * : properties * ) {
    OPTIONS on $(targets) = ...  # Get from feature values
}
make cov2.xml : : @coverage-from-features ;

Obviously without repeating the action commands itself (DRY and all that).

Christian Aichinger
  • 6,989
  • 4
  • 40
  • 60

1 Answers1

0

The key aspect you need is that: You don't need to use actions that mirror the rule invoked. A rule can call any, and multiple actions, to do the work. In your case you can do something like:

actions coverage-action {
  echo coverage $(OPTIONS) >> $(<)
}

rule coverage ( targets * : sources * : properties * ) {
  OPTIONS on $(targets) = ... ; # Get from environment variables
  coverage-action $(target) : $(sources) ;
}

rule coverage-from-features ( targets * : sources * : properties * ) {
  OPTIONS on $(targets) = ... ; # Get from feature values
  coverage-action $(target) : $(sources) ;
}

make cov.xml : : @coverage ;
make cov2.xml : : @coverage-from-features ;
GrafikRobot
  • 3,020
  • 1
  • 20
  • 21
  • Doesn't seem to work for me with "Boost.Build V2 (Milestone 12) Boost.Jam 03.1.19". Copied your code into a Jamroot file in an empty folder, `bjam; bjam cov.xml; bjam cov2.xml`. Produced build directories but not output files, apparently the action was not executed (confirmed with -d+2) – Christian Aichinger Apr 27 '16 at 15:40