Remove Ruby <2.2 support from tool/lib/vcs.rb
BASERUBY now requires at least Ruby 2.2, so there is no point trying to support older ruby versions here.
This commit is contained in:
parent
9a3371be8f
commit
07b2102a88
Notes:
git
2020-05-28 23:57:53 +09:00
120
tool/lib/vcs.rb
120
tool/lib/vcs.rb
@ -23,104 +23,38 @@ def IO.pread(*args)
|
|||||||
popen(*args) {|f|f.read}
|
popen(*args) {|f|f.read}
|
||||||
end
|
end
|
||||||
|
|
||||||
if RUBY_VERSION < "2.0"
|
module DebugPOpen
|
||||||
class IO
|
refine IO.singleton_class do
|
||||||
@orig_popen = method(:popen)
|
def popen(*args)
|
||||||
|
|
||||||
if defined?(fork)
|
|
||||||
def self.popen(command, *rest, &block)
|
|
||||||
if command.kind_of?(Hash)
|
|
||||||
env = command
|
|
||||||
command = rest.shift
|
|
||||||
end
|
|
||||||
opts = rest.last
|
|
||||||
if opts.kind_of?(Hash)
|
|
||||||
dir = opts.delete(:chdir)
|
|
||||||
rest.pop if opts.empty?
|
|
||||||
opts.delete(:external_encoding)
|
|
||||||
end
|
|
||||||
|
|
||||||
if block
|
|
||||||
@orig_popen.call("-", *rest) do |f|
|
|
||||||
if f
|
|
||||||
yield(f)
|
|
||||||
else
|
|
||||||
Dir.chdir(dir) if dir
|
|
||||||
ENV.replace(env) if env
|
|
||||||
exec(*command)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
f = @orig_popen.call("-", *rest)
|
|
||||||
unless f
|
|
||||||
Dir.chdir(dir) if dir
|
|
||||||
ENV.replace(env) if env
|
|
||||||
exec(*command)
|
|
||||||
end
|
|
||||||
f
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
require 'shellwords'
|
|
||||||
def self.popen(command, *rest, &block)
|
|
||||||
if command.kind_of?(Hash)
|
|
||||||
env = command
|
|
||||||
oldenv = ENV.to_hash
|
|
||||||
command = rest.shift
|
|
||||||
end
|
|
||||||
opts = rest.last
|
|
||||||
if opts.kind_of?(Hash)
|
|
||||||
dir = opts.delete(:chdir)
|
|
||||||
rest.pop if opts.empty?
|
|
||||||
opts.delete(:external_encoding)
|
|
||||||
end
|
|
||||||
|
|
||||||
command = command.shelljoin if Array === command
|
|
||||||
Dir.chdir(dir || ".") do
|
|
||||||
ENV.replace(env) if env
|
|
||||||
@orig_popen.call(command, *rest, &block)
|
|
||||||
ENV.replace(oldenv) if oldenv
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
module DebugPOpen
|
|
||||||
verbose, $VERBOSE = $VERBOSE, nil if RUBY_VERSION < "2.1"
|
|
||||||
refine IO.singleton_class do
|
|
||||||
def popen(*args)
|
|
||||||
VCS::DEBUG_OUT.puts args.inspect if $DEBUG
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
|
||||||
ensure
|
|
||||||
$VERBOSE = verbose unless verbose.nil?
|
|
||||||
end
|
|
||||||
using DebugPOpen
|
|
||||||
module DebugSystem
|
|
||||||
def system(*args)
|
|
||||||
VCS::DEBUG_OUT.puts args.inspect if $DEBUG
|
VCS::DEBUG_OUT.puts args.inspect if $DEBUG
|
||||||
exception = false
|
super
|
||||||
opts = Hash.try_convert(args[-1])
|
|
||||||
if RUBY_VERSION >= "2.6"
|
|
||||||
unless opts
|
|
||||||
opts = {}
|
|
||||||
args << opts
|
|
||||||
end
|
|
||||||
exception = opts.fetch(:exception) {opts[:exception] = true}
|
|
||||||
elsif opts
|
|
||||||
exception = opts.delete(:exception) {true}
|
|
||||||
args.pop if opts.empty?
|
|
||||||
end
|
|
||||||
ret = super(*args)
|
|
||||||
raise "Command failed with status (#$?): #{args[0]}" if exception and !ret
|
|
||||||
ret
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
module Kernel
|
end
|
||||||
prepend(DebugSystem)
|
using DebugPOpen
|
||||||
|
module DebugSystem
|
||||||
|
def system(*args)
|
||||||
|
VCS::DEBUG_OUT.puts args.inspect if $DEBUG
|
||||||
|
exception = false
|
||||||
|
opts = Hash.try_convert(args[-1])
|
||||||
|
if RUBY_VERSION >= "2.6"
|
||||||
|
unless opts
|
||||||
|
opts = {}
|
||||||
|
args << opts
|
||||||
|
end
|
||||||
|
exception = opts.fetch(:exception) {opts[:exception] = true}
|
||||||
|
elsif opts
|
||||||
|
exception = opts.delete(:exception) {true}
|
||||||
|
args.pop if opts.empty?
|
||||||
|
end
|
||||||
|
ret = super(*args)
|
||||||
|
raise "Command failed with status (#$?): #{args[0]}" if exception and !ret
|
||||||
|
ret
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
module Kernel
|
||||||
|
prepend(DebugSystem)
|
||||||
|
end
|
||||||
|
|
||||||
class VCS
|
class VCS
|
||||||
prepend(DebugSystem) if defined?(DebugSystem)
|
prepend(DebugSystem) if defined?(DebugSystem)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user