[yesod-bin] improve stack detection for 'stack keter'
The following will now use stack: * `stack query` succeeds from current directory instead of searching that a `stack.yaml` exists * `STACK_YAML` or `STACK_EXE`(set by `stack exec`) environment variables are set
This commit is contained in:
parent
d8414c3c20
commit
d87499deb5
@ -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"]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user