remove ruby 1.8 compatible codes (#742)
This commit is contained in:
commit
bf05651a01
@ -1,5 +1,9 @@
|
|||||||
std_trap = trap("INT") { exit! 130 } # no backtrace thanks
|
std_trap = trap("INT") { exit! 130 } # no backtrace thanks
|
||||||
|
|
||||||
|
# check ruby version before requiring any modules.
|
||||||
|
RUBY_TWO = RUBY_VERSION.split(".").first.to_i >= 2
|
||||||
|
raise "Homebrew must be run under Ruby 2!" unless RUBY_TWO
|
||||||
|
|
||||||
require "pathname"
|
require "pathname"
|
||||||
HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent
|
HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent
|
||||||
$:.unshift(HOMEBREW_LIBRARY_PATH.to_s)
|
$:.unshift(HOMEBREW_LIBRARY_PATH.to_s)
|
||||||
|
|||||||
@ -49,22 +49,12 @@ module Homebrew
|
|||||||
|
|
||||||
HOMEBREW_TAP_REGEX = %r{^([\w-]+)/homebrew-([\w-]+)$}
|
HOMEBREW_TAP_REGEX = %r{^([\w-]+)/homebrew-([\w-]+)$}
|
||||||
|
|
||||||
if ruby_has_encoding?
|
def fix_encoding!(str)
|
||||||
def fix_encoding!(str)
|
# Assume we are starting from a "mostly" UTF-8 string
|
||||||
# Assume we are starting from a "mostly" UTF-8 string
|
str.force_encoding(Encoding::UTF_8)
|
||||||
str.force_encoding(Encoding::UTF_8)
|
return str if str.valid_encoding?
|
||||||
return str if str.valid_encoding?
|
str.encode!(Encoding::UTF_16, :invalid => :replace)
|
||||||
str.encode!(Encoding::UTF_16, :invalid => :replace)
|
str.encode!(Encoding::UTF_8)
|
||||||
str.encode!(Encoding::UTF_8)
|
|
||||||
end
|
|
||||||
elsif require "iconv"
|
|
||||||
def fix_encoding!(str)
|
|
||||||
Iconv.conv("UTF-8//IGNORE", "UTF-8", str)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
def fix_encoding!(str)
|
|
||||||
str
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolve_test_tap
|
def resolve_test_tap
|
||||||
@ -181,7 +171,7 @@ module Homebrew
|
|||||||
verbose = ARGV.verbose?
|
verbose = ARGV.verbose?
|
||||||
# Step may produce arbitrary output and we read it bytewise, so must
|
# Step may produce arbitrary output and we read it bytewise, so must
|
||||||
# buffer it as binary and convert to UTF-8 once complete
|
# buffer it as binary and convert to UTF-8 once complete
|
||||||
output = ruby_has_encoding? ? "".encode!("BINARY") : ""
|
output = "".encode!("BINARY")
|
||||||
working_dir = Pathname.new(@command.first == "git" ? @repository : Dir.pwd)
|
working_dir = Pathname.new(@command.first == "git" ? @repository : Dir.pwd)
|
||||||
read, write = IO.pipe
|
read, write = IO.pipe
|
||||||
|
|
||||||
@ -1046,19 +1036,8 @@ module Homebrew
|
|||||||
def sanitize_output_for_xml(output)
|
def sanitize_output_for_xml(output)
|
||||||
unless output.empty?
|
unless output.empty?
|
||||||
# Remove invalid XML CData characters from step output.
|
# Remove invalid XML CData characters from step output.
|
||||||
if ruby_has_encoding?
|
invalid_xml_pat = /[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/
|
||||||
# This is the regex for valid XML chars, but only works in Ruby 2.0+
|
output = output.gsub(invalid_xml_pat, "\uFFFD")
|
||||||
# /[\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/
|
|
||||||
# For 1.9 compatibility, use the inverse of that, which stays under \u10000
|
|
||||||
# invalid_xml_pat = /[\x00-\x08\x0B\x0C\x0E-\x1F\uD800-\uDFFF\uFFFE\uFFFF]/
|
|
||||||
# But Ruby won't allow you to reference surrogates, so we have:
|
|
||||||
invalid_xml_pat = /[\x00-\x08\x0B\x0C\x0E-\x1F\uFFFE\uFFFF]/
|
|
||||||
output = output.gsub(invalid_xml_pat, "\uFFFD")
|
|
||||||
else
|
|
||||||
# Invalid XML chars, as far as single-byte chars go
|
|
||||||
output = output.delete("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f" \
|
|
||||||
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Truncate to 1MB to avoid hitting CI limits
|
# Truncate to 1MB to avoid hitting CI limits
|
||||||
if output.bytesize > MAX_STEP_OUTPUT_SIZE
|
if output.bytesize > MAX_STEP_OUTPUT_SIZE
|
||||||
|
|||||||
@ -65,8 +65,7 @@ module FileUtils
|
|||||||
Process.gid
|
Process.gid
|
||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
# group_id.to_s makes OS X 10.6.7 (ruby-1.8.7-p174) and earlier happy.
|
chown(nil, group_id, tmpdir)
|
||||||
chown(nil, group_id.to_s, tmpdir)
|
|
||||||
rescue Errno::EPERM
|
rescue Errno::EPERM
|
||||||
opoo "Failed setting group \"#{Etc.getgrgid(group_id).name}\" on #{tmpdir}"
|
opoo "Failed setting group \"#{Etc.getgrgid(group_id).name}\" on #{tmpdir}"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -445,39 +445,7 @@ class Pathname
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# We redefine these private methods in order to add the /o modifier to
|
if RUBY_VERSION == "2.0.0"
|
||||||
# the Regexp literals, which forces string interpolation to happen only
|
|
||||||
# once instead of each time the method is called. This is fixed in 1.9+.
|
|
||||||
if RUBY_VERSION <= "1.8.7"
|
|
||||||
# @private
|
|
||||||
alias_method :old_chop_basename, :chop_basename
|
|
||||||
|
|
||||||
def chop_basename(path)
|
|
||||||
base = File.basename(path)
|
|
||||||
if /\A#{Pathname::SEPARATOR_PAT}?\z/o =~ base
|
|
||||||
return nil
|
|
||||||
else
|
|
||||||
return path[0, path.rindex(base)], base
|
|
||||||
end
|
|
||||||
end
|
|
||||||
private :chop_basename
|
|
||||||
|
|
||||||
# @private
|
|
||||||
alias_method :old_prepend_prefix, :prepend_prefix
|
|
||||||
|
|
||||||
def prepend_prefix(prefix, relpath)
|
|
||||||
if relpath.empty?
|
|
||||||
File.dirname(prefix)
|
|
||||||
elsif /#{SEPARATOR_PAT}/o =~ prefix
|
|
||||||
prefix = File.dirname(prefix)
|
|
||||||
prefix = File.join(prefix, "") if File.basename(prefix + "a") != "a"
|
|
||||||
prefix + relpath
|
|
||||||
else
|
|
||||||
prefix + relpath
|
|
||||||
end
|
|
||||||
end
|
|
||||||
private :prepend_prefix
|
|
||||||
elsif RUBY_VERSION == "2.0.0"
|
|
||||||
# https://bugs.ruby-lang.org/issues/9915
|
# https://bugs.ruby-lang.org/issues/9915
|
||||||
prepend Module.new {
|
prepend Module.new {
|
||||||
def inspect
|
def inspect
|
||||||
|
|||||||
@ -22,16 +22,8 @@ require "config"
|
|||||||
|
|
||||||
HOMEBREW_REPOSITORY.extend(GitRepositoryExtension)
|
HOMEBREW_REPOSITORY.extend(GitRepositoryExtension)
|
||||||
|
|
||||||
if RbConfig.respond_to?(:ruby)
|
RUBY_PATH = Pathname.new(RbConfig.ruby)
|
||||||
RUBY_PATH = Pathname.new(RbConfig.ruby)
|
|
||||||
else
|
|
||||||
RUBY_PATH = Pathname.new(RbConfig::CONFIG["bindir"]).join(
|
|
||||||
RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"]
|
|
||||||
)
|
|
||||||
end
|
|
||||||
RUBY_BIN = RUBY_PATH.dirname
|
RUBY_BIN = RUBY_PATH.dirname
|
||||||
RUBY_TWO = RUBY_VERSION.split(".").first.to_i >= 2
|
|
||||||
raise "Homebrew must be run under Ruby 2!" unless RUBY_TWO
|
|
||||||
|
|
||||||
HOMEBREW_USER_AGENT_CURL = ENV["HOMEBREW_USER_AGENT_CURL"]
|
HOMEBREW_USER_AGENT_CURL = ENV["HOMEBREW_USER_AGENT_CURL"]
|
||||||
HOMEBREW_USER_AGENT_RUBY = "#{ENV["HOMEBREW_USER_AGENT"]} ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
|
HOMEBREW_USER_AGENT_RUBY = "#{ENV["HOMEBREW_USER_AGENT"]} ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
|
||||||
|
|||||||
@ -561,11 +561,6 @@ def number_readable(number)
|
|||||||
numstr
|
numstr
|
||||||
end
|
end
|
||||||
|
|
||||||
# True if this version of Ruby supports text encodings in its strings
|
|
||||||
def ruby_has_encoding?
|
|
||||||
String.method_defined?(:force_encoding)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Truncates a text string to fit within a byte size constraint,
|
# Truncates a text string to fit within a byte size constraint,
|
||||||
# preserving character encoding validity. The returned string will
|
# preserving character encoding validity. The returned string will
|
||||||
# be not much longer than the specified max_bytes, though the exact
|
# be not much longer than the specified max_bytes, though the exact
|
||||||
@ -579,13 +574,8 @@ def truncate_text_to_approximate_size(s, max_bytes, options = {})
|
|||||||
|
|
||||||
glue = "\n[...snip...]\n"
|
glue = "\n[...snip...]\n"
|
||||||
max_bytes_in = [max_bytes - glue.bytesize, 1].max
|
max_bytes_in = [max_bytes - glue.bytesize, 1].max
|
||||||
if ruby_has_encoding?
|
bytes = s.dup.force_encoding("BINARY")
|
||||||
bytes = s.dup.force_encoding("BINARY")
|
glue_bytes = glue.encode("BINARY")
|
||||||
glue_bytes = glue.encode("BINARY")
|
|
||||||
else
|
|
||||||
bytes = s
|
|
||||||
glue_bytes = glue
|
|
||||||
end
|
|
||||||
n_front_bytes = (max_bytes_in * front_weight).floor
|
n_front_bytes = (max_bytes_in * front_weight).floor
|
||||||
n_back_bytes = max_bytes_in - n_front_bytes
|
n_back_bytes = max_bytes_in - n_front_bytes
|
||||||
if n_front_bytes == 0
|
if n_front_bytes == 0
|
||||||
@ -599,10 +589,8 @@ def truncate_text_to_approximate_size(s, max_bytes, options = {})
|
|||||||
back = bytes[-n_back_bytes..-1]
|
back = bytes[-n_back_bytes..-1]
|
||||||
end
|
end
|
||||||
out = front + glue_bytes + back
|
out = front + glue_bytes + back
|
||||||
if ruby_has_encoding?
|
out.force_encoding("UTF-8")
|
||||||
out.force_encoding("UTF-8")
|
out.encode!("UTF-16", :invalid => :replace)
|
||||||
out.encode!("UTF-16", :invalid => :replace)
|
out.encode!("UTF-8")
|
||||||
out.encode!("UTF-8")
|
|
||||||
end
|
|
||||||
out
|
out
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user