From a7cccf2a7c5df8b26da9ea4fdcb6bac5ab3a3b75 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Mon, 29 Jun 2015 08:14:04 +0300 Subject: [PATCH] yesod devel support for stack --- yesod-bin/ChangeLog.md | 5 +++++ yesod-bin/Devel.hs | 10 ++++++++-- yesod-bin/main.hs | 22 ++++++++++++++++++++-- yesod-bin/yesod-bin.cabal | 2 +- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/yesod-bin/ChangeLog.md b/yesod-bin/ChangeLog.md index ec00369c..79f44ca5 100644 --- a/yesod-bin/ChangeLog.md +++ b/yesod-bin/ChangeLog.md @@ -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 * Scaffolding update diff --git a/yesod-bin/Devel.hs b/yesod-bin/Devel.hs index 717d9fe2..d58acfe1 100644 --- a/yesod-bin/Devel.hs +++ b/yesod-bin/Devel.hs @@ -115,6 +115,10 @@ data DevelOpts = DevelOpts , proxyTimeout :: Int , useReverseProxy :: Bool , terminateWith :: DevelTermOpt + + -- Support for GHC_PACKAGE_PATH wrapping + , develConfigOpts :: [String] + , develEnv :: Maybe [(String, String)] } deriving (Show, Eq) getBuildDir :: DevelOpts -> String @@ -353,8 +357,8 @@ configure opts extraArgs = , "--with-ghc=yesod-ghc-wrapper" , "--with-ar=yesod-ar-wrapper" , "--with-hc-pkg=ghc-pkg" - ] ++ extraArgs - ) + ] ++ develConfigOpts opts ++ extraArgs + ) { env = develEnv opts } removeFileIfExists :: FilePath -> IO () removeFileIfExists file = removeFile file `Ex.catch` handler @@ -388,6 +392,8 @@ rebuildCabal :: DevelOpts -> IO Bool rebuildCabal opts = do putStrLn $ "Rebuilding application... (using " ++ cabalProgram opts ++ ")" checkExit =<< createProcess (proc (cabalProgram opts) args) + { env = develEnv opts + } where args | verbose opts = [ "build" ] | otherwise = [ "build", "-v0" ] diff --git a/yesod-bin/main.hs b/yesod-bin/main.hs index b8169131..ae4bc012 100755 --- a/yesod-bin/main.hs +++ b/yesod-bin/main.hs @@ -5,7 +5,9 @@ import Control.Monad (unless) import Data.Monoid import Data.Version (showVersion) import Options.Applicative +import System.Environment (getEnvironment) import System.Exit (ExitCode (ExitSuccess), exitWith) +import System.FilePath (splitSearchPath) import System.Process (rawSystem) import AddHandler (addHandler) @@ -108,7 +110,9 @@ main = do Version -> putStrLn ("yesod-bin version: " ++ showVersion Paths_yesod_bin.version) AddHandler{..} -> addHandler addHandlerRoute addHandlerPattern addHandlerMethods Test -> cabalTest cabal - Devel{..} -> let develOpts = DevelOpts + Devel{..} ->do + (configOpts, menv) <- handleGhcPackagePath + let develOpts = DevelOpts { isCabalDev = optCabalPgm o == CabalDev , forceCabal = _develDisableApi , verbose = optVerbose o @@ -121,14 +125,28 @@ main = do , proxyTimeout = _proxyTimeout , useReverseProxy = not _noReverseProxy , terminateWith = if _interruptOnly then TerminateOnlyInterrupt else TerminateOnEnter + , develConfigOpts = configOpts + , develEnv = menv } - in devel develOpts develExtraArgs + devel develOpts develExtraArgs where cabalTest cabal = do touch' _ <- cabal ["configure", "--enable-tests", "-flibrary-only"] _ <- cabal ["build"] 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' = info (helper <*> optParser) ( fullDesc <> header "Yesod Web Framework command line utility" ) diff --git a/yesod-bin/yesod-bin.cabal b/yesod-bin/yesod-bin.cabal index efe7c219..a457ed7b 100644 --- a/yesod-bin/yesod-bin.cabal +++ b/yesod-bin/yesod-bin.cabal @@ -1,5 +1,5 @@ name: yesod-bin -version: 1.4.10 +version: 1.4.11 license: MIT license-file: LICENSE author: Michael Snoyman