Skip to content

Commit

Permalink
Skip msys2 package install if dependency is already satisfied
Browse files Browse the repository at this point in the history
This avoid unwanted/unnecessary up- or downgrades of msys2/mingw packages
on "gem install" when a package is already installed and the version
meets optional version constraints.

Fixes #67
  • Loading branch information
larskanis committed Sep 5, 2020
1 parent 071ec34 commit b57236b
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/ruby_installer/build/msys2_installation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,26 @@ def install_packages(packages, verbose: false)
return if packages.empty?

with_msys_apps_enabled do
Gem.ui.say("Installing required msys2 packages: #{packages.join(" ")}") if verbose
# Find packages that are already installed
skips, installs = packages.partition do |package|
IO.popen(["pacman", "-Q", package], err: :out, &:read)
$?.success?
end

Gem.ui.say("Using msys2 packages: #{skips.join(" ")}") if verbose && skips.any?

args = ["pacman", "-S", "--needed", "--noconfirm", *packages]
Gem.ui.say("> #{args.join(" ")}") if verbose==1
# Install required packages
if installs.any?
Gem.ui.say("Installing required msys2 packages: #{installs.join(" ")}") if verbose

res = IO.popen(args, &:read)
raise CommandError, "pacman failed with the following output:\n#{res}" if !$? || $?.exitstatus != 0
args = ["pacman", "-S", "--needed", "--noconfirm", *installs]
Gem.ui.say("> #{args.join(" ")}") if verbose==1

Gem.ui.say(res) if verbose==1
res = IO.popen(args, &:read)
raise CommandError, "pacman failed with the following output:\n#{res}" if !$? || $?.exitstatus != 0

Gem.ui.say(res) if verbose==1
end
end
end

Expand Down

0 comments on commit b57236b

Please sign in to comment.