From: "Joe Wölfel" Date: 2008-09-26T01:24:09+09:00 Subject: Re: Rake dependencies unknown prior to running tasks Thanks for the patch. Here's a clunkier variation on your suggestion that seems to work with Drake. Stage 1 serializes an unpredictable set of tasks. Stage 2 creates instances of them and runs them if necessary. There might be a better way that involves making the dependency tree modifiable dynamically. I think allowing all possible dependency changes would get complicated. Maybe that would require reevaluating the entire tree constantly and there's no way to un-execute a task anyway. But most of the real world problems I can think of seem to involve adding tasks that wouldn't have been exercised yet anyway. Could this be solved with an improved dependency tree walking algorithm? require 'rake/clean' # Stage 1 puts a random set of numbers in a file STAGE_ONE_RESULTS = "s1.txt" file STAGE_ONE_RESULTS do open(STAGE_ONE_RESULTS, 'wb') do |file| (1..5).map{|i|rand 10}.uniq.each do |i| puts "stage1 creating dependency #{i}" file.puts i end end end task :stage1 => STAGE_ONE_RESULTS # Stage 2 creates task based on those random numbers task :stage2 => :stage1 if File.exists? STAGE_ONE_RESULTS IO.readlines(STAGE_ONE_RESULTS).each do |task_info| task task_info do puts "stage2 executing #{task_info}" end task :stage2 => task_info end end task :all => :stage1 do puts `drake -j4 stage2` end CLEAN.include STAGE_ONE_RESULTS task :default => :all On 24 sept. 08, at 20:29, James M. Lawrence wrote: > > If only the Internet came with an Undo button... > > Since in the previous example Rake complains unless main_a and main_b > are defined, it sort of defeats the whole purpose. This works: > > task :setup_a do > puts "setup_a" > end > > task :setup_b do > puts "setup_b" > end > > task :setup => [:setup_a, :setup_b] do > puts "setup phase complete. defining new tasks..." > > task :main_a do > puts "main_a" > end > > task :main_b do > puts "main_b" > end > > puts "restarting..." > throw :restart > end > > task :main => [:main_a, :main_b] do > puts "main phase complete." > end > > task :default => [:setup, :main] do > puts "all done." > end > > However this defeats Drake, which I suppose is another matter. > -- > Posted via http://www.ruby-forum.com/. >