From 226c381baa1e81870e6f72a0095ad2662e268030 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Fri, 15 Apr 2016 11:50:06 +1000 Subject: [PATCH 1/6] yesod-core: Make it work with ghc-8.0 Use CPP hackery to make it compile with ghc-8.0 and ghc 7.10. If ghc-7.10 works, I assume earlier supported versions of GHC also work. All tests pass with both GHC versions. Unfortunately, the TH changes force changes in the type signature of Yesod.Routes.TH.RenderRoute.mkRouteCons from: mkRouteCons :: [ResourceTree Type] -> ([Con], [Dec]) to mkRouteCons :: [ResourceTree Type] -> Q ([Con], [Dec]) and I can't see a way around that. --- yesod-core/Yesod/Core/Internal/TH.hs | 5 +++ yesod-core/Yesod/Routes/TH/RenderRoute.hs | 45 +++++++++++++++------ yesod-core/test/YesodCoreTest/Exceptions.hs | 2 +- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/yesod-core/Yesod/Core/Internal/TH.hs b/yesod-core/Yesod/Core/Internal/TH.hs index 7fb4a28d..9f18ccc1 100644 --- a/yesod-core/Yesod/Core/Internal/TH.hs +++ b/yesod-core/Yesod/Core/Internal/TH.hs @@ -86,8 +86,13 @@ mkYesodGeneral namestr args isSub f resS = do case info of TyConI dec -> case dec of +#if MIN_VERSION_template_haskell(2,11,0) + DataD _ _ vs _ _ _ -> length vs + NewtypeD _ _ vs _ _ _ -> length vs +#else DataD _ _ vs _ _ -> length vs NewtypeD _ _ vs _ _ -> length vs +#endif _ -> 0 _ -> 0 _ -> return 0 diff --git a/yesod-core/Yesod/Routes/TH/RenderRoute.hs b/yesod-core/Yesod/Routes/TH/RenderRoute.hs index 4b513f8c..3120bf77 100644 --- a/yesod-core/Yesod/Routes/TH/RenderRoute.hs +++ b/yesod-core/Yesod/Routes/TH/RenderRoute.hs @@ -8,6 +8,9 @@ module Yesod.Routes.TH.RenderRoute ) where import Yesod.Routes.TH.Types +#if MIN_VERSION_template_haskell(2,11,0) +import Language.Haskell.TH (conT) +#endif import Language.Haskell.TH.Syntax import Data.Maybe (maybeToList) import Control.Monad (replicateM) @@ -19,15 +22,15 @@ import Data.Monoid (mconcat) #endif -- | Generate the constructors of a route data type. -mkRouteCons :: [ResourceTree Type] -> ([Con], [Dec]) -mkRouteCons = - mconcat . map mkRouteCon +mkRouteCons :: [ResourceTree Type] -> Q ([Con], [Dec]) +mkRouteCons rttypes = + mconcat <$> mapM mkRouteCon rttypes where mkRouteCon (ResourceLeaf res) = - ([con], []) + return ([con], []) where con = NormalC (mkName $ resourceName res) - $ map (\x -> (NotStrict, x)) + $ map (\x -> (notStrict, x)) $ concat [singles, multi, sub] singles = concatMap toSingle $ resourcePieces res toSingle Static{} = [] @@ -39,14 +42,19 @@ mkRouteCons = case resourceDispatch res of Subsite { subsiteType = typ } -> [ConT ''Route `AppT` typ] _ -> [] - mkRouteCon (ResourceParent name _check pieces children) = - ([con], dec : decs) + + mkRouteCon (ResourceParent name _check pieces children) = do + (cons, decs) <- mkRouteCons children +#if MIN_VERSION_template_haskell(2,11,0) + dec <- DataD [] (mkName name) [] Nothing cons <$> mapM conT [''Show, ''Read, ''Eq] +#else + let dec = DataD [] (mkName name) [] cons [''Show, ''Read, ''Eq] +#endif + return ([con], dec : decs) where - (cons, decs) = mkRouteCons children con = NormalC (mkName name) - $ map (\x -> (NotStrict, x)) + $ map (\x -> (notStrict, x)) $ concat [singles, [ConT $ mkName name]] - dec = DataD [] (mkName name) [] cons [''Show, ''Read, ''Eq] singles = concatMap toSingle pieces toSingle Static{} = [] @@ -143,10 +151,23 @@ mkRenderRouteInstance = mkRenderRouteInstance' [] mkRenderRouteInstance' :: Cxt -> Type -> [ResourceTree Type] -> Q [Dec] mkRenderRouteInstance' cxt typ ress = do cls <- mkRenderRouteClauses ress - let (cons, decs) = mkRouteCons ress + (cons, decs) <- mkRouteCons ress +#if MIN_VERSION_template_haskell(2,11,0) + did <- DataInstD [] ''Route [typ] Nothing cons <$> mapM conT clazzes +#else + let did = DataInstD [] ''Route [typ] cons clazzes +#endif return $ InstanceD cxt (ConT ''RenderRoute `AppT` typ) - [ DataInstD [] ''Route [typ] cons clazzes + [ did , FunD (mkName "renderRoute") cls ] : decs where clazzes = [''Show, ''Eq, ''Read] + +#if MIN_VERSION_template_haskell(2,11,0) +notStrict :: Bang +notStrict = Bang NoSourceUnpackedness NoSourceStrictness +#else +notStrict :: Strict +notStrict = NotStrict +#endif diff --git a/yesod-core/test/YesodCoreTest/Exceptions.hs b/yesod-core/test/YesodCoreTest/Exceptions.hs index 7c2711d9..8134dd9d 100644 --- a/yesod-core/test/YesodCoreTest/Exceptions.hs +++ b/yesod-core/test/YesodCoreTest/Exceptions.hs @@ -41,7 +41,7 @@ case500 :: IO () case500 = runner $ do res <- request defaultRequest assertStatus 500 res - assertBody "FOOBAR" res + assertBodyContains "FOOBAR" res caseRedirect :: IO () caseRedirect = runner $ do From d101c8eebe02390ac75a623ba67a70e95a48bd38 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Fri, 15 Apr 2016 14:41:55 +1000 Subject: [PATCH 2/6] yesod-persistent: Make it work with persistent 2.5 --- yesod-persistent/yesod-persistent.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yesod-persistent/yesod-persistent.cabal b/yesod-persistent/yesod-persistent.cabal index f32221a3..c68a6884 100644 --- a/yesod-persistent/yesod-persistent.cabal +++ b/yesod-persistent/yesod-persistent.cabal @@ -17,7 +17,7 @@ library build-depends: base >= 4 && < 5 , yesod-core >= 1.4.0 && < 1.5 , persistent >= 2.1 && < 2.6 - , persistent-template >= 2.1 && < 2.2 + , persistent-template >= 2.1 && < 2.6 , transformers >= 0.2.2 , blaze-builder , conduit From 34e0c8b638addb00c726b082e7e9055d918bf5f3 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Sat, 16 Apr 2016 09:05:47 +1000 Subject: [PATCH 3/6] yesod-auth: Fixes for persistent 2.5 --- yesod-auth/yesod-auth.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yesod-auth/yesod-auth.cabal b/yesod-auth/yesod-auth.cabal index 1c0cb4f5..c0b91539 100644 --- a/yesod-auth/yesod-auth.cabal +++ b/yesod-auth/yesod-auth.cabal @@ -38,7 +38,7 @@ library , yesod-form >= 1.4 && < 1.5 , transformers >= 0.2.2 , persistent >= 2.1 && < 2.6 - , persistent-template >= 2.1 && < 2.2 + , persistent-template >= 2.1 && < 2.6 , http-client , http-conduit >= 2.1 , aeson >= 0.7 From bd9197fc1e1a7e43ee70198821d321a96e65d216 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Mon, 18 Apr 2016 12:15:15 +1000 Subject: [PATCH 4/6] yesod-auth-oauth: Allow transformers == 0.5* --- yesod-auth-oauth/yesod-auth-oauth.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yesod-auth-oauth/yesod-auth-oauth.cabal b/yesod-auth-oauth/yesod-auth-oauth.cabal index 6a952db6..70cea8ac 100644 --- a/yesod-auth-oauth/yesod-auth-oauth.cabal +++ b/yesod-auth-oauth/yesod-auth-oauth.cabal @@ -27,7 +27,7 @@ library , yesod-auth >= 1.4 && < 1.5 , text >= 0.7 , yesod-form >= 1.4 && < 1.5 - , transformers >= 0.2.2 && < 0.5 + , transformers >= 0.2.2 && < 0.6 , lifted-base >= 0.2 && < 0.3 exposed-modules: Yesod.Auth.OAuth ghc-options: -Wall From 833e74e797a2785b757a903347affe26ef760a5a Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Mon, 18 Apr 2016 13:30:56 +1000 Subject: [PATCH 5/6] yesod-bin: Fixes for ghc-8.0 --- yesod-bin/GhcBuild.hs | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/yesod-bin/GhcBuild.hs b/yesod-bin/GhcBuild.hs index 4d2497ce..eff8e615 100644 --- a/yesod-bin/GhcBuild.hs +++ b/yesod-bin/GhcBuild.hs @@ -85,12 +85,36 @@ getPackageArgs buildDir argv2 = do dflags0 <- GHC.getSessionDynFlags (dflags1, _, _) <- GHC.parseDynamicFlags dflags0 argv3 let pkgFlags = map convertPkgFlag (GHC.packageFlags dflags1) + ignorePkgFlags = +#if __GLASGOW_HASKELL__ >= 800 + map convertIgnorePkgFlag (GHC.ignorePackageFlags dflags1) +#else + [] +#endif + trustPkgFlags = +#if __GLASGOW_HASKELL__ >= 800 + map convertTrustPkgFlag (GHC.trustFlags dflags1) +#else + [] +#endif hideAll | gopt DF.Opt_HideAllPackages dflags1 = [ "-hide-all-packages"] | otherwise = [] ownPkg = packageString (DF.thisPackage dflags1) - return (reverse (extra dflags1) ++ hideAll ++ pkgFlags ++ [ownPkg]) + return (reverse (extra dflags1) ++ hideAll ++ trustPkgFlags ++ ignorePkgFlags ++ pkgFlags ++ [ownPkg]) where -#if __GLASGOW_HASKELL__ >= 710 +#if __GLASGOW_HASKELL__ >= 800 + convertIgnorePkgFlag (DF.IgnorePackage p) = "-ignore-package" ++ p + convertTrustPkgFlag (DF.TrustPackage p) = "-trust" ++ p + convertTrustPkgFlag (DF.DistrustPackage p) = "-distrust" ++ p +#else + convertPkgFlag (DF.IgnorePackage p) = "-ignore-package" ++ p + convertPkgFlag (DF.TrustPackage p) = "-trust" ++ p + convertPkgFlag (DF.DistrustPackage p) = "-distrust" ++ p +#endif +#if __GLASGOW_HASKELL__ >= 800 + convertPkgFlag (DF.ExposePackage _ (DF.PackageArg p) _) = "-package" ++ p + convertPkgFlag (DF.ExposePackage _ (DF.UnitIdArg p) _) = "-package-id" ++ p +#elif __GLASGOW_HASKELL__ == 710 convertPkgFlag (DF.ExposePackage (DF.PackageArg p) _) = "-package" ++ p convertPkgFlag (DF.ExposePackage (DF.PackageIdArg p) _) = "-package-id" ++ p convertPkgFlag (DF.ExposePackage (DF.PackageKeyArg p) _) = "-package-key" ++ p @@ -99,10 +123,9 @@ getPackageArgs buildDir argv2 = do convertPkgFlag (DF.ExposePackageId p) = "-package-id" ++ p #endif convertPkgFlag (DF.HidePackage p) = "-hide-package" ++ p - convertPkgFlag (DF.IgnorePackage p) = "-ignore-package" ++ p - convertPkgFlag (DF.TrustPackage p) = "-trust" ++ p - convertPkgFlag (DF.DistrustPackage p) ="-distrust" ++ p -#if __GLASGOW_HASKELL__ >= 710 +#if __GLASGOW_HASKELL__ >= 800 + packageString flags = "-package-id" ++ Module.unitIdString flags +#elif __GLASGOW_HASKELL__ == 710 packageString flags = "-package-key" ++ Module.packageKeyString flags #else packageString flags = "-package-id" ++ Module.packageIdString flags ++ "-inplace" @@ -162,7 +185,9 @@ buildPackage' argv2 ld ar = do haskellish (f,Nothing) = looksLikeModuleName f || isHaskellSrcFilename f || '.' `notElem` f haskellish (_,Just phase) = -#if MIN_VERSION_ghc(7,8,3) +#if MIN_VERSION_ghc(8,0,0) + phase `notElem` [As True, As False, Cc, Cobjc, Cobjcxx, CmmCpp, Cmm, StopLn] +#elif MIN_VERSION_ghc(7,8,3) phase `notElem` [As True, As False, Cc, Cobjc, Cobjcpp, CmmCpp, Cmm, StopLn] #elif MIN_VERSION_ghc(7,4,0) phase `notElem` [As, Cc, Cobjc, Cobjcpp, CmmCpp, Cmm, StopLn] From 21d27626b2f3fa6f6e77cb30fe2bb1d0684f6cd0 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Tue, 19 Apr 2016 13:58:39 +1000 Subject: [PATCH 6/6] yesod-core: Fix for ghc-7.8 --- yesod-core/Yesod/Routes/TH/RenderRoute.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/yesod-core/Yesod/Routes/TH/RenderRoute.hs b/yesod-core/Yesod/Routes/TH/RenderRoute.hs index 3120bf77..c482e898 100644 --- a/yesod-core/Yesod/Routes/TH/RenderRoute.hs +++ b/yesod-core/Yesod/Routes/TH/RenderRoute.hs @@ -18,6 +18,7 @@ import Data.Text (pack) import Web.PathPieces (PathPiece (..), PathMultiPiece (..)) import Yesod.Routes.Class #if __GLASGOW_HASKELL__ < 710 +import Control.Applicative ((<$>)) import Data.Monoid (mconcat) #endif