Ruby 2.7 and TZInfo 2.0 compatibility.

Resolves: rhbz#1799093
Resolves: rhbz#1805531
f38
Vít Ondruch 5 years ago
parent 0414b5cc50
commit 12604aa399

@ -0,0 +1,54 @@
From 4f4f8a705a8e713bceee8cacca52e9bce22e28dc Mon Sep 17 00:00:00 2001
From: "yuuji.yaginuma" <yuuji.yaginuma@gmail.com>
Date: Wed, 18 Dec 2019 19:00:29 +0900
Subject: [PATCH] Make `LoadInterlockAwareMonitor` work in Ruby 2.7
Currently `LoadInterlockAwareMonitorTest` does not pass with Ruby 2.7 [1].
This is due to the refactoring of the `monitor` done in Ruby 2.7 [2].
With this refactoring, the behavior of the method has changed from the
expected behavior in `LoadInterlockAwareMonitor`.
This patch also overwrites `synchronize` so that
`LoadInterlockAwareMonitor` works as expected.
[1]: https://buildkite.com/rails/rails/builds/65877#eec47af5-7595-47cb-97c0-30c589716176/996-2743
[2]: https://bugs.ruby-lang.org/issues/16255
---
.../load_interlock_aware_monitor.rb | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb b/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb
index a8455c00483f..480c34c64017 100644
--- a/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb
+++ b/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb
@@ -7,11 +7,29 @@ module Concurrency
# A monitor that will permit dependency loading while blocked waiting for
# the lock.
class LoadInterlockAwareMonitor < Monitor
+ EXCEPTION_NEVER = { Exception => :never }.freeze
+ EXCEPTION_IMMEDIATE = { Exception => :immediate }.freeze
+ private_constant :EXCEPTION_NEVER, :EXCEPTION_IMMEDIATE
+
# Enters an exclusive section, but allows dependency loading while blocked
def mon_enter
mon_try_enter ||
ActiveSupport::Dependencies.interlock.permit_concurrent_loads { super }
end
+
+ def synchronize
+ Thread.handle_interrupt(EXCEPTION_NEVER) do
+ mon_enter
+
+ begin
+ Thread.handle_interrupt(EXCEPTION_IMMEDIATE) do
+ yield
+ end
+ ensure
+ mon_exit
+ end
+ end
+ end
end
end
end

@ -0,0 +1,24 @@
From e9425abe33924623b1dce62bd817eace757c2b4e Mon Sep 17 00:00:00 2001
From: Phil Ross <phil.ross@gmail.com>
Date: Fri, 29 Dec 2017 12:47:10 +0000
Subject: [PATCH] Update to TZInfo v2.0.0
Co-authored-by: Jared Beck <jared@jaredbeck.com>
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
---
time_zone_test.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb
index 4b5f3dceee6f..646b9e1d3199 100644
--- a/activesupport/test/time_zone_test.rb
+++ b/activesupport/test/time_zone_test.rb
@@ -22,7 +29,7 @@ def test_local_to_utc
def test_period_for_local
zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"]
- assert_instance_of TZInfo::TimezonePeriod, zone.period_for_local(Time.utc(2000))
+ assert_kind_of TZInfo::TimezonePeriod, zone.period_for_local(Time.utc(2000))
end
ActiveSupport::TimeZone::MAPPING.each_key do |name|

