From 6ebb2acda528ebd324dd74cb0ab2521f2e4aca6f Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Wed, 19 Nov 2014 17:05:13 +0000 Subject: Fix rubygems.to_chunk failing when run inside `bundle exec` By calling Bundler::Dsl.gemspec without specifying :path, this tool was causing the Bundler::Source::Path instance for the target .gemspec to be for path '.', which is relative path that is only valid inside one Dir.chdir block. It seems that all the Bundler resolution code runs inside that block and so there should be no problem, but unless we specify an absolute path for the gemspec then errors like this sometimes appear: /usr/lib/ruby/gems/2.0.0/gems/bundler-1.7.6/lib/bundler/resolver.rb:357:in `resolve': Could not find gem 'ffi-yajl (>= 0) ruby' in source at .. (Bundler::GemNotFound) Source does not contain any versions of 'ffi-yajl (>= 0) ruby' This normally happens when an Omnibus import chains to rubygems.to_chunk for a RubyGem component. The path is clearly valid at the time Bundler::Dsl.gemspec is called (otherwise it'd raise a Bundler::InvalidOption exception at the time) but not valid later (hence the error). Note that the second '.' in that error message is a full stop and not part of the path! --- baserockimport/exts/importer_bundler_extensions.rb | 5 +++-- baserockimport/exts/rubygems.find_deps | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/baserockimport/exts/importer_bundler_extensions.rb b/baserockimport/exts/importer_bundler_extensions.rb index 034b3c2..0e81cf5 100644 --- a/baserockimport/exts/importer_bundler_extensions.rb +++ b/baserockimport/exts/importer_bundler_extensions.rb @@ -28,7 +28,7 @@ end module Importer module BundlerExtensions - def create_bundler_definition_for_gemspec(gem_name) + def create_bundler_definition_for_gemspec(gem_name, path) # Using the real Gemfile doesn't get great results, because people can put # lots of stuff in there that is handy for developers to have but # irrelevant if you just want to produce a .gem. Also, there is only one @@ -41,7 +41,8 @@ module Importer fake_gemfile = Bundler::Dsl.new fake_gemfile.source('https://rubygems.org') begin - fake_gemfile.gemspec({:name => gem_name}) + fake_gemfile.gemspec({:name => gem_name, + :path => path}) rescue Bundler::InvalidOption error "Did not find #{gem_name}.gemspec in current directory." exit 1 diff --git a/baserockimport/exts/rubygems.find_deps b/baserockimport/exts/rubygems.find_deps index 228c88b..5ae9598 100755 --- a/baserockimport/exts/rubygems.find_deps +++ b/baserockimport/exts/rubygems.find_deps @@ -74,7 +74,7 @@ class RubyGemDependencyFinder < Importer::Base "#{source_dir_name}") resolved_specs = Dir.chdir(source_dir_name) do - definition = create_bundler_definition_for_gemspec(gem_name) + definition = create_bundler_definition_for_gemspec(gem_name, source_dir_name) definition.resolve_remotely! end -- cgit v1.2.1