[DRE-commits] [gem2deb] 01/01: debian/gemspec: expand symlinks
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Jul 9 16:48:39 UTC 2017
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to branch master
in repository gem2deb.
commit bbbe23b1b02e16de44e91ff7d2776a5f0d6de75c
Author: Antonio Terceiro <terceiro at debian.org>
Date: Sun Jul 9 13:37:35 2017 -0300
debian/gemspec: expand symlinks
gemspecs will usually contain references to __FILE__, so when
debian/gemspec is a symlink, we will follow the link and load the target
of the symlink.
---
bin/dh_ruby | 3 +++
lib/gem2deb/metadata.rb | 7 ++++++-
test/unit/metadata_test.rb | 18 ++++++++++++++----
3 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/bin/dh_ruby b/bin/dh_ruby
index b4b2a1c..50cc3a4 100755
--- a/bin/dh_ruby
+++ b/bin/dh_ruby
@@ -417,6 +417,9 @@ this is only advised on single-binary source packages, and the behavior of this
feature is undefined for multi-binary source packages (see B<SOURCE PACKAGE
LAYOUT> above).
+If debian/I<gemspec> is a symlink, it will first be expanded, and then the
+symlink target will be used as a gemspec.
+
Hint: for packages with multiple gemspec, you can have debian/I<gemspec> as a
symlink pointing to the one you want to use.
diff --git a/lib/gem2deb/metadata.rb b/lib/gem2deb/metadata.rb
index 1fd3282..7efe0a3 100644
--- a/lib/gem2deb/metadata.rb
+++ b/lib/gem2deb/metadata.rb
@@ -103,7 +103,12 @@ module Gem2Deb
def load_gemspec
if File.exist?('debian/gemspec')
- @gemspec = Gem::Specification.load('debian/gemspec')
+ if File.symlink?('debian/gemspec')
+ path = File.expand_path(File.readlink('debian/gemspec'), 'debian')
+ @gemspec = Gem::Specification.load(path)
+ else
+ @gemspec = Gem::Specification.load('debian/gemspec')
+ end
elsif File.exist?('metadata.yml')
@gemspec = YAML.load_file('metadata.yml')
elsif ENV['DH_RUBY_GEMSPEC']
diff --git a/test/unit/metadata_test.rb b/test/unit/metadata_test.rb
index 2eb8010..df6132d 100644
--- a/test/unit/metadata_test.rb
+++ b/test/unit/metadata_test.rb
@@ -206,17 +206,27 @@ class MetaDataTest < Gem2DebTestCase
end
context 'with debian/gemspec' do
- should 'use it' do
- gemspec = Gem::Specification.new do |spec|
+ setup do
+ @gemspec = Gem::Specification.new do |spec|
spec.name = 'mypkg'
spec.version = '1.2.3'
end
FileUtils.mkdir_p('test/tmp/debian')
- File.open('test/tmp/debian/gemspec', 'w') { |f| f.write(gemspec.to_ruby) }
+ File.open('test/tmp/debian/gemspec', 'w') { |f| f.write(@gemspec.to_ruby) }
+ end
+ should 'use it' do
metadata = Gem2Deb::Metadata.new('test/tmp')
assert_equal 'mypkg-1.2.3', [metadata.gemspec.name, metadata.gemspec.version].join('-')
end
-
+ should 'resolve symlinks' do
+ FileUtils.mv('test/tmp/debian/gemspec', 'test/tmp/mypkg.gemspec')
+ FileUtils.cp('test/tmp/mypkg.gemspec', 'test/tmp/other.gemspec')
+ Dir.chdir('test/tmp/debian') { FileUtils.ln_s('../mypkg.gemspec', 'gemspec') }
+ path = File.expand_path('test/tmp/mypkg.gemspec')
+ Gem::Specification.expects(:load).with(path).returns(@gemspec)
+ metadata = Gem2Deb::Metadata.new('test/tmp')
+ assert_equal 'mypkg', metadata.gemspec.name
+ end
end
context 'on multi-binary source packages' do
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/gem2deb.git
More information about the Pkg-ruby-extras-commits
mailing list