cdfe9bfb489281dda8c158f40feaff855c95c2b5
[ghc.git] / hadrian / src / Oracles / PackageData.hs
1 module Oracles.PackageData (
2 PackageData (..), PackageDataList (..), pkgData, pkgDataList
3 ) where
4
5 import Hadrian.Oracles.TextFile
6
7 import Base
8
9 newtype PackageData = BuildGhciLib FilePath
10
11 data PackageDataList = AsmSrcs FilePath
12 | CcArgs FilePath
13 | CSrcs FilePath
14 | CmmSrcs FilePath
15 | CppArgs FilePath
16 | DepCcArgs FilePath
17 | DepExtraLibs FilePath
18 | DepIds FilePath
19 | DepIncludeDirs FilePath
20 | DepLdArgs FilePath
21 | DepLibDirs FilePath
22 | DepNames FilePath
23 | Deps FilePath
24 | HiddenModules FilePath
25 | HsArgs FilePath
26 | IncludeDirs FilePath
27 | LdArgs FilePath
28 | Modules FilePath
29 | SrcDirs FilePath
30
31 askPackageData :: FilePath -> String -> Action String
32 askPackageData path = lookupValueOrEmpty (path -/- "package-data.mk")
33
34 -- | For each @PackageData path@ the file 'path/package-data.mk' contains a line
35 -- of the form 'path_VERSION = 1.2.3.4'. @pkgData (PackageData path)@ is an
36 -- Action that consults the file and returns "1.2.3.4".
37 pkgData :: PackageData -> Action String
38 pkgData packageData = case packageData of
39 BuildGhciLib path -> askPackageData path "BUILD_GHCI_LIB"
40
41 -- | @PackageDataList path@ is used for multiple string options separated by
42 -- spaces, such as @path_MODULES = Data.Array Data.Array.Base ...@.
43 -- @pkgListData Modules@ therefore returns ["Data.Array", "Data.Array.Base", ...]
44 pkgDataList :: PackageDataList -> Action [String]
45 pkgDataList packageData = fmap (map unquote . words) $ case packageData of
46 AsmSrcs path -> askPackageData path "S_SRCS"
47 CcArgs path -> askPackageData path "CC_OPTS"
48 CSrcs path -> askPackageData path "C_SRCS"
49 CmmSrcs path -> askPackageData path "CMM_SRCS"
50 CppArgs path -> askPackageData path "CPP_OPTS"
51 DepCcArgs path -> askPackageData path "DEP_CC_OPTS"
52 DepExtraLibs path -> askPackageData path "DEP_EXTRA_LIBS"
53 DepIds path -> askPackageData path "DEP_IPIDS"
54 DepIncludeDirs path -> askPackageData path "DEP_INCLUDE_DIRS_SINGLE_QUOTED"
55 DepLibDirs path -> askPackageData path "DEP_LIB_DIRS_SINGLE_QUOTED"
56 DepLdArgs path -> askPackageData path "DEP_LD_OPTS"
57 DepNames path -> askPackageData path "DEP_NAMES"
58 Deps path -> askPackageData path "DEPS"
59 HiddenModules path -> askPackageData path "HIDDEN_MODULES"
60 HsArgs path -> askPackageData path "HC_OPTS"
61 IncludeDirs path -> askPackageData path "INCLUDE_DIRS"
62 LdArgs path -> askPackageData path "LD_OPTS"
63 Modules path -> askPackageData path "MODULES"
64 SrcDirs path -> askPackageData path "HS_SRC_DIRS"
65 where
66 unquote = dropWhile (== '\'') . dropWhileEnd (== '\'')