Module: Debase::RubyCoreSource
- Defined in:
- lib/debase/ruby_core_source.rb,
lib/debase/ruby_core_source/version.rb
Constant Summary collapse
- REVISION_MAP =
{ 37411 => 'ruby-2.0.0-preview1', 38126 => 'ruby-2.0.0-preview2', 38733 => 'ruby-2.0.0-rc1', 39161 => 'ruby-2.0.0-rc2', 47618 => 'ruby-2.2.0-preview1', 48629 => 'ruby-2.2.0-preview2', 48887 => 'ruby-2.2.0-rc1', }
- VERSION =
'0.8.0'
Class Method Summary collapse
- .create_makefile_with_core(hdrs, name) ⇒ Object
- .deduce_packaged_source_dir(ruby_dir) ⇒ Object
- .fallback_source_warning(ruby_version, fallback_version) ⇒ Object
- .no_source_abort(ruby_version) ⇒ Object
- .ruby_source_dir_version(dir) ⇒ Object
Class Method Details
.create_makefile_with_core(hdrs, name) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/debase/ruby_core_source.rb', line 16 def self.create_makefile_with_core(hdrs, name) # First, see if the gem already has the needed headers if hdrs.call create_makefile(name) return true end ruby_dir = if RUBY_PATCHLEVEL < 0 REVISION_MAP[RUBY_REVISION] or no_source_abort("ruby-#{RUBY_VERSION} (revision #{RUBY_REVISION})") else "ruby-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" end # Check if core headers were already downloaded; if so, use them if RbConfig::CONFIG["rubyhdrdir"] dest_dir = RbConfig::CONFIG["rubyhdrdir"] + "/" + ruby_dir with_cppflags("-I" + dest_dir) { if hdrs.call create_makefile(name) return true end } end # Look for sources that ship with gem dest_dir = deduce_packaged_source_dir(ruby_dir) no_source_abort(ruby_dir) unless File.directory?(dest_dir) with_cppflags("-I" + dest_dir) { if hdrs.call create_makefile(name) return true end } return false end |
.deduce_packaged_source_dir(ruby_dir) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/debase/ruby_core_source.rb', line 54 def self.deduce_packaged_source_dir(ruby_dir) prefix = File.dirname(__FILE__) + '/ruby_core_source/' expected_directory = prefix + ruby_dir if File.directory?(expected_directory) expected_directory else # Fallback to an older version. ruby_version = Gem::Version.new(RUBY_VERSION) path, = Dir.glob(prefix + 'ruby-*'). select { |d| File.directory?(d) }. map { |d| [d, ruby_source_dir_version(d)] }. sort { |(_, v1), (_, v2)| -(v1 <=> v2) }. find { |(_, v)| v < ruby_version } version = File.basename(path) fallback_source_warning(ruby_dir, version) path end end |
.fallback_source_warning(ruby_version, fallback_version) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/debase/ruby_core_source.rb', line 79 def self.fallback_source_warning(ruby_version, fallback_version) warn "**************************************************************************\nNo source for \#{ruby_version} provided with debase-ruby_core_source gem.\nFalling back to \#{fallback_version}.\n**************************************************************************\n" end |
.no_source_abort(ruby_version) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/debase/ruby_core_source.rb', line 88 def self.no_source_abort(ruby_version) abort "Makefile creation failed\n**************************************************************************\nNo source for \#{ruby_version} provided with debase-ruby_core_source gem.\n**************************************************************************\n" end |
.ruby_source_dir_version(dir) ⇒ Object
74 75 76 77 |
# File 'lib/debase/ruby_core_source.rb', line 74 def self.ruby_source_dir_version(dir) match = /ruby-([0-9\.]+)-p([0-9]+)/.match(dir) Gem::Version.new("#{match[1]}.#{match[2]}") end |