Skip to content

Commit

Permalink
rename CMD -> Cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
rvion committed Nov 25, 2015
1 parent 4923a3f commit 3d49b6c
Show file tree
Hide file tree
Showing 13 changed files with 964 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ getSetupExe setupHs tmpdir = do
, toFilePath tmpOutputPath
] ++
["-build-runner" | wc == Ghcjs]
runCmd' (\cp -> cp { std_out = UseHandle stderr }) (CMD (Just tmpdir) (compilerExeName wc) menv args) Nothing
runCmd' (\cp -> cp { std_out = UseHandle stderr }) (Cmd (Just tmpdir) (compilerExeName wc) menv args) Nothing
when (wc == Ghcjs) $ renameDir tmpJsExePath jsExePath
renameFile tmpExePath exePath
return $ Just exePath
Expand Down Expand Up @@ -413,7 +413,7 @@ executePlan menv bopts baseConfigOpts locals globalPackages snapshotPackages loc
}
forM_ (boptsExec bopts) $ \(cmd, args) -> do
$logProcessRun cmd args
callProcess (CMD Nothing cmd menv' args)
callProcess (Cmd Nothing cmd menv' args)

-- | Windows can't write over the current executable. Instead, we rename the
-- current executable to something else and then do the copy.
Expand Down
6 changes: 3 additions & 3 deletions src/Stack/Docker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ runContainerAndExit getCmdArgs
oldHandler <- liftIO $ installHandler sig (Catch sigHandler) Nothing
return (sig, oldHandler)
#endif
let cmd = CMD Nothing
let cmd = Cmd Nothing
"docker"
envOverride
(concat [["start"]
Expand Down Expand Up @@ -648,7 +648,7 @@ pullImage envOverride docker image =
do $logInfo (concatT ["Pulling image from registry: '",image,"'"])
when (dockerRegistryLogin docker)
(do $logInfo "You may need to log in."
callProcess $ CMD
callProcess $ Cmd
Nothing
"docker"
envOverride
Expand All @@ -657,7 +657,7 @@ pullImage envOverride docker image =
,maybe [] (\n -> ["--username=" ++ n]) (dockerRegistryUsername docker)
,maybe [] (\p -> ["--password=" ++ p]) (dockerRegistryPassword docker)
,[takeWhile (/= '/') image]]))
e <- try (callProcess (CMD Nothing "docker" envOverride ["pull",image]))
e <- try (callProcess (Cmd Nothing "docker" envOverride ["pull",image]))
case e of
Left (ProcessExitedUnsuccessfully _ _) -> throwM (PullFailedException image)
Right () -> return ()
Expand Down
4 changes: 2 additions & 2 deletions src/Stack/Ide.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ ide targets useropts = do
Platform _ os <- asks getPlatform
when
(os == OSX)
(catch (callProcess (CMD (Just pwd) "stty" menv ["cbreak", "-imaxbel"]))
(catch (callProcess (Cmd (Just pwd) "stty" menv ["cbreak", "-imaxbel"]))
(\(_ :: ProcessExitedUnsuccessfully) -> return ()))
callProcess (CMD (Just pwd) "stack-ide" menv args)
callProcess (Cmd (Just pwd) "stack-ide" menv args)
where
includeDirs pkgopts =
intercalate
Expand Down
4 changes: 2 additions & 2 deletions src/Stack/Image.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ createDockerImage dir = do
(imageName (parent (parent dir)))
(imgDockerImageName =<< dockerConfig)
, toFilePathNoTrailingSep dir]
callProcess $ CMD Nothing "docker" menv args
callProcess $ Cmd Nothing "docker" menv args


-- | Extend the general purpose docker image with entrypoints (if
Expand Down Expand Up @@ -149,7 +149,7 @@ extendDockerImageWithEntrypoint dir = do
, "ENTRYPOINT [\"/usr/local/bin/" ++
ep ++ "\"]"
, "CMD []"]))
callProcess $ CMD
callProcess $ Cmd
Nothing
"docker"
menv
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/New.hs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ runTemplateInits dir = do
case configScmInit config of
Nothing -> return ()
Just Git ->
catch (callProcess $ CMD (Just dir) "git" menv ["init"])
catch (callProcess $ Cmd (Just dir) "git" menv ["init"])
(\(_ :: ProcessExitedUnsuccessfully) ->
$logInfo "git init failed to run, ignoring ...")

Expand Down
12 changes: 6 additions & 6 deletions src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ upgradeCabal menv wc = do
Nothing -> error "upgradeCabal: Invariant violated, dir missing"
Just dir -> return dir

runCmd (CMD (Just dir) (compilerExeName wc) menv ["Setup.hs"]) Nothing
runCmd (Cmd (Just dir) (compilerExeName wc) menv ["Setup.hs"]) Nothing
platform <- asks getPlatform
let setupExe = toFilePath $ dir </>
(case platform of
Expand All @@ -525,9 +525,9 @@ upgradeCabal menv wc = do
, installRoot FP.</> name'
]
args = ( "configure": map dirArgument (words "lib bin data doc") )
runCmd (CMD (Just dir) setupExe menv args) Nothing
runCmd (CMD (Just dir) setupExe menv ["build"]) Nothing
runCmd (CMD (Just dir) setupExe menv ["install"]) Nothing
runCmd (Cmd (Just dir) setupExe menv args) Nothing
runCmd (Cmd (Just dir) setupExe menv ["build"]) Nothing
runCmd (Cmd (Just dir) setupExe menv ["install"]) Nothing
$logInfo "New Cabal library installed"

