Skip to content

Commit

Permalink
Removed inline_package in favor of hoe's packaging.
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//src/RubyInline/dev/": change = 3963]
  • Loading branch information
zenspider committed Jun 3, 2008
1 parent 0581689 commit 5c33154
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 227 deletions.
1 change: 0 additions & 1 deletion Manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ History.txt
Manifest.txt
README.txt
Rakefile
bin/inline_package
demo/fastmath.rb
demo/hello.rb
example.rb
Expand Down
38 changes: 22 additions & 16 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,29 @@

== DESCRIPTION:

Ruby Inline is an analog to Perl's Inline::C. Out of the box, it
allows you to embed C/++ external module code in your ruby script
directly. By writing simple builder classes, you can teach how to cope
with new languages (fortran, perl, whatever). The code is compiled and
run on the fly when needed.
Inline allows you to write foreign code within your ruby code. It
automatically determines if the code in question has changed and
builds it only when necessary. The extensions are then automatically
loaded into the class/module that defines it.

Using the package_inline tool Inline allows you to package up your
inlined object code for distribution to systems without a compiler.
You can even write extra builders that will allow you to write inlined
code in any language. Use Inline::C as a template and look at
Module#inline for the required API.

== PACKAGING:

To package your binaries into a gem, use hoe's INLINE and
FORCE_PLATFORM env vars.

Example:

rake package INLINE=1

or:

rake package INLINE=1 FORCE_PLATFORM=mswin32

See hoe for more details.

== FEATURES/PROBLEMS:

Expand All @@ -26,7 +41,6 @@ inlined object code for distribution to systems without a compiler.
+ Only recompiles if the inlined code has changed.
+ Pretends to be secure.
+ Only requires standard ruby libraries, nothing extra to download.
+ Can generate a basic Rakefile and package up built extensions for distribution.

== SYNOPSYS:

Expand Down Expand Up @@ -62,13 +76,6 @@ inlined object code for distribution to systems without a compiler.
t = MyTest.new()
t.hello(3)

== SYNOPSYS (packaging):

rm -rf ~/.ruby_inline
make test
inline_package packagename 1.0.0
ls lib/inline

== (PSEUDO)BENCHMARKS:

