summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-11-20 12:12:43 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-11-20 12:49:33 +0000
commitaa5c9cfde38f19ae8795ec3b9ef6c64510fc0212 (patch)
tree2f2b69aa39fe907387523ea48e46518b9155d56e
parent5c9560d29891ca10f02e98e0430edff274fb37eb (diff)
downloadimport-aa5c9cfde38f19ae8795ec3b9ef6c64510fc0212.tar.gz
rubygems: Support .gemspec files in subdirectories of the git repo
This is cool because now you can import Ruby on Rails.
-rw-r--r--baserockimport/exts/importer_bundler_extensions.rb38
1 files changed, 26 insertions, 12 deletions
diff --git a/baserockimport/exts/importer_bundler_extensions.rb b/baserockimport/exts/importer_bundler_extensions.rb
index 0e81cf5..88c82e2 100644
--- a/baserockimport/exts/importer_bundler_extensions.rb
+++ b/baserockimport/exts/importer_bundler_extensions.rb
@@ -28,7 +28,25 @@ end
module Importer
module BundlerExtensions
+ def locate_gemspec(gem_name, path)
+ target = "#{gem_name}.gemspec"
+ matches = Dir["#{path}/#{Bundler::Source::Path::DEFAULT_GLOB}"].select do |filename|
+ File.basename(filename) == target
+ end
+ if matches.empty?
+ error "Did not find any files matching #{target} within #{path}."
+ exit 1
+ elsif matches.length > 1
+ error "Multiple files matching #{target} found within #{path}. It's " \
+ "not clear which one to use!"
+ exit 1
+ end
+ matches[0]
+ end
+
def create_bundler_definition_for_gemspec(gem_name, path)
+ gemspec_file = locate_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
@@ -40,14 +58,8 @@ module Importer
# chosen .gemspec. If present, the Gemfile.lock will be honoured.
fake_gemfile = Bundler::Dsl.new
fake_gemfile.source('https://rubygems.org')
- begin
- fake_gemfile.gemspec({:name => gem_name,
- :path => path})
- rescue Bundler::InvalidOption
- error "Did not find #{gem_name}.gemspec in current directory."
- exit 1
- end
-
+ fake_gemfile.gemspec({:name => gem_name,
+ :path => File.dirname(gemspec_file)})
fake_gemfile.to_definition('Gemfile.lock', true)
end
@@ -61,11 +73,13 @@ module Importer
found[0]
end
+ def directory_is_within(path, expected_subpath)
+ File.realpath(expected_subpath).start_with?(File.realpath(path))
+ end
+
def spec_is_from_current_source_tree(spec, source_dir)
- Dir.chdir(source_dir) do
- spec.source.instance_of? Bundler::Source::Path and
- File.identical?(spec.source.path, '.')
- end
+ spec.source.instance_of? Bundler::Source::Path and
+ directory_is_within(source_dir, spec.source.path)
end
def validate_spec(spec, source_dir_name, expected_version)