* tool/vcs.rb (IO.popen): support passing environment variables.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56649 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-11-07 00:04:20 +00:00
Родитель 30e54ac313
Коммит 2bb96b87a7
1 изменённых файлов: 13 добавлений и 0 удалений

Просмотреть файл

@ -24,6 +24,10 @@ if RUBY_VERSION < "2.0"
if defined?(fork) if defined?(fork)
def self.popen(command, *rest, &block) def self.popen(command, *rest, &block)
if command.kind_of?(Hash)
env = command
command = rest.shift
end
opts = rest.last opts = rest.last
if opts.kind_of?(Hash) if opts.kind_of?(Hash)
dir = opts.delete(:chdir) dir = opts.delete(:chdir)
@ -36,6 +40,7 @@ if RUBY_VERSION < "2.0"
yield(f) yield(f)
else else
Dir.chdir(dir) if dir Dir.chdir(dir) if dir
ENV.replace(env) if env
exec(*command) exec(*command)
end end
end end
@ -43,6 +48,7 @@ if RUBY_VERSION < "2.0"
f = @orig_popen.call("-", *rest) f = @orig_popen.call("-", *rest)
unless f unless f
Dir.chdir(dir) if dir Dir.chdir(dir) if dir
ENV.replace(env) if env
exec(*command) exec(*command)
end end
f f
@ -51,6 +57,11 @@ if RUBY_VERSION < "2.0"
else else
require 'shellwords' require 'shellwords'
def self.popen(command, *rest, &block) def self.popen(command, *rest, &block)
if command.kind_of?(Hash)
env = command
oldenv = ENV.to_hash
command = rest.shift
end
opts = rest.last opts = rest.last
if opts.kind_of?(Hash) if opts.kind_of?(Hash)
dir = opts.delete(:chdir) dir = opts.delete(:chdir)
@ -59,7 +70,9 @@ if RUBY_VERSION < "2.0"
command = command.shelljoin if Array === command command = command.shelljoin if Array === command
Dir.chdir(dir || ".") do Dir.chdir(dir || ".") do
ENV.replace(env) if env
@orig_popen.call(command, *rest, &block) @orig_popen.call(command, *rest, &block)
ENV.replace(oldenv) if oldenv
end end
end end
end end