diff options
author | Homu <homu@barosl.com> | 2016-01-31 18:14:54 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2016-01-31 18:14:54 +0900 |
commit | 2f87aafe17eadf53b03c02647e1976035d9ddb27 (patch) | |
tree | 43ca2ba51a73a77057f55ca386c8ed64af7a0d09 | |
parent | bf42ae18cea8bf800318f06278e0f718692dec21 (diff) | |
parent | 8f8c1c420131acf76089bdeaa50b5c609aa2e71f (diff) | |
download | bundler-2f87aafe17eadf53b03c02647e1976035d9ddb27.tar.gz |
Auto merge of #4244 - dtognazzini:fix-path-to-gemfile, r=indirect
Fix the path to the Gemfile during evaluation.
This is a continuation of https://github.com/bundler/bundler/pull/3349 Following up per: https://github.com/bundler/bundler/pull/3349#issuecomment-88307579
The issue here is that paths used with `Bundler::Dsl#gemspec` will only work when the Gemfile being evaluated is `Bundler.default_gemfile`.
Passing a Gemfile other than `Bundler.default_gemfile` to `Bundler::Dsl.evaluate` will break uses of `path:` options in the Gemfile.
These changes update `Bundler::Dsl` to remember the Gemfile passed into `eval_gemfile` and use it to resolve relative paths.
-rw-r--r-- | lib/bundler/dsl.rb | 13 | ||||
-rw-r--r-- | lib/bundler/source/path.rb | 12 | ||||
-rw-r--r-- | spec/bundler/dsl_spec.rb | 1 |
3 files changed, 19 insertions, 7 deletions
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index b09a838fbb..57be120d9f 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -28,10 +28,12 @@ module Bundler @env = nil @ruby_version = nil @gemspecs = [] + @gemfile = nil add_git_sources end def eval_gemfile(gemfile, contents = nil) + @gemfile = Pathname.new(gemfile) contents ||= Bundler.read_file(gemfile.to_s) instance_eval(contents, gemfile.to_s, 1) rescue Exception => e @@ -47,7 +49,7 @@ module Bundler glob = opts && opts[:glob] name = opts && opts[:name] || "{,*}" development_group = opts && opts[:development_group] || :development - expanded_path = File.expand_path(path, Bundler.default_gemfile.dirname) + expanded_path = gemfile_root.join(path) gemspecs = Dir[File.join(expanded_path, "#{name}.gemspec")] @@ -144,7 +146,9 @@ module Bundler end def path(path, options = {}, &blk) - with_source(@sources.add_path_source(normalize_hash(options).merge("path" => Pathname.new(path))), &blk) + source_options = normalize_hash(options).merge("path" => Pathname.new(path), "root_path" => gemfile_root) + source = @sources.add_path_source(source_options) + with_source(source, &blk) end def git(uri, options = {}, &blk) @@ -487,5 +491,10 @@ module Bundler [trace_line, description] end end + + def gemfile_root + @gemfile ||= Bundler.default_gemfile + @gemfile.dirname + end end end diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index ebdab3e813..24a01b4060 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -3,7 +3,7 @@ module Bundler class Path < Source autoload :Installer, "bundler/source/path/installer" - attr_reader :path, :options + attr_reader :path, :options, :root_path attr_writer :name attr_accessor :version @@ -16,6 +16,8 @@ module Bundler @allow_cached = false @allow_remote = false + @root_path = options["root_path"] || Bundler.root + if options["path"] @path = Pathname.new(options["path"]) @path = expand(@path) unless @path.relative? @@ -77,7 +79,7 @@ module Bundler def cache(spec, custom_path = nil) app_cache_path = app_cache_path(custom_path) return unless Bundler.settings[:cache_all] - return if expand(@original_path).to_s.index(Bundler.root.to_s + "/") == 0 + return if expand(@original_path).to_s.index(root_path.to_s + "/") == 0 unless @original_path.exist? raise GemNotFound, "Can't cache gem #{version_message(spec)} because #{self} is missing!" @@ -111,7 +113,7 @@ module Bundler end def expand(somepath) - somepath.expand_path(Bundler.root) + somepath.expand_path(root_path) rescue ArgumentError => e Bundler.ui.debug(e) raise PathError, "There was an error while trying to use the path " \ @@ -164,8 +166,8 @@ module Bundler end def relative_path - if path.to_s.start_with?(Bundler.root.to_s) - return path.relative_path_from(Bundler.root) + if path.to_s.start_with?(root_path.to_s) + return path.relative_path_from(root_path) end path end diff --git a/spec/bundler/dsl_spec.rb b/spec/bundler/dsl_spec.rb index 2d323d64f4..9553c8fd43 100644 --- a/spec/bundler/dsl_spec.rb +++ b/spec/bundler/dsl_spec.rb @@ -235,6 +235,7 @@ describe Bundler::Dsl do it "restores it after it's done" do other_source = double("other-source") allow(Bundler::Source::Rubygems).to receive(:new).and_return(other_source) + allow(Bundler).to receive(:default_gemfile).and_return(Pathname.new("./Gemfile")) subject.source("https://other-source.org") do subject.gem("dobry-pies", :path => "foo") |