Class: Rake::ExtensionTask

Inherits:
BaseExtensionTask show all
Defined in:
lib/rake/extensiontask.rb

Instance Attribute Summary collapse

Attributes inherited from BaseExtensionTask

#config_options, #ext_dir, #extra_options, #extra_sources, #gem_spec, #lib_dir, #name, #platform, #source_pattern, #tmp_dir

Instance Method Summary collapse

Methods inherited from BaseExtensionTask

#initialize

Constructor Details

This class inherits a constructor from Rake::BaseExtensionTask

Instance Attribute Details

#config_includesObject

Returns the value of attribute config_includes.



17
18
19
# File 'lib/rake/extensiontask.rb', line 17

def config_includes
  @config_includes
end

#config_scriptObject

Returns the value of attribute config_script.



12
13
14
# File 'lib/rake/extensiontask.rb', line 12

def config_script
  @config_script
end

#cross_compileObject

Returns the value of attribute cross_compile.



13
14
15
# File 'lib/rake/extensiontask.rb', line 13

def cross_compile
  @cross_compile
end

#cross_config_options(for_platform = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rake/extensiontask.rb', line 70

def cross_config_options(for_platform=nil)
  return @cross_config_options unless for_platform

  # apply options for this platform, only
  @cross_config_options.map do |option|
    if option.kind_of?(Hash)
      option[for_platform] || []
    else
      option
    end
  end.flatten
end

#cross_platformObject



34
35
36
# File 'lib/rake/extensiontask.rb', line 34

def cross_platform
  @cross_platform ||= 'i386-mingw32'
end

#no_nativeObject

Returns the value of attribute no_native.



16
17
18
# File 'lib/rake/extensiontask.rb', line 16

def no_native
  @no_native
end

Instance Method Details

#binary(platform = nil) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/rake/extensiontask.rb', line 42

def binary(platform = nil)
  if platform == "java"
    "#{name}.#{RbConfig::MAKEFILE_CONFIG['DLEXT']}"
  else
    super
  end
end

#cross_compiling(&block) ⇒ Object



38
39
40
# File 'lib/rake/extensiontask.rb', line 38

def cross_compiling(&block)
  @cross_compiling = block if block_given?
end

#defineObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rake/extensiontask.rb', line 50

def define
  super

  unless compiled_files.empty?
    warn "WARNING: rake-compiler found compiled files in '#{@ext_dir}' directory. Please remove them."
  end

  # only gems with 'ruby' platforms are allowed to define native tasks
  define_native_tasks if !@no_native && (@gem_spec && @gem_spec.platform == 'ruby')

  # only define cross platform functionality when enabled
  return unless @cross_compile

  if cross_platform.is_a?(Array) then
    cross_platform.each { |platf| define_cross_platform_tasks(platf) }
  else
    define_cross_platform_tasks(cross_platform)
  end
end

#init(name = nil, gem_spec = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rake/extensiontask.rb', line 19

def init(name = nil, gem_spec = nil)
  super
  @config_script = 'extconf.rb'
  @source_pattern = "*.{c,cc,cpp}"
  @compiled_pattern = "*.{o,obj,so,bundle,dSYM}"
  @cross_compile = false
  @cross_config_options = []
  @cross_compiling = nil
  @no_native = (ENV["RAKE_EXTENSION_TASK_NO_NATIVE"] == "true")
  @config_includes = []
  # Default to an empty list of ruby versions for each platform
  @ruby_versions_per_platform = Hash.new { |h, k| h[k] = [] }
  @make = nil
end

#make_makefile_cmd(root_path, tmp_path, extconf, cross_platform) ⇒ Object

:nodoc:



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rake/extensiontask.rb', line 83

def make_makefile_cmd(root_path, tmp_path, extconf, cross_platform) # :nodoc:
  # include current directory
  include_dirs = ['.'].concat(@config_includes).uniq.join(File::PATH_SEPARATOR)

  # build a relative path to extconf script
  abs_tmp_path = (Pathname.new(root_path) + tmp_path).realpath
  abs_extconf = (Pathname.new(root_path) + extconf).realpath
  rel_extconf = abs_extconf.relative_path_from(abs_tmp_path).to_s

  # base command
  cmd = [Gem.ruby, "-I#{include_dirs}", rel_extconf]

  # add all the options
  cmd += @config_options
  cmd += cross_config_options(cross_platform) if cross_platform
  cmd += extra_options

  cmd.compact
end