diff options
author | Homu <homu@barosl.com> | 2016-01-15 11:18:33 -0800 |
---|---|---|
committer | Homu <homu@barosl.com> | 2016-01-15 11:18:33 -0800 |
commit | 7148859353e0c175bd2c26104553af9d0cc96c88 (patch) | |
tree | d9806825dd4f3fcb7768ed449dc90061a0a6b884 | |
parent | 5269344798ce686fdbaf262c6537f045293d48dd (diff) | |
parent | cca32559824d7d0f867904915ad33df233eaf765 (diff) | |
download | bundler-7148859353e0c175bd2c26104553af9d0cc96c88.tar.gz |
Auto merge of #4143 - deepj:string-frozen-literal, r=indirect
[WIP] Better support of Ruby 2.3 with enabled frozen string literal
This commit prevents several bugs with `RuntimeError: can't modify frozen String` with enabled string frozen literal in Ruby 2.3
-rw-r--r-- | .rubocop.yml | 4 | ||||
-rw-r--r-- | .travis.yml | 5 | ||||
-rw-r--r-- | lib/bundler/definition.rb | 4 | ||||
-rw-r--r-- | lib/bundler/env.rb | 4 | ||||
-rw-r--r-- | lib/bundler/gem_helper.rb | 2 | ||||
-rw-r--r-- | lib/bundler/lazy_specification.rb | 6 | ||||
-rw-r--r-- | lib/bundler/resolver.rb | 2 | ||||
-rw-r--r-- | lib/bundler/rubygems_ext.rb | 4 | ||||
-rw-r--r-- | lib/bundler/source/path.rb | 2 | ||||
-rw-r--r-- | lib/bundler/source/rubygems.rb | 2 |
10 files changed, 23 insertions, 12 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index adf2867b00..ea89254c7d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -63,6 +63,10 @@ Style/TrailingComma: Style/TrailingUnderscoreVariable: Enabled: false +# `String.new` is preferred style with enabled frozen string literal +Style/EmptyLiteral: + Enabled: false + # 1.8.7 support Style/HashSyntax: diff --git a/.travis.yml b/.travis.yml index c7d6deb873..357403e762 100644 --- a/.travis.yml +++ b/.travis.yml @@ -91,6 +91,11 @@ matrix: # Ruby-head (we want to know how we're doing, but not fail the build) - rvm: ruby-head env: RGV=master + # Ruby-head with enabled frozen string literal + - rvm: ruby-head + env: + - RGV=master + - RUBYOPT="--enable-frozen-string-literal --debug=frozen-string-literal" allow_failures: - rvm: 1.8.7 env: RGV=v2.1.11 diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 2729ca75b0..deb6af5cbb 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -53,7 +53,7 @@ module Bundler @specs = nil @ruby_version = ruby_version - @lockfile_contents = "" + @lockfile_contents = String.new @locked_bundler_version = nil if lockfile && File.exist?(lockfile) @@ -298,7 +298,7 @@ module Bundler end def to_lock - out = "" + out = String.new sources.lock_sources.each do |source| # Add the source header diff --git a/lib/bundler/env.rb b/lib/bundler/env.rb index 6942eccaa8..93d35900ae 100644 --- a/lib/bundler/env.rb +++ b/lib/bundler/env.rb @@ -11,7 +11,7 @@ module Bundler print_gemfile = options.delete(:print_gemfile) print_gemspecs = options.delete(:print_gemspecs) - out = "Environment\n\n" + out = String.new("Environment\n\n") out << " Bundler #{Bundler::VERSION}\n" out << " Rubygems #{Gem::VERSION}\n" out << " Ruby #{ruby_version}" @@ -62,7 +62,7 @@ module Bundler end def ruby_version - str = "#{RUBY_VERSION}" + str = String.new("#{RUBY_VERSION}") if RUBY_VERSION < "1.9" str << " (#{RUBY_RELEASE_DATE}" str << " patchlevel #{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index 99d4194edf..8cfbeb4df1 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -173,7 +173,7 @@ module Bundler def sh_with_code(cmd, &block) cmd << " 2>&1" - outbuf = "" + outbuf = String.new Bundler.ui.debug(cmd) SharedHelpers.chdir(base) do outbuf = `#{cmd}` diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index 38ab0a16c6..b3d0d4e732 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -35,10 +35,12 @@ module Bundler end def to_lock + out = String.new + if platform == Gem::Platform::RUBY || platform.nil? - out = " #{name} (#{version})\n" + out << " #{name} (#{version})\n" else - out = " #{name} (#{version}-#{platform})\n" + out << " #{name} (#{version}-#{platform})\n" end dependencies.sort_by(&:to_s).uniq.each do |dep| diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index a798705aa7..82dcd7fbfd 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -21,7 +21,7 @@ module Bundler end o << %( In Gemfile:\n) o << conflict.requirement_trees.sort_by {|t| t.reverse.map(&:name) }.map do |tree| - t = "" + t = String.new depth = 2 tree.each do |req| t << " " * depth << req.to_s diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 33f6308014..e1051a3851 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -94,7 +94,7 @@ module Gem private def dependencies_to_gemfile(dependencies, group = nil) - gemfile = "" + gemfile = String.new if dependencies.any? gemfile << "group :#{group} do\n" if group dependencies.each do |dependency| @@ -126,7 +126,7 @@ module Gem end def to_lock - out = " #{name}" + out = String.new(" #{name}") unless requirement == Gem::Requirement.default reqs = requirement.requirements.map {|o, v| "#{o} #{v}" }.sort.reverse out << " (#{reqs.join(", ")})" diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index 4192015cb7..ebdab3e813 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -42,7 +42,7 @@ module Bundler end def to_lock - out = "PATH\n" + out = String.new("PATH\n") out << " remote: #{relative_path}\n" out << " glob: #{@glob}\n" unless @glob == DEFAULT_GLOB out << " specs:\n" diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 1f45888421..effd4680f6 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -60,7 +60,7 @@ module Bundler end def to_lock - out = "GEM\n" + out = String.new("GEM\n") remotes.reverse_each do |remote| out << " remote: #{suppress_configured_credentials remote}\n" end |