Refactor paths using Context.
[hadrian.git] / src / Settings.hs
1 module Settings (
2 module Settings.Packages,
3 module Settings.Paths,
4 module Settings.User,
5 module Settings.Ways,
6 getPkgData, getPkgDataList, getTopDirectory, isLibrary,
7 getPackagePath, getContextDirectory, getContextPath, getPackageSources
8 ) where
9
10 import Base
11 import Expression
12 import Oracles.ModuleFiles
13 import Oracles.PackageData
14 import Oracles.WindowsPath
15 import Settings.Packages
16 import Settings.Paths
17 import Settings.User
18 import Settings.Ways
19
20 getPackagePath :: Expr FilePath
21 getPackagePath = pkgPath <$> getPackage
22
23 getContextDirectory :: Expr FilePath
24 getContextDirectory = contextDirectory <$> getContext
25
26 getContextPath :: Expr FilePath
27 getContextPath = contextPath <$> getContext
28
29 getPkgData :: (FilePath -> PackageData) -> Expr String
30 getPkgData key = lift . pkgData . key =<< getContextPath
31
32 getPkgDataList :: (FilePath -> PackageDataList) -> Expr [String]
33 getPkgDataList key = lift . pkgDataList . key =<< getContextPath
34
35 getTopDirectory :: Expr FilePath
36 getTopDirectory = lift topDirectory
37
38 -- | Find all Haskell source files for the current target
39 getPackageSources :: Expr [FilePath]
40 getPackageSources = do
41 context <- getContext
42 let buildPath = contextPath context -/- "build"
43 autogen = buildPath -/- "autogen"
44 (found, missingMods) <- lift $ haskellModuleFiles context
45 -- Generated source files live in buildPath and have extension "hs"...
46 let generated = [ buildPath -/- (replaceEq '.' '/' m) <.> "hs" | m <- missingMods ]
47 -- ...except that GHC/Prim.hs lives in autogen. TODO: fix the inconsistency?
48 fixGhcPrim = replaceEq (buildPath -/- "GHC/Prim.hs") (autogen -/- "GHC/Prim.hs")
49 return $ found ++ fixGhcPrim generated