On Thursday 31 March 2005 06:34 pm, Mark Probert wrote:
> I did get around to reading more of the documentation and have ended up
> using rules.  My results where very similar to yours.
>
> When I created th.h -> .cpp rule, it would run against all .h files that it
> could find, rather than just the unit test ones.  So I ended up with:

Rules can be based on more than just file extensions.  The target can be a 
regular expression and the dependency can be an arbitrary lambda that does a 
transform.  The following (untested) might work for you ...

rule(/^test\d+\.cpp$/, '.h') do |t|
  sh "#{CXXTEST} #{CXXTESTOPT} -o #{t.name} #{t.source}"
end

> I have also found that it is useful to have a dependency list for the
> various UTs, as not all of the UTs required all of the files of the
> application.  So, something like the following works:

Likewise, a pattern based rule might work here too (again, untested):

rule(/^test\d+$/, '.cpp') do |t|
  sh "#{CC} #{CCOPT} -o #{t.name} #{t.prerequisites.join(' ')}"
end

And then the dependencies can be given explicitly.

file "test1" => ["test1.cpp", "foo.o"]
file "test2" => ["test2.cpp", "bar.o"]
file "test3" => ["test3.cpp", "foo.o", "bar.o"]

This become really powerful when you can write a little ruby to scan your 
source for #includes and generate the dependencies automatically.

Hmmm ... now that I look at the above, I'm wondering if the explicit 
dependencies will prevent the rules from triggering.  Try it and let me know 
if it doesn't work here.

> The first question:  is there a way to factor the UT drivers into a rule? 
> I can't seem to get the dependcies right.

> Second:  What is the best way of making this work in a sub-directory?  Use
> explicit paths in the UT_*_DEP lines to ensure the link is right?  Have a
> Rakefile in the UT director driven by one in the main directory?

I'm not a big fan of having one Rakefile invoke a Rakefile in a subdirectory.  
I  would rather see one Rakefile control the whole process. (You can get 
finer grain dependencies that way).  An alternative would be to place 
Rakefile fragments in the directories and have a main rakefile load them.  
The downside to this is that there is no namespaces in the Rakefile, all 
tasks exist at a single global level, so there would need to be some 
coordination between the subdirectories.

> Have you thought of doing the equivalent of Jambase and having a packaged
> library of default rules that will be applied, based on the platform that
> Rake is invoked on?  So, if Linux, CC=gcc, if Win32 CC=cl, etc..

Yep.  I'm thinking through some ways of making namespaces work with Rake tasks 
and how library modules might fit into this.  When RubyGems slows down a bit, 
I plan to revisit Rake and do something along the lines that you suggest.

Thanks for the feedback.

-- 
-- Jim Weirich    jim / weirichhouse.org     http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct, 
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)