From 9f7d079cfebfa3a53f2c850a1fc7acec316c9f2f Mon Sep 17 00:00:00 2001 From: Bryan Richter Date: Tue, 13 Feb 2024 14:40:51 +0200 Subject: [PATCH] Hack to support building with Cabal >=3.4 It remains to be seen if this has any user-visible change. Hopefully not, but even if it does, it shouldn't cause any breakage: ">=0" is forward and backward-compatible. --- src/Types.hs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Types.hs b/src/Types.hs index 2d4de53..6533bf4 100644 --- a/src/Types.hs +++ b/src/Types.hs @@ -407,7 +407,25 @@ instance ToMarkup VersionRangeP where instance PersistField VersionRangeP where toPersistValue = PersistText . textDisplay fromPersistValue v = - fromPersistValue v >>= bimap (T.pack . displayException) VersionRangeP . dtParse + fromPersistValue v >>= bimap (T.pack . displayException) VersionRangeP . dtParse . hackwardCompat_3_4 + where + -- We use parseSimple under the hood, which always parses using + -- the latest version of the Cabal spec. In practice, this hasn't + -- been a problem. Until now. + -- + -- Cabal spec 3.4 dropped support for "-any" as a version range, and the + -- database is full of such values. Luckily, ">=0" is a + -- backward-compatible synonym for "-any". New versions of this app will + -- write ">=0" instead of "-any", which old versions of this app will + -- understand just fine. We just need to substitute on read. + -- + -- FIXME: strictly speaking, VersionRange cannot be parsed without + -- knowing the Cabal spec version of the package that used it. There's + -- nothing *wrong* with "-any". That means we probably need to decode it + -- no further than Text and do further processing outside of the + -- PersistField instance. + hackwardCompat_3_4 "-any" = ">=0" + hackwardCompat_3_4 t = t instance PersistFieldSql VersionRangeP where sqlType _ = SqlString