Skip to content

Commit

Permalink
* tool/rbinstall.rb: use rubygems to load gemspecs, copy actual
Browse files Browse the repository at this point in the history
  gemspecs on install rather than generate fake ones for all gems.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
tenderlove committed Aug 3, 2011
1 parent 92f3904 commit e9ddb1a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 16 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
Thu Aug 4 03:02:54 2011 Aaron Patterson <aaron@tenderlovemaking.com>

* tool/rbinstall.rb: use rubygems to load gemspecs, copy actual
gemspecs on install rather than generate fake ones for all gems.

Thu Aug 4 02:45:10 2011 Kenta Murata <mrkn@mrkn.jp>

* configure.in: set CXX variable to the C++ compiler that matches the
Expand Down
72 changes: 56 additions & 16 deletions tool/rbinstall.rb
Expand Up @@ -532,6 +532,53 @@ class << (w = [])
end
end

# :stopdoc:
module RbInstall
module Specs
class Reader < Struct.new(:name, :src, :execs)
def gemspec
@gemspec ||= begin
Gem::Specification.load(src) || raise("invalid spec in #{src}")
end
end

def spec_source
File.read src
end
end

class Generator < Struct.new(:name, :src, :execs)
def gemspec
@gemspec ||= eval spec_source
end

def spec_source
<<-GEMSPEC
Gem::Specification.new do |s|
s.name = #{name.dump}
s.version = #{version.dump}
s.summary = "This #{name} is bundled with Ruby"
s.executables = #{execs.inspect}
end
GEMSPEC
end

private
def version
version = open(src) { |f|
f.find { |s| /^\s*\w*VERSION\s*=(?!=)/ =~ s }
} or return
version.split(%r"=\s*", 2)[1].strip[/\A([\'\"])(.*?)\1/, 2]
end
end

def self.generator_for(file)
File.extname(file) == '.gemspec' ? Reader : Generator
end
end
end
# :startdoc:

install?(:ext, :comm, :gem) do
$:.unshift(File.join(srcdir, "lib"))
require("rubygems.rb")
Expand All @@ -550,29 +597,22 @@ class << (w = [])
end
name, src, execs = *words
next unless name and src
execs ||= []
src = File.join(srcdir, src)
version = open(src) {|f| f.find {|s| /^\s*\w*VERSION\s*=(?!=)/ =~ s}} or next
version = version.split(%r"=\s*", 2)[1].strip[/\A([\'\"])(.*?)\1/, 2]
full_name = "#{name}-#{version}"

puts "#{" "*30}#{name} #{version}"
src = File.join(srcdir, src)
specgen = RbInstall::Specs.generator_for(src).new(name, src, execs || [])
gemspec = specgen.gemspec
full_name = "#{gemspec.name}-#{gemspec.version}"

puts "#{" "*30}#{gemspec.name} #{gemspec.version}"
open_for_install(File.join(spec_dir, "#{full_name}.gemspec"), $data_mode) do
<<-GEMSPEC
Gem::Specification.new do |s|
s.name = #{name.dump}
s.version = #{version.dump}
s.summary = "This #{name} is bundled with Ruby"
s.executables = #{execs.inspect}
end
GEMSPEC
specgen.spec_source
end

unless execs.empty? then
unless gemspec.executables.empty? then
bin_dir = File.join(gem_dir, 'gems', full_name, 'bin')
makedirs(bin_dir)

execs = execs.map {|exec| File.join(srcdir, 'bin', exec)}
execs = gemspec.executables.map {|exec| File.join(srcdir, 'bin', exec)}
install(execs, bin_dir, :mode => $prog_mode)
end
end
Expand Down

0 comments on commit e9ddb1a

Please sign in to comment.