Skip to content

Commit

Permalink
add a --gem option to macruby_deploy which will embed the given gem(s…
Browse files Browse the repository at this point in the history
…) and their dependencies inside the application bundle

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@5217 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
lrz committed Feb 1, 2011
1 parent 3d57630 commit 793eeed
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion bin/ruby_deploy
Expand Up @@ -13,13 +13,15 @@ class Deployer

def initialize(argv)
@stdlib = []
@gems = []

OptionParser.new do |opts|
opts.banner = "Usage: #{NAME} [options] application-bundle"
opts.on('--compile', 'Compile the bundle source code') { @compile = true }
opts.on('--embed', 'Embed MacRuby inside the bundle') { @embed = true }
opts.on('--no-stdlib', 'Do not embed the standard library') { @no_stdlib = true }
opts.on('--stdlib [LIB]', 'Embed only LIB from the standard library') { |lib| @stdlib << lib }
opts.on('--gem [GEM]', 'Embed GEM and its dependencies') { |gem| @gems << gem }
opts.on('--verbose', 'Log actions to standard out') { @verbose = true }
opts.on('-v', '--version', 'Display the version') do
puts RUBY_DESCRIPTION
Expand Down Expand Up @@ -105,10 +107,33 @@ class Deployer
fix_install_name if File.exist?(app_macruby)
end

def gem_deps_libdirs(gem_name)
# Locate gem spec.
require 'rubygems'
gemspecs = Gem.source_index.find_name(gem_name)
if gemspecs.size == 0
die "Cannot locate gem `#{gem_name}' in #{Gem.path}"
end
gemspec = gemspecs.last

# Load dependencies libdirs first.
gem_libdirs = []
gemspec.runtime_dependencies.each do |dep|
gem_libdirs.concat(gem_deps_libdirs(dep.name))
end

# Load the gem libdirs.
gem_libdirs.concat(gemspec.require_paths.map { |x| File.join(gemspec.full_gem_path, x) })
return gem_libdirs
end

STDLIB_PATTERN = "lib/ruby/{,site_ruby/}1.9.*{,/universal-darwin*}"
KEEP_STDLIB_PATTERN = "{%s}{,{.,/**/*.}{rb,rbo,bundle}}"

def embed
# Prepare the list of gems to embed.
gems_libdirs_to_embed = @gems.map { |x| gem_deps_libdirs(x) }.flatten

# Copy MacRuby.framework inside MyApp.app/Contents/Frameworks.
mkdir_p(app_frameworks)
rm_rf(app_macruby)
Expand All @@ -117,7 +142,7 @@ class Deployer
# Delete unnecessary things in the MacRuby.framework copy.
dirs = ['bin', 'include', 'lib/libmacruby-static.a', 'share']
dirs << 'lib/ruby' if @no_stdlib
dirs << 'lib/ruby/Gems' # TODO add gems support
dirs << 'lib/ruby/Gems'
dirs.each { |x| rm_rf(File.join(app_macruby_usr, x)) }

# Only keep specific libs from stdlib.
Expand All @@ -128,6 +153,15 @@ class Deployer
all.select { |f| keep.grep(/^#{f}/).empty? }.each { |x| rm_rf(x) }
end

# Copy the gems libdirs.
unless gems_libdirs_to_embed.empty?
gems_libdirs_dest = File.join(app_macruby_usr, 'lib', 'ruby', 'site_ruby', RUBY_VERSION)
mkdir_p(gems_libdirs_dest)
gems_libdirs_to_embed.each do |libdir|
execute("/usr/bin/ditto #{libdir} #{gems_libdirs_dest}")
end
end

# Only keep the Current version of the MacRuby.framework copy.
Dir.glob(File.join(app_macruby, 'Versions/*')).select { |x|
base = File.basename(x)
Expand Down

0 comments on commit 793eeed

Please sign in to comment.