|
| 1 | +{-# LANGUAGE ConstraintKinds #-} |
| 2 | +{-# LANGUAGE DataKinds #-} |
| 3 | +{-# LANGUAGE FlexibleInstances #-} |
| 4 | +{-# LANGUAGE MultiParamTypeClasses #-} |
| 5 | +{-# LANGUAGE OverloadedStrings #-} |
| 6 | +{-# LANGUAGE TypeApplications #-} |
| 7 | +module HaskellCI.Config.Grammar where |
| 8 | + |
| 9 | +import HaskellCI.Prelude |
| 10 | + |
| 11 | +import qualified Data.Map as M |
| 12 | +import qualified Distribution.Compat.CharParsing as C |
| 13 | +import qualified Distribution.Compat.Newtype as C |
| 14 | +import qualified Distribution.FieldGrammar as C |
| 15 | +import qualified Distribution.Parsec as C |
| 16 | +import qualified Distribution.Pretty as C |
| 17 | +import qualified Text.PrettyPrint as PP |
| 18 | + |
| 19 | +import HaskellCI.Config.Components |
| 20 | +import HaskellCI.Config.CopyFields |
| 21 | +import HaskellCI.Config.Docspec |
| 22 | +import HaskellCI.Config.Doctest |
| 23 | +import HaskellCI.Config.History |
| 24 | +import HaskellCI.Config.Installed |
| 25 | +import HaskellCI.Config.Jobs |
| 26 | +import HaskellCI.Config.PackageScope |
| 27 | +import HaskellCI.Config.Type |
| 28 | +import HaskellCI.Config.Ubuntu |
| 29 | +import HaskellCI.GrammarDefault |
| 30 | +import HaskellCI.Newtypes |
| 31 | +import HaskellCI.OptionsGrammar |
| 32 | +import HaskellCI.TestedWith |
| 33 | + |
| 34 | +------------------------------------------------------------------------------- |
| 35 | +-- Grammar |
| 36 | +------------------------------------------------------------------------------- |
| 37 | + |
| 38 | +configGrammar |
| 39 | + :: ( OptionsGrammar c g |
| 40 | + , c Components |
| 41 | + , c CopyFields |
| 42 | + , c CopyFields |
| 43 | + , c Env |
| 44 | + , c HeadVersion |
| 45 | + , c Jobs |
| 46 | + , c Natural |
| 47 | + , c PackageScope |
| 48 | + , c TestedWithJobs |
| 49 | + , c Ubuntu |
| 50 | + , c Version |
| 51 | + , c (C.List C.FSep (Identity Installed) Installed) |
| 52 | + , Applicative (g DoctestConfig) |
| 53 | + , Applicative (g DocspecConfig) |
| 54 | + ) |
| 55 | + => g Config Config |
| 56 | +configGrammar = Config |
| 57 | + <$> optionalFieldDefAla "cabal-install-version" HeadVersion (field @"cfgCabalInstallVersion") defaultConfig |
| 58 | + ^^^ metahelp "VERSION" "cabal-install version for all jobs" |
| 59 | + <*> optionalField "jobs" (field @"cfgJobs") |
| 60 | + ^^^ metahelp "JOBS" "jobs (N:M - cabal:ghc)" |
| 61 | + <*> optionalFieldDef "distribution" (field @"cfgUbuntu") defaultConfig |
| 62 | + ^^^ metahelp "DIST" (concat |
| 63 | + [ "distribution version (" |
| 64 | + , intercalate ", " $ map showUbuntu [minBound..maxBound] |
| 65 | + , ")" |
| 66 | + ]) |
| 67 | + <*> optionalFieldDef "jobs-selection" (field @"cfgTestedWith") defaultConfig |
| 68 | + ^^^ metahelp "uniform|any" "Jobs selection across packages" |
| 69 | + <*> rangeField "enabled" (field @"cfgEnabledJobs") defaultConfig |
| 70 | + ^^^ metahelp "RANGE" "Restrict jobs selection futher from per package tested-with" |
| 71 | + <*> optionalFieldDef "copy-fields" (field @"cfgCopyFields") defaultConfig |
| 72 | + ^^^ metahelp "none|some|all" "Copy ? fields from cabal.project fields" |
| 73 | + <*> monoidalFieldAla "local-ghc-options" (C.alaList' C.NoCommaFSep C.Token') (field @"cfgLocalGhcOptions") |
| 74 | + ^^^ metahelp "OPTS" "--ghc-options for local packages" |
| 75 | + <*> booleanFieldDef "submodules" (field @"cfgSubmodules") defaultConfig |
| 76 | + ^^^ help "Clone submodules, i.e. recursively" |
| 77 | + <*> booleanFieldDef "cache" (field @"cfgCache") defaultConfig |
| 78 | + ^^^ help "Disable caching" |
| 79 | + <*> booleanFieldDef "install-dependencies" (field @"cfgInstallDeps") defaultConfig |
| 80 | + ^^^ help "Skip separate dependency installation step" |
| 81 | + <*> monoidalFieldAla "installed" (C.alaList C.FSep) (field @"cfgInstalled") |
| 82 | + ^^^ metahelp "+/-PKG" "Specify 'constraint: ... installed' packages" |
| 83 | + <*> rangeField "tests" (field @"cfgTests") defaultConfig |
| 84 | + ^^^ metahelp "RANGE" "Build tests with" |
| 85 | + <*> rangeField "run-tests" (field @"cfgRunTests") defaultConfig |
| 86 | + ^^^ metahelp "RANGE" "Run tests with (note: only built tests are run)" |
| 87 | + <*> rangeField "benchmarks" (field @"cfgBenchmarks") defaultConfig |
| 88 | + ^^^ metahelp "RANGE" "Build benchmarks" |
| 89 | + <*> rangeField "haddock" (field @"cfgHaddock") defaultConfig |
| 90 | + ^^^ metahelp "RANGE" "Haddock step" |
| 91 | + <*> optionalFieldDef "haddock-components" (field @"cfgHaddockComponents") defaultConfig |
| 92 | + ^^^ metahelp "all|libs" "Haddock components" |
| 93 | + <*> rangeField "no-tests-no-benchmarks" (field @"cfgNoTestsNoBench") defaultConfig |
| 94 | + ^^^ metahelp "RANGE" "Build without tests and benchmarks" |
| 95 | + <*> rangeField "unconstrained" (field @"cfgUnconstrainted") defaultConfig |
| 96 | + ^^^ metahelp "RANGE" "Make unconstrained build" |
| 97 | + <*> rangeField "head-hackage" (field @"cfgHeadHackage") defaultConfig |
| 98 | + ^^^ metahelp "RANGE" "Use head.hackage repository. Also marks as allow-failures" |
| 99 | + <*> booleanFieldDef "head-hackage-override" (field @"cfgHeadHackageOverride") defaultConfig |
| 100 | + ^^^ help "Use :override for head.hackage repository" |
| 101 | + <*> booleanFieldDef "ghcjs-tests" (field @"cfgGhcjsTests") defaultConfig |
| 102 | + ^^^ help "Run tests with GHCJS (experimental, relies on cabal-plan finding test-suites)" |
| 103 | + <*> monoidalFieldAla "ghcjs-tools" (C.alaList C.FSep) (field @"cfgGhcjsTools") |
| 104 | +-- ^^^ metahelp "TOOL" "Additional host tools to install with GHCJS" |
| 105 | + <*> booleanFieldDef "test-output-direct" (field @"cfgTestOutputDirect") defaultConfig |
| 106 | + ^^^ help "Use --test-show-details=direct, may cause problems with build-type: Custom" |
| 107 | + <*> booleanFieldDef "cabal-check" (field @"cfgCheck") defaultConfig |
| 108 | + ^^^ help "Disable cabal check run" |
| 109 | + <*> monoidalFieldAla "branches" (C.alaList' C.FSep C.Token') (field @"cfgOnlyBranches") |
| 110 | + ^^^ metahelp "BRANCH" "Enable builds only for specific branches" |
| 111 | + <*> monoidalFieldAla "irc-channels" (C.alaList' C.FSep C.Token') (field @"cfgIrcChannels") |
| 112 | + ^^^ metahelp "IRC" "Enable IRC notifications to given channel (e.g. 'irc.libera.chat#haskell-lens')" |
| 113 | + <*> freeTextField "irc-nickname" (field @"cfgIrcNickname") |
| 114 | + ^^^ metahelp "NICKNAME" "Nickname with which to authenticate to an IRC server. Only used if `irc-channels` are set." |
| 115 | + <*> freeTextField "irc-password" (field @"cfgIrcPassword") |
| 116 | + ^^^ metahelp "PASSWORD" "Password with which to authenticate to an IRC server. Only used if `irc-channels` are set." |
| 117 | + <*> booleanFieldDef "irc-if-in-origin-repo" (field @"cfgIrcIfInOriginRepo") defaultConfig |
| 118 | + ^^^ help "Only send IRC notifications if run from the original remote (GitHub Actions only)" |
| 119 | + <*> booleanFieldDef "email-notifications" (field @"cfgEmailNotifications") defaultConfig |
| 120 | + ^^^ help "Disable email notifications" |
| 121 | + <*> optionalFieldAla "project-name" C.Token' (field @"cfgProjectName") |
| 122 | + ^^^ metahelp "NAME" "Project name (used for IRC notifications), defaults to package name or name of first package listed in cabal.project file" |
| 123 | + <*> booleanFieldDef "ghc-head" (field @"cfgGhcHead") defaultConfig |
| 124 | + ^^^ help "Add ghc-head job" |
| 125 | + <*> booleanFieldDef "postgresql" (field @"cfgPostgres") defaultConfig |
| 126 | + ^^^ help "Add postgresql service" |
| 127 | + <*> booleanFieldDef "google-chrome" (field @"cfgGoogleChrome") defaultConfig |
| 128 | + ^^^ help "Add google-chrome service" |
| 129 | + <*> monoidalFieldAla "env" Env (field @"cfgEnv") |
| 130 | + ^^^ metahelp "ENV" "Environment variables per job (e.g. `8.0.2:HADDOCK=false`)" |
| 131 | + <*> optionalFieldDefAla "allow-failures" Range (field @"cfgAllowFailures") defaultConfig |
| 132 | + ^^^ metahelp "JOB" "Allow failures of particular GHC version" |
| 133 | + <*> booleanFieldDef "last-in-series" (field @"cfgLastInSeries") defaultConfig |
| 134 | + ^^^ help "[Discouraged] Assume there are only GHCs last in major series: 8.2.* will match only 8.2.2" |
| 135 | + <*> rangeField "linux-jobs" (field @"cfgLinuxJobs") defaultConfig |
| 136 | + ^^^ metahelp "RANGE" "Jobs to build on Linux" |
| 137 | + <*> rangeField "macos-jobs" (field @"cfgMacosJobs") defaultConfig |
| 138 | + ^^^ metahelp "RANGE" "Jobs to additionally build with OSX" |
| 139 | + <*> booleanFieldDef "ghcup-cabal" (field @"cfgGhcupCabal") defaultConfig |
| 140 | + ^^^ help "Use (or don't) ghcup to install cabal" |
| 141 | + <*> rangeField "ghcup-jobs" (field @"cfgGhcupJobs") defaultConfig |
| 142 | + ^^^ metahelp "RANGE" "(Linux) jobs to use ghcup to install tools" |
| 143 | + <*> optionalFieldDef "ghcup-version" (field @"cfgGhcupVersion") defaultConfig |
| 144 | + ^^^ metahelp "VERSION" "ghcup version" |
| 145 | + <*> monoidalFieldAla "apt" (alaSet' C.NoCommaFSep C.Token') (field @"cfgApt") |
| 146 | + ^^^ metahelp "PKG" "Additional apt packages to install" |
| 147 | + <*> monoidalFieldAla "travis-patches" (C.alaList' C.NoCommaFSep C.Token') (field @"cfgTravisPatches") |
| 148 | + ^^^ metaActionHelp "PATCH" "file" ".patch files to apply to the generated Travis YAML file" |
| 149 | + <*> monoidalFieldAla "github-patches" (C.alaList' C.NoCommaFSep C.Token') (field @"cfgGitHubPatches") |
| 150 | + ^^^ metaActionHelp "PATCH" "file" ".patch files to apply to the generated GitHub Actions YAML file" |
| 151 | + <*> booleanFieldDef "insert-version" (field @"cfgInsertVersion") defaultConfig |
| 152 | + ^^^ help "Don't insert the haskell-ci version into the generated Travis YAML file" |
| 153 | + <*> optionalFieldDef "error-missing-methods" (field @"cfgErrorMissingMethods") defaultConfig |
| 154 | + ^^^ metahelp "PKGSCOPE" "Insert -Werror=missing-methods for package scope (none, local, all)" |
| 155 | + <*> C.blurFieldGrammar (field @"cfgDoctest") doctestConfigGrammar |
| 156 | + <*> C.blurFieldGrammar (field @"cfgDocspec") docspecConfigGrammar |
| 157 | + <*> pure [] -- constraint sets |
| 158 | + <*> pure [] -- raw project fields |
| 159 | + <*> freeTextFieldDef "raw-travis" (field @"cfgRawTravis") |
| 160 | + ^^^ help "Raw travis commands which will be run at the very end of the script" |
| 161 | + <*> freeTextField "github-action-name" (field @"cfgGitHubActionName") |
| 162 | + ^^^ help "The name of GitHub Action" |
| 163 | + <*> optionalFieldDef "timeout-minutes" (field @"cfgTimeoutMinutes") defaultConfig |
| 164 | + ^^^ metahelp "MINUTES" "The maximum number of minutes to let a job run" |
| 165 | + |
| 166 | +------------------------------------------------------------------------------- |
| 167 | +-- Env |
| 168 | +------------------------------------------------------------------------------- |
| 169 | + |
| 170 | +newtype Env = Env (M.Map Version String) |
| 171 | + deriving anyclass (C.Newtype (M.Map Version String)) |
| 172 | + |
| 173 | +instance C.Parsec Env where |
| 174 | + parsec = Env . M.fromList <$> C.parsecLeadingCommaList p where |
| 175 | + p = do |
| 176 | + v <- C.parsec |
| 177 | + _ <- C.char ':' |
| 178 | + s <- C.munch1 $ \c -> c /= ',' |
| 179 | + return (v, s) |
| 180 | + |
| 181 | +instance C.Pretty Env where |
| 182 | + pretty (Env m) = PP.fsep . PP.punctuate PP.comma . map p . M.toList $ m where |
| 183 | + p (v, s) = C.pretty v PP.<> PP.colon PP.<> PP.text s |
0 commit comments