PackageData.hs 1.97 KB
Newer Older
1
{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
2
3

module Oracles.PackageData (
Andrey Mokhov's avatar
Andrey Mokhov committed
4
    PackageDataKey (..),
5
    PackageData (..)
6
7
8
9
10
11
    ) where

import Development.Shake.Classes
import Base
import Util

Andrey Mokhov's avatar
Andrey Mokhov committed
12
newtype PackageDataKey = PackageDataKey (FilePath, String)
13
14
                        deriving (Show, Typeable, Eq, Hashable, Binary, NFData)

15
16
data PackageData = Version     FilePath
                 | Modules     FilePath
Andrey Mokhov's avatar
Andrey Mokhov committed
17
18
19
20
21
                 | SrcDirs     FilePath
                 | PackageKey  FilePath
                 | IncludeDirs FilePath
                 | Deps        FilePath
                 | DepKeys     FilePath
22
                 | DepNames    FilePath
Andrey Mokhov's avatar
Andrey Mokhov committed
23
                 | Synopsis    FilePath
Andrey Mokhov's avatar
Andrey Mokhov committed
24
                 | CppOpts     FilePath
Andrey Mokhov's avatar
Andrey Mokhov committed
25
                 | HsOpts      FilePath
26

Andrey Mokhov's avatar
Andrey Mokhov committed
27
instance ShowArgs PackageData where
Andrey Mokhov's avatar
Andrey Mokhov committed
28
29
    showArgs packageData = do
        let (key, file, defaultValue) = case packageData of
30
               Version     file -> ("VERSION"     , file, "" )
31
32
33
34
35
36
               Modules     file -> ("MODULES"     , file, "" )
               SrcDirs     file -> ("HS_SRC_DIRS" , file, ".")
               PackageKey  file -> ("PACKAGE_KEY" , file, "" )
               IncludeDirs file -> ("INCLUDE_DIRS", file, ".")
               Deps        file -> ("DEPS"        , file, "" )
               DepKeys     file -> ("DEP_KEYS"    , file, "" )
37
               DepNames    file -> ("DEP_NAMES"   , file, "" )
Andrey Mokhov's avatar
Andrey Mokhov committed
38
               Synopsis    file -> ("SYNOPSIS"    , file, "" )
Andrey Mokhov's avatar
Andrey Mokhov committed
39
               CppOpts     file -> ("CPP_OPTS"    , file, "" )
Andrey Mokhov's avatar
Andrey Mokhov committed
40
               HsOpts      file -> ("HC_OPTS"     , file, "" )
Andrey Mokhov's avatar
Andrey Mokhov committed
41
42
43
            fullKey = replaceSeparators '_' $ file ++ "_" ++ key
            pkgData = file </> "package-data.mk"
        res <- askOracle $ PackageDataKey (pkgData, fullKey)
Andrey Mokhov's avatar
Andrey Mokhov committed
44
        return $ words $ case res of
Andrey Mokhov's avatar
Andrey Mokhov committed
45
46
            Nothing    -> error $ "No key '" ++ key ++ "' in "
                                ++ toStandard pkgData ++ "."
Andrey Mokhov's avatar
Andrey Mokhov committed
47
            Just ""    -> defaultValue
Andrey Mokhov's avatar
Andrey Mokhov committed
48
            Just value -> value