Skip to content

Commit

Permalink
[#142] Add base bounds to the generated cabal file
Browse files Browse the repository at this point in the history
  • Loading branch information
vrom911 committed Nov 12, 2018
1 parent f5b12ed commit 0e9ac0a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* [#168](https://github.com/kowainik/summoner/issues/168):
Upgrade `stack` `intall-cabal` option's version to `2.2.0.1` in
the generated Travis file.
* [#142](https://github.com/kowainik/summoner/issues/142):
Add version bounds to `base` in the generated `.cabal` file.

1.1.0.1
=======
Expand Down
45 changes: 38 additions & 7 deletions src/Summoner/GhcVer.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
module Summoner.GhcVer
( GhcVer (..)
, Pvp (..)
, showGhcVer
, parseGhcVer
, latestLts
, baseVer
, cabalBaseVersions
) where

import Data.List (maximum, minimum)

import qualified Text.Show as Show


-- | Represents some selected set of GHC versions.
data GhcVer
= Ghc7103
Expand Down Expand Up @@ -36,11 +43,35 @@ latestLts = \case
Ghc822 -> "11.22"
Ghc843 -> "12.14"

-- | Returns base version by 'GhcVer'.
-- | Represents PVP versioning (4 numbers).
data Pvp = Pvp
{ pvpFirst :: Int
, pvpSecond :: Int
, pvpThird :: Int
, pvpFourth :: Int
}

-- | Show PVP version in a standard way: @1.2.3.4@
instance Show Pvp where
show (Pvp a b c d) = intercalate "." $ map Show.show [a, b, c, d]

-- | Returns base version by 'GhcVer' as 'Pvp'.
baseVerPvp :: GhcVer -> Pvp
baseVerPvp = \case
Ghc7103 -> Pvp 4 8 0 2
Ghc801 -> Pvp 4 9 0 0
Ghc802 -> Pvp 4 9 1 0
Ghc822 -> Pvp 4 10 1 0
Ghc843 -> Pvp 4 11 1 0

baseVer :: GhcVer -> Text
baseVer = \case
Ghc7103 -> "4.8.0.2"
Ghc801 -> "4.9.0.0"
Ghc802 -> "4.9.1.0"
Ghc822 -> "4.10.1.0"
Ghc843 -> "4.11.1.0"
baseVer = show . baseVerPvp

cabalBaseVersions :: [GhcVer] -> Text
cabalBaseVersions [] = ""
cabalBaseVersions [v] = "^>= " <> baseVer v
cabalBaseVersions ghcs = ">= " <> baseVer (minimum ghcs) <> " && < " <> upperBound
where
upperBound :: Text
upperBound = let Pvp{..} = baseVerPvp $ maximum ghcs in
show pvpFirst <> "." <> show (pvpSecond + 1)
13 changes: 8 additions & 5 deletions src/Summoner/Template/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Summoner.Template.Cabal

import NeatInterpolation (text)

import Summoner.GhcVer (GhcVer (..), showGhcVer)
import Summoner.GhcVer (GhcVer (..), cabalBaseVersions, showGhcVer)
import Summoner.Settings (CustomPrelude (..), Settings (..))
import Summoner.Text (intercalateMap, packageToModule)
import Summoner.Tree (TreeFs (..))
Expand Down Expand Up @@ -71,6 +71,9 @@ cabalFile Settings{..} = File (toString settingsRepo ++ ".cabal") cabalFileConte
location: ${githubUrl}.git
|]

baseBounds :: Text
baseBounds = cabalBaseVersions settingsTestedVersions

libraryStanza :: Text
libraryStanza =
[text|
Expand All @@ -80,7 +83,7 @@ cabalFile Settings{..} = File (toString settingsRepo ++ ".cabal") cabalFileConte
exposed-modules: $libModuleName
$preludeMod

build-depends: $settingsBaseType
build-depends: $settingsBaseType $baseBounds
$commaPreludeLibrary

ghc-options: -Wall
Expand All @@ -97,7 +100,7 @@ cabalFile Settings{..} = File (toString settingsRepo ++ ".cabal") cabalFileConte
hs-source-dirs: app
main-is: Main.hs

build-depends: $settingsBaseType
build-depends: $settingsBaseType $baseBounds
$commaRepo
$commaPreludeLibrary

Expand All @@ -119,7 +122,7 @@ cabalFile Settings{..} = File (toString settingsRepo ++ ".cabal") cabalFileConte
hs-source-dirs: test
main-is: Spec.hs

build-depends: $settingsBaseType
build-depends: $settingsBaseType $baseBounds
$commaRepo
$commaPreludeLibrary

Expand All @@ -141,7 +144,7 @@ cabalFile Settings{..} = File (toString settingsRepo ++ ".cabal") cabalFileConte
hs-source-dirs: benchmark
main-is: Main.hs

build-depends: $settingsBaseType
build-depends: $settingsBaseType $baseBounds
, gauge
$commaRepo
$commaPreludeLibrary
Expand Down

0 comments on commit 0e9ac0a

Please sign in to comment.