From a313fbac056c45f39995a4015292bc0188033ff8 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Tue, 7 Jan 2025 17:57:31 +0900 Subject: [PATCH] Fix default system packages detection --- lib/rubygems-requirements-system/installer.rb | 8 ++++++++ lib/rubygems-requirements-system/platform/base.rb | 10 +++++----- .../platform/red-hat-enterprise-linux.rb | 8 ++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/rubygems-requirements-system/installer.rb b/lib/rubygems-requirements-system/installer.rb index 1e8802d..a7fb0db 100644 --- a/lib/rubygems-requirements-system/installer.rb +++ b/lib/rubygems-requirements-system/installer.rb @@ -72,6 +72,7 @@ def install private def parse_requirements(gemspec_requirements) + all_packages_set = {} requirements = {} gemspec_requirements.each do |gemspec_requirement| components = gemspec_requirement.split(/: +/, 4) @@ -83,10 +84,17 @@ def parse_requirements(gemspec_requirements) packages = parse_packages(raw_packages) next if packages.empty? + all_packages_set[packages] = true + next unless @platform.target?(platform) requirements[packages] ||= [] requirements[packages] << system_package end + (all_packages_set.keys - requirements.keys).each do |not_used_packages| + system_packages = @platform.default_system_packages(not_used_packages) + next if system_packages.nil? + requirements[not_used_packages] = system_packages + end requirements.collect do |packages, system_packages| Requirement.new(packages, system_packages) end diff --git a/lib/rubygems-requirements-system/platform/base.rb b/lib/rubygems-requirements-system/platform/base.rb index d5a90bd..f2c9be6 100644 --- a/lib/rubygems-requirements-system/platform/base.rb +++ b/lib/rubygems-requirements-system/platform/base.rb @@ -27,9 +27,13 @@ def target?(platform) raise NotImpelementedError end + def default_system_packages(packages) + nil + end + def install(requirement) synchronize do - target_packages(requirement).any? do |package| + requirement.system_packages.any? do |package| install_package(package) and requirement.satisfied? end end @@ -75,10 +79,6 @@ def have_priviledge? super_user? end - def target_packages(requirement) - requirement.system_packages - end - def install_package(package) command_line = prepare_command_line(package) if command_line diff --git a/lib/rubygems-requirements-system/platform/red-hat-enterprise-linux.rb b/lib/rubygems-requirements-system/platform/red-hat-enterprise-linux.rb index d656bd0..0c9bb24 100644 --- a/lib/rubygems-requirements-system/platform/red-hat-enterprise-linux.rb +++ b/lib/rubygems-requirements-system/platform/red-hat-enterprise-linux.rb @@ -38,12 +38,12 @@ def target?(platform) end end - private - def target_packages(requirement) - super + - requirement.packages.collect {|package| "pkgconfig(#{package.id})"} + def default_system_packages(packages) + packages.collect {|package| "pkgconfig(#{package.id})"} end + private + def install_command_line(package) if major_version >= 9 ["dnf", "install", "--enablerepo=crb", "-y", package]