diff --git a/CHANGELOG.md b/CHANGELOG.md index b3d1d2b2..69415b41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### 5.17.0 /2022-10-30 +- Added + - The RPM dependency file can now use `ignores` to remove items instead of + needing to redefine the entire dependency stack to remove deps + ### 5.16.0 / 2022-06-24 - Added - The `puppet-lint-optional_default-check` was added to prevent setting diff --git a/lib/simp/rake/build/rpmdeps.rb b/lib/simp/rake/build/rpmdeps.rb index 6bc0eb43..2d9be7ca 100644 --- a/lib/simp/rake/build/rpmdeps.rb +++ b/lib/simp/rake/build/rpmdeps.rb @@ -104,7 +104,8 @@ def self.generate_custom_rpm_obsoletes(obsoletes_hash, module_metadata) # * Requires rpm-name <= 2.0.0 # +module_metadata+:: Hash containing the contents of the # module's 'metadata.json' file - def self.generate_custom_rpm_requires(requires_list, module_metadata) + # +ignores+:: Array of package names to ignore during processing + def self.generate_custom_rpm_requires(requires_list, module_metadata, ignores=[]) rpm_metadata_content = [] requires_list.each do |pkg_to_modify| @@ -114,6 +115,8 @@ def self.generate_custom_rpm_requires(requires_list, module_metadata) pkg, min_version, max_version = pkg if pkg.is_a?(Array) + next if ignores.include?(pkg) + rpm_version_chars = ['<','>','='] if min_version && rpm_version_chars.none? { |x| min_version.include?(x) } @@ -140,7 +143,7 @@ def self.generate_custom_rpm_requires(requires_list, module_metadata) end if dep_info.empty? - err_msg = "Could not find #{short_names.first} dependency" + err_msg = "Could not find '#{short_names.first}' dependency" raise SIMPRpmDepException.new(err_msg) else dep_version = dep_info.first['version_requirement'] @@ -154,7 +157,7 @@ def self.generate_custom_rpm_requires(requires_list, module_metadata) begin rpm_metadata_content << get_version_requires(pkg, dep_version) rescue SIMPRpmDepVersionException - err_msg = "Unable to parse #{short_names.first} dependency" + + err_msg = "Unable to parse '#{short_names.first}' dependency" + " version '#{dep_version}'" raise SIMPRpmDepException.new(err_msg) end @@ -174,15 +177,19 @@ def self.generate_custom_rpm_requires(requires_list, module_metadata) # is a Hash containing the version info. For example, # [ 'package1' => { :min => '1.0.0' }, # 'package2' => { :min => '3.1-1', :max => '4.0' } ] - def self.generate_external_rpm_requires(ext_deps_list) + # +ignores+:: Array of package names to ignore during processing + def self.generate_external_rpm_requires(ext_deps_list, ignores=[]) requires = [] ext_deps_list.each do |pkg_name, options| + next if ignores.include?(pkg_name) + requires << "Requires: #{pkg_name} >= #{options[:min]}" if options[:max] requires << "Requires: #{pkg_name} < #{options[:max]}" end end + requires end @@ -197,7 +204,8 @@ def self.generate_external_rpm_requires(ext_deps_list) # # +module_metadata+:: Hash containing the contents of the # module's 'metadata.json' file - def self.generate_module_rpm_requires(module_metadata) + # +ignores+:: Array of package names to ignore during processing + def self.generate_module_rpm_requires(module_metadata, ignores=[]) rpm_metadata_content = [] deps = [] @@ -214,12 +222,15 @@ def self.generate_module_rpm_requires(module_metadata) deps.sort! { |x,y| x['name'] <=> y['name'] } deps.each do |dep| pkg = "pupmod-#{dep['name'].gsub('/', '-')}" + + next if ignores.include?(pkg) + dep_version = dep['version_requirement'] begin rpm_metadata_content << get_version_requires(pkg, dep_version) rescue SIMPRpmDepVersionException - err_msg = "Unable to parse #{dep['name']} dependency" + + err_msg = "Unable to parse '#{dep['name']}' dependency" + " version '#{dep_version}'" raise SIMPRpmDepException.new(err_msg) end @@ -252,6 +263,10 @@ def self.rpm_requires_up_to_date?(new_requires, rpm_requires_file) # dependencies are pulled from module_metadata. # * 'Requires' line(s) for any external dependencies specified # in the module_rpm_meta hash. + # * Any items matching the name in an 'ignores' array will be removed from the + # dependency list. + # * This will be an *exact* match, globbing and regexes are not supported + # * Does not affect Obsoletes statements # # Otherwise, the generated 'requires' file will contain "Requires" # lines for each dependency and each SIMP optional dependency @@ -269,18 +284,31 @@ def self.rpm_requires_up_to_date?(new_requires, rpm_requires_file) # 'dependencies.yaml' file or nil, if no entry exists def self.generate_rpm_requires_file(dir, module_metadata, module_rpm_meta) rpm_metadata_content = [] + + ignores = module_rpm_meta ? Array(module_rpm_meta[:ignores]) : [] + if module_rpm_meta and module_rpm_meta[:obsoletes] - rpm_metadata_content = generate_custom_rpm_obsoletes(module_rpm_meta[:obsoletes], module_metadata) + rpm_metadata_content = generate_custom_rpm_obsoletes( + module_rpm_meta[:obsoletes], + module_metadata + ) end if module_rpm_meta and module_rpm_meta[:requires] - rpm_metadata_content += generate_custom_rpm_requires(module_rpm_meta[:requires], module_metadata) + rpm_metadata_content += generate_custom_rpm_requires( + module_rpm_meta[:requires], + module_metadata, + ignores + ) else - rpm_metadata_content += generate_module_rpm_requires(module_metadata) + rpm_metadata_content += generate_module_rpm_requires(module_metadata, ignores) end if module_rpm_meta and module_rpm_meta[:external_dependencies] - rpm_metadata_content += generate_external_rpm_requires(module_rpm_meta[:external_dependencies]) + rpm_metadata_content += generate_external_rpm_requires( + module_rpm_meta[:external_dependencies], + ignores + ) end rpm_metadata_file = File.join(dir, 'build', 'rpm_metadata', 'requires') diff --git a/lib/simp/rake/helpers/version.rb b/lib/simp/rake/helpers/version.rb index 483d0069..e52dbe4b 100644 --- a/lib/simp/rake/helpers/version.rb +++ b/lib/simp/rake/helpers/version.rb @@ -2,5 +2,5 @@ module Simp; end module Simp::Rake; end class Simp::Rake::Helpers - VERSION = '5.16.0' + VERSION = '5.17.0' end diff --git a/spec/lib/simp/rake/build/files/dependencies.yaml b/spec/lib/simp/rake/build/files/dependencies.yaml index 110f6234..d56db2d5 100644 --- a/spec/lib/simp/rake/build/files/dependencies.yaml +++ b/spec/lib/simp/rake/build/files/dependencies.yaml @@ -20,7 +20,10 @@ # does NOT include puppetlabs/apt - 'pupmod-puppetlabs-stdlib' - 'pupmod-ceritsc-yum' + - 'i-should-not-exist' - ['pupmod-richardc-datacat', '1.2.3', '<=3.4.5'] + :ignores: + - 'i-should-not-exist' :release: '2017.0' :external_dependencies: 'rubygem-puppetserver-toml': diff --git a/spec/lib/simp/rake/build/rpmdeps_spec.rb b/spec/lib/simp/rake/build/rpmdeps_spec.rb index 8fe8e568..f6d52186 100644 --- a/spec/lib/simp/rake/build/rpmdeps_spec.rb +++ b/spec/lib/simp/rake/build/rpmdeps_spec.rb @@ -194,7 +194,7 @@ context 'dependency from dependencies.yaml not found in metadata.json' do it 'should fail when dep in depedencies.yaml is not found in metadata.json' do mod_dir = File.join(@tmp_dir, 'files', 'unknown_dep_mod') - err_msg = "Could not find oops/unknown dependency in #{mod_dir}/metadata.json" + err_msg = "Could not find 'oops/unknown' dependency in #{mod_dir}/metadata.json" expect { Simp::Rake::Build::RpmDeps::generate_rpm_meta_files(mod_dir, rpm_metadata) }.to raise_error(err_msg) @@ -204,7 +204,7 @@ context 'malformed dependency version' do it 'should fail for managed component with invalid dep version in metadata.json' do mod_dir = File.join(@tmp_dir, 'files', 'malformed_dep_meta_mod') - err_msg = "Unable to parse foo1/bar1 dependency version '1.0.0.1' in #{mod_dir}/metadata.json" + err_msg = "Unable to parse 'foo1/bar1' dependency version '1.0.0.1' in #{mod_dir}/metadata.json" expect { Simp::Rake::Build::RpmDeps::generate_rpm_meta_files(mod_dir, rpm_metadata) }.to raise_error(err_msg) @@ -214,7 +214,7 @@ rpm_meta = rpm_metadata.dup rpm_meta ['malformed_dep_meta_mod'] = nil mod_dir = File.join(@tmp_dir, 'files', 'malformed_dep_meta_mod') - err_msg = "Unable to parse foo1/bar1 dependency version '1.0.0.1' in #{mod_dir}/metadata.json" + err_msg = "Unable to parse 'foo1/bar1' dependency version '1.0.0.1' in #{mod_dir}/metadata.json" expect { Simp::Rake::Build::RpmDeps::generate_rpm_meta_files(mod_dir, rpm_meta) }.to raise_error(err_msg)