summaryrefslogtreecommitdiff
path: root/instruby.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-21 00:24:30 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-21 00:24:30 +0000
commitc367a39c14f66bcc3be49d8606ace35fa568357a (patch)
treed16c152a9b0a81f4d550676343b9b9dbf32e2798 /instruby.rb
parent5cce095f1181a006b6ef4a5cda678d9f4ace270c (diff)
* instruby.rb (open_for_install): write block result and rewrite only
if changed from existing file. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@15819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'instruby.rb')
-rwxr-xr-xinstruby.rb20
1 files changed, 12 insertions, 8 deletions
diff --git a/instruby.rb b/instruby.rb
index aa93e6a721..0201f28883 100755
--- a/instruby.rb
+++ b/instruby.rb
@@ -80,7 +80,7 @@ def parse_args(argv = ARGV)
$mflags.unshift(*mflags)
def $mflags.set?(flag)
- grep(/\A-(?!-).*#{'%c' % flag}/i) { return true }
+ grep(/\A-(?!-).*#{flag.chr}/i) { return true }
false
end
def $mflags.defined?(var)
@@ -183,9 +183,13 @@ def install_recursive(srcdir, dest, options = {})
end
end
-def open_for_install(path, mode, &block)
+def open_for_install(path, mode)
+ data = open(realpath = with_destdir(path), "rb") {|f| f.read} rescue nil
+ newdata = yield
unless $dryrun
- open(realpath = with_destdir(path), "wb", mode, &block)
+ unless newdata == data
+ open(realpath, "wb", mode) {|f| f.write newdata}
+ end
File.chmod(mode, realpath)
end
$installed_list.puts path if $installed_list
@@ -280,7 +284,7 @@ install?(:local, :comm, :bin, :'bin-comm') do
makedirs [bindir, rubylibdir]
ruby_shebang = File.join(bindir, ruby_install_name)
- if $cmdtype
+ if File::ALT_SEPARATOR
ruby_bin = ruby_shebang.tr(File::SEPARATOR, File::ALT_SEPARATOR)
end
for src in Dir["bin/*"]
@@ -301,10 +305,10 @@ install?(:local, :comm, :bin, :'bin-comm') do
cmd = File.join(bindir, name)
cmd << ".#{$cmdtype}" if $cmdtype
- open_for_install(cmd, $script_mode) do |f|
+ open_for_install(cmd, $script_mode) do
case $cmdtype
when "bat"
- f.print((<<EOH+shebang+body+<<EOF).gsub(/$/, "\r"))
+ "#{<<EOH}#{shebang}#{body}#{<<EOF}".gsub(/$/, "\r")
@echo off
@if not "%~d0" == "~d0" goto WinNT
#{ruby_bin} -x "#{cmd}" %1 %2 %3 %4 %5 %6 %7 %8 %9
@@ -317,12 +321,12 @@ __END__
:endofruby
EOF
when "cmd"
- f.print(<<EOH, shebang, body)
+ "#{<<EOH}#{shebang}#{body}"
@"%~dp0#{ruby_install_name}" -x "%~f0" %*
@exit /b %ERRORLEVEL%
EOH
else
- f.print shebang, body
+ shebang + body
end
end
end