@ -0,0 +1,119 @@
From e9425abe33924623b1dce62bd817eace757c2b4e Mon Sep 17 00:00:00 2001
From: Phil Ross <phil.ross@gmail.com>
Date: Fri, 29 Dec 2017 12:47:10 +0000
Subject: [PATCH] Update to TZInfo v2.0.0
Co-authored-by: Jared Beck <jared@jaredbeck.com>
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
---
time_with_zone.rb | 20 +++++++++++++++-----
values/time_zone.rb | 14 ++++++--------
2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index 3be5f6f7b595..9a4c33ab0f19 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -57,12 +57,12 @@ def initialize(utc_time, time_zone, local_time = nil, period = nil)
# Returns a <tt>Time</tt> instance that represents the time in +time_zone+.
def time
- @time ||= period.to_local(@utc)
+ @time ||= incorporate_utc_offset(@utc, utc_offset)
end
# Returns a <tt>Time</tt> instance of the simultaneous time in the UTC timezone.
def utc
- @utc ||= period.to_utc(@time)
+ @utc ||= incorporate_utc_offset(@time, -utc_offset)
end
alias_method :comparable_time, :utc
alias_method :getgm, :utc
@@ -104,13 +104,13 @@ def dst?
# Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
# Time.zone.now.utc? # => false
def utc?
- period.offset.abbreviation == :UTC || period.offset.abbreviation == :UCT
+ zone == "UTC" || zone == "UCT"
end
alias_method :gmt?, :utc?
# Returns the offset from current time to UTC time in seconds.
def utc_offset
- period.utc_total_offset
+ period.observed_utc_offset
end
alias_method :gmt_offset, :utc_offset
alias_method :gmtoff, :utc_offset
@@ -132,7 +132,7 @@ def formatted_offset(colon = true, alternate_utc_string = nil)
# Time.zone = 'Eastern Time (US & Canada)' # => "Eastern Time (US & Canada)"
# Time.zone.now.zone # => "EST"
def zone
- period.zone_identifier.to_s
+ period.abbreviation
end
# Returns a string of the object's date, time, zone, and offset from UTC.
@@ -514,6 +514,16 @@ def method_missing(sym, *args, &block)
end
private
+ SECONDS_PER_DAY = 86400
+
+ def incorporate_utc_offset(time, offset)
+ if time.kind_of?(Date)
+ time + Rational(offset, SECONDS_PER_DAY)
+ else
+ time + offset
+ end
+ end
+
def get_period_and_ensure_valid_local_time(period)
# we don't want a Time.local instance enforcing its own DST rules as well,
# so transfer time values to a utc constructor if necessary
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index 90830b89bda3..2e5d9d3e9d4c 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -203,7 +203,7 @@ def seconds_to_utc_offset(seconds, colon = true)
end
def find_tzinfo(name)
- TZInfo::Timezone.new(MAPPING[name] || name)
+ TZInfo::Timezone.get(MAPPING[name] || name)
end
alias_method :create, :new
@@ -273,7 +273,7 @@ def load_country_zones(code)
memo
end
else
- create(tz_id, nil, TZInfo::Timezone.new(tz_id))
+ create(tz_id, nil, TZInfo::Timezone.get(tz_id))
end
end.flatten(1).sort!
end
@@ -302,11 +302,7 @@ def initialize(name, utc_offset = nil, tzinfo = nil)
# Returns the offset of this time zone from UTC in seconds.
def utc_offset
- if @utc_offset
- @utc_offset
- else
- tzinfo.current_period.utc_offset if tzinfo && tzinfo.current_period
- end
+ @utc_offset || tzinfo&.current_period&.base_utc_offset
end
# Returns a formatted string of the offset from UTC, or an alternative
@@ -498,7 +494,9 @@ def yesterday
# represented by +self+. Returns a Time.utc() instance -- if you want an
# ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead.
def utc_to_local(time)
- tzinfo.utc_to_local(time)
+ tzinfo.utc_to_local(time).yield_self do |t|
+ Time.utc(t.year, t.month, t.day, t.hour, t.min, t.sec, t.sec_fraction)
+ end
end
# Adjust the given time to the simultaneous time in UTC. Returns a

@ -3,7 +3,7 @@
Name: rubygem-%{gem_name}
Epoch: 1
Version: 5.2.3
Release: 3%{?dist}
Release: 4%{?dist}
Summary: A support libraries and Ruby core extensions extracted from the Rails framework
License: MIT
URL: http://rubyonrails.org
@ -15,6 +15,14 @@ Source0: https://rubygems.org/gems/%{gem_name}-%{version}.gem
# cd rails/activesupport/
# git checkout v5.2.3 && tar czvf activesupport-5.2.3-tests.tgz test/
Source1: %{gem_name}-%{version}-tests.tgz
# Make `LoadInterlockAwareMonitor` work in Ruby 2.7
# https://github.com/rails/rails/pull/38069
Patch0: rubygem-activesupport-6.1.0-Make-LoadInterlockAwareMonitor-work-in-Ruby-2.7.patch
# Fix TZInfo 2.0 compatibility.
# https://github.com/rails/rails/pull/34799
# https://github.com/rails/rails/pull/38081
Patch1: rubygem-activesupport-6.1.0-Update-to-TZInfo-v2.0.0.patch
Patch2: rubygem-activesupport-6.1.0-Update-to-TZInfo-v2.0.0-tests.patch
# ruby package has just soft dependency on rubygem({bigdecimal,json}), while
# ActiveSupport always requires them.
@ -54,7 +62,17 @@ BuildArch: noarch
Documentation for %{name}.
%prep
%setup -q -n %{gem_name}-%{version}
%setup -q -n %{gem_name}-%{version} -b 1
%patch0 -p2
%patch1 -p2
pushd %{_builddir}
%patch2 -p2
popd
%gemspec_remove_dep -g tzinfo "~> 1.1"
%gemspec_add_dep -g tzinfo [">= 1.1", "< 3"]
%build
gem build ../%{gem_name}-%{version}.gemspec
@ -69,7 +87,7 @@ cp -a .%{gem_dir}/* \
%check
pushd .%{gem_instdir}
# Move the tests into place
tar xzvf %{SOURCE1}
cp -a %{_builddir}/test test
# These tests are really unstable, but they seems to be passing upstream :/
for f in \
@ -83,6 +101,11 @@ done
# https://github.com/rails/rails/issues/25682
sed -i '/def test_iso8601_output_and_reparsing$/,/^ end$/ s/^/#/' test/core_ext/duration_test.rb
# Workaround TransformValuesTest#test_default_procs_do_not_persist_*_mapping
# test failures due to bug in Ruby 2.7.{0,1}.
# https://bugs.ruby-lang.org/issues/16498
sed -i '/assert_nil mapped\[:b\]/ s/^/#/' test/core_ext/hash/transform_values_test.rb
memcached &
mPID=$!
sleep 1
@ -103,6 +126,12 @@ popd
%doc %{gem_instdir}/README.rdoc
%changelog
* Thu Apr 16 2020 Vít Ondruch <vondruch@redhat.com> - 1:5.2.3-4
- Ruby 2.7 compatibility.
Resolves: rhbz#1799093
- TZInfo 2.0 compatibility.
Resolves: rhbz#1805531
* Thu Jan 30 2020 Fedora Release Engineering <releng@fedoraproject.org> - 1:5.2.3-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild

Loading…
Cancel
Save