@@ -18,7 +18,6 @@ module Stackage2.BuildPlan
1818import Distribution.Package (Dependency (..))
1919import Distribution.PackageDescription
2020import Distribution.Version (withinRange, intersectVersionRanges)
21−import Stackage2.CorePackages
2221import Stackage2.PackageConstraints
2322import Stackage2.PackageIndex
2423import Stackage2.Prelude
@@ -122,44 +121,23 @@ instance desc ~ () => FromJSON (PackageBuild desc) where
122121
123122 efail = either (fail . show) return
124123
125−data TestState = ExpectSuccess
126− | ExpectFailure
127− | Don'tBuild -- ^ when the test suite will pull in things we don't want
128− deriving (Show, Eq, Ord, Bounded, Enum)
129−
130−testStateToText :: TestState -> Text
131−testStateToText ExpectSuccess = "expect-success"
132−testStateToText ExpectFailure = "expect-failure"
133−testStateToText Don'tBuild = "do-not-build"
134−
135−instance ToJSON TestState where
136− toJSON = toJSON . testStateToText
137−instance FromJSON TestState where
138− parseJSON = withText "TestState" $ \t ->
139− case lookup t states of
140− Nothing -> fail $ "Invalid state: " ++ unpack t
141− Just v -> return v
142− where
143− states = asHashMap $ mapFromList
144− $ map (\x -> (testStateToText x, x)) [minBound..maxBound]
145−
146−newBuildPlan :: MonadIO m => m (BuildPlan FlatComponent)
147−newBuildPlan = liftIO $ do
148− core <- getCorePackages
149− coreExes <- getCoreExecutables
150− extraOrig <- getLatestDescriptions (isAllowed core) mkPackageBuild
124+newBuildPlan :: MonadIO m => PackageConstraints -> m (BuildPlan FlatComponent)
125+newBuildPlan pc = liftIO $ do
126+ extraOrig <- getLatestDescriptions (isAllowed pc) (mkPackageBuild pc)
151127 let toolMap = makeToolMap extraOrig
152− extra = populateUsers $ removeUnincluded toolMap coreExes extraOrig
128+ extra = populateUsers $ removeUnincluded pc toolMap extraOrig
153129 toolNames :: [ExeName]
154130 toolNames = concatMap (Map.keys . seTools . fcExtra . pbDesc) extra
155131 tools <- topologicalSortTools toolMap $ mapFromList $ do
156132 exeName <- toolNames
157− guard $ exeName `notMember` coreExes
133+ guard $ exeName `notMember` pcCoreExecutables pc
158134 packageName <- maybe mempty setToList $ lookup exeName toolMap
159135 packageBuild <- maybeToList $ lookup packageName extraOrig
160136 return (packageName, packageBuild)
137+ -- FIXME topologically sort packages? maybe just leave that to the build phase
161138 return BuildPlan
162− { bpCore = core
139+ { bpCore = pcCorePackages pc
140+ -- bpCoreExes = pcCoreExecutables pc
163141 , bpTools = tools
164142 , bpExtra = extra
165143 }
@@ -206,16 +184,18 @@ data TopologicalSortException key = NoEmptyDeps (Map key (Set key))
206184 deriving (Show, Typeable)
207185instance (Show key, Typeable key) => Exception (TopologicalSortException key)
208186
209−removeUnincluded :: Map ExeName (Set PackageName)
210− -> Set ExeName -- ^ core exes
187+removeUnincluded :: PackageConstraints
188+ -> Map ExeName (Set PackageName)
211189 -> Map PackageName (PackageBuild FlatComponent)
212190 -> Map PackageName (PackageBuild FlatComponent)
213−removeUnincluded toolMap coreExes orig =
191+removeUnincluded pc toolMap orig =
214192 mapFromList $ filter (\(x, _) -> x `member` included) $ mapToList orig
215193 where
194+ coreExes = pcCoreExecutables pc
195+
216196 included :: Set PackageName
217197 included = flip execState mempty $
218− mapM_ (add . fst) $ mapToList $ pcPackages defaultPackageConstraints
198+ mapM_ (add . fst) $ mapToList $ pcPackages pc
219199
220200 add name = do
221201 inc <- get
@@ -240,56 +220,46 @@ populateUsers orig =
240220 | dep `member` fcDeps (pbDesc pb) = singletonSet user
241221 | otherwise = mempty
242222
243−isAllowed :: Map PackageName Version -- ^ core
223+isAllowed :: PackageConstraints
244224 -> PackageName -> Version -> Bool
245−isAllowed core = \name version ->
246− case lookup name core of
225+isAllowed pc = \name version ->
226+ case lookup name $ pcCorePackages pc of
247227 Just _ -> False -- never reinstall a core package
248228 Nothing ->
249− case lookup name $ pcPackages defaultPackageConstraints of
229+ case lookup name $ pcPackages pc of
250230 Nothing -> True -- no constraints
251231 Just (range, _) -> withinRange version range
252232
253233mkPackageBuild :: MonadThrow m
254− => GenericPackageDescription
234+ => PackageConstraints
235+ -> GenericPackageDescription
255236 -> m (PackageBuild FlatComponent)
256−mkPackageBuild gpd = do
257− let overrides = packageFlags name ++ defaultGlobalFlags
237+mkPackageBuild pc gpd = do
238+ let overrides = pcFlagOverrides pc name
258239 getFlag MkFlag {..} =
259240 (flagName, fromMaybe flagDefault $ lookup flagName overrides)
260241 flags = mapFromList $ map getFlag $ genPackageFlags gpd
261242 desc <- getFlattenedComponent
262243 CheckCond
263244 { ccPackageName = name
264− , ccOS = Distribution.System.Linux
265− , ccArch = Distribution.System.X86_64
245+ , ccOS = pcOS pc
246+ , ccArch = pcArch pc
266247 , ccCompilerFlavor = Distribution.Compiler.GHC
267− , ccCompilerVersion = ghcVerCabal
248+ , ccCompilerVersion = pcGhcVersion pc
268249 , ccFlags = flags
269250 }
270− (tryBuildTest name)
271− (tryBuildBenchmark name)
251+ (pcTests pc name /= Don'tBuild)
252+ (pcBuildBenchmark pc name)
272253 gpd
273254 return PackageBuild
274255 { pbVersion = version
275− , pbMaintainer = fmap snd $ lookup name $ pcPackages defaultPackageConstraints
256+ , pbMaintainer = fmap snd $ lookup name $ pcPackages pc
276257 , pbGithubPings = getGithubPings gpd
277258 , pbUsers = mempty -- must be filled in later
278259 , pbFlags = flags
279− , pbTestState =
280− case () of
281− ()
282− | not $ tryBuildTest name -> Don'tBuild
283− | name `member` pcExpectedFailures defaultPackageConstraints
284− -> ExpectFailure
285− | otherwise -> ExpectSuccess
286− , pbHaddockState =
287− case () of
288− ()
289− | name `member` pcExpectedFailures defaultPackageConstraints
290− -> ExpectFailure
291− | otherwise -> ExpectSuccess
292− , pbTryBuildBenchmark = tryBuildBenchmark name
260+ , pbTestState = pcTests pc name
261+ , pbHaddockState = pcHaddocks pc name
262+ , pbTryBuildBenchmark = pcBuildBenchmark pc name
293263 , pbDesc = desc
294264 }
295265 where