Skip to content

Commit d3034fa

Browse files
authored
Merge pull request #21644 from Homebrew/future-disable
formula: handle future deprecation and disable dates
2 parents 3ad8be1 + 51c9fd7 commit d3034fa

File tree

2 files changed

+117
-9
lines changed

2 files changed

+117
-9
lines changed

Library/Homebrew/formula.rb

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4687,12 +4687,17 @@ def deprecate!(date:, because:, replacement: nil, replacement_formula: nil, repl
46874687
)
46884688

46894689
@deprecation_date = T.let(Date.parse(date), T.nilable(Date))
4690-
return if T.must(@deprecation_date) > Date.today
4691-
4692-
@deprecation_reason = T.let(because, T.nilable(T.any(String, Symbol)))
4693-
@deprecation_replacement_formula = T.let(replacement_formula.presence || replacement, T.nilable(String))
4694-
@deprecation_replacement_cask = T.let(replacement_cask.presence || replacement, T.nilable(String))
4695-
@deprecated = T.let(true, T.nilable(T::Boolean))
4690+
@deprecated = T.let(T.must(@deprecation_date) <= Date.today, T.nilable(T::Boolean))
4691+
if @deprecated
4692+
@deprecation_reason = T.let(because, T.nilable(T.any(String, Symbol)))
4693+
@deprecation_replacement_formula = T.let(replacement_formula.presence || replacement, T.nilable(String))
4694+
@deprecation_replacement_cask = T.let(replacement_cask.presence || replacement, T.nilable(String))
4695+
else
4696+
# Reset these to handle disable! before deprecate!
4697+
@deprecation_reason = nil
4698+
@deprecation_replacement_formula = nil
4699+
@deprecation_replacement_cask = nil
4700+
end
46964701
end
46974702

46984703
# Whether this {Formula} is deprecated (i.e. warns on installation).
@@ -4740,9 +4745,9 @@ def deprecated?
47404745
sig { returns(T.nilable(T::Hash[Symbol, T.nilable(T.any(String, Symbol))])) }
47414746
attr_reader :deprecate_args
47424747

4743-
# Disables a {Formula} (on the given date) so it cannot be
4744-
# installed. If the date has not yet passed the formula
4745-
# will be deprecated instead of disabled.
4748+
# Disables a {Formula} (on the given date) so it cannot be installed.
4749+
# If the date has not yet passed and there is no deprecate! date,
4750+
# then the formula will be deprecated.
47464751
#
47474752
# ### Examples
47484753
#
@@ -4794,6 +4799,8 @@ def disable!(date:, because:, replacement: nil, replacement_formula: nil, replac
47944799
@disable_date = T.let(Date.parse(date), T.nilable(Date))
47954800

47964801
if T.must(@disable_date) > Date.today
4802+
return if @deprecation_date.present?
4803+
47974804
@deprecation_reason = T.let(because, T.nilable(T.any(String, Symbol)))
47984805
@deprecation_replacement_formula = T.let(replacement_formula.presence || replacement, T.nilable(String))
47994806
@deprecation_replacement_cask = T.let(replacement_cask.presence || replacement, T.nilable(String))

Library/Homebrew/test/formula_spec.rb

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,4 +2053,105 @@ def install
20532053
expect(f.class.preserve_rpath?).to be(false)
20542054
end
20552055
end
2056+
2057+
describe "#deprecate! and #disable!" do
2058+
let(:deprecation_date) { "2020-01-01" }
2059+
let(:disable_date) { "2021-01-01" }
2060+
2061+
context "with both dates provided in correct order" do
2062+
let(:f) do
2063+
deprecation_date_ = deprecation_date
2064+
disable_date_ = disable_date
2065+
formula "foo" do
2066+
url "foo-1.0"
2067+
deprecate! date: deprecation_date_.to_s, because: :unmaintained
2068+
disable! date: disable_date_.to_s, because: :unsupported
2069+
end
2070+
end
2071+
2072+
it "is not deprecated before deprecation date" do
2073+
allow(Date).to receive(:today).and_return(Date.parse(deprecation_date) - 1)
2074+
expect(f.deprecated?).to be(false)
2075+
expect(f.deprecation_reason).to be_nil
2076+
expect(f.disabled?).to be(false)
2077+
expect(f.disable_reason).to be_nil
2078+
end
2079+
2080+
it "is deprecated on deprecation date" do
2081+
allow(Date).to receive(:today).and_return(Date.parse(deprecation_date))
2082+
expect(f.deprecated?).to be(true)
2083+
expect(f.deprecation_reason).to be(:unmaintained)
2084+
expect(f.disabled?).to be(false)
2085+
expect(f.disable_reason).to be_nil
2086+
end
2087+
2088+
it "is disabled on disable date" do
2089+
allow(Date).to receive(:today).and_return(Date.parse(disable_date))
2090+
expect(f.deprecated?).to be(true)
2091+
expect(f.deprecation_reason).to be(:unmaintained)
2092+
expect(f.disabled?).to be(true)
2093+
expect(f.disable_reason).to be(:unsupported)
2094+
end
2095+
end
2096+
2097+
context "with both dates provided in incorrect order" do
2098+
let(:f) do
2099+
deprecation_date_ = deprecation_date
2100+
disable_date_ = disable_date
2101+
formula "foo" do
2102+
url "foo-1.0"
2103+
disable! date: disable_date_.to_s, because: :unsupported
2104+
deprecate! date: deprecation_date_.to_s, because: :unmaintained
2105+
end
2106+
end
2107+
2108+
it "is not deprecated before deprecation date" do
2109+
allow(Date).to receive(:today).and_return(Date.parse(deprecation_date) - 1)
2110+
expect(f.deprecated?).to be(false)
2111+
expect(f.deprecation_reason).to be_nil
2112+
expect(f.disabled?).to be(false)
2113+
expect(f.disable_reason).to be_nil
2114+
end
2115+
2116+
it "is deprecated on deprecation date" do
2117+
allow(Date).to receive(:today).and_return(Date.parse(deprecation_date))
2118+
expect(f.deprecated?).to be(true)
2119+
expect(f.deprecation_reason).to be(:unmaintained)
2120+
expect(f.disabled?).to be(false)
2121+
expect(f.disable_reason).to be_nil
2122+
end
2123+
2124+
it "is disabled on disable date" do
2125+
allow(Date).to receive(:today).and_return(Date.parse(disable_date))
2126+
expect(f.deprecated?).to be(true)
2127+
expect(f.deprecation_reason).to be(:unmaintained)
2128+
expect(f.disabled?).to be(true)
2129+
expect(f.disable_reason).to be(:unsupported)
2130+
end
2131+
end
2132+
2133+
context "with only disable date" do
2134+
let(:f) do
2135+
disable_date_ = disable_date
2136+
formula "foo" do
2137+
url "foo-1.0"
2138+
disable! date: disable_date_.to_s, because: :unsupported
2139+
end
2140+
end
2141+
2142+
it "is deprecated before disable date" do
2143+
allow(Date).to receive(:today).and_return(Date.parse(disable_date) << 12)
2144+
expect(f.deprecated?).to be(true)
2145+
expect(f.deprecation_reason).to be(:unsupported)
2146+
expect(f.disabled?).to be(false)
2147+
expect(f.disable_reason).to be_nil
2148+
end
2149+
2150+
it "is disabled on disable date" do
2151+
allow(Date).to receive(:today).and_return(Date.parse(disable_date))
2152+
expect(f.disabled?).to be(true)
2153+
expect(f.disable_reason).to be(:unsupported)
2154+
end
2155+
end
2156+
end
20562157
end

0 commit comments

Comments
 (0)