-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from ekohl/respect-doc-rules
Introduce a template context for proper loading
- Loading branch information
Showing
6 changed files
with
103 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'gem2rpm/template_helpers' | ||
|
||
module Gem2Rpm | ||
class Context | ||
include Gem2Rpm::TemplateHelpers | ||
|
||
attr_reader :nongem, :local, :doc_subpackage, :package, :format, :spec, | ||
:config, :runtime_dependencies, :development_dependencies, :tests, | ||
:files, :download_path | ||
|
||
def initialize(fname, nongem = true, local = false, doc_subpackage = true) | ||
@nongem = nongem | ||
@local = local | ||
@doc_subpackage = doc_subpackage | ||
|
||
@package = Gem2Rpm::Package.new(fname) | ||
# Deprecate, kept just for backward compatibility. | ||
@format = Gem2Rpm::Format.new(@package) | ||
@spec = Gem2Rpm::Specification.new(@package.spec) | ||
|
||
@config = Configuration.instance.reset | ||
|
||
@runtime_dependencies = Gem2Rpm::RpmDependencyList.new(@spec.runtime_dependencies) | ||
@development_dependencies = Gem2Rpm::RpmDependencyList.new(@spec.development_dependencies) | ||
|
||
@tests = TestSuite.new(spec) | ||
|
||
# Ruby 2.0 doesn't have sorted files | ||
@files = RpmFileList.new(spec.files.sort) | ||
|
||
@download_path = "" | ||
unless @local | ||
begin | ||
@download_path = Gem2Rpm.find_download_url(@spec.name, @spec.version) | ||
rescue DownloadUrlError => e | ||
$stderr.puts "Warning: Could not retrieve full URL for #{@spec.name}\nWarning: Edit the specfile and enter the full download URL as 'Source0' manually" | ||
$stderr.puts e.inspect | ||
end | ||
end | ||
end | ||
|
||
def main_files | ||
@files.top_level_entries.main_entries | ||
end | ||
|
||
def doc_files | ||
@files.top_level_entries.doc_entries | ||
end | ||
|
||
def packager | ||
Gem2Rpm.packager | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<%- | ||
# Move runtime to the doc subpackage | ||
config.rules[:misc] << 'runtime' | ||
# %exclude Gemfile | ||
config.rules[:ignore] << 'Gemfile' | ||
-%> | ||
%files | ||
<%= main_files.to_rpm %> | ||
|
||
%files doc | ||
<%= doc_files.to_rpm %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'helper' | ||
|
||
class TestConfigOverride < Minitest::Test | ||
def test_rules_respected | ||
template = Gem2Rpm::Template.new(File.join(__dir__, 'fake_files', 'config-override.erb')) | ||
out = StringIO.new | ||
Gem2Rpm.convert(gem_path, template, out, false) | ||
|
||
expected = <<-EXPECTED.gsub(/^ */, '') | ||
%files | ||
%exclude %{gem_instdir}/.travis.yml | ||
%{gem_instdir}/exe | ||
%{gem_instdir}/ext | ||
%{gem_libdir} | ||
%files doc | ||
%exclude %{gem_instdir}/Gemfile | ||
%doc %{gem_instdir}/README | ||
%{gem_instdir}/Rakefile | ||
%{gem_instdir}/runtime | ||
%{gem_instdir}/testing_gem.gemspec | ||
EXPECTED | ||
assert_equal(expected, out.string) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
require 'helper' | ||
require 'gem2rpm/template_helpers' | ||
|
||
class ConcreteTemplateHelpers | ||
extend Gem2Rpm::TemplateHelpers | ||
end | ||
|
||
class TestTemplateHelpers < Minitest::Test | ||
def test_requirement | ||
assert_equal "rubygem(foo)", Gem2Rpm.requirement("rubygem(foo)") | ||
assert_equal "rubygem(foo) >= 1.0", Gem2Rpm.requirement("rubygem(foo)", ">= 1.0") | ||
assert_equal "rubygem(foo)", Gem2Rpm.requirement("rubygem(foo)", "") | ||
assert_equal "rubygem(foo)", ConcreteTemplateHelpers.requirement("rubygem(foo)") | ||
assert_equal "rubygem(foo) >= 1.0", ConcreteTemplateHelpers.requirement("rubygem(foo)", ">= 1.0") | ||
assert_equal "rubygem(foo)", ConcreteTemplateHelpers.requirement("rubygem(foo)", "") | ||
|
||
artificial_object = Object.new | ||
assert_equal "rubygem(foo)", Gem2Rpm.requirement("rubygem(foo)", artificial_object) | ||
assert_equal "rubygem(foo)", ConcreteTemplateHelpers.requirement("rubygem(foo)", artificial_object) | ||
end | ||
end |