summaryrefslogtreecommitdiff
path: root/baserockimport/exts
diff options
context:
space:
mode:
Diffstat (limited to 'baserockimport/exts')
-rw-r--r--baserockimport/exts/importer_bundler_extensions.rb39
-rwxr-xr-xbaserockimport/exts/rubygems.find_deps7
-rwxr-xr-xbaserockimport/exts/rubygems.to_chunk8
3 files changed, 37 insertions, 17 deletions
diff --git a/baserockimport/exts/importer_bundler_extensions.rb b/baserockimport/exts/importer_bundler_extensions.rb
index 034b3c2..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 create_bundler_definition_for_gemspec(gem_name)
+ 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,13 +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})
- 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
@@ -60,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)
diff --git a/baserockimport/exts/rubygems.find_deps b/baserockimport/exts/rubygems.find_deps
index 228c88b..ae08b65 100755
--- a/baserockimport/exts/rubygems.find_deps
+++ b/baserockimport/exts/rubygems.find_deps
@@ -36,6 +36,7 @@ class RubyGemDependencyFinder < Importer::Base
def initialize
local_data = YAML.load_file(local_data_path("rubygems.yaml"))
@build_dependency_whitelist = local_data['build-dependency-whitelist']
+ @ignore_list = local_data['ignore-list']
end
def parse_options(arguments)
@@ -64,7 +65,9 @@ class RubyGemDependencyFinder < Importer::Base
end
def runtime_deps_for_gem(spec)
- spec.dependencies.select {|d| d.type == :runtime}
+ spec.dependencies.select do |d|
+ d.type == :runtime && ! @ignore_list.member?(d.name)
+ end
end
def run
@@ -74,7 +77,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
diff --git a/baserockimport/exts/rubygems.to_chunk b/baserockimport/exts/rubygems.to_chunk
index c1a3e7c..1573d8b 100755
--- a/baserockimport/exts/rubygems.to_chunk
+++ b/baserockimport/exts/rubygems.to_chunk
@@ -154,9 +154,11 @@ class RubyGemChunkMorphologyGenerator < Importer::Base
"source code in #{source_dir_name}")
resolved_specs = Dir.chdir(source_dir_name) do
- # FIXME: we don't need to do this here, it'd be enough just to load
- # the given gemspec
- definition = create_bundler_definition_for_gemspec(gem_name)
+ # FIXME: resolving the specs for all the dependencies of the target gem
+ # isn't necessary here. In fact, just reading/executing the .gemspec
+ # would be enough, and would speed this program up and remove a lot of
+ # pointless network access to rubygems.org.
+ definition = create_bundler_definition_for_gemspec(gem_name, source_dir_name)
definition.resolve_remotely!
end