File: inline.rb

package info (click to toggle)
ruby-hoe 3.22.1%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 512 kB
  • sloc: ruby: 2,379; makefile: 5
file content (72 lines) | stat: -rw-r--r-- 1,932 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require "rbconfig"

##
# Hoe allows bundling of pre-compiled extensions in the +package+ task.
#
# To create a package for your current platform:
#
#   rake package INLINE=1
#
# This will force Hoe analize your +Inline+ already compiled
# extensions and include them in your gem.
#
# If somehow you need to force a specific platform:
#
#   rake package INLINE=1 FORCE_PLATFORM=mswin32
#
# This will set the +Gem::Specification+ platform to the one indicated in
# +FORCE_PLATFORM+ (instead of default Gem::Platform::CURRENT)

module Hoe::Inline
  def initialize_inline # :nodoc:
    clean_globs << File.expand_path("~/.ruby_inline")
  end

  ##
  # Activate the inline dependencies.

  def activate_inline_deps
    dependency "RubyInline", "~> 3.9"
  end

  ##
  # Define tasks for plugin.

  def define_inline_tasks
    task :test => :clean

    return unless ENV["INLINE"]

    s.platform = ENV["FORCE_PLATFORM"] || Gem::Platform::CURRENT

    return unless defined? Inline

    # Try collecting Inline extensions for +name+
    directory "lib/inline"

    dlext = RbConfig::CONFIG["DLEXT"]

    Inline.registered_inline_classes.each do |cls|
      name = cls.name.gsub(/::/, "")
      # name of the extension is CamelCase
      alternate_name = if name =~ /[A-Z]/ then
                         name.gsub(/([A-Z])/, '_\1').downcase.sub(/^_/, "")
                       elsif name =~ /_/ then
                         name.capitalize.gsub(/_([a-z])/) { $1.upcase }
                       end
      extensions = Dir.chdir(Inline.directory) {
        Dir["Inline_{#{name},#{alternate_name}}_*.#{dlext}"]
      }

      extensions.each do |ext|
        # add the inlined extension to the spec files
        s.files += ["lib/inline/#{ext}"]

        # include the file in the tasks
        file "lib/inline/#{ext}" => ["lib/inline"] do
          cp File.join(Inline.directory, ext), "lib/inline"
        end
      end
    end
  end
end