Class: Inventory::Rake::Tasks::Compile

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/inventory-rake-1.0/tasks/compile.rb

Overview

Defines tasks for compiling and cleaning extensions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|?| ... } ⇒ Compile

Sets up tasks based on INVENTORY, optionally yields the task object for further customization, then #defines the tasks.

Parameters:

  • (defaults to: {})

Options Hash (options):

  • :inventory (Inventory) — default: Inventory::Rake::Tasks.inventory

    The inventory to use

Yields:

  • (?)

Yield Parameters:

  • task (self)


15
16
17
18
19
# File 'lib/inventory-rake-1.0/tasks/compile.rb', line 15

def initialize(options = {})
  self.inventory = options.fetch(:inventory, Inventory::Rake::Tasks.inventory)
  yield self if block_given?
  define
end

Instance Attribute Details

#inventory=(value) ⇒ Inventory (writeonly)

Returns The inventory to use: VALUE.

Parameters:

Returns:

  • The inventory to use: VALUE



112
113
114
# File 'lib/inventory-rake-1.0/tasks/compile.rb', line 112

def inventory=(value)
  @inventory = value
end

Instance Method Details

#defineObject

Defines the following task:

compile
Compile all extensions; depends on each compile:name.

Then, for each extension in the inventory, define the following tasks:

compile:name
Compile extension name; depends on lib/path/so file.
lib/path/so
Installed dynamic library of extension name inside inventory path; depends on ext/name/so.
ext/name/so
Dynamic library of extension name; depends on ext/name/Makefile and the source files of the extension.
ext/name/Makefile
Makefile for extension name; depends on inventory path, ext/name/extconf.rb file, and ext/name/depend file. Will be created by extconf.rb, which may take options from environment variable name#upcase_EXTCONF_OPTIONS or EXTCONF_OPTIONS if defined.
clean:name
Clean files built for extension name; depended upon by clean.

Finally, if defined, the test task is set to depend on the compile task.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/inventory-rake-1.0/tasks/compile.rb', line 57

def define
  desc 'Compile extensions' unless Rake::Task.task_defined? :compile
  task :compile

  @inventory.extensions.each do |extension|
    name = :"compile:#{extension}"
    makefile = '%s/Makefile' % extension.directory
    ext_so = '%s/%s.%s' % [extension.directory,
                           extension.name.delete('-'),
                           RbConfig::CONFIG['DLEXT']]
    lib_so = 'lib/%s/%s' % [@inventory.package_path, File.basename(ext_so)]

    task :compile => name

    task name => lib_so

    file lib_so => ext_so do
      install ext_so, lib_so
    end

    file ext_so => [makefile] + extension.source_files do
      sh 'make -C %s' % extension.directory
    end

    file makefile => [@inventory.path, extension.extconf, extension.depend] do
      Dir.chdir extension.directory do
        options = ENV['%s_EXTCONF_OPTIONS' % extension.to_s.upcase] || ENV['EXTCONF_OPTIONS']
        file = '%s.options' % File.basename(extension.extconf)
        write = options
        options = begin
                    File.open(file, 'rb', &:read)
                  rescue Errno::ENOENT
                    nil
                  end unless options
        ruby '%s %s' % [File.basename(extension.extconf), options]
        File.open(file, 'wb'){ |f| f.write(options) } if write
      end
    end

    %w[clean distclean].each do |cname|
      clean_name = :"#{cname}:#{extension}"
      desc 'Clean files built for extension %s' % extension
      task clean_name do
        sh 'make -C %s %s' % [extension.directory, cname] if File.exist? makefile
      end

      task :"#{cname}" => clean_name
    end
  end

  task :test => :compile if Rake::Task.task_defined? :test
end