From 089f8f1e12882bb28f2164527036b44d17df2791 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Thu, 14 Nov 2013 21:10:26 +0200 Subject: [PATCH 1/5] Ignore sandbox files #620 --- yesod-bin/hsfiles/mongo.hsfiles | 2 ++ yesod-bin/hsfiles/mysql.hsfiles | 2 ++ yesod-bin/hsfiles/postgres-fay.hsfiles | 2 ++ yesod-bin/hsfiles/postgres.hsfiles | 2 ++ yesod-bin/hsfiles/simple.hsfiles | 2 ++ yesod-bin/hsfiles/sqlite.hsfiles | 2 ++ yesod-bin/yesod-bin.cabal | 2 +- 7 files changed, 13 insertions(+), 1 deletion(-) diff --git a/yesod-bin/hsfiles/mongo.hsfiles b/yesod-bin/hsfiles/mongo.hsfiles index a478d691..e3055394 100644 --- a/yesod-bin/hsfiles/mongo.hsfiles +++ b/yesod-bin/hsfiles/mongo.hsfiles @@ -12,6 +12,8 @@ config/client_session_key.aes .hsenv* cabal-dev/ yesod-devel/ +.cabal-sandbox +cabal.sandbox.config {-# START_FILE Application.hs #-} {-# OPTIONS_GHC -fno-warn-orphans #-} diff --git a/yesod-bin/hsfiles/mysql.hsfiles b/yesod-bin/hsfiles/mysql.hsfiles index 0711321a..2657e63e 100644 --- a/yesod-bin/hsfiles/mysql.hsfiles +++ b/yesod-bin/hsfiles/mysql.hsfiles @@ -12,6 +12,8 @@ config/client_session_key.aes .hsenv* cabal-dev/ yesod-devel/ +.cabal-sandbox +cabal.sandbox.config {-# START_FILE Application.hs #-} {-# OPTIONS_GHC -fno-warn-orphans #-} diff --git a/yesod-bin/hsfiles/postgres-fay.hsfiles b/yesod-bin/hsfiles/postgres-fay.hsfiles index 607b654d..ded715f0 100644 --- a/yesod-bin/hsfiles/postgres-fay.hsfiles +++ b/yesod-bin/hsfiles/postgres-fay.hsfiles @@ -13,6 +13,8 @@ fay/Language/Fay/Yesod.hs .hsenv* cabal-dev/ yesod-devel/ +.cabal-sandbox +cabal.sandbox.config {-# START_FILE Application.hs #-} {-# OPTIONS_GHC -fno-warn-orphans #-} diff --git a/yesod-bin/hsfiles/postgres.hsfiles b/yesod-bin/hsfiles/postgres.hsfiles index 3fda126c..9aef1ae3 100644 --- a/yesod-bin/hsfiles/postgres.hsfiles +++ b/yesod-bin/hsfiles/postgres.hsfiles @@ -12,6 +12,8 @@ config/client_session_key.aes .hsenv* cabal-dev/ yesod-devel/ +.cabal-sandbox +cabal.sandbox.config {-# START_FILE Application.hs #-} {-# OPTIONS_GHC -fno-warn-orphans #-} diff --git a/yesod-bin/hsfiles/simple.hsfiles b/yesod-bin/hsfiles/simple.hsfiles index fb212169..73fc703c 100644 --- a/yesod-bin/hsfiles/simple.hsfiles +++ b/yesod-bin/hsfiles/simple.hsfiles @@ -12,6 +12,8 @@ config/client_session_key.aes .hsenv* cabal-dev/ yesod-devel/ +.cabal-sandbox +cabal.sandbox.config {-# START_FILE Application.hs #-} {-# OPTIONS_GHC -fno-warn-orphans #-} diff --git a/yesod-bin/hsfiles/sqlite.hsfiles b/yesod-bin/hsfiles/sqlite.hsfiles index 4558081a..9b7ca111 100644 --- a/yesod-bin/hsfiles/sqlite.hsfiles +++ b/yesod-bin/hsfiles/sqlite.hsfiles @@ -12,6 +12,8 @@ config/client_session_key.aes .hsenv* cabal-dev/ yesod-devel/ +.cabal-sandbox +cabal.sandbox.config {-# START_FILE Application.hs #-} {-# OPTIONS_GHC -fno-warn-orphans #-} diff --git a/yesod-bin/yesod-bin.cabal b/yesod-bin/yesod-bin.cabal index 27110e13..e1017c46 100644 --- a/yesod-bin/yesod-bin.cabal +++ b/yesod-bin/yesod-bin.cabal @@ -1,5 +1,5 @@ name: yesod-bin -version: 1.2.4 +version: 1.2.4.1 license: MIT license-file: LICENSE author: Michael Snoyman From 8390802a6b677871cd3760ca0951f261acbdfce4 Mon Sep 17 00:00:00 2001 From: Greg Weber Date: Tue, 19 Nov 2013 11:23:48 -0800 Subject: [PATCH 2/5] randomly show one motivational refresh messages --- yesod-bin/refreshing.html | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/yesod-bin/refreshing.html b/yesod-bin/refreshing.html index 316c5cca..a0ff1c9e 100644 --- a/yesod-bin/refreshing.html +++ b/yesod-bin/refreshing.html @@ -58,7 +58,8 @@

