Module: Rake
- Defined in:
- lib/rbbt/resource/rake.rb
Defined Under Namespace
Classes: TaskNotFound
Class Method Summary collapse
Class Method Details
.run(rakefile, dir, task, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rbbt/resource/rake.rb', line 4 def self.run(rakefile, dir, task, &block) old_pwd = FileUtils.pwd Rake::FileTask.module_eval do if not self.respond_to? :old_define_task class << self alias_method :old_define_task, :define_task end def self.define_task(file, *args, &block) @@files ||= [] @@files << file old_define_task(file, *args, &block) end end def self.files @@files end def self.clear_files @@files = [] end end Rake::Task.clear Rake::FileTask.clear_files t = nil pid = Process.fork{ if block_given? TOPLEVEL_BINDING.receiver.instance_exec &block else if Misc.is_filename? rakefile load rakefile else TmpFile.with_file(rakefile) do |tmpfile| load tmpfile end end end raise TaskNotFound if Rake::Task[task].nil? Misc.pre_fork begin Misc.in_dir(dir) do Rake::Task[task].invoke Rake::Task.clear Rake::FileTask.clear_files end rescue Log.error "Error in rake: #{$!.}" Log.exception $! Kernel.exit! -1 end Kernel.exit! 0 } Process.waitpid(pid) raise "Rake failed" unless $?.success? end |