Skip to content

Commit 0c1148d

Browse files
committed
Use rubygems-requirements-system as backend
1 parent 1531114 commit 0c1148d

File tree

3 files changed

+21
-119
lines changed

3 files changed

+21
-119
lines changed

dockerfiles/run-test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@ else
2727
rake install
2828
fi
2929

30+
# Disable rubygems-requirements-system RubyGems plugin and Bundler
31+
# plugin.
32+
export RUBYGEMS_REQUIREMENTS_SYSTEM=false
3033
export GNUMAKEFLAGS="-j$(nproc)"
3134
gem install --user-install cairo "$@"

lib/native-package-installer.rb

Lines changed: 10 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2017-2021 Ruby-GNOME Project Team
1+
# Copyright (C) 2017-2025 Ruby-GNOME Project Team
22
#
33
# This library is free software: you can redistribute it and/or modify
44
# it under the terms of the GNU Lesser General Public License as published by
@@ -13,8 +13,9 @@
1313
# You should have received a copy of the GNU Lesser General Public License
1414
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1515

16-
require "shellwords"
16+
require "rubygems-requirements-system/installer"
1717

18+
# Other files exist only for backward compatibility.
1819
require_relative "native-package-installer/version"
1920

2021
require_relative "native-package-installer/executable-finder"
@@ -31,122 +32,16 @@ def install(spec)
3132

3233
def initialize(spec)
3334
@spec = spec
34-
@platform = Platform.detect
35+
@platform = RubyGemsRequirementsSystem::Platform.detect
3536
end
3637

3738
def install
38-
package = @platform.package(@spec)
39-
return false if package.nil?
40-
41-
package_name, *options = package
42-
package_command_line = [package_name, *options].collect do |component|
43-
Shellwords.escape(component)
44-
end.join(" ")
45-
46-
install_command = "#{@platform.install_command} #{package_command_line}"
47-
if have_priviledge?
48-
sudo = nil
49-
else
50-
sudo = ExecutableFinder.find("sudo")
51-
end
52-
53-
installing_message = "installing '#{package_name}' native package... "
54-
log_message("%s", installing_message)
55-
failed_to_get_super_user_priviledge = false
56-
if have_priviledge?
57-
succeeded = run_command(install_command)
58-
else
59-
if sudo
60-
prompt = "[sudo] password for %u to install <#{package_name}>: "
61-
sudo_options = "-p #{Shellwords.escape(prompt)}"
62-
install_command = "#{sudo} #{sudo_options} #{install_command}"
63-
succeeded = run_command(install_command)
64-
else
65-
succeeded = false
66-
failed_to_get_super_user_priviledge = true
67-
end
68-
end
69-
70-
if failed_to_get_super_user_priviledge
71-
result_message = "require super user privilege"
72-
else
73-
result_message = succeeded ? "succeeded" : "failed"
74-
end
75-
show_postpone_message do
76-
"#{installing_message}#{result_message}\n"
77-
end
78-
log_message("#{result_message}\n")
79-
80-
error_message = nil
81-
unless succeeded
82-
if failed_to_get_super_user_priviledge
83-
error_message = <<-MESSAGE
84-
'#{package_name}' native package is required.
85-
Run the following command as super user to install required native package:
86-
\# #{install_command}
87-
MESSAGE
88-
else
89-
error_message = <<-MESSAGE
90-
Failed to run '#{install_command}'.
91-
MESSAGE
92-
end
93-
end
94-
if error_message
95-
log_message("%s", error_message)
96-
show_message("%s", error_message)
97-
end
98-
99-
show_message("--------------------\n\n")
100-
101-
succeeded
102-
end
103-
104-
private
105-
def super_user?
106-
Process.uid.zero?
107-
end
108-
109-
def have_priviledge?
110-
return true unless @platform.need_super_user_priviledge?
111-
super_user?
112-
end
113-
114-
def with_mkmf?
115-
Object.const_defined?(:MakeMakefile)
116-
end
117-
118-
def run_command(command_line)
119-
if with_mkmf?
120-
xsystem(command_line)
121-
else
122-
system(command_line)
123-
end
124-
end
125-
126-
def log_message(format, *args)
127-
if with_mkmf?
128-
message(format, *args)
129-
else
130-
printf(format, *args)
131-
$stdout.flush
132-
end
133-
end
134-
135-
def show_message(format, *args)
136-
if with_mkmf?
137-
MakeMakefile::Logging.message(format, *args)
138-
else
139-
printf(format, *args)
140-
$stdout.flush
141-
end
142-
end
143-
144-
def show_postpone_message(&block)
145-
if with_mkmf?
146-
MakeMakefile::Logging.postpone(&block)
147-
else
148-
print(yield)
149-
$stdout.flush
39+
@spec.each do |platform_id, system_packages|
40+
next unless @platform.target?(platform_id.to_s)
41+
system_packages = [system_packages] unless system_packages.is_a?(Array)
42+
requirement =
43+
RubyGemsRequirementsSystem::Requirement.new([], system_packages)
44+
@platform.install(requirement)
15045
end
15146
end
15247
end

native-package-installer.gemspec

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2013-2022 Ruby-GNOME Project Team
1+
# Copyright (C) 2013-2025 Ruby-GNOME Project Team
22
#
33
# This library is free software: you can redistribute it and/or modify
44
# it under the terms of the GNU Lesser General Public License as published by
@@ -21,10 +21,12 @@ require "native-package-installer/version"
2121
Gem::Specification.new do |spec|
2222
spec.name = "native-package-installer"
2323
spec.version = NativePackageInstaller::VERSION
24-
spec.authors = ["Kouhei Sutou"]
24+
spec.authors = ["Sutou Kouhei"]
2525
spec.email = ["[email protected]"]
26-
spec.summary = "native-package-installer helps to install native packages on \"gem install\""
26+
spec.summary = "Deprecated. Use rubygems-requirements-system instead. native-package-installer helps to install native packages on \"gem install\"."
2727
spec.description = <<-DESCRIPTION.strip
28+
Deprecated. Use rubygems-requirements-system instead.
29+
2830
Users need to install native packages to install an extension library
2931
that depends on native packages. It bores users because users need to
3032
install native packages and an extension library separately.
@@ -34,10 +36,12 @@ Users can install both native packages and an extension library by one action,
3436
"gem install".
3537
DESCRIPTION
3638
spec.homepage = "https://github.com/ruby-gnome/native-package-installer"
37-
spec.licenses = ["LGPL-3+"]
39+
spec.licenses = ["LGPL-3-or-later"]
3840
spec.require_paths = ["lib"]
3941

4042
spec.files = ["README.md", "Rakefile"]
4143
spec.files += Dir.glob("lib/**/*.rb")
4244
spec.files += Dir.glob("doc/text/**/*.*")
45+
46+
spec.add_runtime_dependency("rubygems-requirements-system")
4347
end

0 commit comments

Comments
 (0)