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

ruby-changes:11244

From: nobu <ko1@a...>
Date: Mon, 9 Mar 2009 16:03:52 +0900 (JST)
Subject: [ruby-changes:11244] Ruby:r22853 (trunk): * lib/rubygems/installer.rb (Gem::Installer#initialize): env may

nobu	2009-03-09 16:03:39 +0900 (Mon, 09 Mar 2009)

  New Revision: 22853

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

  Log:
    * lib/rubygems/installer.rb (Gem::Installer#initialize): env may
      not be under /usr/bin.
    * lib/rubygems/installer.rb (Gem::Installer#shebang): uses /bin/sh
      if shebang has any options, since env shebang trick does not
      work with options.

  Modified files:
    trunk/ChangeLog
    trunk/lib/rubygems/installer.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 22852)
+++ ChangeLog	(revision 22853)
@@ -1,3 +1,12 @@
+Mon Mar  9 16:03:37 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/rubygems/installer.rb (Gem::Installer#initialize): env may
+	  not be under /usr/bin.
+
+	* lib/rubygems/installer.rb (Gem::Installer#shebang): uses /bin/sh
+	  if shebang has any options, since env shebang trick does no
+	  work with options.
+
 Mon Mar  9 15:19:55 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* instruby.rb (manpages): use basename to compare and for Tempfile.
Index: lib/rubygems/installer.rb
===================================================================
--- lib/rubygems/installer.rb	(revision 22852)
+++ lib/rubygems/installer.rb	(revision 22853)
@@ -98,7 +98,12 @@
       :source_index => Gem.source_index,
     }.merge options
 
-    @env_shebang = options[:env_shebang]
+    if @env_shebang = options[:env_shebang]
+      unless File.executable?(shebang = "/usr/bin/env")
+        shebang = "/bin/env"
+      end
+      @env_shebang = shebang
+    end
     @force = options[:force]
     gem_home = options[:install_dir]
     @gem_home = Pathname.new(gem_home).expand_path
@@ -387,22 +392,24 @@
   # necessary.
 
   def shebang(bin_file_name)
-    if @env_shebang then
-      "#!/usr/bin/env " + Gem::ConfigMap[:ruby_install_name]
+    ruby_name = Gem::ConfigMap[:ruby_install_name] unless @env_shebang
+    path = File.join @gem_dir, @spec.bindir, bin_file_name
+    first_line = File.open(path, "rb") {|file| file.gets}
+    if /\A#!/ =~ first_line then
+      # Preserve extra words on shebang line, like "-w".  Thanks RPA.
+      shebang = first_line.sub(/\A\#!.*?ruby\S*(?=\s*(\S+))/, "#!#{Gem.ruby}")
+      shebang.strip! # Avoid nasty ^M issues.
+      if ruby_name and $1
+        %{#!/bin/sh\n'exec' '#{ruby_name}' '-x' "$0" "$@"\n#{shebang}}
+      else
+        shebang
+      end
     else
-      path = File.join @gem_dir, @spec.bindir, bin_file_name
-
-      File.open(path, "rb") do |file|
-        first_line = file.gets
-        if first_line =~ /^#!/ then
-          # Preserve extra words on shebang line, like "-w".  Thanks RPA.
-          shebang = first_line.sub(/\A\#!.*?ruby\S*/, "#!#{Gem.ruby}")
-        else
-          # Create a plain shebang line.
-          shebang = "#!#{Gem.ruby}"
-        end
-
-        shebang.strip # Avoid nasty ^M issues.
+      # Create a plain shebang line.
+      if ruby_name
+        "#!#@env_shebang #{ruby_name}"
+      else
+        "#!#{Gem.ruby}"
       end
     end
   end

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

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