Sha256: 7fdfdf75a58f386bfd63f83f71cdef8fa0bc501b71ce24cbbc31c305f08b732c

Contents?: true

Size: 1.39 KB

Versions: 12

Compression:

Stored size: 1.39 KB

Contents

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

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rbbt-util-5.44.1 lib/rbbt/resource/rake.rb
rbbt-util-5.43.0 lib/rbbt/resource/rake.rb
rbbt-util-5.42.0 lib/rbbt/resource/rake.rb
rbbt-util-5.41.1 lib/rbbt/resource/rake.rb
rbbt-util-5.41.0 lib/rbbt/resource/rake.rb
rbbt-util-5.40.5 lib/rbbt/resource/rake.rb
rbbt-util-5.40.4 lib/rbbt/resource/rake.rb
rbbt-util-5.40.3 lib/rbbt/resource/rake.rb
rbbt-util-5.40.0 lib/rbbt/resource/rake.rb
rbbt-util-5.39.0 lib/rbbt/resource/rake.rb
rbbt-util-5.38.1 lib/rbbt/resource/rake.rb
rbbt-util-5.38.0 lib/rbbt/resource/rake.rb