From b6f0e610525eed99029221540bf06764ac4231f1 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 16 Apr 2020 15:48:45 -0400 Subject: [PATCH] ruby 2.7 compatibility - #117 --- lib/rscons.rb | 1 + lib/rscons/environment.rb | 6 +----- lib/rscons/util.rb | 34 ++++++++++++++++++++++++++++++++++ spec/build_tests_spec.rb | 2 +- 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 lib/rscons/util.rb diff --git a/lib/rscons.rb b/lib/rscons.rb index 5691fc1..1796e5a 100644 --- a/lib/rscons.rb +++ b/lib/rscons.rb @@ -5,6 +5,7 @@ require_relative "rscons/cache" require_relative "rscons/environment" require_relative "rscons/job_set" require_relative "rscons/threaded_command" +require_relative "rscons/util" require_relative "rscons/varset" require_relative "rscons/version" diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 5f26a81..d5b4947 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -1,7 +1,6 @@ require "fileutils" require "set" require "shellwords" -require "thwait" module Rscons # The Environment class is the main programmatic interface to Rscons. It @@ -1012,10 +1011,7 @@ module Rscons !thread.alive? end else - if threads.empty? - raise "No threads to wait for" - end - ThreadsWait.new(*threads).next_wait + Util.wait_for_thread(*threads) end end diff --git a/lib/rscons/util.rb b/lib/rscons/util.rb new file mode 100644 index 0000000..09e92ce --- /dev/null +++ b/lib/rscons/util.rb @@ -0,0 +1,34 @@ +module Rscons + # A collection of stand-alone utility methods. + module Util + class << self + + # Wait for any of a number of threads to complete. + # + # @param threads [Array] + # Threads to wait for. + # + # @return [Thread] + # The Thread that completed. + def wait_for_thread(*threads) + if threads.empty? + raise "No threads to wait for" + end + queue = Queue.new + threads.each do |thread| + # Create a wait thread for each thread we're waiting for. + Thread.new do + begin + thread.join + ensure + queue.push(thread) + end + end + end + # Wait for any thread to complete. + queue.pop + end + + end + end +end diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index fcd0b45..3c88f90 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -97,7 +97,7 @@ ENV["TERM"] = nil EOF end stdout, stderr, status = nil, nil, nil - Bundler.with_clean_env do + Bundler.with_unbundled_env do stdout, stderr, status = Open3.capture3(*command) end # Remove output lines generated as a result of the test environment