on 48457d1 help sign in
stackage/Stackage2/UpdateBuildPlan.hs
51 lines 2.0 kB history raw
1{-# LANGUAGE NoImplicitPrelude #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE RecordWildCards #-}
4-- | Take an existing build plan and bump all packages to the newest version in
5-- the same major version number.
6module Stackage2.UpdateBuildPlan
7 ( updateBuildConstraints
8 , updateBuildPlan
9 ) where
11import qualified Data.Map as Map
12import Distribution.Version (anyVersion, earlierVersion,
13 orLaterVersion)
14import Stackage2.BuildConstraints
15import Stackage2.BuildPlan
16import Stackage2.Prelude
18updateBuildPlan :: BuildPlan -> IO BuildPlan
19updateBuildPlan = newBuildPlan . updateBuildConstraints
21updateBuildConstraints :: BuildPlan -> BuildConstraints
22updateBuildConstraints BuildPlan {..} =
23 BuildConstraints {..}
24 where
25 bcSystemInfo = bpSystemInfo
26 bcPackages = Map.keysSet bpPackages
28 bcPackageConstraints name = PackageConstraints
29 { pcVersionRange = addBumpRange (maybe anyVersion pcVersionRange moldPC)
30 , pcMaintainer = moldPC >>= pcMaintainer
31 , pcTests = maybe ExpectSuccess pcTests moldPC
32 , pcHaddocks = maybe ExpectSuccess pcHaddocks moldPC
33 , pcBuildBenchmarks = maybe True pcBuildBenchmarks moldPC
34 , pcFlagOverrides = maybe mempty pcFlagOverrides moldPC
35 }
36 where
37 moldBP = lookup name bpPackages
38 moldPC = ppConstraints <$> moldBP
40 addBumpRange oldRange =
41 case moldBP of
42 Nothing -> oldRange
43 Just bp -> intersectVersionRanges oldRange
44 $ bumpRange $ ppVersion bp
46 bumpRange version = intersectVersionRanges
47 (orLaterVersion version)
48 (earlierVersion $ bumpVersion version)
49 bumpVersion (Version (x:y:_) _) = Version [x, y + 1] []
50 bumpVersion (Version [x] _) = Version [x, 1] []
51 bumpVersion (Version [] _) = assert False $ Version [1, 0] []