2015-02-08 13:17:53 +00:00
|
|
|
{-# LANGUAGE TemplateHaskell, RecordWildCards, StandaloneDeriving #-}
|
2015-02-04 00:12:51 +00:00
|
|
|
module SetupCompat where
|
|
|
|
|
2015-02-08 13:17:53 +00:00
|
|
|
import Control.Arrow
|
2015-03-28 18:11:09 +00:00
|
|
|
import Control.Monad.Trans.State
|
2015-02-04 00:12:51 +00:00
|
|
|
import Data.List
|
|
|
|
import Data.Maybe
|
|
|
|
import Data.Functor
|
|
|
|
import Data.Function
|
|
|
|
import Distribution.Simple.LocalBuildInfo
|
|
|
|
import Distribution.PackageDescription
|
|
|
|
|
2015-02-08 13:17:53 +00:00
|
|
|
import Distribution.Simple
|
|
|
|
import Distribution.Simple.Setup
|
|
|
|
import Distribution.Simple.Install
|
|
|
|
|
|
|
|
import qualified Data.Map as M
|
2015-03-04 20:48:21 +00:00
|
|
|
import Data.Map (Map)
|
2015-02-08 13:17:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
import NotCPP.Declarations
|
|
|
|
import Language.Haskell.TH
|
|
|
|
|
2015-03-04 20:48:21 +00:00
|
|
|
-- $(ifdefD "componentsConfigs" [d| deriving instance (Ord ComponentName) |] )
|
|
|
|
|
|
|
|
$(ifD [d|
|
|
|
|
|
|
|
|
showComponentName :: ComponentName -> String
|
|
|
|
showComponentName CLibName = "library"
|
|
|
|
showComponentName (CExeName name) = "executable '" ++ name ++ "'"
|
|
|
|
showComponentName (CTestName name) = "test suite '" ++ name ++ "'"
|
|
|
|
showComponentName (CBenchName name) = "benchmark '" ++ name ++ "'"
|
|
|
|
|
|
|
|
|])
|
2015-02-08 13:17:53 +00:00
|
|
|
|
|
|
|
$(ifelsedefD "componentsConfigs" [d|
|
|
|
|
|
|
|
|
setComponentsConfigs
|
|
|
|
:: LocalBuildInfo
|
|
|
|
-> [(ComponentName, ComponentLocalBuildInfo, [ComponentName])]
|
|
|
|
-> LocalBuildInfo
|
|
|
|
setComponentsConfigs lbi cs = $(recUpdE' (nE "lbi") (mkName "componentsConfigs") (VarE $ mkName "cs"))
|
|
|
|
|
|
|
|
|] [d|
|
|
|
|
|
|
|
|
setComponentsConfigs
|
|
|
|
:: LocalBuildInfo
|
|
|
|
-> [(ComponentName, ComponentLocalBuildInfo, a)]
|
|
|
|
-> LocalBuildInfo
|
|
|
|
setComponentsConfigs lbi cs = flip execState lbi $ mapM setClbis gcs
|
|
|
|
where
|
2015-03-04 20:48:21 +00:00
|
|
|
gcs = groupBy (sameKind `on` fst3) $ sortBy (compare `on` showComponentName . fst3) cs
|
2015-02-08 13:17:53 +00:00
|
|
|
|
|
|
|
fst3 (x,_,_) = x
|
|
|
|
|
|
|
|
sameKind CLibName CLibName = True
|
|
|
|
sameKind CLibName _ = False
|
|
|
|
sameKind (CExeName _) (CExeName _) = True
|
|
|
|
sameKind (CExeName _) _ = False
|
|
|
|
sameKind (CTestName _) (CTestName _) = True
|
|
|
|
sameKind (CTestName _) _ = False
|
|
|
|
sameKind (CBenchName _) (CBenchName _) = True
|
|
|
|
sameKind (CBenchName _) _ = False
|
|
|
|
|
|
|
|
setClbis [(CLibName, clbi, _)] =
|
|
|
|
get >>= \lbi ->
|
|
|
|
put $ $(recUpdE' (nE "lbi") (mkName "libraryConfig") (AppE (ConE (mkName "Just")) (VarE (mkName "clbi"))))
|
|
|
|
|
|
|
|
setClbis cs@((CExeName _, _, _):_) =
|
|
|
|
let cfg = (\((CExeName n), clbi, _) -> (n, clbi)) <$> cs in
|
|
|
|
get >>= \lbi ->
|
|
|
|
put $ $(recUpdE' (nE "lbi") (mkName "executableConfigs") (VarE $ mkName "cfg"))
|
|
|
|
|
|
|
|
setClbis cs@((CTestName _, _, _):_) =
|
|
|
|
let cfg = (\((CTestName n), clbi, _) -> (n, clbi)) <$> cs in
|
|
|
|
get >>= \lbi ->
|
|
|
|
put $ $(recUpdE' (nE "lbi") (mkName "testSuiteConfigs") (VarE $ mkName "cfg"))
|
|
|
|
|
|
|
|
setClbis cs@((CBenchName _, _, _):_) =
|
|
|
|
let cfg = (\((CBenchName n), clbi, _) -> (n, clbi)) <$> cs in
|
|
|
|
get >>= \lbi ->
|
|
|
|
put $ $(recUpdE' (nE "lbi") (mkName "benchmarkConfigs") (VarE $ mkName "cfg"))
|
|
|
|
|
|
|
|
|])
|
|
|
|
|
|
|
|
|
|
|
|
$(ifD [d|
|
|
|
|
|
|
|
|
componentsConfigs ::
|
2015-02-04 00:12:51 +00:00
|
|
|
LocalBuildInfo -> [(ComponentName, ComponentLocalBuildInfo, [ComponentName])]
|
2015-02-08 13:17:53 +00:00
|
|
|
componentsConfigs LocalBuildInfo {..} =
|
|
|
|
(maybe [] (\c -> [(CLibName, c, [])]) $(nE "libraryConfig"))
|
|
|
|
++ ((\(n, clbi) -> (CExeName n, clbi, [])) <$> $(nE "executableConfigs"))
|
|
|
|
++ ((\(n, clbi) -> (CTestName n, clbi, [])) <$> $(nE "testSuiteConfigs"))
|
|
|
|
++ ((\(n, clbi) -> (CBenchName n, clbi, [])) <$> $(nE "benchmarkConfigs"))
|
|
|
|
|
|
|
|
getComponent :: PackageDescription -> ComponentName -> Component
|
|
|
|
getComponent pkg cname =
|
2015-02-04 00:12:51 +00:00
|
|
|
case lookupComponent pkg cname of
|
|
|
|
Just cpnt -> cpnt
|
|
|
|
Nothing -> missingComponent
|
|
|
|
where
|
|
|
|
missingComponent =
|
|
|
|
error $ "internal error: the package description contains no "
|
|
|
|
++ "component corresponding to " ++ show cname
|
|
|
|
|
2015-02-08 13:17:53 +00:00
|
|
|
lookupComponent :: PackageDescription -> ComponentName -> Maybe Component
|
|
|
|
lookupComponent pkg CLibName =
|
2015-02-04 00:12:51 +00:00
|
|
|
fmap CLib $ library pkg
|
2015-02-08 13:17:53 +00:00
|
|
|
lookupComponent pkg (CExeName name) =
|
2015-02-04 00:12:51 +00:00
|
|
|
fmap CExe $ find ((name ==) . exeName) (executables pkg)
|
2015-02-08 13:17:53 +00:00
|
|
|
lookupComponent pkg (CTestName name) =
|
2015-02-04 00:12:51 +00:00
|
|
|
fmap CTest $ find ((name ==) . testName) (testSuites pkg)
|
2015-02-08 13:17:53 +00:00
|
|
|
lookupComponent pkg (CBenchName name) =
|
2015-02-04 00:12:51 +00:00
|
|
|
fmap CBench $ find ((name ==) . benchmarkName) (benchmarks pkg)
|
|
|
|
|
|
|
|
-- We're lying here can't be bothered to order these
|
2015-02-08 13:17:53 +00:00
|
|
|
allComponentsInBuildOrder :: LocalBuildInfo
|
2015-02-04 00:12:51 +00:00
|
|
|
-> [(ComponentName, ComponentLocalBuildInfo)]
|
2015-02-08 13:17:53 +00:00
|
|
|
allComponentsInBuildOrder lbi =
|
2015-02-04 00:12:51 +00:00
|
|
|
[ (cname, clbi) | (cname, clbi, _) <- componentsConfigs lbi ]
|
|
|
|
|
2015-02-08 13:17:53 +00:00
|
|
|
getComponentLocalBuildInfo :: LocalBuildInfo -> ComponentName -> ComponentLocalBuildInfo
|
|
|
|
getComponentLocalBuildInfo lbi cname =
|
2015-02-04 00:12:51 +00:00
|
|
|
case [ clbi
|
|
|
|
| (cname', clbi, _) <- componentsConfigs lbi
|
|
|
|
, cname == cname' ] of
|
|
|
|
[clbi] -> clbi
|
|
|
|
_ -> missingComponent
|
|
|
|
where
|
|
|
|
missingComponent =
|
|
|
|
error $ "internal error: there is no configuration data "
|
|
|
|
++ "for component " ++ show cname
|
|
|
|
|
2015-02-08 13:17:53 +00:00
|
|
|
componentBuildInfo :: Component -> BuildInfo
|
|
|
|
componentBuildInfo =
|
|
|
|
foldComponent libBuildInfo buildInfo testBuildInfo benchmarkBuildInfo
|
2015-02-04 00:12:51 +00:00
|
|
|
|
2015-02-08 13:17:53 +00:00
|
|
|
|])
|
2015-02-04 00:12:51 +00:00
|
|
|
|
|
|
|
|
2015-02-08 13:17:53 +00:00
|
|
|
$(ifelsedefD "componentPackageRenaming" [d|
|
2015-03-04 20:48:21 +00:00
|
|
|
-- M.Map PackageName
|
|
|
|
newtype Deps = Deps { unDeps :: ([(InstalledPackageId, PackageId)], Map PackageName $(cT "ModuleRenaming")) }
|
|
|
|
-- $(return $ TySynD $(mkName "Deps") [] [t| |] )
|
2015-02-04 00:12:51 +00:00
|
|
|
|
2015-03-04 20:48:21 +00:00
|
|
|
noDeps = Deps ([], M.empty)
|
2015-02-04 00:12:51 +00:00
|
|
|
|
2015-02-08 13:17:53 +00:00
|
|
|
getDeps :: ComponentLocalBuildInfo -> Deps
|
2015-03-04 20:48:21 +00:00
|
|
|
getDeps = componentPackageDeps &&& $(nE "componentPackageRenaming") >>> Deps
|
2015-02-04 00:12:51 +00:00
|
|
|
|
2015-02-08 13:17:53 +00:00
|
|
|
setUnionDeps :: Deps -> ComponentLocalBuildInfo -> ComponentLocalBuildInfo
|
2015-03-04 20:48:21 +00:00
|
|
|
setUnionDeps (Deps (deps, rns)) clbi = let
|
2015-02-08 13:17:53 +00:00
|
|
|
clbi' = setComponentPackageRenaming clbi rns
|
|
|
|
cpdeps = componentPackageDeps clbi
|
|
|
|
in
|
|
|
|
clbi' {
|
|
|
|
componentPackageDeps = cpdeps `union` deps
|
|
|
|
}
|
2015-02-04 00:12:51 +00:00
|
|
|
|
2015-02-08 13:17:53 +00:00
|
|
|
setComponentPackageRenaming clbi cprn =
|
|
|
|
-- [| clbi { componentPackageRenaming = componentPackageRenaming clbi `M.union` cprn } |]
|
|
|
|
$(recUpdE'
|
|
|
|
(nE "clbi")
|
|
|
|
(mkName "componentPackageRenaming")
|
|
|
|
(InfixE
|
|
|
|
(Just
|
|
|
|
(AppE
|
|
|
|
(VarE
|
|
|
|
(mkName "componentPackageRenaming"))
|
|
|
|
(VarE (mkName "clbi"))
|
|
|
|
))
|
|
|
|
(VarE (mkName "M.union"))
|
|
|
|
(Just (VarE (mkName "cprn")))
|
|
|
|
)
|
|
|
|
)
|
2015-02-04 00:12:51 +00:00
|
|
|
|
2015-02-08 13:17:53 +00:00
|
|
|
|] [d|
|
|
|
|
|
2015-03-04 20:48:21 +00:00
|
|
|
newtype Deps = Deps { unDeps :: [(InstalledPackageId, PackageId)] }
|
2015-02-08 13:17:53 +00:00
|
|
|
|
2015-03-04 20:48:21 +00:00
|
|
|
noDeps = Deps []
|
2015-02-04 00:12:51 +00:00
|
|
|
|
2015-02-08 13:17:53 +00:00
|
|
|
getDeps :: ComponentLocalBuildInfo -> Deps
|
2015-03-04 20:48:21 +00:00
|
|
|
getDeps lbi = Deps $ componentPackageDeps lbi
|
2015-02-07 22:05:04 +00:00
|
|
|
|
2015-02-08 13:17:53 +00:00
|
|
|
setUnionDeps :: Deps -> ComponentLocalBuildInfo -> ComponentLocalBuildInfo
|
2015-03-04 20:48:21 +00:00
|
|
|
setUnionDeps (Deps deps) clbi = let
|
2015-02-08 13:17:53 +00:00
|
|
|
cpdeps = componentPackageDeps clbi
|
|
|
|
in
|
|
|
|
clbi {
|
|
|
|
componentPackageDeps = cpdeps `union` deps
|
|
|
|
}
|
2015-02-07 22:05:04 +00:00
|
|
|
|
|
|
|
|
2015-02-08 13:17:53 +00:00
|
|
|
-- setComponentPackageRenaming clbi _cprn = clbi
|
2015-02-07 22:05:04 +00:00
|
|
|
|
2015-02-08 13:17:53 +00:00
|
|
|
|])
|