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/helper/testgem/testgem2.gemspec b/test/helper/testgem/testgem2.gemspec new file mode 100644 index 000000000..e6a95a4bf --- /dev/null +++ b/test/helper/testgem/testgem2.gemspec @@ -0,0 +1,18 @@ +Gem::Specification.new do |s| + s.name = 'testgem2' + s.version = '1.0.0' + s.author = 'Lars Kanis' + s.email = 'lars@greiz-reinsdorf.de' + s.homepage = 'https://github.com/larskanis/rubyinstaller2' + s.summary = 'RubyInstaller2 testgem' + s.description = 'A gem to test gem installation with RubyInstaller2' + s.files = `git ls-files`.split("\n") + s.extensions << 'ext/extconf.rb' + s.license = 'BSD-3-Clause' + s.require_paths << 'lib' + s.bindir = "exe" + s.executables = ["testgem-exe"] + s.required_ruby_version = '>= 2.1.0' + s.metadata['msys2_dependencies'] = 'ed>=1.0' + s.metadata['msys2_mingw_dependencies'] = 'libguess>=1.0 gcc>=8.0' +end 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