RubyInline 3.2.1 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +8 -1
- data/Manifest.txt +1 -1
- data/inline.rb +25 -4
- data/inline_package +128 -0
- data/test_inline.rb +117 -2
- metadata +3 -3
- data/inline-compat.rb +0 -44
data/History.txt
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
+
*** 3.3.0 / 2005-04-22
|
2
|
+
|
3
|
+
+ 2 minor enhancement
|
4
|
+
+ Added inline_package, which helps you package inlined code into gems.
|
5
|
+
+ inline_package also generates a Rakefile for you if you need it.
|
6
|
+
+ inline.rb now (only) loads packaged code when present.
|
7
|
+
|
1
8
|
*** 3.2.1 / 2005-04-19
|
2
9
|
|
3
|
-
+ 2
|
10
|
+
+ 2 bug fixes
|
4
11
|
+ Added double to typemap. Thanks Phil Tomson!
|
5
12
|
+ Added a minor hack to get cygwin to work right--lemme know pls.
|
6
13
|
|
data/Manifest.txt
CHANGED
data/inline.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/local/bin/ruby -w
|
2
2
|
|
3
|
+
##
|
3
4
|
# Ruby Inline is a framework for writing ruby extensions in foreign
|
4
|
-
# languages
|
5
|
+
# languages.
|
5
6
|
#
|
6
7
|
# = SYNOPSIS
|
7
8
|
#
|
@@ -26,6 +27,10 @@
|
|
26
27
|
# builds it only when necessary. The extensions are then automatically
|
27
28
|
# loaded into the class/module that defines it.
|
28
29
|
#
|
30
|
+
# Using the package_inline tool Inline now allows you to package up
|
31
|
+
# your inlined object code for distribution to systems without a
|
32
|
+
# compiler (read: windows)!
|
33
|
+
#
|
29
34
|
# You can even write extra builders that will allow you to write
|
30
35
|
# inlined code in any language. Use Inline::C as a template and look
|
31
36
|
# at Module#inline for the required API.
|
@@ -38,13 +43,14 @@ $TESTING = false unless defined? $TESTING
|
|
38
43
|
|
39
44
|
class CompilationError < RuntimeError; end
|
40
45
|
|
46
|
+
##
|
41
47
|
# The Inline module is the top-level module used. It is responsible
|
42
48
|
# for instantiating the builder for the right language used,
|
43
49
|
# compilation/linking when needed, and loading the inlined code into
|
44
50
|
# the current namespace.
|
45
51
|
|
46
52
|
module Inline
|
47
|
-
VERSION = '3.
|
53
|
+
VERSION = '3.3.0'
|
48
54
|
|
49
55
|
$stderr.puts "RubyInline v #{VERSION}" if $DEBUG
|
50
56
|
|
@@ -227,6 +233,19 @@ module Inline
|
|
227
233
|
|
228
234
|
public
|
229
235
|
|
236
|
+
def load_cache
|
237
|
+
begin
|
238
|
+
file = File.join("inline", File.basename(@so_name))
|
239
|
+
if require file then
|
240
|
+
dir = Inline.directory
|
241
|
+
warn "WARNING: #{dir} exists but is not being used" if test ?d, dir
|
242
|
+
return true
|
243
|
+
end
|
244
|
+
rescue LoadError
|
245
|
+
end
|
246
|
+
return false
|
247
|
+
end
|
248
|
+
|
230
249
|
def load
|
231
250
|
require "#{@so_name}" or raise LoadError, "require on #{@so_name} failed"
|
232
251
|
end
|
@@ -432,8 +451,10 @@ class Module
|
|
432
451
|
yield builder
|
433
452
|
|
434
453
|
unless testing then
|
435
|
-
builder.
|
436
|
-
|
454
|
+
unless builder.load_cache then
|
455
|
+
builder.build
|
456
|
+
builder.load
|
457
|
+
end
|
437
458
|
end
|
438
459
|
end
|
439
460
|
end
|
data/inline_package
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
require 'rbconfig'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'inline'
|
6
|
+
|
7
|
+
$TESTING ||= false
|
8
|
+
|
9
|
+
class Packager
|
10
|
+
|
11
|
+
RAKEFILE_TEMPLATE = <<'EOF'
|
12
|
+
%[require 'rake'
|
13
|
+
require 'rake/gempackagetask'
|
14
|
+
|
15
|
+
summary = #{summary.inspect}
|
16
|
+
|
17
|
+
if summary.empty? then
|
18
|
+
STDERR.puts "*************************************"
|
19
|
+
STDERR.puts "*** Summary not filled in, SHAME! ***"
|
20
|
+
STDERR.puts "*************************************"
|
21
|
+
end
|
22
|
+
|
23
|
+
spec = Gem::Specification.new do |s|
|
24
|
+
s.name = #{name.inspect}
|
25
|
+
s.version = #{version.inspect}
|
26
|
+
s.summary = summary
|
27
|
+
|
28
|
+
s.has_rdoc = false
|
29
|
+
s.files = #{gem_libs.inspect}
|
30
|
+
s.add_dependency 'RubyInline', '>= 3.3.0'
|
31
|
+
s.require_path = 'lib'
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Builds a gem with #{name} in it"
|
35
|
+
Rake::GemPackageTask.new spec do |pkg|
|
36
|
+
pkg.need_zip = false
|
37
|
+
pkg.need_tar = false
|
38
|
+
end
|
39
|
+
]
|
40
|
+
EOF
|
41
|
+
|
42
|
+
attr_accessor :name, :version, :summary
|
43
|
+
|
44
|
+
def initialize(name, version, summary = '')
|
45
|
+
@name = name
|
46
|
+
@version = version
|
47
|
+
@summary = summary
|
48
|
+
|
49
|
+
@libs_copied = false
|
50
|
+
end
|
51
|
+
|
52
|
+
def package
|
53
|
+
copy_libs
|
54
|
+
generate_rakefile
|
55
|
+
build_gem
|
56
|
+
end
|
57
|
+
|
58
|
+
def copy_libs
|
59
|
+
FileUtils.mkdir_p inline_dir
|
60
|
+
FileUtils.cp built_libs, inline_dir
|
61
|
+
@libs_copied = true
|
62
|
+
end
|
63
|
+
|
64
|
+
def generate_rakefile
|
65
|
+
if File.exists? 'Rakefile' then
|
66
|
+
unless $TESTING then
|
67
|
+
STDERR.puts "Hrm, you already have a Rakefile, so I didn't touch it."
|
68
|
+
STDERR.puts "You might have to add the following files to your gemspec's files list:"
|
69
|
+
STDERR.puts "\t#{gem_libs.join "\n\t"}"
|
70
|
+
end
|
71
|
+
return
|
72
|
+
end
|
73
|
+
|
74
|
+
rakefile = eval RAKEFILE_TEMPLATE
|
75
|
+
|
76
|
+
STDERR.puts "==> Generating Rakefile" unless $TESTING
|
77
|
+
File.open 'Rakefile', 'w' do |fp|
|
78
|
+
fp.puts rakefile
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def build_gem
|
83
|
+
STDERR.puts "==> Running rake" unless $TESTING
|
84
|
+
|
85
|
+
cmd = "rake package"
|
86
|
+
cmd += "> /dev/null 2> /dev/null" if $TESTING
|
87
|
+
system cmd
|
88
|
+
|
89
|
+
STDERR.puts unless $TESTING
|
90
|
+
STDERR.puts "Ok, you now have a gem in ./pkg, enjoy!" unless $TESTING
|
91
|
+
end
|
92
|
+
|
93
|
+
def inline_dir
|
94
|
+
@inline_dir ||= File.join "lib", "inline" # TODO put libs in platform dir
|
95
|
+
end
|
96
|
+
|
97
|
+
def built_libs
|
98
|
+
Dir.glob File.join(Inline.directory, "*.#{Config::CONFIG['DLEXT']}")
|
99
|
+
end
|
100
|
+
|
101
|
+
def gem_libs
|
102
|
+
copy_libs unless @libs_copied
|
103
|
+
unless defined? @gem_libs then
|
104
|
+
@gem_libs = Dir.glob File.join(inline_dir, "*.#{Config::CONFIG['DLEXT']}")
|
105
|
+
files = Dir.glob(File.join('lib', '*')).select { |f| test ?f, f }
|
106
|
+
|
107
|
+
@gem_libs.push(*files)
|
108
|
+
@gem_libs.sort!
|
109
|
+
end
|
110
|
+
@gem_libs
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
if __FILE__ == $0 then
|
116
|
+
name = ARGV.shift
|
117
|
+
version = ARGV.shift
|
118
|
+
summary = ARGV.shift || ""
|
119
|
+
|
120
|
+
if version.nil? then # TODO better usage
|
121
|
+
STDERR.puts "Usage: packager NAME VERSION SUMMARY"
|
122
|
+
exit 1
|
123
|
+
end
|
124
|
+
|
125
|
+
packager = Packager.new name, version, summary
|
126
|
+
packager.package
|
127
|
+
end
|
128
|
+
|
data/test_inline.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
$TESTING = true
|
4
4
|
|
5
5
|
require 'inline'
|
6
|
+
load 'inline_package'
|
6
7
|
require 'tempfile'
|
7
8
|
require 'test/unit'
|
8
9
|
|
@@ -475,8 +476,6 @@ puts(s); return rb_str_new2(s)}"
|
|
475
476
|
begin
|
476
477
|
Kernel.module_eval { require rb_file }
|
477
478
|
yield if block_given?
|
478
|
-
rescue Exception => err
|
479
|
-
raise err
|
480
479
|
ensure
|
481
480
|
File.unlink rb_file
|
482
481
|
end
|
@@ -584,3 +583,119 @@ class TestModule < Test::Unit::TestCase
|
|
584
583
|
end
|
585
584
|
|
586
585
|
end
|
586
|
+
|
587
|
+
class TestPackager < Test::Unit::TestCase
|
588
|
+
|
589
|
+
def setup
|
590
|
+
@name = "Packager Test"
|
591
|
+
@version = "1.0.0"
|
592
|
+
@summary = "This is a Packager test gem"
|
593
|
+
@packager = Packager.new @name, @version, @summary
|
594
|
+
|
595
|
+
@inline_dir = "/tmp/#{$$}_inline"
|
596
|
+
@package_dir = "/tmp/#{$$}_package"
|
597
|
+
|
598
|
+
ENV['INLINEDIR'] = @inline_dir
|
599
|
+
|
600
|
+
Dir.mkdir @inline_dir, 0700
|
601
|
+
Dir.mkdir @package_dir, 0700
|
602
|
+
@orig_dir = Dir.pwd
|
603
|
+
Dir.chdir @package_dir
|
604
|
+
|
605
|
+
@ext = Config::CONFIG['DLEXT']
|
606
|
+
end
|
607
|
+
|
608
|
+
def teardown
|
609
|
+
Dir.chdir @orig_dir
|
610
|
+
return if $DEBUG
|
611
|
+
`rm -rf #{@inline_dir}`
|
612
|
+
`rm -rf #{@package_dir}`
|
613
|
+
end
|
614
|
+
|
615
|
+
def util_generate_rakefile
|
616
|
+
summary = @summary
|
617
|
+
name = @name
|
618
|
+
version = @version
|
619
|
+
gem_libs = []
|
620
|
+
|
621
|
+
eval Packager::RAKEFILE_TEMPLATE
|
622
|
+
end
|
623
|
+
|
624
|
+
def test_package
|
625
|
+
assert_nothing_raised do
|
626
|
+
@packager.package
|
627
|
+
end
|
628
|
+
end
|
629
|
+
|
630
|
+
def test_copy_libs
|
631
|
+
assert_equal false, @packager.instance_variable_get("@libs_copied")
|
632
|
+
|
633
|
+
built_lib = "Inline_Test.#{@ext}"
|
634
|
+
dir = "#{@inline_dir}/.ruby_inline"
|
635
|
+
|
636
|
+
Dir.mkdir dir, 0700
|
637
|
+
Dir.chdir dir do
|
638
|
+
FileUtils.touch built_lib
|
639
|
+
end
|
640
|
+
|
641
|
+
@packager.copy_libs
|
642
|
+
|
643
|
+
assert_equal true, File.directory?("#{@package_dir}/lib/inline")
|
644
|
+
assert_equal true, File.exists?("#{@package_dir}/lib/inline/#{built_lib}")
|
645
|
+
|
646
|
+
assert_equal true, @packager.instance_variable_get("@libs_copied")
|
647
|
+
end
|
648
|
+
|
649
|
+
def test_generate_rakefile_has_rakefile
|
650
|
+
FileUtils.touch 'Rakefile'
|
651
|
+
|
652
|
+
@packager.generate_rakefile
|
653
|
+
|
654
|
+
assert_equal "", File.read('Rakefile')
|
655
|
+
end
|
656
|
+
|
657
|
+
def test_generate_rakefile_no_rakefile
|
658
|
+
@packager.generate_rakefile
|
659
|
+
|
660
|
+
assert_equal util_generate_rakefile, File.read('Rakefile')
|
661
|
+
end
|
662
|
+
|
663
|
+
def test_build_gem
|
664
|
+
File.open 'Rakefile', 'w' do |fp|
|
665
|
+
fp.puts util_generate_rakefile
|
666
|
+
end
|
667
|
+
|
668
|
+
@packager.build_gem
|
669
|
+
package_name = "pkg/#{@name}-#{@version}.gem"
|
670
|
+
assert_equal true, File.exists?(package_name)
|
671
|
+
assert_equal true, system("gem check #{package_name}")
|
672
|
+
end
|
673
|
+
|
674
|
+
def test_inline_dir
|
675
|
+
assert_equal "lib/inline", @packager.inline_dir
|
676
|
+
end
|
677
|
+
|
678
|
+
def test_built_libs
|
679
|
+
expected = ["Inline_Test.#{@ext}"]
|
680
|
+
|
681
|
+
dir = "#{@inline_dir}/.ruby_inline"
|
682
|
+
Dir.mkdir dir, 0700
|
683
|
+
Dir.chdir dir
|
684
|
+
|
685
|
+
FileUtils.touch(expected)
|
686
|
+
|
687
|
+
assert_equal expected.map { |f| "#{dir}/#{f}"}, @packager.built_libs
|
688
|
+
end
|
689
|
+
|
690
|
+
def test_gem_libs
|
691
|
+
@packager.instance_variable_set "@libs_copied", true
|
692
|
+
expected = ["lib/blah.rb", "lib/inline/Inline_Test.#{@ext}"]
|
693
|
+
|
694
|
+
FileUtils.mkdir_p "lib/inline"
|
695
|
+
FileUtils.touch(expected)
|
696
|
+
|
697
|
+
assert_equal expected, @packager.gem_libs
|
698
|
+
end
|
699
|
+
|
700
|
+
end
|
701
|
+
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
4
4
|
name: RubyInline
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 3.
|
7
|
-
date: 2005-04-
|
6
|
+
version: 3.3.0
|
7
|
+
date: 2005-04-22
|
8
8
|
summary: Multi-language extension coding within ruby.
|
9
9
|
require_paths:
|
10
10
|
- "."
|
@@ -38,7 +38,7 @@ files:
|
|
38
38
|
- example2.rb
|
39
39
|
- inline.gemspec
|
40
40
|
- inline.rb
|
41
|
-
-
|
41
|
+
- inline_package
|
42
42
|
- test_inline.rb
|
43
43
|
- tutorial/example1.rb
|
44
44
|
- tutorial/example2.rb
|
data/inline-compat.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
#!/usr/local/bin/ruby -w
|
2
|
-
|
3
|
-
require "inline"
|
4
|
-
|
5
|
-
############################################################
|
6
|
-
# DEPRECATED: Remove by version 3.1 or 2003-03-01
|
7
|
-
#
|
8
|
-
# This file is only provided for those who require backwards compatibility with version 2.x.
|
9
|
-
# If you don't need it, don't use it. If you do, please heed the deprecation warnings and
|
10
|
-
# migrate to the new system as fast as you can. Thanks...
|
11
|
-
|
12
|
-
module Inline
|
13
|
-
class C
|
14
|
-
|
15
|
-
$INLINE_FLAGS = nil
|
16
|
-
$INLINE_LIBS = nil
|
17
|
-
|
18
|
-
trace_var(:$INLINE_FLAGS) do |val|
|
19
|
-
$stderr.puts "WARNING: $INLINE_FLAGS is deprecated. Use #add_link_flags. Called from #{caller[1]}."
|
20
|
-
end
|
21
|
-
|
22
|
-
trace_var(:$INLINE_LIBS) do |val|
|
23
|
-
$stderr.puts "WARNING: $INLINE_LIBS is deprecated. Use #add_compile_flags. Called from #{caller[1]}."
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class Module
|
29
|
-
public
|
30
|
-
|
31
|
-
def inline_c(src)
|
32
|
-
$stderr.puts "WARNING: inline_c is deprecated. Switch to Inline module"
|
33
|
-
inline(:C) do | builder |
|
34
|
-
builder.c src
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def inline_c_raw(src)
|
39
|
-
$stderr.puts "WARNING: inline_c_raw is deprecated. Switch to Inline module"
|
40
|
-
inline(:C) do | builder |
|
41
|
-
builder.c_raw src
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|