-
Notifications
You must be signed in to change notification settings - Fork 1
/
Setup.hs
89 lines (76 loc) · 2.86 KB
/
Setup.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{-
Here is a very unfortunate hack that allows me to re-export modules of
the "constraints" library if flag "constraints" is enabled.
I have to do this because:
* if flag "constraints" is disabled, the library exports its own modules
(copied from the "constraints" library, thus the same API);
* if I add reexported-modules in the package description, cabal check
complains for duplicate modules
(even though they are under mutually exclusive conditions);
* I still want library users import the modules without PackageImports or alike
independently of their choice of flags.
-}
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE CPP #-}
#ifndef MIN_VERSION_Cabal
#define MIN_VERSION_Cabal(x,y,z) 0
#endif
module Main (main) where
import Distribution.PackageDescription
import Distribution.Simple
import qualified Distribution.ModuleName as ModuleName
#if MIN_VERSION_Cabal(3,4,0)
import Distribution.Types.ModuleReexport
#elif MIN_VERSION_Cabal(2,0,0)
import Distribution.Types.CondTree (CondBranch(CondBranch))
#endif
main :: IO ()
main = defaultMainWithHooks simpleUserHooks
{ confHook = \(gpd, hbi) -> confHook simpleUserHooks (addReexportsGPD gpd, hbi) }
addReexportsGPD :: GenericPackageDescription -> GenericPackageDescription
addReexportsGPD gpd = gpd { condLibrary = addReexportsCT <$> condLibrary gpd }
addReexportsCT :: CondTree ConfVar [Dependency] Library
-> CondTree ConfVar [Dependency] Library
addReexportsCT ct = ct
{ condTreeComponents = reexportBranch : condTreeComponents ct }
where
constraintsCondition = Var (
#if MIN_VERSION_Cabal(3,4,0)
PackageFlag
#else
Flag
#endif
(mkFlagName "constraints"))
reexportContent = mempty
{ reexportedModules =
[ ModuleReexport
{ moduleReexportOriginalPackage = Just (mkPackageName "constraints")
, moduleReexportOriginalName = ModuleName.fromString "Data.Constraint"
, moduleReexportName = ModuleName.fromString "Data.Constraint"
}
, ModuleReexport
{ moduleReexportOriginalPackage = Just (mkPackageName "constraints")
, moduleReexportOriginalName = ModuleName.fromString "Data.Constraint.Unsafe"
, moduleReexportName = ModuleName.fromString "Data.Constraint.Unsafe"
}
]
}
constraintsTrueTree = CondNode
{ condTreeData = reexportContent
, condTreeConstraints = []
, condTreeComponents = []
}
constraintsFalseTree = Nothing
reexportBranch =
#if MIN_VERSION_Cabal(2,0,0)
CondBranch
#else
(,,)
#endif
constraintsCondition constraintsTrueTree constraintsFalseTree
#if !MIN_VERSION_Cabal(2,0,0)
mkFlagName :: String -> FlagName
mkFlagName = FlagName
mkPackageName :: String -> PackageName
mkPackageName = PackageName
#endif