[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Rake newbie needs help

DaZoner

3/29/2005 6:55:00 PM


I've read the rake docs online and I've got a very simple rakefile to work.
Now I'd like to make it more complex and I can't figure out how to do it.
Can anyone let me know if what I want to do is possible and how to do it?

Why doesn't the following rakefile print "Making ..."?

task :default => [:build]

task :build do
print "In build\n"
file "newzip.zip" do |t|
print "Making ",t.name,"\n"
end
end

Also I'd like to give the filetask prereq's saying only do this step if the
file is out of date with *.rb and data/*.dat. Can I do this? Does it look
like this?

file "zipfile.zip" => ["*.rb","data/*.dat"] do |t|
end

Thanks for your help.


6 Answers

Tilman Sauerbeck

3/29/2005 7:27:00 PM

0

DaZoner <bugmenot@world.com> [2005-03-30 04:19]:
> I've read the rake docs online and I've got a very simple rakefile to work.
> Now I'd like to make it more complex and I can't figure out how to do it.
> Can anyone let me know if what I want to do is possible and how to do it?
>
> Why doesn't the following rakefile print "Making ..."?
>
> task :default => [:build]
>
> task :build do
> print "In build\n"
> file "newzip.zip" do |t|
> print "Making ",t.name,"\n"
> end
> end

Because rake doesn't see the need to invoke the "newzip.zip" task.
Your build task does *not* depend on the "newzip.zip" task! :)

The following line would add that dependency:
task :build => ["newzip.zip"]

> Also I'd like to give the filetask prereq's saying only do this step if the
> file is out of date with *.rb and data/*.dat. Can I do this? Does it look
> like this?
>
> file "zipfile.zip" => ["*.rb","data/*.dat"] do |t|
> end

Yep. This looks like Rake's PackageTask would also help :]

--
Regards,
Tilman


Jim Weirich

3/29/2005 7:58:00 PM

0


DaZoner said:
> I've read the rake docs online and I've got a very simple rakefile to
> work.
> Now I'd like to make it more complex and I can't figure out how to do it.
> Can anyone let me know if what I want to do is possible and how to do it?
>
> Why doesn't the following rakefile print "Making ..."?
>
> task :default => [:build]
>
> task :build do
> print "In build\n"
> file "newzip.zip" do |t|
> print "Making ",t.name,"\n"
> end
> end

Hi DaZoner ... welcome to Rake!

Let me rewrite your Rakefile and then talk about the changes ... I think
you were wanting something along these lines ...

task :default => [:build]

task :build => ["newzip.zip"] do
puts "Done building"
end

file "newzip.zip" do |t|
print "Making ",t.name,"\n"
end

In your version, you nested the newzip.zip file task inside the build
task. That meant that the task wasn't defined until you invoked build.
That's a perfectly fine thing to do and is great for the dynamic building
of tasks, but its a more advanced concept. I suspect you only want the
build task to invoke the newzip.zip task whenever necessary. So, put both
tasks at the top level and list newzip.zip as a dependency of build.

The other subtle thing is that the message "In Build" prints *after* the
newzip.zip task is complete. The body of a task only executes after all
the prerequisites are finished. I changed the message to read "Build
Done" to emphasize that.

> Also I'd like to give the filetask prereq's saying only do this step if
> the
> file is out of date with *.rb and data/*.dat. Can I do this? Does it look
> like this?
>
> file "zipfile.zip" => ["*.rb","data/*.dat"] do |t|
> end

Close. "*.rb" is not a file name, but a pattern for a file name. It must
be expanded to a list of files to be useful. You can use a FileList
object to do that ...

file "zipfile.zip" => FileList['*.rb', 'data/*.dat'] do |t| ... end

--
-- Jim Weirich jim@weirichhouse.org http://onest...
-----------------------------------------------------------------
"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)



Stefan Lang

3/29/2005 8:10:00 PM

0

On Tuesday 29 March 2005 21:19, DaZoner wrote:
> I've read the rake docs online and I've got a very simple rakefile to work.
> Now I'd like to make it more complex and I can't figure out how to do it.
> Can anyone let me know if what I want to do is possible and how to do it?
>
> Why doesn't the following rakefile print "Making ..."?
>
> task :default => [:build]
>
> task :build do
> print "In build\n"
> file "newzip.zip" do |t|
> print "Making ",t.name,"\n"
> end
> end
>
> Also I'd like to give the filetask prereq's saying only do this step if the
> file is out of date with *.rb and data/*.dat. Can I do this? Does it look
> like this?
>
> file "zipfile.zip" => ["*.rb","data/*.dat"] do |t|
> end
>
> Thanks for your help.

I think you really want this:

task :default => ["newzip.zip"]

file "newzip.zip" => ["*.rb", "data/*.dat"] do |t|
puts "Making #{t.name}"
end

The "file" function already defines a task for you.
You don't need to wrap a task around you "file" definition.

When your "build" task was run, it *defined* the "newzip.zip" task.

Stefan


Stefan Lang

3/29/2005 8:16:00 PM

0

On Tuesday 29 March 2005 22:10, Stefan Lang wrote:
> On Tuesday 29 March 2005 21:19, DaZoner wrote:
> > I've read the rake docs online and I've got a very simple rakefile to
> > work. Now I'd like to make it more complex and I can't figure out how to
> > do it. Can anyone let me know if what I want to do is possible and how to
> > do it?
> >
> > Why doesn't the following rakefile print "Making ..."?
> >
> > task :default => [:build]
> >
> > task :build do
> > print "In build\n"
> > file "newzip.zip" do |t|
> > print "Making ",t.name,"\n"
> > end
> > end
> >
> > Also I'd like to give the filetask prereq's saying only do this step if
> > the file is out of date with *.rb and data/*.dat. Can I do this? Does it
> > look like this?
> >
> > file "zipfile.zip" => ["*.rb","data/*.dat"] do |t|
> > end
> >
> > Thanks for your help.
>
> I think you really want this:
>
> task :default => ["newzip.zip"]
>
> file "newzip.zip" => ["*.rb", "data/*.dat"] do |t|
^^^^^^^^^^^^^^^^^^^^^^
Sorry. Should be: FileList["*.rb", "data/*.dat"]
> puts "Making #{t.name}"
> end
>
> The "file" function already defines a task for you.
> You don't need to wrap a task around you "file" definition.
>
> When your "build" task was run, it *defined* the "newzip.zip" task.
>
> Stefan


DaZoner

3/29/2005 9:03:00 PM

0


Thanks Jim (and thanks for the tool). I've made changes to my rakefile and
it almost works flawlessly. The only problem is that if I change "*.rb" my
filetask fires but if I change a "reports/*.rb" it does not. (Note how I'm
using "reports/*.rb" instead of the old "data/*.dat" purposely here). Any
idea what I've done wrong? Here is my mini-rakefile that shows the problem:


MyZip = "newzip.zip"

task :default => [:build]

task :build => [MyZip] do
print "Build done\n"
end

dependencies = FileList['*.rb','reports/*.rb']

file MyZip => dependencies do |t|

print "Making ",t.name,"\n"

# zipping code is here

print t.name," made!\n"
end



DaZoner

3/30/2005 4:17:00 PM

0

Found the problem. My bad. I assumed *.rb would catch *.RB and of course it
doesn't.