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. #3349

Closed
wants to merge 2 commits into from
Closed
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
15 changes: 13 additions & 2 deletions lib/bundler/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ def initialize
@platforms = []
@env = nil
@ruby_version = nil
@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 SyntaxError => e
Expand All @@ -44,7 +46,7 @@ def gemspec(opts = nil)
path = opts && opts[:path] || '.'
name = opts && opts[:name] || '{,*}'
development_group = opts && opts[:development_group] || :development
expanded_path = File.expand_path(path, Bundler.default_gemfile.dirname)
expanded_path = path_relative_to_gemfile(path)

gemspecs = Dir[File.join(expanded_path, "#{name}.gemspec")]

Expand Down Expand Up @@ -130,7 +132,7 @@ 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)
with_source(@sources.add_path_source(normalize_hash(options).merge("path" => path_relative_to_gemfile(path))), &blk)
end

def git(uri, options = {}, &blk)
Expand Down Expand Up @@ -284,6 +286,10 @@ def normalize_options(name, version, opts)
opts["git"] = @git_sources[git_name].call(opts[git_name])
end

if opts.key?("path")
opts["path"] = path_relative_to_gemfile(opts["path"])
end

["git", "path", "svn"].each do |type|
if param = opts[type]
if version.first && version.first =~ /^\s*=?\s*(\d[^\s]*)\s*$/
Expand Down Expand Up @@ -315,5 +321,10 @@ def normalize_source(source)
raise GemfileError, "Unknown source '#{source}'"
end
end

def path_relative_to_gemfile(path)
@gemfile ||= Bundler.default_gemfile
@gemfile.dirname + path
end
end
end