Class: Shoe::Tasks::Compile

Inherits:
Task
  • Object
show all
Defined in:
lib/shoe/tasks/compile.rb

Overview

Defines `rake compile` to build your C extensions.

Uses {Gem::Ext::ExtConfBuilder}[http://rubygems.rubyforge.org/rubygems-update/Gem/Ext/ExtConfBuilder.html], so extensions are compiled locally just as they will be with `gem install`. Your users will thank you.

To enable and configure, add extensions[http://docs.rubygems.org/read/chapter/20#extensions] to your gemspec.

Instance Attribute Summary

Attributes inherited from Task

#spec

Instance Method Summary collapse

Methods inherited from Task

#initialize

Constructor Details

This class inherits a constructor from Shoe::Tasks::Task

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/shoe/tasks/compile.rb', line 17

def active?
  !spec.extensions.empty?
end

#defineObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/shoe/tasks/compile.rb', line 21

def define
  desc <<-END.gsub(/^ */, '')
    Compile C extensions.
    Configure via the `extensions` field in #{spec.name}.gemspec.
  END

  task :compile do
    top_level_path   = File.expand_path('.')
    destination_path = File.join(top_level_path, spec.require_paths.first)

    spec.extensions.each do |extension|
      Dir.chdir File.dirname(extension) do
        Gem::Ext::ExtConfBuilder.build(
          extension,
          top_level_path,
          destination_path,
          results = []
        )
      end
    end
  end

  task :prepare => :compile
end