PackageData.hs 3.36 KB
Newer Older
1
module Oracles.PackageData (
2
    PackageData (..), PackageDataList (..), pkgData, pkgDataList
3
4
    ) where

5
import Hadrian.Oracles.KeyValue
Andrey Mokhov's avatar
Andrey Mokhov committed
6
7

import Base
Andrey Mokhov's avatar
Andrey Mokhov committed
8

9
data PackageData = BuildGhciLib FilePath
10
                 | ComponentId  FilePath
11
                 | Synopsis     FilePath
12
                 | Version      FilePath
13

14
15
data PackageDataList = AsmSrcs        FilePath
                     | CcArgs         FilePath
Andrey Mokhov's avatar
Andrey Mokhov committed
16
                     | CSrcs          FilePath
17
                     | CmmSrcs        FilePath
Andrey Mokhov's avatar
Andrey Mokhov committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
                     | CppArgs        FilePath
                     | DepCcArgs      FilePath
                     | DepExtraLibs   FilePath
                     | DepIds         FilePath
                     | DepIncludeDirs FilePath
                     | DepLdArgs      FilePath
                     | DepLibDirs     FilePath
                     | DepNames       FilePath
                     | Deps           FilePath
                     | HiddenModules  FilePath
                     | HsArgs         FilePath
                     | IncludeDirs    FilePath
                     | LdArgs         FilePath
                     | Modules        FilePath
                     | SrcDirs        FilePath
33

34
askPackageData :: FilePath -> String -> Action String
35
askPackageData path = lookupValueOrEmpty (path -/- "package-data.mk")
36

Andrey Mokhov's avatar
Andrey Mokhov committed
37
38
39
-- | For each @PackageData path@ the file 'path/package-data.mk' contains a line
-- of the form 'path_VERSION = 1.2.3.4'. @pkgData (PackageData path)@ is an
-- Action that consults the file and returns "1.2.3.4".
40
pkgData :: PackageData -> Action String
41
pkgData packageData = case packageData of
42
    BuildGhciLib path -> askPackageData path "BUILD_GHCI_LIB"
43
    ComponentId  path -> askPackageData path "COMPONENT_ID"
44
    Synopsis     path -> askPackageData path "SYNOPSIS"
45
    Version      path -> askPackageData path "VERSION"
46

Andrey Mokhov's avatar
Andrey Mokhov committed
47
48
49
-- | @PackageDataList path@ is used for multiple string options separated by
-- spaces, such as @path_MODULES = Data.Array Data.Array.Base ...@.
-- @pkgListData Modules@ therefore returns ["Data.Array", "Data.Array.Base", ...]
50
pkgDataList :: PackageDataList -> Action [String]
51
pkgDataList packageData = fmap (map unquote . words) $ case packageData of
52
    AsmSrcs        path -> askPackageData path "S_SRCS"
Andrey Mokhov's avatar
Andrey Mokhov committed
53
54
    CcArgs         path -> askPackageData path "CC_OPTS"
    CSrcs          path -> askPackageData path "C_SRCS"
55
    CmmSrcs        path -> askPackageData path "CMM_SRCS"
Andrey Mokhov's avatar
Andrey Mokhov committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    CppArgs        path -> askPackageData path "CPP_OPTS"
    DepCcArgs      path -> askPackageData path "DEP_CC_OPTS"
    DepExtraLibs   path -> askPackageData path "DEP_EXTRA_LIBS"
    DepIds         path -> askPackageData path "DEP_IPIDS"
    DepIncludeDirs path -> askPackageData path "DEP_INCLUDE_DIRS_SINGLE_QUOTED"
    DepLibDirs     path -> askPackageData path "DEP_LIB_DIRS_SINGLE_QUOTED"
    DepLdArgs      path -> askPackageData path "DEP_LD_OPTS"
    DepNames       path -> askPackageData path "DEP_NAMES"
    Deps           path -> askPackageData path "DEPS"
    HiddenModules  path -> askPackageData path "HIDDEN_MODULES"
    HsArgs         path -> askPackageData path "HC_OPTS"
    IncludeDirs    path -> askPackageData path "INCLUDE_DIRS"
    LdArgs         path -> askPackageData path "LD_OPTS"
    Modules        path -> askPackageData path "MODULES"
    SrcDirs        path -> askPackageData path "HS_SRC_DIRS"
71
72
  where
    unquote = dropWhile (== '\'') . dropWhileEnd (== '\'')