Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Rake newbie needs help
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.



Report this thread to moderator Post Follow-up to this message
Old Post
DaZoner
03-29-05 09:01 PM


Re: Rake newbie needs help
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 th
e
> 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



Report this thread to moderator Post Follow-up to this message
Old Post
Tilman Sauerbeck
03-29-05 09:01 PM


Re: Rake newbie needs help
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://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)




Report this thread to moderator Post Follow-up to this message
Old Post
Jim Weirich
03-30-05 02:00 AM


Re: Rake newbie needs help
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 th
e
> 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



Report this thread to moderator Post Follow-up to this message
Old Post
Stefan Lang
03-30-05 02:00 AM


Re: Rake newbie needs help
On Tuesday 29 March 2005 22:10, Stefan Lang wrote:
> On Tuesday 29 March 2005 21:19, DaZoner wrote: 
>
> 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



Report this thread to moderator Post Follow-up to this message
Old Post
Stefan Lang
03-30-05 02:00 AM


Re: Rake newbie needs help
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




Report this thread to moderator Post Follow-up to this message
Old Post
DaZoner
03-30-05 02:00 AM


Re: Rake newbie needs help
Found the problem. My bad. I assumed *.rb would catch *.RB and of course it
doesn't.



Report this thread to moderator Post Follow-up to this message
Old Post
DaZoner
03-30-05 09:01 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Ruby archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:49 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.