From: Jim Weirich Date: 2005-03-30T04:57:34+09:00 Subject: 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)