Patrick Doyle
10/21/2008 5:43:00 PM
[Note: parts of this message were removed to make it a legal post.]
>
> task :default do
> @name = "do some stuff here to get path and name"
> Rake::Task[:go].invoke
> end
>
> task :go =>["#{@name}.c"]
>
> rule '.c' => ['.xml'] do |t|
> p t.name
> p t.source
> end
>
> rule '.xml' do
> #create the xml file in here
> end
>
> The misunderstanding is in how rakefiles get interpreted. A rakefile is
simply a bunch of Ruby code. When you invoke rake at the command line, it
effectively loads a few libraries, which define some handy methods for you,
and then hands your rakefile off to the Ruby interpreter.
One of those "handy methods" I mentioned was one called "task" which takes
takes an argument (or two, or three) and a block. It records the first
argument as the name of the task (and records things like the prerequisites
and argument names if you pass more parameters) and it records the block to
be executed if/when that named task gets invoked.
By default, after the Ruby interpreter interprets all of the Ruby code in
the makefile, the rake utility invokes the task named :default.
So, in your case, when the interpreter hits the first "task" method call, it
records the name, :default, and some code to be executed if/when the
:default task is executed. Notice that the code inside the "do" block is
not executed at this point.
When the interpreter hits the second "task" method call, it records the
name, :go, and says that that task has a prerequisite of, hmmm... at that
point, the interpreter doesn't know anything about @name, so the :go task
has a prerequisite of ".c".
At least, that's what I think is going on. Try replacing the line that
reads:
task :go =>["#{@name}.c"]
with a line that reads:
task :go =>["blah.c"]
and see if that gives you more insight into what's going on.
I'm not sure I have any good suggestions for accomplishing what you want to
do. One idea might be to recognize that a Rakefile is simply ruby code, and
instead of defining a '.c' => ['.xml'] rule, you could define a method:
def c_to_xml(source)
sh blah blah blah
end
and invoke #c_to_xml from your :default task.
hth
--wpd