module Polisher::RPM::SpecUpdater
Public Instance Methods
build_requires_contents()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 50 def build_requires_contents @metadata[:build_requires].collect { |r| "BuildRequires: #{r.str}" } .join("\n") end
changelog_end_index()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 40 def changelog_end_index ci = changelog_index ci.nil? ? (@metadata[:contents].length - 1) : (@metadata[:contents].index "\n", ci) + 1 end
changelog_index()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 36 def changelog_index @metadata[:contents].index RPM::Spec::SPEC_CHANGELOG_MATCHER end
description_index()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 78 def description_index @metadata[:contents].index RPM::Spec::SPEC_DESCRIPTION_MATCHER end
excludes_contents()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 126 def excludes_contents if @metadata[:pkg_excludes][gem_name] @metadata[:pkg_excludes][gem_name] .collect { |exclude| "%exclude #{exclude}" } .join("\n") + "\n\n" else '' end end
files_end_index()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 140 def files_end_index @metadata[:contents].index RPM::Spec::SPEC_CHANGELOG_MATCHER end
files_index()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 136 def files_index @metadata[:contents].index RPM::Spec::SPEC_FILES_MATCHER end
first_build_requires_index()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 59 def first_build_requires_index @metadata[:contents].index RPM::Spec::SPEC_BUILD_REQUIRES_MATCHER end
first_requires_index()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 55 def first_requires_index @metadata[:contents].index RPM::Spec::SPEC_REQUIRES_MATCHER end
last_build_requires_index()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 94 def last_build_requires_index @metadata[:contents].rindex(RPM::Spec::SPEC_BUILD_REQUIRES_MATCHER, last_main_package_index) || -1 end
last_main_package_index()
click to toggle source
Main package ends either with subpkg specification or with a %description or %prep section
# File lib/polisher/rpm/spec/updater.rb, line 74 def last_main_package_index description_index || subpkg_index || prep_index || -1 end
last_requirement_index()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 98 def last_requirement_index lri = last_requires_index lbri = last_build_requires_index lri > lbri ? lri : lbri end
last_requires_index()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 90 def last_requires_index @metadata[:contents].rindex(RPM::Spec::SPEC_REQUIRES_MATCHER, last_main_package_index) || -1 end
new_files_contents_for(pkg)
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 108 def new_files_contents_for(pkg) has_new_files = @metadata.key?(:new_files) && @metadata[:new_files].key?(pkg) return "" unless has_new_files title = pkg == gem_name ? "%files\n" : "%files #{pkg}\n" contents = @metadata[:new_files][pkg].join("\n") + "\n" title + contents end
new_subpkg_files_contents()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 117 def new_subpkg_files_contents has_new_files = @metadata.key?(:new_files) return "" unless has_new_files @metadata[:new_files].keys .select { |pkg| pkg != gem_name } .collect { |pkg| new_files_contents_for(pkg) }.join("\n\n") + "\n\n" end
prep_index()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 82 def prep_index @metadata[:contents].index RPM::Spec::SPEC_PREP_MATCHER end
requirement_section_end_index()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 104 def requirement_section_end_index @metadata[:contents].index "\n", last_requirement_index end
requirement_section_index()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 63 def requirement_section_index ri = first_requires_index bri = first_build_requires_index # Requires missing (e.g. section is auto-generated) return bri unless ri ri < bri ? ri : bri end
requires_contents()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 46 def requires_contents @metadata[:requires].collect { |r| "Requires: #{r.str}" }.join("\n") end
subpkg_index()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 86 def subpkg_index @metadata[:contents].index RPM::Spec::SPEC_SUBPACKAGE_MATCHER end
update_to(new_source)
click to toggle source
Update RPM::Spec
metadata to new gem
@param [Polisher::Gem] new_source new gem to update rpmspec to
# File lib/polisher/rpm/spec/updater.rb, line 15 def update_to(new_source) update_deps_from(new_source) update_files_from(new_source) update_metadata_from(new_source) update_contents end
updated_build_requires_for(new_source)
click to toggle source
Return updated spec build requires
# File lib/polisher/rpm/spec/updater.rb, line 30 def updated_build_requires_for(new_source) non_gem_build_requirements + extra_gem_build_requirements(new_source) + new_source.dev_deps.select { |r| !excludes_dev_dep?(r.name) } .collect { |r| RPM::Requirement.from_gem_dep(r, true) }.flatten end
updated_requires_for(new_source)
click to toggle source
Return updated spec requirements
# File lib/polisher/rpm/spec/updater.rb, line 23 def updated_requires_for(new_source) non_gem_requirements + extra_gem_requirements(new_source) + new_source.deps.select { |r| !excludes_dep?(r.name) } .collect { |r| RPM::Requirement.from_gem_dep(r) }.flatten end
Private Instance Methods
update_build_requires_from(new_source)
click to toggle source
Update build requires from new source
# File lib/polisher/rpm/spec/updater.rb, line 180 def update_build_requires_from(new_source) @metadata[:build_requires] = updated_build_requires_for(new_source) end
update_changelog()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 253 def update_changelog # add changelog entry cei = changelog_end_index @metadata[:contents] = @metadata[:contents][0...cei] + @metadata[:changelog_entries].join("\n\n") end
update_contents()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 260 def update_contents update_metadata_contents update_changelog update_requires update_files end
update_deps_from(new_source)
click to toggle source
Update spec dependencies from new source
# File lib/polisher/rpm/spec/updater.rb, line 169 def update_deps_from(new_source) update_requires_from new_source update_build_requires_from new_source end
update_files()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 155 def update_files # update files fi = files_index || files_end_index || length fei = files_end_index @metadata[:contents].slice!(fi...files_end_index) unless fei.nil? contents = new_files_contents_for(gem_name) + excludes_contents + new_subpkg_files_contents @metadata[:contents].insert fi, contents end
update_files_from(new_source)
click to toggle source
Internal helper to update spec files from new source
# File lib/polisher/rpm/spec/updater.rb, line 185 def update_files_from(new_source) # populate file list from rpmized versions of new source files # minus excluded files minus duplicates (files taken care by other # dirs on list) # # TODO: also detect / add files from SOURCES & PATCHES gem_files = new_source.file_paths - excluded_files gem_files.reject! do |file| gem_files.any? do |other| other != file && self.class.file_satisfies?(other, file) end end @metadata[:new_files] = {} @metadata[:pkg_excludes] ||= {} gem_files.each do |gem_file| pkg = subpkg_containing(gem_file) pkg = gem_name if pkg.nil? if Gem.ignorable_file?(gem_file) @metadata[:pkg_excludes] ||= [] @metadata[:pkg_excludes][pkg] << gem_file.rpmize elsif Gem.runtime_file?(gem_file) || Gem.license_file?(gem_file) @metadata[:new_files][pkg] ||= [] @metadata[:new_files][pkg] << gem_file.rpmize # All files not required for runtime should go # into -doc subpackage if -doc subpackage exists else package = has_doc_subpkg? ? 'doc' : pkg @metadata[:new_files][package] ||= [] @metadata[:new_files][package] << gem_file.rpmize end end extra_gem_files.each do |pkg, files| @metadata[:new_files][pkg] ||= [] @metadata[:new_files][pkg] += files.collect { |file| file.rpmize } end end
update_metadata_contents()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 245 def update_metadata_contents # replace version / release @metadata[:contents].gsub!(RPM::Spec::SPEC_VERSION_MATCHER, "Version: #{@metadata[:version]}") @metadata[:contents].gsub!(RPM::Spec::SPEC_RELEASE_MATCHER, "Release: #{@metadata[:release]}") end
update_metadata_from(new_source)
click to toggle source
Internal helper to update spec metadata from new source
# File lib/polisher/rpm/spec/updater.rb, line 228 def update_metadata_from(new_source) # update to new version @metadata[:version] = new_source.version @metadata[:release] = "1%{?dist}" # invalidate the local gem @update_gem = true # add changelog entry changelog_entry = <<EOS * #{Time.now.strftime("%a %b %d %Y")} #{RPM.current_author} - #{@metadata[:version]}-1 - Update #{@metadata[:gem_name]} to version #{new_source.version} EOS @metadata[:changelog_entries] ||= [] @metadata[:changelog_entries].unshift changelog_entry.rstrip end
update_requires()
click to toggle source
# File lib/polisher/rpm/spec/updater.rb, line 146 def update_requires new_contents = (requires_contents + "\n" + build_requires_contents).strip rsi = requirement_section_index || last_main_package_index rsei = requirement_section_end_index @metadata[:contents].slice!(rsi...rsei) unless rsei.nil? @metadata[:contents].insert rsi, new_contents end
update_requires_from(new_source)
click to toggle source
Update requires from new source
# File lib/polisher/rpm/spec/updater.rb, line 175 def update_requires_from(new_source) @metadata[:requires] = updated_requires_for(new_source) end