yesod devel support for stack

This commit is contained in:
Michael Snoyman 2015-06-29 08:14:04 +03:00
parent bd7659017f
commit a7cccf2a7c
4 changed files with 34 additions and 5 deletions

View File

@ -1,3 +1,8 @@
## 1.4.11
* Add support to `yesod devel` to detect and use `GHC_PACKAGE_PATH`. This makes
`yesod devel` compatible with `stack`, just run: `stack exec -- yesod devel`.
## 1.4.10 ## 1.4.10
* Scaffolding update * Scaffolding update

View File

@ -115,6 +115,10 @@ data DevelOpts = DevelOpts
, proxyTimeout :: Int , proxyTimeout :: Int
, useReverseProxy :: Bool , useReverseProxy :: Bool
, terminateWith :: DevelTermOpt , terminateWith :: DevelTermOpt
-- Support for GHC_PACKAGE_PATH wrapping
, develConfigOpts :: [String]
, develEnv :: Maybe [(String, String)]
} deriving (Show, Eq) } deriving (Show, Eq)
getBuildDir :: DevelOpts -> String getBuildDir :: DevelOpts -> String
@ -353,8 +357,8 @@ configure opts extraArgs =
, "--with-ghc=yesod-ghc-wrapper" , "--with-ghc=yesod-ghc-wrapper"
, "--with-ar=yesod-ar-wrapper" , "--with-ar=yesod-ar-wrapper"
, "--with-hc-pkg=ghc-pkg" , "--with-hc-pkg=ghc-pkg"
] ++ extraArgs ] ++ develConfigOpts opts ++ extraArgs
) ) { env = develEnv opts }
removeFileIfExists :: FilePath -> IO () removeFileIfExists :: FilePath -> IO ()
removeFileIfExists file = removeFile file `Ex.catch` handler removeFileIfExists file = removeFile file `Ex.catch` handler
@ -388,6 +392,8 @@ rebuildCabal :: DevelOpts -> IO Bool
rebuildCabal opts = do rebuildCabal opts = do
putStrLn $ "Rebuilding application... (using " ++ cabalProgram opts ++ ")" putStrLn $ "Rebuilding application... (using " ++ cabalProgram opts ++ ")"
checkExit =<< createProcess (proc (cabalProgram opts) args) checkExit =<< createProcess (proc (cabalProgram opts) args)
{ env = develEnv opts
}
where where
args | verbose opts = [ "build" ] args | verbose opts = [ "build" ]
| otherwise = [ "build", "-v0" ] | otherwise = [ "build", "-v0" ]

View File

@ -5,7 +5,9 @@ import Control.Monad (unless)
import Data.Monoid import Data.Monoid
import Data.Version (showVersion) import Data.Version (showVersion)
import Options.Applicative import Options.Applicative
import System.Environment (getEnvironment)
import System.Exit (ExitCode (ExitSuccess), exitWith) import System.Exit (ExitCode (ExitSuccess), exitWith)
import System.FilePath (splitSearchPath)
import System.Process (rawSystem) import System.Process (rawSystem)
import AddHandler (addHandler) import AddHandler (addHandler)
@ -108,7 +110,9 @@ main = do
Version -> putStrLn ("yesod-bin version: " ++ showVersion Paths_yesod_bin.version) Version -> putStrLn ("yesod-bin version: " ++ showVersion Paths_yesod_bin.version)
AddHandler{..} -> addHandler addHandlerRoute addHandlerPattern addHandlerMethods AddHandler{..} -> addHandler addHandlerRoute addHandlerPattern addHandlerMethods
Test -> cabalTest cabal Test -> cabalTest cabal
Devel{..} -> let develOpts = DevelOpts Devel{..} ->do
(configOpts, menv) <- handleGhcPackagePath
let develOpts = DevelOpts
{ isCabalDev = optCabalPgm o == CabalDev { isCabalDev = optCabalPgm o == CabalDev
, forceCabal = _develDisableApi , forceCabal = _develDisableApi
, verbose = optVerbose o , verbose = optVerbose o
@ -121,14 +125,28 @@ main = do
, proxyTimeout = _proxyTimeout , proxyTimeout = _proxyTimeout
, useReverseProxy = not _noReverseProxy , useReverseProxy = not _noReverseProxy
, terminateWith = if _interruptOnly then TerminateOnlyInterrupt else TerminateOnEnter , terminateWith = if _interruptOnly then TerminateOnlyInterrupt else TerminateOnEnter
, develConfigOpts = configOpts
, develEnv = menv
} }
in devel develOpts develExtraArgs devel develOpts develExtraArgs
where where
cabalTest cabal = do touch' cabalTest cabal = do touch'
_ <- cabal ["configure", "--enable-tests", "-flibrary-only"] _ <- cabal ["configure", "--enable-tests", "-flibrary-only"]
_ <- cabal ["build"] _ <- cabal ["build"]
cabal ["test"] cabal ["test"]
handleGhcPackagePath :: IO ([String], Maybe [(String, String)])
handleGhcPackagePath = do
env <- getEnvironment
case lookup "GHC_PACKAGE_PATH" env of
Nothing -> return ([], Nothing)
Just gpp -> do
let opts = "--package-db=clear"
: "--package-db=global"
: map ("--package-db=" ++)
(drop 1 $ reverse $ splitSearchPath gpp)
return (opts, Just $ filter (\(x, _) -> x /= "GHC_PACKAGE_PATH") env)
optParser' :: ParserInfo Options optParser' :: ParserInfo Options
optParser' = info (helper <*> optParser) ( fullDesc <> header "Yesod Web Framework command line utility" ) optParser' = info (helper <*> optParser) ( fullDesc <> header "Yesod Web Framework command line utility" )

View File

@ -1,5 +1,5 @@
name: yesod-bin name: yesod-bin
version: 1.4.10 version: 1.4.11
license: MIT license: MIT
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com> author: Michael Snoyman <michael@snoyman.com>