Skip to content

Commit 21a49fb

Browse files
authored
Merge pull request #613 from haskell-CI/haddock-components
Configurable haddock components
2 parents 2bfa685 + 9125f92 commit 21a49fb

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

haskell-ci.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: haskell-ci
3-
version: 0.15.20220821
3+
version: 0.15.20220822
44
synopsis: Cabal package script generator for Travis-CI
55
description:
66
Script generator (@haskell-ci@) for
@@ -84,6 +84,7 @@ library haskell-ci-internal
8484
HaskellCI.Cli
8585
HaskellCI.Compiler
8686
HaskellCI.Config
87+
HaskellCI.Config.Components
8788
HaskellCI.Config.ConstraintSet
8889
HaskellCI.Config.CopyFields
8990
HaskellCI.Config.Docspec

src/HaskellCI/Auxiliary.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import Cabal.Project
2727
import Cabal.SourceRepo
2828
import HaskellCI.Compiler
2929
import HaskellCI.Config
30+
import HaskellCI.Config.Components
3031
import HaskellCI.Config.CopyFields
3132
import HaskellCI.Config.Docspec
3233
import HaskellCI.Config.Doctest
@@ -46,6 +47,8 @@ data Auxiliary = Auxiliary
4647
, extraCabalProjectFields :: FilePath -> [C.PrettyField ()]
4748
, testShowDetails :: String
4849
, anyJobUsesHeadHackage :: Bool
50+
, runHaddock :: Bool
51+
, haddockFlags :: String
4952
}
5053

5154
auxiliary :: Config -> Project URI Void Package -> JobVersions -> Auxiliary
@@ -72,6 +75,15 @@ auxiliary Config {..} prj JobVersions {..} = Auxiliary {..}
7275

7376
hasLibrary = any (\Pkg{pkgGpd} -> isJust $ C.condLibrary pkgGpd) pkgs
7477

78+
runHaddock = not (equivVersionRanges C.noVersion cfgHaddock)
79+
&& case cfgHaddockComponents of
80+
ComponentsAll -> True
81+
ComponentsLibs -> hasLibrary
82+
83+
haddockFlags = case cfgHaddockComponents of
84+
ComponentsAll -> " --haddock-all"
85+
ComponentsLibs -> ""
86+
7587
extraCabalProjectFields :: FilePath -> [C.PrettyField ()]
7688
extraCabalProjectFields rootdir = buildList $ do
7789
-- generate package fields for URI packages.

src/HaskellCI/Config.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import qualified Distribution.Types.Version as C
2323
import qualified Distribution.Types.VersionRange as C
2424
import qualified Text.PrettyPrint as PP
2525

26+
import HaskellCI.Config.Components
2627
import HaskellCI.Config.ConstraintSet
2728
import HaskellCI.Config.CopyFields
2829
import HaskellCI.Config.Docspec
@@ -61,6 +62,7 @@ data Config = Config
6162
, cfgRunTests :: !VersionRange
6263
, cfgBenchmarks :: !VersionRange
6364
, cfgHaddock :: !VersionRange
65+
, cfgHaddockComponents :: !Components
6466
, cfgNoTestsNoBench :: !VersionRange
6567
, cfgUnconstrainted :: !VersionRange
6668
, cfgHeadHackage :: !VersionRange
@@ -129,6 +131,7 @@ configGrammar
129131
, c (Identity CopyFields)
130132
, c (Identity Version)
131133
, c (Identity Natural)
134+
, c (Identity Components)
132135
, c Env, c Folds, c CopyFields, c HeadVersion
133136
, c (C.List C.FSep (Identity Installed) Installed)
134137
, Applicative (g DoctestConfig)
@@ -170,6 +173,8 @@ configGrammar = Config
170173
^^^ metahelp "RANGE" "Build benchmarks"
171174
<*> rangeField "haddock" (field @"cfgHaddock") anyVersion
172175
^^^ metahelp "RANGE" "Haddock step"
176+
<*> C.optionalFieldDef "haddock-components" (field @"cfgHaddockComponents") ComponentsAll
177+
^^^ metahelp "all|libs" "Haddock components"
173178
<*> rangeField "no-tests-no-benchmarks" (field @"cfgNoTestsNoBench") anyVersion
174179
^^^ metahelp "RANGE" "Build without tests and benchmarks"
175180
<*> rangeField "unconstrained" (field @"cfgUnconstrainted") anyVersion

src/HaskellCI/Config/Components.hs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module HaskellCI.Config.Components where
2+
3+
import HaskellCI.Prelude
4+
5+
import qualified Distribution.Compat.CharParsing as C
6+
import qualified Distribution.Parsec as C
7+
import qualified Distribution.Pretty as C
8+
import qualified Text.PrettyPrint as PP
9+
10+
-------------------------------------------------------------------------------
11+
-- Single action
12+
-------------------------------------------------------------------------------
13+
14+
data Components
15+
= ComponentsAll
16+
| ComponentsLibs
17+
deriving (Eq, Show)
18+
19+
instance C.Pretty Components where
20+
pretty ComponentsAll = PP.text "all"
21+
pretty ComponentsLibs = PP.text "libs"
22+
23+
instance C.Parsec Components where
24+
parsec = do
25+
t <- C.parsecToken
26+
case t of
27+
"all" -> return ComponentsAll
28+
"libs" -> return ComponentsLibs
29+
_ -> C.unexpected $ "Component " ++ t

src/HaskellCI/GitHub.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,9 @@ makeGitHub _argv config@Config {..} gitconfig prj jobs@JobVersions {..} = do
563563
sh_if range "${CABAL} -vnormal check"
564564

565565
-- haddock
566-
when (not (equivVersionRanges C.noVersion cfgHaddock)) $ githubRun "haddock" $ do
566+
when runHaddock $ githubRun "haddock" $ do
567567
let range = RangeGHC /\ Range cfgHaddock
568-
sh_if range "$CABAL v2-haddock --haddock-all $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all"
568+
sh_if range $ "$CABAL v2-haddock" ++ haddockFlags ++ " $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all"
569569

570570
-- unconstrained build
571571
unless (equivVersionRanges C.noVersion cfgUnconstrainted) $ githubRun "unconstrained build" $ do
@@ -596,7 +596,7 @@ makeGitHub _argv config@Config {..} gitconfig prj jobs@JobVersions {..} = do
596596
when (csRunTests cs) $
597597
sh_cs' hasTests $ "$CABAL v2-test $ARG_COMPILER " ++ allFlags ++ " all"
598598
when (csHaddock cs) $
599-
sh_cs $ "$CABAL v2-haddock --haddock-all $ARG_COMPILER " ++ withHaddock ++ " " ++ allFlags ++ " all"
599+
sh_cs $ "$CABAL v2-haddock" ++ haddockFlags ++ " $ARG_COMPILER " ++ withHaddock ++ " " ++ allFlags ++ " all"
600600

601601
-- assembling everything
602602
return GitHub

0 commit comments

Comments
 (0)