From 9039df924db22a54c188167ae80855c3e64d634a Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Tue, 22 Mar 2022 20:29:50 +0000 Subject: [PATCH 1/6] Allow building with template-haskell-2.18.0 --- yesod-core/src/Yesod/Routes/TH/Dispatch.hs | 16 ++++++++++++---- yesod-core/src/Yesod/Routes/TH/RenderRoute.hs | 11 +++++++++-- yesod-core/src/Yesod/Routes/TH/RouteAttrs.hs | 7 ++++++- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/yesod-core/src/Yesod/Routes/TH/Dispatch.hs b/yesod-core/src/Yesod/Routes/TH/Dispatch.hs index c061a1c2..1d12c9d9 100644 --- a/yesod-core/src/Yesod/Routes/TH/Dispatch.hs +++ b/yesod-core/src/Yesod/Routes/TH/Dispatch.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE RecordWildCards, TemplateHaskell, ViewPatterns #-} module Yesod.Routes.TH.Dispatch ( MkDispatchSettings (..) @@ -73,7 +74,7 @@ mkDispatchClause MkDispatchSettings {..} resources = do handlePiece (Static str) = return (LitP $ StringL str, Nothing) handlePiece (Dynamic _) = do x <- newName "dyn" - let pat = ViewP (VarE 'fromPathPiece) (ConP 'Just [VarP x]) + let pat = ViewP (VarE 'fromPathPiece) (conPCompat 'Just [VarP x]) return (pat, Just $ VarE x) handlePieces :: [Piece a] -> Q ([Pat], [Exp]) @@ -86,7 +87,7 @@ mkDispatchClause MkDispatchSettings {..} resources = do mkPathPat final = foldr addPat final where - addPat x y = ConP '(:) [x, y] + addPat x y = conPCompat '(:) [x, y] go :: SDC -> ResourceTree a -> Q Clause go sdc (ResourceParent name _check pieces children) = do @@ -124,11 +125,11 @@ mkDispatchClause MkDispatchSettings {..} resources = do Methods multi methods -> do (finalPat, mfinalE) <- case multi of - Nothing -> return (ConP '[] [], Nothing) + Nothing -> return (conPCompat '[] [], Nothing) Just _ -> do multiName <- newName "multi" let pat = ViewP (VarE 'fromPathMultiPiece) - (ConP 'Just [VarP multiName]) + (conPCompat 'Just [VarP multiName]) return (pat, Just $ VarE multiName) let dynsMulti = @@ -200,3 +201,10 @@ mkDispatchClause MkDispatchSettings {..} resources = do defaultGetHandler :: Maybe String -> String -> Q Exp defaultGetHandler Nothing s = return $ VarE $ mkName $ "handle" ++ s defaultGetHandler (Just method) s = return $ VarE $ mkName $ map toLower method ++ s + +conPCompat :: Name -> [Pat] -> Pat +conPCompat n pats = ConP n +#if MIN_VERSION_template_haskell(2,18,0) + [] +#endif + pats diff --git a/yesod-core/src/Yesod/Routes/TH/RenderRoute.hs b/yesod-core/src/Yesod/Routes/TH/RenderRoute.hs index 09654c83..6d9e4de1 100644 --- a/yesod-core/src/Yesod/Routes/TH/RenderRoute.hs +++ b/yesod-core/src/Yesod/Routes/TH/RenderRoute.hs @@ -67,7 +67,7 @@ mkRenderRouteClauses = let cnt = length $ filter isDynamic pieces dyns <- replicateM cnt $ newName "dyn" child <- newName "child" - let pat = ConP (mkName name) $ map VarP $ dyns ++ [child] + let pat = conPCompat (mkName name) $ map VarP $ dyns ++ [child] pack' <- [|pack|] tsp <- [|toPathPiece|] @@ -100,7 +100,7 @@ mkRenderRouteClauses = case resourceDispatch res of Subsite{} -> return <$> newName "sub" _ -> return [] - let pat = ConP (mkName $ resourceName res) $ map VarP $ dyns ++ sub + let pat = conPCompat (mkName $ resourceName res) $ map VarP $ dyns ++ sub pack' <- [|pack|] tsp <- [|toPathPiece|] @@ -182,3 +182,10 @@ notStrict = Bang NoSourceUnpackedness NoSourceStrictness instanceD :: Cxt -> Type -> [Dec] -> Dec instanceD = InstanceD Nothing + +conPCompat :: Name -> [Pat] -> Pat +conPCompat n pats = ConP n +#if MIN_VERSION_template_haskell(2,18,0) + [] +#endif + pats diff --git a/yesod-core/src/Yesod/Routes/TH/RouteAttrs.hs b/yesod-core/src/Yesod/Routes/TH/RouteAttrs.hs index 0f1aeece..72b24b49 100644 --- a/yesod-core/src/Yesod/Routes/TH/RouteAttrs.hs +++ b/yesod-core/src/Yesod/Routes/TH/RouteAttrs.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE RecordWildCards #-} module Yesod.Routes.TH.RouteAttrs @@ -26,7 +27,11 @@ goTree front (ResourceParent name _check pieces trees) = toIgnore = length $ filter isDynamic pieces isDynamic Dynamic{} = True isDynamic Static{} = False - front' = front . ConP (mkName name) . ignored + front' = front . ConP (mkName name) +#if MIN_VERSION_template_haskell(2,18,0) + [] +#endif + . ignored goRes :: (Pat -> Pat) -> Resource a -> Q Clause goRes front Resource {..} = From 24d3ea9e53a9e8b29d168bf5574f8c341c100312 Mon Sep 17 00:00:00 2001 From: Teo Camarasu Date: Tue, 22 Mar 2022 23:02:44 +0000 Subject: [PATCH 2/6] Fix building yesod-bin with Cabal-3.6 --- yesod-bin/AddHandler.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/yesod-bin/AddHandler.hs b/yesod-bin/AddHandler.hs index 52d57cdd..d06df811 100644 --- a/yesod-bin/AddHandler.hs +++ b/yesod-bin/AddHandler.hs @@ -16,6 +16,9 @@ import Distribution.PackageDescription.Parse (readGenericPackageDescription) #else import Distribution.PackageDescription.Parse (readPackageDescription) #endif +#if MIN_VERSION_Cabal(3, 6, 0) +import Distribution.Utils.Path +#endif import Distribution.PackageDescription.Configuration (flattenPackageDescription) import Distribution.PackageDescription (allBuildInfo, hsSourceDirs) import Distribution.Verbosity (normal) @@ -247,4 +250,8 @@ getSrcDir cabal = do #endif let buildInfo = allBuildInfo pd srcDirs = concatMap hsSourceDirs buildInfo +#if MIN_VERSION_Cabal(3, 6, 0) + return $ maybe "." getSymbolicPath $ listToMaybe srcDirs +#else return $ fromMaybe "." $ listToMaybe srcDirs +#endif From 3c2b50e08c8f5e24dd74bc52bdc6e9aae41adf9e Mon Sep 17 00:00:00 2001 From: Teo Camarasu Date: Tue, 22 Mar 2022 23:31:12 +0000 Subject: [PATCH 3/6] bump yesod-core --- yesod-core/yesod-core.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yesod-core/yesod-core.cabal b/yesod-core/yesod-core.cabal index f01e5ff9..e33d36e1 100644 --- a/yesod-core/yesod-core.cabal +++ b/yesod-core/yesod-core.cabal @@ -1,5 +1,5 @@ name: yesod-core -version: 1.6.21.0 +version: 1.6.21.1 license: MIT license-file: LICENSE author: Michael Snoyman From 87427c12908a0e963a8187f2aa0deff0ed92fef7 Mon Sep 17 00:00:00 2001 From: Teo Camarasu Date: Tue, 22 Mar 2022 23:31:19 +0000 Subject: [PATCH 4/6] bump yesod-bin --- yesod-bin/yesod-bin.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yesod-bin/yesod-bin.cabal b/yesod-bin/yesod-bin.cabal index 1296d7ff..bf83bf8b 100644 --- a/yesod-bin/yesod-bin.cabal +++ b/yesod-bin/yesod-bin.cabal @@ -1,5 +1,5 @@ name: yesod-bin -version: 1.6.2 +version: 1.6.2.1 license: MIT license-file: LICENSE author: Michael Snoyman From b117e5a4cd6db4eaca6eac9d765723f09338c593 Mon Sep 17 00:00:00 2001 From: Teo Camarasu Date: Tue, 22 Mar 2022 23:36:16 +0000 Subject: [PATCH 5/6] update yesod-core changelog --- yesod-core/ChangeLog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yesod-core/ChangeLog.md b/yesod-core/ChangeLog.md index 47d63ffb..88f29b61 100644 --- a/yesod-core/ChangeLog.md +++ b/yesod-core/ChangeLog.md @@ -1,8 +1,9 @@ # ChangeLog for yesod-core -## Unreleased +## 1.6.21.1 * Add missing list to documentation for ``Yesod.Core.Dispatch.warp``. [#1745](https://github.com/yesodweb/yesod/pull/1745) +* Support template-haskell 2.18 [#1754](https://github.com/yesodweb/yesod/pull/1754) ## 1.6.21.0 From c6fab6f4105d4618c06b17898383a21846a1d94f Mon Sep 17 00:00:00 2001 From: Teo Camarasu Date: Tue, 22 Mar 2022 23:36:25 +0000 Subject: [PATCH 6/6] update yesod-bin changelog --- yesod-bin/ChangeLog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/yesod-bin/ChangeLog.md b/yesod-bin/ChangeLog.md index 9f05e13d..e3366b11 100644 --- a/yesod-bin/ChangeLog.md +++ b/yesod-bin/ChangeLog.md @@ -1,5 +1,9 @@ # ChangeLog for yesod-bin +## 1.6.2.1 + +* Support Cabal 3.6 [#1754](https://github.com/yesodweb/yesod/pull/1754) + ## 1.6.2 * aeson 2.0