ruby-changes:37376
From: nobu <ko1@a...>
Date: Sat, 31 Jan 2015 18:02:09 +0900 (JST)
Subject: [ruby-changes:37376] nobu:r49457 (trunk): rbinstall.rb: trilingual batch files
nobu 2015-01-31 18:01:59 +0900 (Sat, 31 Jan 2015) New Revision: 49457 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49457 Log: rbinstall.rb: trilingual batch files * tool/rbinstall.rb (bin-comm): trilingual, (sh, cmd, and ruby) prolog for batch files. Modified files: trunk/tool/rbinstall.rb Index: tool/rbinstall.rb =================================================================== --- tool/rbinstall.rb (revision 49456) +++ tool/rbinstall.rb (revision 49457) @@ -335,7 +335,8 @@ enable_shared = CONFIG["ENABLE_SHARED"] https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L335 dll = CONFIG["LIBRUBY_SO", enable_shared] lib = CONFIG["LIBRUBY", true] arc = CONFIG["LIBRUBY_A", true] -load_relative = configure_args.include?("--enable-load-relative") +config_h = File.read(CONFIG["EXTOUT"]+"/include/"+CONFIG["arch"]+"/ruby/config.h") +load_relative = config_h[/^\s*#\s*define\s+LOAD_RELATIVE\s+(\d+)/, 1].to_i.nonzero? install?(:local, :arch, :bin, :'bin-arch') do prepare "binary commands", bindir @@ -466,20 +467,21 @@ install?(:local, :comm, :bin, :'bin-comm https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L467 else trans = proc {|base| base} end + prebatch = ':""||{ ""=> %q<-*- ruby -*-'"\n" + postbatch = PROLOG_SCRIPT ? "};{\n#{PROLOG_SCRIPT.sub(/\A(?:#.*\n)*/, '')}" : '' + postbatch << ">,\n}\n" + postbatch.gsub!(/(?=\n)/, ' #') install_recursive(File.join(srcdir, "bin"), bindir, :maxdepth => 1) do |src, cmd| cmd = cmd.sub(/[^\/]*\z/m) {|n| RbConfig.expand(trans[n])} - shebang = '' - body = '' - open(src, "rb") do |f| - shebang = f.gets - body = f.read + shebang, body = open(src, "rb") do |f| + next f.gets, f.read end shebang or raise "empty file - #{src}" - if PROLOG_SCRIPT + if PROLOG_SCRIPT and !$cmdtype shebang.sub!(/\A(\#!.*?ruby\b)?/) {PROLOG_SCRIPT + ($1 || "#!ruby\n")} else - shebang.sub!(/\A\#!.*?ruby\b/) {"#!" + ruby_shebang} + shebang.sub!(/\A(\#!.*?ruby\b)?/) {"#!" + ruby_shebang + ($1 ? "" : "\n")} end shebang.sub!(/\r$/, '') body.gsub!(/\r$/, '') @@ -490,7 +492,7 @@ install?(:local, :comm, :bin, :'bin-comm https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L492 when "exe" stub + shebang + body when "bat" - [<<-"EOH".gsub(/^\s+/, ''), shebang, body, "__END__\n:endofruby\n"].join.gsub(/(?=\n)/, "\r") + (prebatch + <<-"EOH".gsub(/^\s+/, '') << postbatch << shebang << body << "__END__\n:endofruby\n").gsub(/(?=\n)/, "\r") @echo off @if not "%~d0" == "~d0" goto WinNT #{ruby_bin} -x "#{cmd}" %1 %2 %3 %4 %5 %6 %7 %8 %9 @@ -500,7 +502,7 @@ install?(:local, :comm, :bin, :'bin-comm https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L502 @goto endofruby EOH when "cmd" - <<"/EOH" << shebang << body + prebatch + <<"/EOH" << postbatch << shebang << body @"%~dp0#{ruby_install_name}" -x "%~f0" %* @exit /b %ERRORLEVEL% /EOH -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/