forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckInstall.hs
More file actions
53 lines (50 loc) · 2.45 KB
/
CheckInstall.hs
File metadata and controls
53 lines (50 loc) · 2.45 KB
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
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
module Path.CheckInstall where
import Control.Monad.Extra (anyM, (&&^))
import qualified Data.Text as T
import Stack.Prelude
import RIO.PrettyPrint
import Stack.Types.Config
import qualified System.Directory as D
import qualified System.FilePath as FP
-- | Checks if the installed executable will be available on the user's
-- PATH. This doesn't use @envSearchPath menv@ because it includes paths
-- only visible when running in the stack environment.
warnInstallSearchPathIssues :: HasConfig env => FilePath -> [Text] -> RIO env ()
warnInstallSearchPathIssues destDir installed = do
searchPath <- liftIO FP.getSearchPath
destDirIsInPATH <- liftIO $
anyM (\dir -> D.doesDirectoryExist dir &&^ fmap (FP.equalFilePath destDir) (D.canonicalizePath dir)) searchPath
if destDirIsInPATH
then forM_ installed $ \exe -> do
mexePath <- (liftIO . D.findExecutable . T.unpack) exe
case mexePath of
Just exePath -> do
exeDir <- (liftIO . fmap FP.takeDirectory . D.canonicalizePath) exePath
unless (exeDir `FP.equalFilePath` destDir) $ do
prettyWarnL
[ flow "The"
, style File . fromString . T.unpack $ exe
, flow "executable found on the PATH environment variable is"
, style File . fromString $ exePath
, flow "and not the version that was just installed."
, flow "This means that"
, style File . fromString . T.unpack $ exe
, "calls on the command line will not use this version."
]
Nothing -> do
prettyWarnL
[ flow "Installation path"
, style Dir . fromString $ destDir
, flow "is on the PATH but the"
, style File . fromString . T.unpack $ exe
, flow "executable that was just installed could not be found on the PATH."
]
else do
prettyWarnL
[ flow "Installation path "
, style Dir . fromString $ destDir
, "not found on the PATH environment variable."
]