diff --git a/lib/ruby_installer/build/msys2_installation.rb b/lib/ruby_installer/build/msys2_installation.rb index 19438ca57..9868387b0 100644 --- a/lib/ruby_installer/build/msys2_installation.rb +++ b/lib/ruby_installer/build/msys2_installation.rb @@ -319,29 +319,36 @@ def disable_msys_apps_per_ps1 end.join(";") end + @@pacman_lock = Mutex.new + private def with_pacman_lock(&block) + @@pacman_lock.synchronize(&block) + end + def install_packages(packages, verbose: false) return if packages.empty? with_msys_apps_enabled do - # Find packages that are already installed - skips, installs = packages.partition do |package| - IO.popen(["pacman", "-Q", package], err: :out, &:read) - $?.success? - end + with_pacman_lock do + # 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? + Gem.ui.say("Using msys2 packages: #{skips.join(" ")}") if verbose && skips.any? - # Install required packages - if installs.any? - Gem.ui.say("Installing required msys2 packages: #{installs.join(" ")}") if verbose + # Install required packages + if installs.any? + Gem.ui.say("Installing required msys2 packages: #{installs.join(" ")}") if verbose - args = ["pacman", "-S", "--needed", "--noconfirm", *installs] - Gem.ui.say("> #{args.join(" ")}") if verbose==1 + args = ["pacman", "-S", "--needed", "--noconfirm", *installs] + Gem.ui.say("> #{args.join(" ")}") if verbose==1 - res = IO.popen(args, &:read) - raise CommandError, "pacman failed with the following output:\n#{res}" if !$? || $?.exitstatus != 0 + 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 + Gem.ui.say(res) if verbose==1 + end end end end diff --git a/test/helper/testgem/Gemfile b/test/helper/testgem/Gemfile index 8033850c2..e01964928 100644 --- a/test/helper/testgem/Gemfile +++ b/test/helper/testgem/Gemfile @@ -1,2 +1,3 @@ source "https://dummy-url.nonexit" +gem "testgem2", "1.0.0" gem "testgem", "1.0.0" diff --git a/test/test_gem_install.rb b/test/test_gem_install.rb index 2c9187b71..bea4b666a 100644 --- a/test/test_gem_install.rb +++ b/test/test_gem_install.rb @@ -33,15 +33,17 @@ def test_bundle_install res = system <<-EOT.gsub("\n", "&") cd test/helper/testgem gem build testgem.gemspec + gem build testgem2.gemspec copy /b testgem-1.0.0.gem "vendor/cache/" - bundle install --local + copy /b testgem2-1.0.0.gem "vendor/cache/" + bundle install --local -j16 EOT assert res, "shell commands should succeed" out = IO.popen("bundle exec ruby -rtestgem -e \"puts Libguess.determine_encoding('abc', 'Greek')\"", chdir: "test/helper/testgem", &:read) assert_match(/UTF-8/, out.scrub, "call the ruby API of the testgem") - assert system("gem uninstall testgem --executables --force"), "uninstall testgem" + assert system("gem uninstall testgem testgem2 --executables --force"), "uninstall testgem" FileUtils.rm("test/helper/testgem/testgem-1.0.0.gem") end