[前][次][番号順一覧][スレッド一覧]

ruby-changes:20790

From: tenderlove <ko1@a...>
Date: Thu, 4 Aug 2011 03:10:39 +0900 (JST)
Subject: [ruby-changes:20790] tenderlove:r32838 (trunk): * tool/rbinstall.rb: use rubygems to load gemspecs, copy actual

tenderlove	2011-08-04 03:08:57 +0900 (Thu, 04 Aug 2011)

  New Revision: 32838

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32838

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

  Modified files:
    trunk/ChangeLog
    trunk/tool/rbinstall.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32837)
+++ ChangeLog	(revision 32838)
@@ -1,3 +1,8 @@
+Thu Aug  4 03:02:54 2011  Aaron Patterson <aaron@t...>
+
+	* 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@m...>
 
 	* configure.in: set CXX variable to the C++ compiler that matches the
Index: tool/rbinstall.rb
===================================================================
--- tool/rbinstall.rb	(revision 32837)
+++ tool/rbinstall.rb	(revision 32838)
@@ -532,6 +532,53 @@
   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")
@@ -550,29 +597,22 @@
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]