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) ⇒ Object

Raises:



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
# File 'lib/rbbt/resource/rake.rb', line 4

def self.run(rakefile, dir, task)
  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

  if block_given?
    yield
  else
    load rakefile
  end

  raise TaskNotFound if Rake::Task[task].nil?

  t = nil
  pid = Process.fork{
    Misc.pre_fork
    begin
      Misc.in_dir(dir) do
        Rake::Task[task].invoke

        Rake::Task.clear
        Rake::FileTask.clear_files
      end
    rescue Exception
      Log.error "Error in rake: #{$!.message}"
      Log.exception $!
      Kernel.exit! -1
    end
    Kernel.exit! 0
  }
  Process.waitpid(pid)
  raise "Rake failed" unless $?.success?

end