Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

Fix the path to the Gemfile during evaluation. #4244

Merged
merged 3 commits into from
Jan 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/bundler/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ def initialize
@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
Expand All @@ -47,7 +49,7 @@ def gemspec(opts = nil)
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")]

Expand Down Expand Up @@ -144,7 +146,9 @@ def git_source(name, &block)
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)
Expand Down Expand Up @@ -487,5 +491,10 @@ def parse_line_number_from_description
[trace_line, description]
end
end

def gemfile_root
@gemfile ||= Bundler.default_gemfile
@gemfile.dirname
end
end
end
12 changes: 7 additions & 5 deletions lib/bundler/source/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Source
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

Expand All @@ -16,6 +16,8 @@ def initialize(options)
@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?
Expand Down Expand Up @@ -77,7 +79,7 @@ def install(spec, force = false)
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!"
Expand Down Expand Up @@ -111,7 +113,7 @@ def expanded_path
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 " \
Expand Down Expand Up @@ -164,8 +166,8 @@ def load_spec_files
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
Expand Down
1 change: 1 addition & 0 deletions spec/bundler/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
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")
Expand Down