From ab125675f37421098ab070dbd85b4f40bbbf17cd Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Wed, 3 Dec 2014 16:25:37 +0000 Subject: rubygems: Fix broken build-commands when .gemspec is in a subdirectory The rubygems.to_chunk tool was assuming the .gemspec file always lived at the top of the chunk repo, but this isn't the case for . Now it is smarter. --- baserockimport/exts/importer_bundler_extensions.rb | 4 +--- baserockimport/exts/rubygems.find_deps | 4 +++- baserockimport/exts/rubygems.to_chunk | 22 ++++++++++++++++------ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/baserockimport/exts/importer_bundler_extensions.rb b/baserockimport/exts/importer_bundler_extensions.rb index 88c82e2..8eba91b 100644 --- a/baserockimport/exts/importer_bundler_extensions.rb +++ b/baserockimport/exts/importer_bundler_extensions.rb @@ -44,9 +44,7 @@ module Importer matches[0] end - def create_bundler_definition_for_gemspec(gem_name, path) - gemspec_file = locate_gemspec(gem_name, path) - + def create_bundler_definition_for_gemspec(gem_name, gemspec_file) # 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 diff --git a/baserockimport/exts/rubygems.find_deps b/baserockimport/exts/rubygems.find_deps index ae08b65..df7e302 100755 --- a/baserockimport/exts/rubygems.find_deps +++ b/baserockimport/exts/rubygems.find_deps @@ -76,8 +76,10 @@ class RubyGemDependencyFinder < Importer::Base log.info("Finding dependencies for #{gem_name} based on source code in " \ "#{source_dir_name}") + gemspec_file = locate_gemspec(gem_name, source_dir_name) + resolved_specs = Dir.chdir(source_dir_name) do - definition = create_bundler_definition_for_gemspec(gem_name, source_dir_name) + definition = create_bundler_definition_for_gemspec(gem_name, gemspec_file) definition.resolve_remotely! end diff --git a/baserockimport/exts/rubygems.to_chunk b/baserockimport/exts/rubygems.to_chunk index 1573d8b..323cbb0 100755 --- a/baserockimport/exts/rubygems.to_chunk +++ b/baserockimport/exts/rubygems.to_chunk @@ -66,7 +66,7 @@ class RubyGemChunkMorphologyGenerator < Importer::Base spec.signing_key != nil end - def generate_chunk_morph_for_gem(spec) + def generate_chunk_morph_for_gem(gemspec_file, spec) description = 'Automatically generated by rubygems.to_chunk' bin_dir = "\"$DESTDIR/$PREFIX/bin\"" @@ -122,17 +122,21 @@ class RubyGemChunkMorphologyGenerator < Importer::Base # provide the private key of the Gem's maintainer. configure_commands << "sed -e '/cert_chain\\s*=/d' -e '/signing_key\\s*=/d' -i " \ - "#{spec.name}.gemspec" + "#{gemspec_file}" end + gemspec_dirname = File.dirname(gemspec_file) + gemspec_basename = File.basename(gemspec_file) + build_commands = [ - "gem build #{spec.name}.gemspec", + "cd #{gemspec_dirname} && gem build #{gemspec_basename}", ] install_commands = [ "mkdir -p #{gem_dir}", "gem install --install-dir #{gem_dir} --bindir #{bin_dir} " \ - "--ignore-dependencies --local ./#{spec.full_name}.gem" + "--ignore-dependencies --local " \ + "#{gemspec_dirname}/#{spec.full_name}.gem" ] { @@ -153,19 +157,25 @@ class RubyGemChunkMorphologyGenerator < Importer::Base log.info("Creating chunk morph for #{gem_name} based on " \ "source code in #{source_dir_name}") + gemspec_file = locate_gemspec(gem_name, source_dir_name) + resolved_specs = Dir.chdir(source_dir_name) do # 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 = create_bundler_definition_for_gemspec(gem_name, gemspec_file) definition.resolve_remotely! end spec = get_spec_for_gem(resolved_specs, gem_name) validate_spec(spec, source_dir_name, expected_version) - morph = generate_chunk_morph_for_gem(spec) + gemspec_file_in_chunk_repo = + Pathname.new(gemspec_file). + relative_path_from(Pathname.new(source_dir_name)) + + morph = generate_chunk_morph_for_gem(gemspec_file_in_chunk_repo, spec) write_morph(STDOUT, morph) end end -- cgit v1.2.1