Class: Inventory::Rake::Tasks::Compile
- Inherits:
-
Object
- Object
- Inventory::Rake::Tasks::Compile
- 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
-
#inventory ⇒ Inventory
writeonly
The inventory to use: VALUE.
Instance Method Summary collapse
-
#define ⇒ Object
Defines the following task:.
-
#initialize(options = {}) {|?| ... } ⇒ Compile
constructor
Sets up tasks based on INVENTORY, optionally yields the task object for further customization, then #defines the tasks.
Constructor Details
#initialize(options = {}) {|?| ... } ⇒ Compile
Sets up tasks based on INVENTORY, optionally yields the task object for further customization, then #defines the tasks.
15 16 17 18 19 |
# File 'lib/inventory-rake-1.0/tasks/compile.rb', line 15 def initialize( = {}) self.inventory = .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.
112 113 114 |
# File 'lib/inventory-rake-1.0/tasks/compile.rb', line 112 def inventory=(value) @inventory = value end |
Instance Method Details
#define ⇒ Object
Defines the following task:
<dl>
<dt>compile</dt>
<dd>Compile all extensions; depends on each compile:<em>name</em>.</dd>
</dl>
Then, for each extension in the inventory, define the following tasks:
<dl>
<dt>compile:<em>name</em></dt>
<dd>Compile extension <em>name</em>; depends on
lib/<em>path</em>/<em>so</em> file.</dd>
<dt>lib/<em>path</em>/<em>so</em></dt>
<dd>Installed dynamic library of extension <em>name</em> inside inventory
path; depends on ext/<em>name</em>/<em>so</em>.</dd>
<dt>ext/<em>name</em>/<em>so</em></dt>
<dd>Dynamic library of extension <em>name</em>; depends on
ext/<em>name</em>/Makefile and the source files of the extension.</dd>
<dt>ext/<em>name</em>/Makefile</dt>
<dd>Makefile for extension <em>name</em>; depends on inventory path,
ext/<em>name</em>/extconf.rb file, and ext/<em>name</em>/depend file.
Will be created by extconf.rb, which may take from environment
variable <em>name#upcase</em><code>_EXTCONF_OPTIONS</code> or
<code>EXTCONF_OPTIONS</code> if defined.</dd>
<dt>clean:<em>name</em></dt>
<dd>Clean files built for extension <em>name</em>; depended upon by
clean.</dd>
</dl>
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 = ENV['%s_EXTCONF_OPTIONS' % extension.to_s.upcase] || ENV['EXTCONF_OPTIONS'] file = '%s.options' % File.basename(extension.extconf) write = = begin File.open(file, 'rb', &:read) rescue Errno::ENOENT nil end unless ruby '%s %s' % [File.basename(extension.extconf), ] File.open(file, 'wb'){ |f| f.write() } 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 |