Code Comments
Programming Forum and web based access to our favorite programming groups.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.
Post Follow-up to this messageDaZoner <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
Post Follow-up to this messageDaZoner 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)
Post Follow-up to this messageOn 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
Post Follow-up to this messageOn 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
Post Follow-up to this messageThanks 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
Post Follow-up to this messageFound the problem. My bad. I assumed *.rb would catch *.RB and of course it doesn't.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.