Sha256: 749f069f890c22adb2e88e6c1cb63fe0b947f32bc858618fc9ba67a0b7cdcae8

Contents?: true

Size: 1.13 KB

Versions: 13

Compression:

Stored size: 1.13 KB

Contents

require 'rake'
module Rake
  class TaskNotFound < StandardError; end
  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
        Log.error "Error in rake: #{$!.message}"
        Kernel.exit! -1
      end
    }
    Process.waitpid(pid)
    raise "Rake failed" unless $?.success?

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rbbt-util-5.14.28 lib/rbbt/resource/rake.rb
rbbt-util-5.14.26 lib/rbbt/resource/rake.rb
rbbt-util-5.14.25 lib/rbbt/resource/rake.rb
rbbt-util-5.14.24 lib/rbbt/resource/rake.rb
rbbt-util-5.14.23 lib/rbbt/resource/rake.rb
rbbt-util-5.14.22 lib/rbbt/resource/rake.rb
rbbt-util-5.14.21 lib/rbbt/resource/rake.rb
rbbt-util-5.14.20 lib/rbbt/resource/rake.rb
rbbt-util-5.14.18 lib/rbbt/resource/rake.rb
rbbt-util-5.14.17 lib/rbbt/resource/rake.rb
rbbt-util-5.14.16 lib/rbbt/resource/rake.rb
rbbt-util-5.14.15 lib/rbbt/resource/rake.rb
rbbt-util-5.14.14 lib/rbbt/resource/rake.rb