> make bench
Expand Down Expand Up @@ -100,7 +107,6 @@ inlined object code for distribution to systems without a compiler.
+ POSIX compliant system (ie pretty much any UNIX, or Cygwin on MS platforms).
+ A C/C++ compiler (the same one that compiled your ruby interpreter).
+ test::unit for running tests ( http://testunit.talbott.ws/ ).
+ rubygems & rake if you'd like - these are used by inline_package.

== INSTALL:

Expand Down
15 changes: 0 additions & 15 deletions bin/inline_package

This file was deleted.

100 changes: 18 additions & 82 deletions lib/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Ruby Inline is a framework for writing ruby extensions in foreign
# languages.
#
# = SYNOPSIS
# == SYNOPSIS
#
# require 'inline'
# class MyClass
Expand All @@ -20,20 +20,32 @@
# end
# end
#
# = DESCRIPTION
# == DESCRIPTION
#
# Inline allows you to write foreign code within your ruby code. It
# automatically determines if the code in question has changed and
# builds it only when necessary. The extensions are then automatically
# loaded into the class/module that defines it.
#
# Using the package_inline tool Inline now allows you to package up
# your inlined object code for distribution to systems without a
# compiler (read: windows)!
#
# You can even write extra builders that will allow you to write
# inlined code in any language. Use Inline::C as a template and look
# at Module#inline for the required API.
#
# == PACKAGING
#
# To package your binaries into a gem, use hoe's INLINE and
# FORCE_PLATFORM env vars.
#
# Example:
#
# rake package INLINE=1
#
# or:
#
# rake package INLINE=1 FORCE_PLATFORM=mswin32
#
# See hoe for more details.
#

require "rbconfig"
require "digest/md5"
Expand Down Expand Up @@ -599,82 +611,6 @@ def c_raw_singleton src, options = {}
end

end # class Inline::C
class Packager
attr_accessor :name, :version, :summary, :libs_copied, :inline_dir

def initialize(name, version, summary = '')
@name = name
@version = version
@summary = summary
@libs_copied = false
@ext = Config::CONFIG['DLEXT']

# TODO (maybe) put libs in platform dir
@inline_dir = File.join "lib", "inline"
end

def package
copy_libs
generate_rakefile
build_gem
end

def copy_libs
unless @libs_copied then
FileUtils.mkdir_p @inline_dir
built_libs = Dir.glob File.join(Inline.directory, "*.#{@ext}")
FileUtils.cp built_libs, @inline_dir
@libs_copied = true
end
end

def generate_rakefile
if File.exists? 'Rakefile' then
unless $TESTING then
STDERR.puts "Hrm, you already have a Rakefile, so I didn't touch it."
STDERR.puts "You might have to add the following files to your gemspec's files list:"
STDERR.puts "\t#{gem_libs.join "\n\t"}"
end
return
end

rakefile = eval RAKEFILE_TEMPLATE

STDERR.puts "==> Generating Rakefile" unless $TESTING
File.open 'Rakefile', 'w' do |fp|
fp.puts rakefile
end
end

def build_gem
STDERR.puts "==> Running rake" unless $TESTING or $DEBUG

cmd = "#{RAKE} package"
cmd += "> #{DEV_NULL} 2> #{DEV_NULL}" if $TESTING unless $DEBUG

if system cmd then
unless $TESTING then
STDERR.puts
STDERR.puts "Ok, you now have a gem in ./pkg, enjoy!"
end
else
STDERR.puts "Calling rake to build the gem failed." unless $TESTING
end
end

def gem_libs
unless defined? @gem_libs then
@gem_libs = Dir.glob File.join(@inline_dir, "*.#{@ext}")
files = Dir.glob(File.join('lib', '*')).select { |f| test ?f, f }

@gem_libs.push(*files)
@gem_libs.sort!
end
@gem_libs
end

RAKEFILE_TEMPLATE = '%[require "rake"\nrequire "rake/gempackagetask"\n\nsummary = #{summary.inspect}\n\nif summary.empty? then\n STDERR.puts "*************************************"\n STDERR.puts "*** Summary not filled in, SHAME! ***"\n STDERR.puts "*************************************"\nend\n\nspec = Gem::Specification.new do |s|\n s.name = #{name.inspect}\n s.version = #{version.inspect}\n s.summary = summary\n\n s.author = "Fred"\n s.email = "[email protected]"\n s.homepage = "http://blah.example.com/"\n s.rubyforge_project = "#{name.downcase}"\n s.has_rdoc = true\n s.files = #{gem_libs.inspect}\n s.add_dependency "RubyInline", ">= 3.3.0"\n s.require_path = "lib"\nend\n\ndesc "Builds a gem with #{name} in it"\nRake::GemPackageTask.new spec do |pkg|\n pkg.need_zip = false\n pkg.need_tar = false\nend\n]'
end # class Packager
end # module Inline

class Module
Expand Down
113 changes: 0 additions & 113 deletions test/test_inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -688,116 +688,3 @@ def util_arity_check
end
end
end

class TestInlinePackager < InlineTestCase
def setup
super

@name = "Packager-Test"
@version = "1.0.0"
@summary = "This is a Packager test gem"
@packager = Inline::Packager.new @name, @version, @summary

@package_dir = @rootdir + "_package"
Dir.mkdir @package_dir, 0700 unless test ?d, @package_dir
@orig_dir = Dir.pwd
Dir.chdir @package_dir

@ext = Config::CONFIG['DLEXT']
end

def teardown
super
Dir.chdir @orig_dir
FileUtils.rm_rf @package_dir unless $DEBUG
end

def util_generate_rakefile
summary = @summary
name = @name
version = @version
gem_libs = []

eval Inline::Packager::RAKEFILE_TEMPLATE
end

def test_initialize
assert_equal "lib/inline", @packager.inline_dir
assert_equal false, @packager.libs_copied
end

def test_package
assert_nothing_raised do
@packager.package
end
end

def test_copy_libs
assert_equal false, @packager.libs_copied

built_lib = "Inline_Test.#{@ext}"
dir = "#{@rootdir}/.ruby_inline"

Dir.mkdir dir, 0700 unless test ?d, dir
Dir.chdir dir do
FileUtils.touch built_lib
end

@packager.copy_libs

assert_equal true, File.directory?("#{@package_dir}/lib/inline")
assert_equal true, File.exists?("#{@package_dir}/lib/inline/#{built_lib}")

assert_equal true, @packager.libs_copied
end

def test_generate_rakefile_has_rakefile
FileUtils.rm 'Rakefile' if test ?f, 'Rakefile' and $DEBUG
FileUtils.touch 'Rakefile'

@packager.generate_rakefile

assert_equal "", File.read('Rakefile')
end

def test_generate_rakefile_no_rakefile
FileUtils.rm 'Rakefile' if test ?f, 'Rakefile' and $DEBUG
FileUtils.rm_r 'lib' if test ?d, 'lib' and $DEBUG

@packager.generate_rakefile

assert_equal util_generate_rakefile, File.read('Rakefile')
end

def test_build_gem
begin
require "rubygems" # let things like rubinius die gracefully
rescue LoadError
return
end

pwd = Dir.pwd

File.open 'Rakefile', 'w' do |fp|
src = util_generate_rakefile
fp.puts src
end

@packager.build_gem

package_name = "pkg/#{@name}-#{@version}.gem"
assert File.exists?(package_name), "File #{package_name} must exist in #{Dir.pwd}: #{Dir.entries(Dir.pwd).inspect}"
assert system("#{Inline::GEM} check #{package_name}"), "gem check must pass"
end unless defined? RUBY_ENGINE # HACK

def test_gem_libs
system "rm lib/inline/*" if $DEBUG # hacky
@packager.libs_copied = true
expected = ["lib/blah.rb", "lib/inline/Inline_Test.#{@ext}"]

FileUtils.mkdir_p "lib/inline"
FileUtils.touch(expected)

assert_equal expected, @packager.gem_libs
end
end

0 comments on commit 5c33154

Please sign in to comment.