Joel VanderWerf
3/20/2006 6:05:00 PM
Jim Weirich wrote:
> Joel VanderWerf wrote:
>> Is it possible to have a rule which has a prerequisite specified by a
>> proc and also a FileList? I can use several procs, as a workaround:
>>
>> generic_files = [proc {"foo"}, proc {"bar"}, proc {"baz"}]
>> rule /^site_\w+/ => [
>> proc {|fn| site_cfg_file(fn)},
>> *generic_files
>> ] do ... end
>>
>>
>> But it would be nice to use a FileList. However, when I try
>>
>> generic_files = FileList["foo", "bar", "baz"]
>>
>> rake says it doesn't know how to build the task.
>>
>> Is there a better way of doing this?
>
> Actually that should work. If rake is reporting that it cannot build
> your task, then probably one of the prerequisites cannot be built.
> Remember, your rule says that you can build a site_XXX file if the
> following file (or rules to build the following files) exist:
> site_cfg_file(fn), "foo", "bar" and "baz". I would check to see if
> "foo", "bar" and "baz" all exist.
Here's what happens in this example:
---------
generic_files = [proc {"foo"}, proc {"bar"}, proc {"baz"}]
#generic_files = FileList["foo", "bar", "baz"]
rule /^site_\w+/ => [
proc {|fn| "__#{fn}"},
*generic_files
] do |t|
p t.name
end
task :__site_stuff
file "foo" do touch "foo"; end
file "bar" do touch "bar"; end
file "baz" do touch "baz"; end
---------
As it is, it works:
$ rake site_stuff
(in /home/vjoel/ruby/misc/rake)
touch foo
touch bar
touch baz
"site_stuff"
But when I flip comments on the first two lines, I get:
$ rake site_stuff --trace
(in /home/vjoel/ruby/misc/rake)
rake aborted!
Don't know how to build task 'site_stuff'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:1287:in `[]'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:300:in `[]'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:1719:in `run'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.0/lib/rake.rb:1719:in `run'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.0/bin/rake:7
/usr/local/bin/rake:18
Furthermore, if I comment out the proc:
# proc {|fn| "__#{fn}"},
(still using the FileList) then rake goes into a tailspin:
$ rake site_stuff --trace
(in /home/vjoel/ruby/misc/rake)
rake aborted!
Rule Recursion Too Deep: [site_stuff => site_stuff => site_stuff =>
site_stuff =.......
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407