-- | Get the version of the system compiler, if available
Expand Down Expand Up @@ -1074,14 +1074,14 @@ installMsys2Windows osKey si archiveFile archiveType destDir = do
-- I couldn't find this officially documented anywhere, but you need to run
-- the shell once in order to initialize some pacman stuff. Once that run
-- happens, you can just run commands as usual.
runCmd (CMD (Just destDir) "sh" menv ["--login", "-c", "true"]) Nothing
runCmd (Cmd (Just destDir) "sh" menv ["--login", "-c", "true"]) Nothing

-- No longer installing git, it's unreliable
-- (https://github.com/commercialhaskell/stack/issues/1046) and the
-- MSYS2-installed version has bad CRLF defaults.
--
-- Install git. We could install other useful things in the future too.
-- runCmd (CMD (Just destDir) "pacman" menv ["-Sy", "--noconfirm", "git"]) Nothing
-- runCmd (Cmd (Just destDir) "pacman" menv ["-Sy", "--noconfirm", "git"]) Nothing

-- | Unpack a compressed tarball using 7zip. Expects a single directory in
-- the unpacked results, which is renamed to the destination directory.
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ import Stack.Types.Image as X
import Stack.Types.Build as X
import Stack.Types.Package as X
import Stack.Types.Compiler as X
import Stack.Types.CMD as X
import Stack.Types.Cmd as X
8 changes: 4 additions & 4 deletions src/Stack/Types/CMD.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module Stack.Types.CMD
( CMD(..)
module Stack.Types.Cmd
( Cmd(..)
) where

import System.Process.Read (EnvOverride)
import Path (Path, Abs, Dir)
import Data.Text (Text)
import GHC.IO.Handle (Handle)

-- | CMD holds common infos needed to running a process in most cases
data CMD = CMD
-- | Cmd holds common infos needed to running a process in most cases
data Cmd = Cmd
{ cmdDirectoryToRunIn :: Maybe (Path Abs Dir) -- ^ directory to run in
, cmdCommandToRun :: FilePath -- ^ command to run
, cmdEnvOverride::EnvOverride
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Upgrade.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ upgrade gitRepo mresolver = withCanonicalizedSystemTempDirectory "stack-upgrade"
else do
$logInfo "Cloning stack"
let args = [ "clone", repo , "stack", "--depth", "1"]
runCmd (CMD (Just tmp) "git" menv args) Nothing
runCmd (Cmd (Just tmp) "git" menv args) Nothing
return $ Just $ tmp </> $(mkRelDir "stack")
Nothing -> do
updateAllIndices menv
Expand Down
16 changes: 7 additions & 9 deletions src/System/Process/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ import Prelude -- Fix AMP warning
import System.Exit (exitWith, ExitCode (..))
import qualified System.Process
import System.Process.Read
import Stack.Types (CMD(..))
import Stack.Types (Cmd(..))

-- | Run the given command in the given directory, inheriting stdout and stderr.
--
-- If it exits with anything but success, prints an error
-- and then calls 'exitWith' to exit the program.
runCmd :: forall (m :: * -> *).
(MonadLogger m,MonadIO m,MonadBaseControl IO m)
=> CMD
=> Cmd
-> Maybe Text -- ^ optional additional error message
-> m ()
runCmd = runCmd' id

runCmd' :: forall (m :: * -> *).
(MonadLogger m,MonadIO m,MonadBaseControl IO m)
=> (CreateProcess -> CreateProcess)
-> CMD
-> Cmd
-> Maybe Text -- ^ optional additional error message
-> m ()
runCmd' modCP cmd@(CMD{..}) mbErrMsg = do
runCmd' modCP cmd@(Cmd{..}) mbErrMsg = do
result <- try (callProcess' modCP cmd)
case result of
Left (ProcessExitedUnsuccessfully _ ec) -> do
Expand All @@ -72,7 +72,7 @@ runCmd' modCP cmd@(CMD{..}) mbErrMsg = do
-- process exits unsuccessfully.
--
-- Inherits stdout and stderr.
callProcess :: (MonadIO m, MonadLogger m) => CMD -> m ()
callProcess :: (MonadIO m, MonadLogger m) => Cmd -> m ()
callProcess = callProcess' id

-- | Like 'System.Process.callProcess', but takes an optional working directory and
Expand All @@ -81,10 +81,8 @@ callProcess = callProcess' id
--
-- Inherits stdout and stderr.
callProcess' :: (MonadIO m, MonadLogger m)
=> (CreateProcess -> CreateProcess)
-> CMD
-> m ()
callProcess' modCP (CMD wd cmd0 menv args) = do
=> (CreateProcess -> CreateProcess) -> Cmd -> m ()
callProcess' modCP (Cmd wd cmd0 menv args) = do
cmd <- preProcess wd menv cmd0
let c = modCP $ (proc cmd args) { delegate_ctlc = True
, cwd = fmap toFilePath wd
Expand Down
2 changes: 1 addition & 1 deletion stack.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ library
Stack.Types
Stack.Types.Internal
Stack.Types.BuildPlan
Stack.Types.CMD
Stack.Types.Cmd
Stack.Types.Compiler
Stack.Types.Config
Stack.Types.Docker
Expand Down
Loading

0 comments on commit 3d49b6c

Please sign in to comment.