diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-09-04 12:06:18 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-09-11 13:26:27 +0100 |
commit | b9e92ac70f6fc4c6edb3f1f95308ea253603bba6 (patch) | |
tree | 0a618fdb903dc89c2e5e9181405d44b2da74a380 | |
parent | fb48e0a6c2152d8eafa67a432ea8c61f2928bbc4 (diff) | |
download | morph-b9e92ac70f6fc4c6edb3f1f95308ea253603bba6.tar.gz |
import: Remove a bunch of dead code
-rwxr-xr-x | import/rubygem.to_chunk | 185 |
1 files changed, 0 insertions, 185 deletions
diff --git a/import/rubygem.to_chunk b/import/rubygem.to_chunk index 03848562..fdb44273 100755 --- a/import/rubygem.to_chunk +++ b/import/rubygem.to_chunk @@ -24,39 +24,11 @@ require 'yaml' BASEROCK_RUBY_VERSION = '2.0.0' -# I'm no longer convinced about 'ignoring' Gems. My thinking is that it is -# much easier to add a missing dependency than it is to detect and remove -# unneeded dependencies. Therefore, a whilelist is perhaps the way forwards -# instead. - BUILD_DEPENDENCY_WHITELIST = [ 'hoe', # rake is bundled with Ruby, so it is not included in the whitelist. ] -#IGNORED_GROUPS = [:compat_testing, :test] -# -# Users of traditional distros seem to find it useful to override the versions -# of these Gems that come bundled with the MRI Ruby intepreter with newer -# versions from rubygems.org. In Baserock it should be just as easy to update -# MRI. We should avoid building components from two places. -#BUNDLED_GEMS = [ -# 'rake', -#] - -# Ignoring the :test group isn't enough for these Gems, they are often in the -# :development group too and thus we need to explicitly ignore them. -#TEST_GEMS = [ -# 'rspec', -# 'rspec_junit_formatter', -# 'rspec-core', -# 'rspec-expectations', -# 'rspec-mocks', -# 'simplecov', -#] -# -#IGNORED_GEMS = BUNDLED_GEMS + TEST_GEMS - # Log information was passed in from the main import process, probably. # This global constant approach seems a little ugly, but it seems to be # recommended here: @@ -92,148 +64,6 @@ def spec_is_from_current_source_tree(spec) spec.source.path.fnmatch?('.') end -class Dsl < Bundler::Dsl - # The Bundler::Dsl class parses the Gemfile. We override it so that we can - # extend the class of the Bundler::Definition instance that is created, and - # so we can filter the results down to a specific Gem from the repo rather - # than the top-level one. - - def self.evaluate(gemfile, lockfile, unlock, target_gem_name) - builder = new - builder.eval_gemfile(gemfile) - builder.to_definition(lockfile, unlock, target_gem_name) - end - - def to_definition(lockfile, unlock, target_gem_name) - @sources << rubygems_source unless @sources.include?(rubygems_source) - - #@dependencies = filter_dependencies_for_target_gem(@dependencies, - # target_gem_name) - #Log.debug "The modified list of dependencies is: #{@dependencies}" - - Definition.new(lockfile, @dependencies, @sources, unlock, @ruby_version) - end - - def filter_dependencies_for_target_gem(dependencies, target_gem_name) - # Find the local Bundler::Source object, remove everything from that - # source except the Gem we actually care about. This is necessary - # because Bundler is designed for people who want to develop or deploy - # all Gems from a given repo, but in this case we only care about *one* - # Gem from the repo, which may not be the top level one. - - # Note that this doesn't solve all our problems!!!! For Rails, for - # example, the top-level Gemfile lists a bunch of stuff that isn't - # needed for all the Gems. For example some databases, which are not at - # all necessary for activesupport! And jquery-rails, which brings in - # railties, which brings in actionpack, which is just not needed! - # - # To be honest, I have no idea what to do about this right now. Maybe - # a blacklist for certain nested Gems? - # - # One possible solution is to ignore everything the Gemfile says except - # for the target gemspec. So ditch @dependencies altogether except for - # the one Gem we want. Will need to test this with the whole dependency - # graph of Chef and see if it works .... - local_source = nil - new_deps = [] - have_target = false - dependencies.each do |dep| - Log.debug " - #{dep} #{dep.source} #{dep.groups}" - if spec_is_from_current_source_tree(dep) - local_source = local_source || dep.source - if dep.name == target_gem_name - new_deps << dep - have_target = true - end - else - new_deps << dep - end - end - - if not local_source - # While Bundler recommends using 'gemspec' in the Gemfile[1] it's not - # required, and some Gems are old enough to not have a .gemspec anyway. - # In this case the code will fail later on at get_spec_for_gem(), right - # now :) We need to manually search for Gemspecs. - Log.info "No gemspecs were included in the Gemfile, so the full " + - "list of specified dependencies will be used." - return dependencies - end - - if not have_target - target_dep = Bundler::Dependency.new( - target_gem_name, '>= 0', - {"type" => :runtime, "source" => local_source} - ) - new_deps << target_dep - Log.debug "The target gem #{target_dep} was not found in the " + - "dependencies list, so I have added it." - Log.debug "Its source is: #{target_dep.source.inspect}" - end - new_deps - end -end - -class Definition < Bundler::Definition - # The Bundler::Definition class holds the dependency info we need. - - def self.build(gemfile, lockfile, unlock, target_gem_name) - # Overridden so that our subclassed Dsl is used. - unlock ||= {} - gemfile = Pathname.new(gemfile).expand_path - - unless gemfile.file? - raise Bundler::GemfileNotFound, "#{gemfile} not found" - end - - Dsl.evaluate(gemfile, lockfile, unlock, target_gem_name) - end - - def requested_dependencies - # Overridden to remove more stuff from the list: excluding certain - # groups using Bundler.settings.without is a good first step, but some - # test tools seem to be in the generic :development group and thus - # need to be explicitly removed from the list. - #result = super.reject { |d| IGNORED_GEMS.member? d.name } - #removed = dependencies - result - #Log.info "Removed dependencies: #{removed.collect {|d| d.name}}" - - #result - super - end - - def resolve_dependencies - # The term "build dependencies" is my own. RubyGems seem to mostly care - # about "needed at runtime" (:runtime) vs. "useful during development" - # (:development). We actually want "needed at runtime or during `rake - # install`" but we have to work this out for ourselves. - - # Note you can set ENV['DEBUG_RESOLVER'] for more debug info. - - # Here we do the equivalent of resolve_remotely! and resolve_cached! - # combined. In the hope that they work OK together. Ideally we'd - # cache the specs after fetching them the first time so that on the - # next run we only needed to fetch the ones we didn't already have. Not - # sure the Bundler code makes this at all easy though. Probably - # extending Source::Rubygems would be the way forwards. - @remote = true - @sources.each { |s| s.remote! } - @sources.each { |s| s.cached! } - - build_deps = specs_for([:development]) - # FIXME: this list seems to always just contain 'bundler'. - # not what I want, I think. Any value achieves the same thing so - # I guess ':runtime' is not right. Maybe Bundler doesn't track - # runtime deps at all? - runtime_deps = specs_for([:runtime]) - STDERR.puts "Build deps: " - build_deps.each { |s| STDERR.puts " - #{s.name}" } - STDERR.puts "Runtime deps:" - runtime_deps.each { |s| STDERR.puts " - #{s.name}" } - return [build_deps, runtime_deps] - end -end - class RubyGemChunkMorphologyGenerator def parse_options(arguments) # No options so far .. @@ -284,13 +114,6 @@ class RubyGemChunkMorphologyGenerator source end - def load_definition(target_gem_name) - # Load and parse the Gemfile and, if found, the Gemfile.lock file. - Log.info("Loading Gemfile and Gemfile.lock for gem #{target_gem_name}") - definition = Definition.build( - 'Gemfile', 'Gemfile.lock', update=false, target_gem_name) - end - def get_spec_for_gem(specs, gem_name) found = specs[gem_name].select {|s| Gem::Platform.match(s.platform)} if found.empty? @@ -394,12 +217,6 @@ class RubyGemChunkMorphologyGenerator Dir.chdir(source_dir_name) - ## Find the .gemspec file in the project repo corresponding to the Gem - ## requested on the commandline. - #local_source = load_local_gemspecs - #local_specset = Bundler::SpecSet.new(local_source.local_specs) - #spec = get_spec_for_gem(local_specset, gem_name) - # Instead of reading the real Gemfile, invent one that simply includes the # chosen .gemspec. If present, the Gemfile.lock will be honoured. fake_gemfile = Bundler::Dsl.new @@ -409,8 +226,6 @@ class RubyGemChunkMorphologyGenerator definition = fake_gemfile.to_definition('Gemfile.lock', true) resolved_specs = definition.resolve_remotely! - #build_specs, runtime_specs = definition.resolve_dependencies - spec = get_spec_for_gem(resolved_specs, gem_name) if not spec_is_from_current_source_tree(spec) |