WindowsRoot.hs 838 Bytes
Newer Older
1
{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
Andrey Mokhov's avatar
Andrey Mokhov committed
2
module Oracles.WindowsRoot (windowsRoot, windowsRootOracle) where
3

Ben Gamari's avatar
Ben Gamari committed
4
import Data.Char (isSpace)
5
import Base
6
7
8
9
10
11
12
13
14
15
16
17

newtype WindowsRoot = WindowsRoot ()
    deriving (Show, Typeable, Eq, Hashable, Binary, NFData)

-- Looks up cygwin/msys root on Windows
windowsRoot :: Action String
windowsRoot = askOracle $ WindowsRoot ()

-- Oracle for windowsRoot. This operation requires caching as looking up
-- the root is slow (at least the current implementation).
windowsRootOracle :: Rules ()
windowsRootOracle = do
Andrey Mokhov's avatar
Andrey Mokhov committed
18
    root <- newCache $ \_ -> do
19
20
21
22
        Stdout out <- quietly $ cmd ["cygpath", "-m", "/"]
        let root = dropWhileEnd isSpace out
        putOracle $ "Detected root on Windows: " ++ root
        return root
Andrey Mokhov's avatar
Andrey Mokhov committed
23
    _ <- addOracle $ \WindowsRoot{} -> root ()
24
    return ()