Skip to content

Commit

Permalink
By default use latest GHC to run HLint
Browse files Browse the repository at this point in the history
  • Loading branch information
phadej committed Feb 10, 2019
1 parent eb12f2b commit 1126bb1
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 45 deletions.
2 changes: 2 additions & 0 deletions haskell-ci.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ library
exposed-modules:
HaskellCI
HaskellCI.Config
HaskellCI.Config.Doctest
HaskellCI.Config.HLint
HaskellCI.Glob

ghc-options:
Expand Down
67 changes: 44 additions & 23 deletions src/HaskellCI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ import Lens.Micro
import Data.Generics.Labels () -- IsLabel (->) ...

import HaskellCI.Config
import HaskellCI.Config.Doctest
import HaskellCI.Config.HLint
import HaskellCI.Glob

#if !(MIN_VERSION_Cabal(2,0,0))
Expand Down Expand Up @@ -818,7 +820,6 @@ genTravisFromConfigs (argv,opts) xpkgs isCabalProject config prj@Project { prjPa
]

-- Install doctest
let doctestConfig = cfgDoctest config
let doctestVersionConstraint
| isAnyVersion (cfgDoctestVersion doctestConfig) = ""
| otherwise = " --constraint='doctest " ++ display (cfgDoctestVersion doctestConfig) ++ "'"
Expand All @@ -828,10 +829,10 @@ genTravisFromConfigs (argv,opts) xpkgs isCabalProject config prj@Project { prjPa

-- Install hlint
let hlintVersionConstraint
| isAnyVersion (cfgHLintVersion config) = ""
| otherwise = " --constraint='hlint " ++ display (cfgHLintVersion config) ++ "'"
when (cfgHLint config) $ tellStrLns
[ sh $ "if [ $HCNUMVER -eq 80403 ]; then cabal new-install -w ${HC} -j2 --symlink-bindir=$HOME/.local/bin hlint" ++ hlintVersionConstraint ++ "; fi"
| isAnyVersion (cfgHLintVersion hlintConfig) = ""
| otherwise = " --constraint='hlint " ++ display (cfgHLintVersion hlintConfig) ++ "'"
when (cfgHLintEnabled hlintConfig) $ tellStrLns
[ sh $ "if [ $HCNUMVER -eq " ++ hlintJobVersion versions (cfgHLintJob hlintConfig) ++ " ]; then cabal new-install -w ${HC} -j2 --symlink-bindir=$HOME/.local/bin hlint" ++ hlintVersionConstraint ++ "; fi"
]

-- create cabal.project file
Expand Down Expand Up @@ -948,15 +949,15 @@ genTravisFromConfigs (argv,opts) xpkgs isCabalProject config prj@Project { prjPa
]
tellStrLns [ "" ]

when (cfgHLint config) $ do
when (cfgHLintEnabled hlintConfig) $ do
let "" <+> ys = ys
xs <+> "" = xs
xs <+> ys = xs ++ " " ++ ys

prependSpace "" = ""
prependSpace xs = " " ++ xs

let hlintOptions = prependSpace $ maybe "" ("-h ${ROOTDIR}/" ++) (cfgHLintYaml config) <+> unwords (cfgHLintOptions config)
let hlintOptions = prependSpace $ maybe "" ("-h ${ROOTDIR}/" ++) (cfgHLintYaml hlintConfig) <+> unwords (cfgHLintOptions hlintConfig)

tellStrLns [ comment "hlint" ]
foldedTellStrLns FoldHLint "HLint.." folds $ do
Expand Down Expand Up @@ -1040,6 +1041,9 @@ genTravisFromConfigs (argv,opts) xpkgs isCabalProject config prj@Project { prjPa

return ()
where
doctestConfig = cfgDoctest config
hlintConfig = cfgHLint config

hasTests = F.any (\Pkg{pkgGpd} -> not . null $ condTestSuites pkgGpd) pkgs
hasLibrary = F.any (\Pkg{pkgGpd} -> isJust $ condLibrary pkgGpd) pkgs

Expand Down Expand Up @@ -1172,6 +1176,23 @@ collToGhcVer cid = case simpleParse cid of
| isPrefixOf [7] v -> mkVersion [8,0,1]
| otherwise -> error ("unknown collection " ++ show cid)

-------------------------------------------------------------------------------
-- HLint
-------------------------------------------------------------------------------

hlintJobVersion :: Set (Maybe Version) -> HLintJob -> String
hlintJobVersion vs HLintJobLatest = case S.maxView vs of
Just (Just v, _) -> ghcVersionToString v
_ -> "80603" -- it really doesn't matter, if there are no jobs
hlintJobVersion _ (HLintJob v) = ghcVersionToString v

ghcVersionToString :: Version -> String
ghcVersionToString v = case versionNumbers v of
[] -> "0"
[x] -> show (x * 10000)
[x,y] -> show (x * 10000 + y * 100)
(x:y:z:_) -> show (x * 10000 + y * 100 + z)

-------------------------------------------------------------------------------
-- Jobs
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -1356,16 +1377,16 @@ options =
(reqArgReadP parse (set $ #cfgDoctest . #cfgDoctestVersion) "VERSION")
"Doctest version range"
, Option ['l'] ["hlint"]
(NoArg $ successCM $ \cfg -> cfg { cfgHLint = True })
(NoArg $ successCM $ set (#cfgHLint . #cfgHLintEnabled) True)
"Run hlint (only on GHC-8.4.3 target)"
, Option [] ["hlint-yaml"]
(ReqArg (successCM' $ \arg cfg -> cfg { cfgHLintYaml = Just arg }) "HLINT.YAML")
(ReqArg (successCM' $ set (#cfgHLint . #cfgHLintYaml) . Just) "HLINT.YAML")
"Relative path to .hlint.yaml."
, Option [] ["hlint-options"]
(reqArgReadP parseOptsQ (\xs cfg -> cfg { cfgHLintOptions = xs }) "OPTIONS")
(reqArgReadP parseOptsQ (set $ #cfgHLint . #cfgHLintOptions) "OPTIONS")
"Additional hlint options."
, Option [] ["hlint-version"]
(reqArgReadP parse (\arg cfg -> cfg { cfgHLintVersion = arg }) "VERSION")
(reqArgReadP parse (set $ #cfgHLint . #cfgHLintVersion) "VERSION")
"HLint version range"
, Option [] ["cabal-install-version"]
(reqArgReadP parse (\arg cfg -> cfg { cfgCabalInstallVersion = Just arg }) "VERSION")
Expand Down Expand Up @@ -1478,19 +1499,23 @@ configFieldDescrs =
cfgJobs
(\x cfg -> cfg { cfgJobs = x })
, PU.boolField "hlint"
cfgHLint
(\b cfg -> cfg { cfgHLint = b })
(view $ #cfgHLint . #cfgHLintEnabled)
(set $ #cfgHLint . #cfgHLintEnabled)
, PU.simpleField "hlint-yaml"
(error "we don't pretty print")
(fmap Just PU.parseFilePathQ)
cfgHLintYaml
(\x cfg -> cfg { cfgHLintYaml = x })
(view $ #cfgHLint . #cfgHLintYaml)
(set $ #cfgHLint . #cfgHLintYaml)
, PU.simpleField "hlint-version"
(error "we don't pretty print")
parse
cfgHLintVersion
(\x cfg -> cfg { cfgHLintVersion = x })
-- TODO: hlint-options
(view $ #cfgHLint . #cfgHLintVersion)
(set $ #cfgHLint . #cfgHLintVersion)
, PU.simpleField "hlint-options"
(error "we don't pretty print")
parseOptsQ
(view $ #cfgHLint . #cfgHLintOptions)
(set $ #cfgHLint . #cfgHLintOptions)
, PU.boolField "doctest"
(view $ #cfgDoctest . #cfgDoctestEnabled)
(set $ #cfgDoctest . #cfgDoctestEnabled)
Expand Down Expand Up @@ -1637,11 +1662,7 @@ ghcVersionPredicate = conj . asVersionIntervals
upper v InclusiveBound = "[ $HCNUMVER -le " ++ f v ++ " ]"
upper v ExclusiveBound = "[ $HCNUMVER -lt " ++ f v ++ " ]"

f v = case versionNumbers v of
[] -> "0"
[x] -> show (x * 10000)
[x,y] -> show (x * 10000 + y * 100)
(x:y:z:_) -> show (x * 10000 + y * 100 + z)
f = ghcVersionToString

-------------------------------------------------------------------------------
-- From Cabal
Expand Down
35 changes: 13 additions & 22 deletions src/HaskellCI/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import GHC.Generics (Generic)
import qualified Data.Set as S
import qualified Data.Map as M

import HaskellCI.Config.Doctest
import HaskellCI.Config.HLint

data Fold
= FoldSDist
| FoldUnpack
Expand All @@ -32,22 +35,12 @@ data ConstraintSet = ConstraintSet
emptyConstraintSet :: String -> ConstraintSet
emptyConstraintSet n = ConstraintSet n anyVersion []

data DoctestConfig = DoctestConfig
{ cfgDoctestEnabled :: !Bool
, cfgDoctestOptions :: [String]
, cfgDoctestVersion :: !VersionRange
}
deriving (Show, Generic)

-- TODO: split other blocks like DoctestConfig
data Config = Config
{ cfgCabalInstallVersion :: Maybe Version
, cfgHLint :: !Bool
, cfgHLintYaml :: !(Maybe FilePath)
, cfgHLintVersion :: !VersionRange
, cfgHLintOptions :: [String]
, cfgJobs :: (Maybe Int, Maybe Int)
, cfgDoctest :: !DoctestConfig
, cfgHLint :: !HLintConfig
, cfgLocalGhcOptions :: [String]
, cfgConstraintSets :: [ConstraintSet]
, cfgCache :: !Bool
Expand All @@ -70,15 +63,18 @@ data Config = Config
emptyConfig :: Config
emptyConfig = Config
{ cfgCabalInstallVersion = Nothing
, cfgHLint = False
, cfgHLintYaml = Nothing
, cfgHLintVersion = defaultHLintVersion
, cfgHLintOptions = []
, cfgJobs = (Nothing, Nothing)
, cfgDoctest = DoctestConfig
{ cfgDoctestEnabled = False
, cfgDoctestOptions = []
, cfgDoctestVersion = defaultDoctestVersion
, cfgDoctestOptions = []
, cfgDoctestVersion = defaultDoctestVersion
}
, cfgHLint = HLintConfig
{ cfgHLintEnabled = False
, cfgHLintJob = HLintJobLatest
, cfgHLintYaml = Nothing
, cfgHLintVersion = defaultHLintVersion
, cfgHLintOptions = []
}
, cfgLocalGhcOptions = []
, cfgConstraintSets = []
Expand All @@ -98,8 +94,3 @@ emptyConfig = Config
, cfgLastInSeries = False
}

defaultHLintVersion :: VersionRange
defaultHLintVersion = withinVersion (mkVersion [2,1])

defaultDoctestVersion :: VersionRange
defaultDoctestVersion = withinVersion (mkVersion [0,16])
15 changes: 15 additions & 0 deletions src/HaskellCI/Config/Doctest.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{-# LANGUAGE DeriveGeneric #-}
module HaskellCI.Config.Doctest where

import Distribution.Version
import GHC.Generics (Generic)

data DoctestConfig = DoctestConfig
{ cfgDoctestEnabled :: !Bool
, cfgDoctestOptions :: [String]
, cfgDoctestVersion :: !VersionRange
}
deriving (Show, Generic)

defaultDoctestVersion :: VersionRange
defaultDoctestVersion = withinVersion (mkVersion [0,16])
22 changes: 22 additions & 0 deletions src/HaskellCI/Config/HLint.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{-# LANGUAGE DeriveGeneric #-}
module HaskellCI.Config.HLint where

import Distribution.Version
import GHC.Generics (Generic)

data HLintJob
= HLintJobLatest -- ^ run with latest GHC
| HLintJob Version -- ^ run with specified GHC version
deriving Show

data HLintConfig = HLintConfig
{ cfgHLintEnabled :: !Bool
, cfgHLintJob :: !HLintJob
, cfgHLintYaml :: !(Maybe FilePath)
, cfgHLintVersion :: !VersionRange
, cfgHLintOptions :: [String]
}
deriving (Show, Generic)

defaultHLintVersion :: VersionRange
defaultHLintVersion = withinVersion (mkVersion [2,1])

0 comments on commit 1126bb1

Please sign in to comment.