diff --git a/yesod-bin/Keter.hs b/yesod-bin/Keter.hs index 3cf021e1..12c1a5c9 100644 --- a/yesod-bin/Keter.hs +++ b/yesod-bin/Keter.hs @@ -6,11 +6,12 @@ module Keter import Data.Yaml import qualified Data.HashMap.Strict as Map import qualified Data.Text as T +import System.Environment (getEnvironment) import System.Exit import System.Process import Control.Monad import System.Directory hiding (findFiles) -import Data.Maybe (mapMaybe) +import Data.Maybe (mapMaybe,isJust,maybeToList) import Data.Monoid import System.FilePath (()) import qualified Codec.Archive.Tar as Tar @@ -48,6 +49,8 @@ keter cabal noBuild noCopyTo buildArgs = do _ -> return value Just _ -> error $ ketercfg ++ " is not an object" + env' <- getEnvironment + cwd' <- getCurrentDirectory files <- getDirectoryContents "." project <- case mapMaybe (T.stripSuffix ".cabal" . T.pack) files of @@ -74,11 +77,22 @@ keter cabal noBuild noCopyTo buildArgs = do collapse' (x:xs) = x : collapse' xs collapse' [] = [] - unless noBuild $ if elem "stack.yaml" files - then do run "stack" ["clean"] - createDirectoryIfMissing True "./dist/bin" + stackQueryRunSuccess <- do + (ec,_,_) <- readProcessWithExitCode "stack" ["query"] "" + return (ec == ExitSuccess) + + let inStackExec = isJust $ lookup "STACK_EXE" env' + mStackYaml = lookup "STACK_YAML" env' + useStack = inStackExec || isJust mStackYaml || stackQueryRunSuccess + + unless noBuild $ if useStack + then do let stackYaml = maybeToList $ fmap ("--stack-yaml="<>) mStackYaml + localBinPath = cwd' "dist/bin" + run "stack" $ stackYaml <> ["clean"] + createDirectoryIfMissing True localBinPath run "stack" - ((words "--local-bin-path ./dist/bin build --copy-bins") + (stackYaml + <> ["--local-bin-path",localBinPath,"build","--copy-bins"] <> buildArgs) else do run cabal ["clean"] run cabal ["configure"]