-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathProcess.hs
72 lines (60 loc) · 1.91 KB
/
Process.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Mafia.Cabal.Process
( cabal
, cabal_
, cabalAnnihilate
, cabalFrom
) where
import Control.Monad.Trans.Bifunctor (firstT)
import Control.Monad.Trans.Either (EitherT)
import Data.Map (Map)
import qualified Data.Map as Map
import qualified Data.Text as T
import Mafia.Cabal.Types
import Mafia.IO (getEnvironment)
import Mafia.P
import Mafia.Process
import System.IO (IO)
cabal :: ProcessResult a => Argument -> [Argument] -> EitherT CabalError IO a
cabal cmd args = call CabalProcessError "cabal" (cmd : args)
cabal_ :: Argument -> [Argument] -> EitherT CabalError IO ()
cabal_ cmd args = do
PassErr <- cabal cmd args
return ()
cabalAnnihilate :: Argument -> [Argument] -> EitherT CabalError IO ()
cabalAnnihilate cmd args = do
PassErrAnnihilate <- cabal cmd args
return ()
cabalFrom ::
ProcessResult a =>
Directory ->
SandboxConfigFile ->
[Directory] ->
Argument ->
[Argument] ->
EitherT CabalError IO a
cabalFrom dir sbcfg extraPath cmd args = do
env <- liftIO (mkEnv sbcfg extraPath)
let process =
Process {
processCommand = "cabal"
, processArguments = cmd : args
, processDirectory = Just dir
, processEnvironment = Just env
}
firstT CabalProcessError (callProcess process)
mkEnv :: SandboxConfigFile -> [Directory] -> IO (Map EnvKey EnvValue)
mkEnv sbcfg extraPaths =
fmap (Map.insert "CABAL_SANDBOX_CONFIG" sbcfg . prependPaths extraPaths) getEnvironment
prependPaths :: [Directory] -> Map EnvKey EnvValue -> Map EnvKey EnvValue
prependPaths new kvs =
let
key =
"PATH"
in
case Map.lookup key kvs of
Nothing ->
Map.insert key (T.intercalate ":" new) kvs
Just old ->
Map.insert key (T.intercalate ":" $ new <> T.splitOn ":" old) kvs