diff options
author | Homu <homu@barosl.com> | 2016-08-04 12:23:42 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2016-08-04 12:23:42 +0900 |
commit | dda6432b71043b8065080f2fb83358614c4d04e8 (patch) | |
tree | db9aacea31b9c289d80c45e57ba045f43b16523e | |
parent | dfea4f22d32c5833ba373f4ecf7575cb49259d6c (diff) | |
parent | 8f1f1071c9e6ebc32697a9b046a07a9ef89b6d6f (diff) | |
download | bundler-dda6432b71043b8065080f2fb83358614c4d04e8.tar.gz |
Auto merge of #4832 - bundler:seg-remove-environment, r=indirect
Remove Bundler::Environment
Pretty straightforward refactoring
-rw-r--r-- | lib/bundler.rb | 12 | ||||
-rw-r--r-- | lib/bundler/cli/binstubs.rb | 2 | ||||
-rw-r--r-- | lib/bundler/environment.rb | 46 | ||||
-rw-r--r-- | lib/bundler/installer.rb | 17 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 25 | ||||
-rw-r--r-- | spec/commands/config_spec.rb | 9 | ||||
-rw-r--r-- | spec/install/upgrade_spec.rb | 26 | ||||
-rw-r--r-- | spec/other/major_deprecation_spec.rb | 8 |
8 files changed, 48 insertions, 97 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 98f8123466..307f6e5d05 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -26,7 +26,6 @@ module Bundler autoload :Dsl, "bundler/dsl" autoload :EndpointSpecification, "bundler/endpoint_specification" autoload :Env, "bundler/env" - autoload :Environment, "bundler/environment" autoload :Fetcher, "bundler/fetcher" autoload :GemHelper, "bundler/gem_helper" autoload :GemHelpers, "bundler/gem_helpers" @@ -112,7 +111,8 @@ module Bundler end def environment - Bundler::Environment.new(root, definition) + SharedHelpers.major_deprecation "Bundler.environment has been removed in favor of Bundler.load" + load end # Returns an instance of Bundler::Definition for given Gemfile and lockfile @@ -124,7 +124,6 @@ module Bundler @definition = nil if unlock @definition ||= begin configure - upgrade_lockfile Definition.build(default_gemfile, default_lockfile, unlock) end end @@ -448,13 +447,6 @@ module Bundler Bundler.rubygems.clear_paths end - def upgrade_lockfile - lockfile = default_lockfile - return unless lockfile.exist? && lockfile.read(3) == "---" - Bundler.ui.warn "Detected Gemfile.lock generated by 0.9, deleting..." - lockfile.rmtree - end - # @param env [Hash] def with_env(env) backup = ENV.to_hash diff --git a/lib/bundler/cli/binstubs.rb b/lib/bundler/cli/binstubs.rb index 971d80755e..f7a27b01bb 100644 --- a/lib/bundler/cli/binstubs.rb +++ b/lib/bundler/cli/binstubs.rb @@ -21,7 +21,7 @@ module Bundler end gems.each do |gem_name| - spec = installer.specs.find {|s| s.name == gem_name } + spec = Bundler.definition.specs.find {|s| s.name == gem_name } unless spec raise GemNotFound, Bundler::CLI::Common.gem_not_found_message( gem_name, Bundler.definition.specs diff --git a/lib/bundler/environment.rb b/lib/bundler/environment.rb deleted file mode 100644 index fedc6b298f..0000000000 --- a/lib/bundler/environment.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true -module Bundler - class Environment - attr_reader :root - - def initialize(root, definition) - @root = root - @definition = definition - - env_file = Bundler.app_config_path.join("environment.rb") - env_file.rmtree if env_file.exist? - end - - def inspect - @definition.to_lock.inspect - end - - def requested_specs - @definition.requested_specs - end - - def specs - @definition.specs - end - - def dependencies - @definition.dependencies - end - - def current_dependencies - @definition.current_dependencies - end - - def requires - @definition.requires - end - - def lock(opts = {}) - @definition.lock(Bundler.default_lockfile, opts[:preserve_unknown_sections]) - end - - def update(*gems) - # Nothing - end - end -end diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 3d51505bb9..402d7fb611 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -7,7 +7,7 @@ require "bundler/installer/standalone" require "bundler/installer/gem_installer" module Bundler - class Installer < Environment + class Installer class << self attr_accessor :post_install_messages, :ambiguous_gems @@ -23,6 +23,11 @@ module Bundler installer end + def initialize(root, definition) + @root = root + @definition = definition + end + # Runs the install procedures for a specific Gemfile. # # Firstly, this method will check to see if Bundler.bundle_path exists @@ -61,7 +66,7 @@ module Bundler @definition.ensure_equivalent_gemfile_and_lockfile(options[:deployment]) end - if dependencies.empty? + if @definition.dependencies.empty? Bundler.ui.warn "The Gemfile specifies no dependencies" lock return @@ -160,7 +165,7 @@ module Bundler def ensure_specs_are_compatible! system_ruby = Bundler::RubyVersion.system rubygems_version = Gem::Version.create(Gem::VERSION) - specs.each do |spec| + @definition.specs.each do |spec| if required_ruby_version = spec.required_ruby_version unless required_ruby_version.satisfied_by?(system_ruby.gem_version) raise InstallError, "#{spec.full_name} requires ruby version #{required_ruby_version}, " \ @@ -187,7 +192,7 @@ module Bundler end def install_in_parallel(size, standalone, force = false) - ParallelInstaller.call(self, specs, size, standalone, force) + ParallelInstaller.call(self, @definition.specs, size, standalone, force) end def create_bundle_path @@ -213,5 +218,9 @@ module Bundler return if local options["local"] ? @definition.resolve_with_cache! : @definition.resolve_remotely! end + + def lock(opts = {}) + @definition.lock(Bundler.default_lockfile, opts[:preserve_unknown_sections]) + end end end diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 3a86fe9226..fb2c76bc0c 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -2,9 +2,14 @@ require "digest/sha1" module Bundler - class Runtime < Environment + class Runtime include SharedHelpers + def initialize(root, definition) + @root = root + @definition = definition + end + def setup(*groups) groups.map!(&:to_sym) @@ -107,6 +112,24 @@ module Bundler end end + def self.definition_method(meth) + define_method(meth) do + raise ArgumentError, "no definition when calling Runtime##{meth}" unless @definition + @definition.send(meth) + end + end + private_class_method :definition_method + + definition_method :requested_specs + definition_method :specs + definition_method :dependencies + definition_method :current_dependencies + definition_method :requires + + def lock(opts = {}) + @definition.lock(Bundler.default_lockfile, opts[:preserve_unknown_sections]) + end + alias_method :gems, :specs def cache(custom_path = nil) diff --git a/spec/commands/config_spec.rb b/spec/commands/config_spec.rb index b7a1d55172..fce6102c29 100644 --- a/spec/commands/config_spec.rb +++ b/spec/commands/config_spec.rb @@ -30,15 +30,6 @@ describe ".bundle/config" do expect(bundled_app("../foo/config")).to exist expect(the_bundle).to include_gems "rack 1.0.0" end - - it "removes environment.rb from BUNDLE_APP_CONFIG's path" do - FileUtils.mkdir_p(tmp("foo/bar")) - ENV["BUNDLE_APP_CONFIG"] = tmp("foo/bar").to_s - bundle "install" - FileUtils.touch tmp("foo/bar/environment.rb") - expect(the_bundle).to include_gems "rack 1.0.0" - expect(tmp("foo/bar/environment.rb")).not_to exist - end end describe "global" do diff --git a/spec/install/upgrade_spec.rb b/spec/install/upgrade_spec.rb deleted file mode 100644 index d979b97647..0000000000 --- a/spec/install/upgrade_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true -require "spec_helper" - -describe "bundle install for the first time with v1.0" do - before :each do - in_app_root - - gemfile <<-G - source "file://#{gem_repo1}" - gem "rack" - G - end - - it "removes lockfiles in 0.9 YAML format" do - File.open("Gemfile.lock", "w") {|f| YAML.dump({}, f) } - bundle :install - expect(Pathname.new("Gemfile.lock")).not_to read_as(a_string_starting_with("---")) - end - - it "removes env.rb if it exists" do - bundled_app.join(".bundle").mkdir - bundled_app.join(".bundle/environment.rb").open("w") {|f| f.write("raise 'nooo'") } - bundle :install - expect(bundled_app.join(".bundle/environment.rb")).not_to exist - end -end diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb index a28a7e2e97..c8a2633279 100644 --- a/spec/other/major_deprecation_spec.rb +++ b/spec/other/major_deprecation_spec.rb @@ -31,6 +31,14 @@ describe "major deprecations" do end end + describe ".environment" do + it "is deprecated in favor of .load" do + source = "Bundler.environment" + bundle "exec ruby -e #{source.dump}" + expect(warnings).to have_major_deprecation "Bundler.environment has been removed in favor of Bundler.load" + end + end + shared_examples_for "environmental deprecations" do |trigger| describe "ruby version", :ruby => "< 2.0" do it "requires a newer ruby version" do |