From 1126bb10ff1c01786464ba59a7bd3e9d97e09798 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Sun, 10 Feb 2019 21:48:05 +0200 Subject: [PATCH] By default use latest GHC to run HLint --- haskell-ci.cabal | 2 + src/HaskellCI.hs | 67 ++++++++++++++++++++++----------- src/HaskellCI/Config.hs | 35 +++++++---------- src/HaskellCI/Config/Doctest.hs | 15 ++++++++ src/HaskellCI/Config/HLint.hs | 22 +++++++++++ 5 files changed, 96 insertions(+), 45 deletions(-) create mode 100644 src/HaskellCI/Config/Doctest.hs create mode 100644 src/HaskellCI/Config/HLint.hs diff --git a/haskell-ci.cabal b/haskell-ci.cabal index 538fa0ae..792b16be 100644 --- a/haskell-ci.cabal +++ b/haskell-ci.cabal @@ -63,6 +63,8 @@ library exposed-modules: HaskellCI HaskellCI.Config + HaskellCI.Config.Doctest + HaskellCI.Config.HLint HaskellCI.Glob ghc-options: diff --git a/src/HaskellCI.hs b/src/HaskellCI.hs index 38d14422..0f43ea65 100644 --- a/src/HaskellCI.hs +++ b/src/HaskellCI.hs @@ -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)) @@ -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) ++ "'" @@ -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 @@ -948,7 +949,7 @@ 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 @@ -956,7 +957,7 @@ genTravisFromConfigs (argv,opts) xpkgs isCabalProject config prj@Project { prjPa 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 @@ -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 @@ -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 ------------------------------------------------------------------------------- @@ -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") @@ -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) @@ -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 diff --git a/src/HaskellCI/Config.hs b/src/HaskellCI/Config.hs index 03ee672d..1b39fb04 100644 --- a/src/HaskellCI/Config.hs +++ b/src/HaskellCI/Config.hs @@ -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 @@ -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 @@ -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 = [] @@ -98,8 +94,3 @@ emptyConfig = Config , cfgLastInSeries = False } -defaultHLintVersion :: VersionRange -defaultHLintVersion = withinVersion (mkVersion [2,1]) - -defaultDoctestVersion :: VersionRange -defaultDoctestVersion = withinVersion (mkVersion [0,16]) diff --git a/src/HaskellCI/Config/Doctest.hs b/src/HaskellCI/Config/Doctest.hs new file mode 100644 index 00000000..49b9b525 --- /dev/null +++ b/src/HaskellCI/Config/Doctest.hs @@ -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]) diff --git a/src/HaskellCI/Config/HLint.hs b/src/HaskellCI/Config/HLint.hs new file mode 100644 index 00000000..f104a086 --- /dev/null +++ b/src/HaskellCI/Config/HLint.hs @@ -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])