Commit 268155a0 authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Minor revision

parent 8586ab84
......@@ -11,7 +11,6 @@
-----------------------------------------------------------------------------
module Hadrian.Haskell.Cabal (pkgNameVersion, pkgDependencies) where
import Data.List
import Development.Shake
import Hadrian.Haskell.Cabal.Parse
......@@ -32,4 +31,4 @@ pkgNameVersion pkg = do
pkgDependencies :: Package -> Action [PackageName]
pkgDependencies pkg = do
cabal <- readCabalFile (pkgCabalFile pkg)
return (dependencies cabal \\ [pkgName pkg])
return (dependencies cabal)
......@@ -44,14 +44,14 @@ parseCabal :: FilePath -> IO Cabal
parseCabal file = do
gpd <- liftIO $ C.readGenericPackageDescription C.silent file
let pkgId = C.package (C.packageDescription gpd)
name = C.unPackageName (C.pkgName pkgId)
version = C.display (C.pkgVersion pkgId)
libDeps = collectDeps (C.condLibrary gpd)
exeDeps = map (collectDeps . Just . snd) (C.condExecutables gpd)
allDeps = concat (libDeps : exeDeps)
sorted = sort [ C.unPackageName p | C.Dependency p _ <- allDeps ]
return $ Cabal
(C.unPackageName $ C.pkgName pkgId)
(C.display $ C.pkgVersion pkgId)
(nubOrd sorted)
deps = nubOrd sorted \\ [name]
return $ Cabal name version deps
collectDeps :: Maybe (C.CondTree v [C.Dependency] a) -> [C.Dependency]
collectDeps Nothing = []
......
......@@ -52,11 +52,11 @@ pathOracle = do
void $ addOracle $ \(WindowsPath path) -> do
Stdout out <- quietly $ cmd ["cygpath", "-m", path]
let windowsPath = unifyPath $ dropWhileEnd isSpace out
putLoud $ "Windows path mapping: " ++ path ++ " => " ++ windowsPath
putLoud $ "| Windows path mapping: " ++ path ++ " => " ++ windowsPath
return windowsPath
void $ addOracle $ \(LookupInPath name) -> do
let unpack = fromMaybe . error $ "Cannot find executable " ++ quote name
path <- unifyPath <$> unpack <$> liftIO (findExecutable name)
putLoud $ "Executable found: " ++ name ++ " => " ++ path
putLoud $ "| Executable found: " ++ name ++ " => " ++ path
return path
......@@ -23,8 +23,8 @@ import Development.Shake
import Development.Shake.Classes
import Development.Shake.Config
import Hadrian.Utilities
import Hadrian.Haskell.Cabal.Parse
import Hadrian.Utilities
newtype TextFile = TextFile FilePath
deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
......@@ -32,7 +32,7 @@ type instance RuleResult TextFile = String
newtype CabalFile = CabalFile FilePath
deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
type instance RuleResult CabalFile = String
type instance RuleResult CabalFile = Cabal
newtype KeyValue = KeyValue (FilePath, String)
deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
......@@ -99,22 +99,25 @@ textFileOracle :: Rules ()
textFileOracle = do
text <- newCache $ \file -> do
need [file]
putLoud $ "Reading " ++ file ++ "..."
putLoud $ "| TextFile oracle: reading " ++ quote file ++ "..."
liftIO $ readFile file
void $ addOracle $ \(TextFile file) -> text file
kv <- newCache $ \file -> do
need [file]
putLoud $ "Reading " ++ file ++ "..."
putLoud $ "| KeyValue oracle: reading " ++ quote file ++ "..."
liftIO $ readConfigFile file
void $ addOracle $ \(KeyValue (file, key)) -> Map.lookup key <$> kv file
kvs <- newCache $ \file -> do
need [file]
putLoud $ "Reading " ++ file ++ "..."
putLoud $ "| KeyValues oracle: reading " ++ quote file ++ "..."
contents <- map words <$> readFileLines file
return $ Map.fromList [ (key, values) | (key:values) <- contents ]
void $ addOracle $ \(KeyValues (file, key)) -> Map.lookup key <$> kvs file
cabal <- newCache $ \file -> do
need [file]
putLoud $ "Reading " ++ file ++ "..."
putLoud $ "| CabalFile oracle: reading " ++ quote file ++ "..."
liftIO $ parseCabal file
void $ addOracle $ \(TextFile file ) -> text file
void $ addOracle $ \(KeyValue (file, key)) -> Map.lookup key <$> kv file
void $ addOracle $ \(KeyValues (file, key)) -> Map.lookup key <$> kvs file
void $ addOracle $ \(CabalFile file ) -> cabal file
void $ addOracle $ \(CabalFile file) -> cabal file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment