on c9e55a7 help sign in
stackage/Stackage/UpdateBuildPlan.hs
52 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 Stackage.UpdateBuildPlan
7 ( updateBuildConstraints
8 , updateBuildPlan
9 ) where
11import qualified Data.Map as Map
12import Distribution.Version (anyVersion, earlierVersion,
13 orLaterVersion)
14import Stackage.BuildConstraints
15import Stackage.BuildPlan
16import Stackage.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
27 bcGithubUsers = bpGithubUsers
29 bcPackageConstraints name = PackageConstraints
30 { pcVersionRange = addBumpRange (maybe anyVersion pcVersionRange moldPC)
31 , pcMaintainer = moldPC >>= pcMaintainer
32 , pcTests = maybe ExpectSuccess pcTests moldPC
33 , pcHaddocks = maybe ExpectSuccess pcHaddocks moldPC
34 , pcBuildBenchmarks = maybe True pcBuildBenchmarks moldPC
35 , pcFlagOverrides = maybe mempty pcFlagOverrides moldPC
36 }
37 where
38 moldBP = lookup name bpPackages
39 moldPC = ppConstraints <$> moldBP
41 addBumpRange oldRange =
42 case moldBP of
43 Nothing -> oldRange
44 Just bp -> intersectVersionRanges oldRange
45 $ bumpRange $ ppVersion bp
47 bumpRange version = intersectVersionRanges
48 (orLaterVersion version)
49 (earlierVersion $ bumpVersion version)
50 bumpVersion (Version (x:y:_) _) = Version [x, y + 1] []
51 bumpVersion (Version [x] _) = Version [x, 1] []
52 bumpVersion (Version [] _) = assert False $ Version [1, 0] []