mirror of
https://github.com/commercialhaskell/stackage.git
synced 2026-01-25 05:31:57 +01:00
Proper conditional tracking
This commit is contained in:
parent
c05cacf39f
commit
69f3a1b8e7
@ -28,6 +28,8 @@ import qualified Data.Map as Map
|
|||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Stackage2.PackageDescription
|
import Stackage2.PackageDescription
|
||||||
|
import qualified Distribution.System
|
||||||
|
import qualified Distribution.Compiler
|
||||||
|
|
||||||
data BuildPlan desc = BuildPlan
|
data BuildPlan desc = BuildPlan
|
||||||
{ bpCore :: Map PackageName Version
|
{ bpCore :: Map PackageName Version
|
||||||
@ -251,10 +253,25 @@ isAllowed core = \name version ->
|
|||||||
Nothing -> True -- no constraints
|
Nothing -> True -- no constraints
|
||||||
Just (range, _) -> withinRange version range
|
Just (range, _) -> withinRange version range
|
||||||
|
|
||||||
mkPackageBuild :: Monad m
|
mkPackageBuild :: MonadThrow m
|
||||||
=> GenericPackageDescription
|
=> GenericPackageDescription
|
||||||
-> m (PackageBuild FlatComponent)
|
-> m (PackageBuild FlatComponent)
|
||||||
mkPackageBuild gpd =
|
mkPackageBuild gpd = do
|
||||||
|
let overrides = packageFlags name ++ defaultGlobalFlags
|
||||||
|
getFlag MkFlag {..} =
|
||||||
|
(flagName, fromMaybe flagDefault $ lookup flagName overrides)
|
||||||
|
desc <- getFlattenedComponent
|
||||||
|
CheckCond
|
||||||
|
{ ccPackageName = name
|
||||||
|
, ccOS = Distribution.System.Linux
|
||||||
|
, ccArch = Distribution.System.X86_64
|
||||||
|
, ccCompilerFlavor = Distribution.Compiler.GHC
|
||||||
|
, ccCompilerVersion = ghcVerCabal
|
||||||
|
, ccFlags = mapFromList $ map getFlag $ genPackageFlags gpd
|
||||||
|
}
|
||||||
|
(tryBuildTest name)
|
||||||
|
(tryBuildBenchmark name)
|
||||||
|
gpd
|
||||||
return PackageBuild
|
return PackageBuild
|
||||||
{ pbVersion = version
|
{ pbVersion = version
|
||||||
, pbMaintainer = fmap snd $ lookup name $ pcPackages defaultPackageConstraints
|
, pbMaintainer = fmap snd $ lookup name $ pcPackages defaultPackageConstraints
|
||||||
@ -275,10 +292,7 @@ mkPackageBuild gpd =
|
|||||||
-> ExpectFailure
|
-> ExpectFailure
|
||||||
| otherwise -> ExpectSuccess
|
| otherwise -> ExpectSuccess
|
||||||
, pbTryBuildBenchmark = tryBuildBenchmark name
|
, pbTryBuildBenchmark = tryBuildBenchmark name
|
||||||
, pbDesc = getFlattenedComponent
|
, pbDesc = desc
|
||||||
(tryBuildTest name)
|
|
||||||
(tryBuildBenchmark name)
|
|
||||||
gpd
|
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
PackageIdentifier name version = package $ packageDescription gpd
|
PackageIdentifier name version = package $ packageDescription gpd
|
||||||
|
|||||||
@ -9,6 +9,7 @@ module Stackage2.PackageConstraints
|
|||||||
, packageFlags
|
, packageFlags
|
||||||
, tryBuildTest
|
, tryBuildTest
|
||||||
, tryBuildBenchmark
|
, tryBuildBenchmark
|
||||||
|
, ghcVerCabal
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Stackage2.Prelude
|
import Stackage2.Prelude
|
||||||
@ -36,9 +37,14 @@ defaultPackageConstraints = PackageConstraints
|
|||||||
, pcExpectedFailures = Old.defaultExpectedFailures ghcVer False
|
, pcExpectedFailures = Old.defaultExpectedFailures ghcVer False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- FIXME below here shouldn't be so hard-coded
|
||||||
|
|
||||||
ghcVer :: Old.GhcMajorVersion
|
ghcVer :: Old.GhcMajorVersion
|
||||||
ghcVer = Old.GhcMajorVersion 7 8
|
ghcVer = Old.GhcMajorVersion 7 8
|
||||||
|
|
||||||
|
ghcVerCabal :: Version
|
||||||
|
ghcVerCabal = Version [7, 8, 3] []
|
||||||
|
|
||||||
oldSettings :: Old.SelectSettings
|
oldSettings :: Old.SelectSettings
|
||||||
oldSettings = Old.defaultSelectSettings ghcVer False
|
oldSettings = Old.defaultSelectSettings ghcVer False
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{-# LANGUAGE NoImplicitPrelude #-}
|
{-# LANGUAGE NoImplicitPrelude #-}
|
||||||
|
{-# LANGUAGE DeriveDataTypeable #-}
|
||||||
{-# LANGUAGE RecordWildCards #-}
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE DeriveFunctor #-}
|
{-# LANGUAGE DeriveFunctor #-}
|
||||||
@ -11,6 +12,7 @@ module Stackage2.PackageDescription
|
|||||||
( FlatComponent (..)
|
( FlatComponent (..)
|
||||||
, getFlattenedComponent
|
, getFlattenedComponent
|
||||||
, SimpleExtra (..)
|
, SimpleExtra (..)
|
||||||
|
, CheckCond (..)
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Distribution.Package (Dependency (..))
|
import Distribution.Package (Dependency (..))
|
||||||
@ -25,6 +27,8 @@ import Control.Monad.State.Strict (execState, get, put)
|
|||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
|
import Distribution.System (OS, Arch)
|
||||||
|
import Distribution.Compiler (CompilerFlavor)
|
||||||
|
|
||||||
data SimpleTree = SimpleTree
|
data SimpleTree = SimpleTree
|
||||||
{ stDeps :: Map PackageName VersionRange
|
{ stDeps :: Map PackageName VersionRange
|
||||||
@ -51,12 +55,16 @@ instance Monoid SimpleExtra where
|
|||||||
(b ++ y)
|
(b ++ y)
|
||||||
|
|
||||||
getFlattenedComponent
|
getFlattenedComponent
|
||||||
:: Bool -- ^ include test suites?
|
:: MonadThrow m
|
||||||
|
=> CheckCond
|
||||||
|
-> Bool -- ^ include test suites?
|
||||||
-> Bool -- ^ include benchmarks?
|
-> Bool -- ^ include benchmarks?
|
||||||
-> GenericPackageDescription
|
-> GenericPackageDescription
|
||||||
-> FlatComponent
|
-> m FlatComponent
|
||||||
getFlattenedComponent includeTests includeBench gpd =
|
getFlattenedComponent checkCond' includeTests includeBench gpd =
|
||||||
foldMap flattenComponent $ getSimpleTrees includeTests includeBench gpd
|
liftM fold
|
||||||
|
$ mapM (flattenComponent checkCond')
|
||||||
|
$ getSimpleTrees includeTests includeBench gpd
|
||||||
|
|
||||||
getSimpleTrees :: Bool -- ^ include test suites?
|
getSimpleTrees :: Bool -- ^ include test suites?
|
||||||
-> Bool -- ^ include benchmarks?
|
-> Bool -- ^ include benchmarks?
|
||||||
@ -103,14 +111,45 @@ instance Monoid FlatComponent where
|
|||||||
(unionWith intersectVersionRanges a x)
|
(unionWith intersectVersionRanges a x)
|
||||||
(b ++ y)
|
(b ++ y)
|
||||||
|
|
||||||
flattenComponent :: SimpleTree -> FlatComponent
|
flattenComponent :: MonadThrow m => CheckCond -> SimpleTree -> m FlatComponent
|
||||||
flattenComponent (SimpleTree deps conds extra) =
|
flattenComponent checkCond' (SimpleTree deps conds extra) = do
|
||||||
mconcat $ here : map goCond conds
|
conds' <- mapM goCond conds
|
||||||
|
return $ mconcat $ here : conds'
|
||||||
where
|
where
|
||||||
here = FlatComponent { fcDeps = deps, fcExtra = extra }
|
here = FlatComponent { fcDeps = deps, fcExtra = extra }
|
||||||
goCond (cond, tree1, mtree2)
|
goCond (cond, tree1, mtree2) = do
|
||||||
| checkCond cond = flattenComponent tree1
|
b <- checkCond checkCond' cond
|
||||||
| otherwise = maybe mempty flattenComponent mtree2
|
if b
|
||||||
|
then flattenComponent checkCond' tree1
|
||||||
|
else maybe (return mempty) (flattenComponent checkCond') mtree2
|
||||||
|
|
||||||
checkCond :: Condition ConfVar -> Bool
|
checkCond :: MonadThrow m => CheckCond -> Condition ConfVar -> m Bool
|
||||||
checkCond _ = False -- FIXME
|
checkCond CheckCond {..} cond0 =
|
||||||
|
go cond0
|
||||||
|
where
|
||||||
|
go (Var (OS os)) = return $ os == ccOS
|
||||||
|
go (Var (Arch arch)) = return $ arch == ccArch
|
||||||
|
go (Var (Flag flag)) =
|
||||||
|
case lookup flag ccFlags of
|
||||||
|
Nothing -> throwM $ FlagNotDefined ccPackageName flag cond0
|
||||||
|
Just b -> return b
|
||||||
|
go (Var (Impl flavor range)) = return
|
||||||
|
$ flavor == ccCompilerFlavor
|
||||||
|
&& ccCompilerVersion `withinRange` range
|
||||||
|
go (Lit b) = return b
|
||||||
|
go (CNot c) = not `liftM` go c
|
||||||
|
go (CAnd x y) = (&&) `liftM` go x `ap` go y
|
||||||
|
go (COr x y) = (||) `liftM` go x `ap` go y
|
||||||
|
|
||||||
|
data CheckCondException = FlagNotDefined PackageName FlagName (Condition ConfVar)
|
||||||
|
deriving (Show, Typeable)
|
||||||
|
instance Exception CheckCondException
|
||||||
|
|
||||||
|
data CheckCond = CheckCond
|
||||||
|
{ ccPackageName :: PackageName -- for debugging only
|
||||||
|
, ccOS :: OS
|
||||||
|
, ccArch :: Arch
|
||||||
|
, ccFlags :: Map FlagName Bool
|
||||||
|
, ccCompilerFlavor :: CompilerFlavor
|
||||||
|
, ccCompilerVersion :: Version
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user