on 335fa91 help sign in
stackage/Stackage/UpdateBuildPlan.hs
53 lines 2.1 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 , pcEnableLibProfile = maybe False pcEnableLibProfile moldPC
37 }
38 where
39 moldBP = lookup name bpPackages
40 moldPC = ppConstraints <$> moldBP
42 addBumpRange oldRange =
43 case moldBP of
44 Nothing -> oldRange
45 Just bp -> intersectVersionRanges oldRange
46 $ bumpRange $ ppVersion bp
48 bumpRange version = intersectVersionRanges
49 (orLaterVersion version)
50 (earlierVersion $ bumpVersion version)
51 bumpVersion (Version (x:y:_) _) = Version [x, y + 1] []
52 bumpVersion (Version [x] _) = Version [x, 1] []
53 bumpVersion (Version [] _) = assert False $ Version [1, 0] []