The application isn’t built

We’ll keep trying to refresh every second

-

Meanwhile, here are some motivational messages:

+ +

Meanwhile, here is a motivational message:

  • You are a beautiful person making a beautiful web site.
  • Keep going, you’ve nearly fixed the bug!
  • @@ -66,7 +67,20 @@
  • Get a glass of water, keep hydrated.
-
+ +
+ + + +
From 79155103220e192d5eaae83a16866daec59f5ea0 Mon Sep 17 00:00:00 2001 From: Greg Weber Date: Tue, 19 Nov 2013 11:24:23 -0800 Subject: [PATCH 3/5] hlint & compiler warnings also tried out embeding the refresh file --- .gitignore | 4 ++- yesod-bin/Devel.hs | 62 ++++++++++++++++++++++++++------------------ yesod-bin/Options.hs | 25 +++++++++--------- yesod-bin/main.hs | 3 ++- 4 files changed, 55 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index e766dea6..00767768 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,9 @@ dist client_session_key.aes cabal-dev/ yesod/foobar/ -.virthualenv +.hsenv/ +.cabal-sandbox/ +cabal.sandbox.config /vendor/ /.shelly/ /tarballs/ diff --git a/yesod-bin/Devel.hs b/yesod-bin/Devel.hs index 3cf90d8b..a6b888c7 100644 --- a/yesod-bin/Devel.hs +++ b/yesod-bin/Devel.hs @@ -1,14 +1,15 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} +#ifdef EMBED_REFRESH +{-# LANGUAGE TemplateHaskell #-} +#endif module Devel ( devel , DevelOpts(..) , defaultDevelOpts ) where -import Paths_yesod_bin - import qualified Distribution.Compiler as D import qualified Distribution.ModuleName as D import qualified Distribution.PackageDescription as D @@ -24,7 +25,7 @@ import Control.Concurrent.MVar (MVar, newEmptyMVar, takeMVar, tryPutMVar) import qualified Control.Exception as Ex import Control.Monad (forever, unless, void, - when) + when, forM) import Control.Monad.IO.Class (liftIO) import Control.Monad.Trans.State (evalStateT, get) import qualified Data.IORef as I @@ -78,6 +79,11 @@ import Network.Socket (sClose) import Network.Wai (responseLBS) import Network.Wai.Handler.Warp (run) import SrcLoc (Located) +#ifdef EMBED_REFRESH +import Data.FileEmbed (embedFile) +#else +import Paths_yesod_bin +#endif lockFile :: DevelOpts -> FilePath lockFile _opts = "yesod-devel/devel-terminate" @@ -122,7 +128,18 @@ cabalProgram opts | isCabalDev opts = "cabal-dev" reverseProxy :: DevelOpts -> I.IORef Int -> IO () reverseProxy opts iappPort = do manager <- newManager def - let loop = forever $ do +#ifdef EMBED_REFRESH + let refreshHtml = LB.fromStrict $(embedFile "refreshing.html") +#else + refreshHtml <- liftIO $ getDataFileName "refreshing.html" >>= LB.readFile +#endif + let onExc _ _ = return $ responseLBS status200 + [ ("content-type", "text/html") + , ("Refresh", "1") + ] + refreshHtml + + let runProxy = run (develPort opts) $ waiProxyToSettings (const $ do appPort <- liftIO $ I.readIORef iappPort @@ -141,20 +158,13 @@ reverseProxy opts iappPort = do else Just (1000000 * proxyTimeout opts) } manager - putStrLn "Reverse proxy stopped, but it shouldn't" - threadDelay 1000000 - putStrLn "Restarting reverse proxy" - loop `Ex.onException` exitFailure + loop runProxy `Ex.onException` exitFailure where - onExc _ _ = do - refreshing <- liftIO $ getDataFileName "refreshing.html" - html <- liftIO $ LB.readFile refreshing - return $ responseLBS - status200 - [ ("content-type", "text/html") - , ("Refresh", "1") - ] - html + loop proxy = forever $ do + void proxy + putStrLn "Reverse proxy stopped, but it shouldn't" + threadDelay 1000000 + putStrLn "Restarting reverse proxy" checkPort :: Int -> IO Bool checkPort p = do @@ -174,10 +184,12 @@ getPort _ p0 = avail <- checkPort p if avail then return p else loop (succ p) +unlessM :: Monad m => m Bool -> m () -> m () +unlessM c a = c >>= \res -> unless res a + devel :: DevelOpts -> [String] -> IO () devel opts passThroughArgs = withSocketsDo $ withManager $ \manager -> do - avail <- checkPort $ develPort opts - unless avail $ error "devel port unavailable" + unlessM (checkPort $ develPort opts) $ error "devel port unavailable" iappPort <- getPort opts 17834 >>= I.newIORef when (useReverseProxy opts) $ void $ forkIO $ reverseProxy opts iappPort checkDevelFile @@ -278,8 +290,8 @@ runBuildHook Nothing = return () -} configure :: DevelOpts -> [String] -> IO Bool configure opts extraArgs = - checkExit =<< (createProcess $ proc (cabalProgram opts) - ([ "configure" + checkExit =<< createProcess (proc (cabalProgram opts) $ + [ "configure" , "-flibrary-only" , "-fdevel" , "--disable-library-profiling" @@ -287,7 +299,7 @@ configure opts extraArgs = , "--with-ghc=yesod-ghc-wrapper" , "--with-ar=yesod-ar-wrapper" , "--with-hc-pkg=ghc-pkg" - ] ++ extraArgs) + ] ++ extraArgs ) removeFileIfExists :: FilePath -> IO () @@ -302,7 +314,7 @@ mkRebuild ghcVer cabalFile opts (ldPath, arPath) | GHC.cProjectVersion /= ghcVer = failWith "Yesod has been compiled with a different GHC version, please reinstall" | forceCabal opts = return (rebuildCabal opts) - | otherwise = do + | otherwise = return $ do ns <- mapM (cabalFile `isNewerThan`) [ "yesod-devel/ghcargs.txt", "yesod-devel/arargs.txt", "yesod-devel/ldargs.txt" ] @@ -327,7 +339,7 @@ rebuildCabal opts = do | otherwise = [ "build", "-v0" ] try_ :: forall a. IO a -> IO () -try_ x = (Ex.try x :: IO (Either Ex.SomeException a)) >> return () +try_ x = void (Ex.try x :: IO (Either Ex.SomeException a)) type FileList = Map.Map FilePath EpochTime @@ -335,7 +347,7 @@ getFileList :: [FilePath] -> [FilePath] -> IO FileList getFileList hsSourceDirs extraFiles = do (files, deps) <- getDeps hsSourceDirs let files' = extraFiles ++ files ++ map fst (Map.toList deps) - fmap Map.fromList $ flip mapM files' $ \f -> do + fmap Map.fromList $ forM files' $ \f -> do efs <- Ex.try $ getFileStatus f return $ case efs of Left (_ :: Ex.SomeException) -> (f, 0) diff --git a/yesod-bin/Options.hs b/yesod-bin/Options.hs index c180f31b..62a2aa30 100644 --- a/yesod-bin/Options.hs +++ b/yesod-bin/Options.hs @@ -11,7 +11,7 @@ import Data.Char (isAlphaNum, isSpace, toLower) import Data.List (foldl') import Data.List.Split (splitOn) import qualified Data.Map as M -import Data.Maybe (catMaybes) +import Data.Maybe (mapMaybe) import Data.Monoid import Options.Applicative import Options.Applicative.Types @@ -52,10 +52,10 @@ updateA env key upd a = -- | really simple key/value file reader: x.y = z -> (["x","y"],"z") configLines :: String -> [([String], String)] -configLines = catMaybes . map (mkLine . takeWhile (/='#')) . lines +configLines = mapMaybe (mkLine . takeWhile (/='#')) . lines where trim = let f = reverse . dropWhile isSpace in f . f - mkLine l | (k, ('=':v)) <- break (=='=') l = Just (splitOn "." (trim k), trim v) + mkLine l | (k, '=':v) <- break (=='=') l = Just (splitOn "." (trim k), trim v) | otherwise = Nothing -- | inject the environment into the parser @@ -75,21 +75,22 @@ injectDefaultP env path p@(OptP o) | (Option (FlagReader names a) _) <- o = p <|> if any ((==Just "1") . getEnvValue env path) names then pure a else empty | otherwise = p + where +#if MIN_VERSION_optparse_applicative(0,6,0) + right= ReadM . Right + left = ReadM . Left + either' f g (ReadM x) = either f g x +#else + right = Right + left = Left + either' = either +#endif injectDefaultP env path (MultP p1 p2) = MultP (injectDefaultP env path p1) (injectDefaultP env path p2) injectDefaultP env path (AltP p1 p2) = AltP (injectDefaultP env path p1) (injectDefaultP env path p2) injectDefaultP _env _path b@(BindP {}) = b -#if MIN_VERSION_optparse_applicative(0,6,0) -right = ReadM . Right -left = ReadM . Left -either' f g (ReadM x) = either f g x -#else -right = Right -left = Left -either' = either -#endif getEnvValue :: M.Map [String] String -> [String] -> OptName -> Maybe String getEnvValue env path (OptLong l) = M.lookup (path ++ [normalizeName l]) env diff --git a/yesod-bin/main.hs b/yesod-bin/main.hs index f0f4e4b0..f4016523 100755 --- a/yesod-bin/main.hs +++ b/yesod-bin/main.hs @@ -15,9 +15,10 @@ import Options (injectDefaults) import qualified Paths_yesod_bin import Scaffolding.Scaffolder -import Options.Applicative.Builder.Internal (Mod, OptionFields) #if MIN_VERSION_optparse_applicative(0,6,0) import Options.Applicative.Types (ReadM (ReadM)) +#else +import Options.Applicative.Builder.Internal (Mod, OptionFields) #endif #ifndef WINDOWS From b81a9721fb1fa51a2ccbee45bba3ed69b7a4d749 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Thu, 21 Nov 2013 22:44:16 +0200 Subject: [PATCH 4/5] Disable CSS minification when combining stylesheets #623 --- yesod-static/Yesod/Static.hs | 5 ++++- yesod-static/yesod-static.cabal | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/yesod-static/Yesod/Static.hs b/yesod-static/Yesod/Static.hs index 85e95e87..ef27f1b8 100644 --- a/yesod-static/Yesod/Static.hs +++ b/yesod-static/Yesod/Static.hs @@ -101,7 +101,7 @@ import Filesystem (createTree) import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy.Encoding as TLE import Data.Default -import Text.Lucius (luciusRTMinified) +--import Text.Lucius (luciusRTMinified) import Network.Wai.Application.Static ( StaticSettings (..) @@ -478,10 +478,13 @@ data CombineSettings = CombineSettings instance Default CombineSettings where def = CombineSettings { csStaticDir = "static" + {- Disabled due to: https://github.com/yesodweb/yesod/issues/623 , csCssPostProcess = \fps -> either (error . (errorIntro fps)) (return . TLE.encodeUtf8) . flip luciusRTMinified [] . TLE.decodeUtf8 + -} + , csCssPostProcess = const return , csJsPostProcess = const return -- FIXME The following borders on a hack. With combining of files, -- the final location of the CSS is no longer fixed, so relative diff --git a/yesod-static/yesod-static.cabal b/yesod-static/yesod-static.cabal index a599b4e4..840e9085 100644 --- a/yesod-static/yesod-static.cabal +++ b/yesod-static/yesod-static.cabal @@ -1,5 +1,5 @@ name: yesod-static -version: 1.2.1 +version: 1.2.1.1 license: MIT license-file: LICENSE author: Michael Snoyman From 6b2e4ef3a426a2a866ed7eb511ba9ad242e144b3 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Mon, 2 Dec 2013 07:59:26 +0200 Subject: [PATCH 5/5] Switch to EMBED_REFRESH --- yesod-bin/Devel.hs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/yesod-bin/Devel.hs b/yesod-bin/Devel.hs index a6b888c7..4d0e8bdb 100644 --- a/yesod-bin/Devel.hs +++ b/yesod-bin/Devel.hs @@ -1,9 +1,7 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} -#ifdef EMBED_REFRESH {-# LANGUAGE TemplateHaskell #-} -#endif module Devel ( devel , DevelOpts(..) @@ -79,11 +77,7 @@ import Network.Socket (sClose) import Network.Wai (responseLBS) import Network.Wai.Handler.Warp (run) import SrcLoc (Located) -#ifdef EMBED_REFRESH import Data.FileEmbed (embedFile) -#else -import Paths_yesod_bin -#endif lockFile :: DevelOpts -> FilePath lockFile _opts = "yesod-devel/devel-terminate" @@ -128,11 +122,7 @@ cabalProgram opts | isCabalDev opts = "cabal-dev" reverseProxy :: DevelOpts -> I.IORef Int -> IO () reverseProxy opts iappPort = do manager <- newManager def -#ifdef EMBED_REFRESH let refreshHtml = LB.fromStrict $(embedFile "refreshing.html") -#else - refreshHtml <- liftIO $ getDataFileName "refreshing.html" >>= LB.readFile -#endif let onExc _ _ = return $ responseLBS status200 [ ("content-type", "text/html") , ("Refresh", "1")