Skip to content

Commit

Permalink
Merge pull request #245 from haskell-CI/issues-182-236
Browse files Browse the repository at this point in the history
Fix #182 and #236
  • Loading branch information
phadej authored Mar 7, 2019
2 parents 6a94361 + 66dfee8 commit e7cc74a
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 48 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ script:

# build & run tests, build benchmarks
- ${CABAL} new-build -w ${HC} ${TEST} ${BENCH} all
- if [ "x$TEST" = "x--enable-tests" ]; then ${CABAL} new-test -w ${HC} ${TEST} ${BENCH} all; fi
- ${CABAL} new-test -w ${HC} ${TEST} ${BENCH} all

# doctest
- (cd haskell-ci-* && doctest --fast -XDeriveFoldable -XDeriveFunctor -XDeriveGeneric -XDeriveTraversable src)
Expand All @@ -164,11 +164,10 @@ script:

# Constraint sets
- rm -rf cabal.project.local

# Constraint set deepseq-1.4
- echo Constraint set deepseq-1.4 && echo -en 'travis_fold:start:constraint-sets-deepseq-1.4\\r'
- if [ $HCNUMVER -ge 70800 ] && [ $HCNUMVER -lt 71000 ] || [ $HCNUMVER -eq 80202 ] ; then ${CABAL} new-build -w ${HC} --disable-tests --disable-benchmarks --constraint='deepseq ==1.4.*' all ; fi

- if [ $HCNUMVER -ge 70800 ] && [ $HCNUMVER -lt 71000 ] || [ $HCNUMVER -eq 80202 ] ; then ${CABAL} v2-build -w ${HC} --disable-tests --disable-benchmarks --constraint='deepseq ==1.4.*' --constraint='binary installed' all ; fi
- if [ $HCNUMVER -ge 70800 ] && [ $HCNUMVER -lt 71000 ] || [ $HCNUMVER -eq 80202 ] ; then ${CABAL} v2-haddock -w ${HC} --disable-tests --disable-benchmarks --constraint='deepseq ==1.4.*' --constraint='binary installed' all ; fi
- echo -en 'travis_fold:end:constraint-sets-deepseq-1.4\\r'

# REGENDATA ["--output=.travis.yml","--config=cabal.haskell-ci","haskell-ci.cabal"]
Expand Down
24 changes: 24 additions & 0 deletions cabal.haskell-ci
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ ghc-head: True
-- remove cabal noise from test output
-- cabal-noise: False

-- Build tests. In addition to True and False you may specify
-- a version range, e.g. >= 8.0 to build tests only in some jobs.
tests: True

-- Run tests. Note that only built tests are run. Accepts booleans or version range.
run-tests: True

-- Build benchmarks. There are no way to run benchmarks. Accepts booleans or version range.
benchmarks: True

-- Build haddocks. Accepts booleans or version range.
haddock: True

-- Run cabal check
-- cabal-check: True

Expand Down Expand Up @@ -60,6 +73,17 @@ osx: 8.4.4
constraint-set deepseq-1.4
ghc: (>= 7.8 && <7.10) || == 8.2.2
constraints: deepseq ==1.4.*
constraints: binary installed

-- Constraint sets accept booleans for few steps, as the main script
-- Defaults are False.
-- These fields don't accept version ranges: you should rather create
-- another constraint set.

-- tests: False
-- run-tests: False
-- benchmarks: False
haddock: True

-- Copy over additional properties specified in a cabal.project file.
-- Possible values are:
Expand Down
2 changes: 1 addition & 1 deletion fixtures/cabal.project.copy-fields.all.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ script:

# build & run tests, build benchmarks
- ${CABAL} new-build -w ${HC} ${TEST} ${BENCH} all
- if [ "x$TEST" = "x--enable-tests" ]; then ${CABAL} new-test -w ${HC} ${TEST} ${BENCH} all; fi
- ${CABAL} new-test -w ${HC} ${TEST} ${BENCH} all

# cabal check
- (cd servant-* && ${CABAL} check)
Expand Down
2 changes: 1 addition & 1 deletion fixtures/cabal.project.copy-fields.none.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ script:

# build & run tests, build benchmarks
- ${CABAL} new-build -w ${HC} ${TEST} ${BENCH} all
- if [ "x$TEST" = "x--enable-tests" ]; then ${CABAL} new-test -w ${HC} ${TEST} ${BENCH} all; fi
- ${CABAL} new-test -w ${HC} ${TEST} ${BENCH} all

# cabal check
- (cd servant-* && ${CABAL} check)
Expand Down
2 changes: 1 addition & 1 deletion fixtures/cabal.project.copy-fields.some.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ script:

# build & run tests, build benchmarks
- ${CABAL} new-build -w ${HC} ${TEST} ${BENCH} all
- if [ "x$TEST" = "x--enable-tests" ]; then ${CABAL} new-test -w ${HC} ${TEST} ${BENCH} all; fi
- ${CABAL} new-test -w ${HC} ${TEST} ${BENCH} all

# cabal check
- (cd servant-* && ${CABAL} check)
Expand Down
2 changes: 1 addition & 1 deletion fixtures/cabal.project.empty-line.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ script:

# build & run tests, build benchmarks
- ${CABAL} new-build -w ${HC} ${TEST} ${BENCH} all
- if [ "x$TEST" = "x--enable-tests" ]; then ${CABAL} new-test -w ${HC} ${TEST} ${BENCH} all; fi
- ${CABAL} new-test -w ${HC} ${TEST} ${BENCH} all

# cabal check
- (cd servant-* && ${CABAL} check)
Expand Down
2 changes: 1 addition & 1 deletion fixtures/cabal.project.messy.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ script:

# build & run tests, build benchmarks
- ${CABAL} new-build -w ${HC} ${TEST} ${BENCH} all
- if [ "x$TEST" = "x--enable-tests" ]; then ${CABAL} new-test -w ${HC} ${TEST} ${BENCH} all; fi
- ${CABAL} new-test -w ${HC} ${TEST} ${BENCH} all

# cabal check
- (cd servant-* && ${CABAL} check)
Expand Down
63 changes: 26 additions & 37 deletions src/HaskellCI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -659,20 +659,17 @@ genTravisFromConfigs argv opts isCabalProject config prj@Project { prjPackages =
]

-- cabal new-test fails if there are no test-suites.
when hasTests $
foldedTellStrLns FoldTest "Testing..." folds $ tellStrLns
[ sh $ mconcat
[ "if [ \"x$TEST\" = \"x--enable-tests\" ]; then "
, if cfgNoise config
then "${CABAL} "
else "(set -o pipefail; ${CABAL} -vnormal+nowrap+markoutput "
, "new-test -w ${HC} ${TEST} ${BENCH} all"
, if cfgNoise config
then ""
else " 2>&1 | sed '/^-----BEGIN CABAL OUTPUT-----$/,/^-----END CABAL OUTPUT-----$/d' )"
, "; fi"
]
when hasTests $ foldedTellStrLns FoldTest "Testing..." folds $ tellStrLns
[ shForJob versions' (C.intersectVersionRanges (cfgTests config) (cfgRunTests config)) $ mconcat
[ if cfgNoise config
then "${CABAL} "
else "(set -o pipefail; ${CABAL} -vnormal+nowrap+markoutput "
, "new-test -w ${HC} ${TEST} ${BENCH} all"
, if cfgNoise config
then ""
else " 2>&1 | sed '/^-----BEGIN CABAL OUTPUT-----$/,/^-----END CABAL OUTPUT-----$/d' )"
]
]

tellStrLns [""]

Expand Down Expand Up @@ -727,21 +724,6 @@ genTravisFromConfigs argv opts isCabalProject config prj@Project { prjPackages =
, ""
]

unless (null colls) $
foldedTellStrLns FoldStackage "Stackage builds..." folds $ tellStrLnsRaw
[ " # try building & testing for package collections"
, " - for COLL in \"${COLLS[@]}\"; do"
, " echo \"== collection $COLL ==\";"
, " ghc-travis collection ${COLL} > /dev/null || break;"
, " ghc-travis collection ${COLL} | " ++ pkgFilter ++ " > cabal.project.freeze;"
, " grep ' collection-id' cabal.project.freeze;"
, " rm -rf dist-newstyle/;"
, " ${CABAL} new-build -w ${HC} ${TEST} ${BENCH} all || break;"
, " if [ \"x$TEST\" = \"x--enable-tests\" ]; then ${CABAL} new-test -w ${HC} ${TEST} ${BENCH} all || break; fi;"
, " done"
, ""
]

-- Have to build last, as we remove cabal.project.local
unless (equivVersionRanges noVersion $ cfgUnconstrainted config) $ foldedTellStrLns FoldBuildInstalled
"Building without installed constraints for packages in global-db..." folds $ tellStrLns
Expand All @@ -757,18 +739,25 @@ genTravisFromConfigs argv opts isCabalProject config prj@Project { prjPackages =
tellStrLns
[ comment "Constraint sets"
, sh "rm -rf cabal.project.local"
, ""
]
forM_ constraintSets $ \cs -> do
let name = csName cs
let constraintFlags = concatMap (\x -> " --constraint='" ++ x ++ "'") (csConstraints cs)
let cmd | csRunTests cs = "${CABAL} new-test -w ${HC} --enable-tests --enable-benchmarks"
| otherwise = "${CABAL} new-build -w ${HC} --disable-tests --disable-benchmarks"
tellStrLns [ comment $ "Constraint set " ++ name ]

let shForCs = shForJob versions' (csGhcVersions cs)
let testFlag = if csTests cs then "--enable-tests" else "--disable-tests"
let benchFlag = if csBenchmarks cs then "--enable-benchmarks" else "--disable-benchmarks"
let constraintFlags = map (\x -> "--constraint='" ++ x ++ "'") (csConstraints cs)
let allFlags = unwords (testFlag : benchFlag : constraintFlags)

foldedTellStrLns' FoldConstraintSets name ("Constraint set " ++ name) folds $ tellStrLns
[ shForJob versions' (csGhcVersions cs) $
cmd ++ " " ++ constraintFlags ++ " all"
, ""
[ shForCs $ "${CABAL} v2-build -w ${HC} " ++ allFlags ++ " all"
, if csRunTests cs
then shForCs $ "${CABAL} v2-test -w ${HC} " ++ allFlags ++ " all"
else RowSkip
, if csHaddock cs
then shForCs $ "${CABAL} v2-haddock -w ${HC} " ++ allFlags ++ " all"
else RowSkip
]
tellStrLns [""]

Expand Down Expand Up @@ -971,7 +960,7 @@ doctestJobVersionRange = orLaterVersion $ mkVersion [8,0]
-- /Note:/ same argument work for hlint too, but not exactly
--
doctestArgs :: GenericPackageDescription -> [[String]]
doctestArgs gpd =
doctestArgs gpd = nub $
[ libraryModuleArgs c
| c <- flattenPackageDescription gpd ^.. L.library . traverse
] ++
Expand Down Expand Up @@ -1017,7 +1006,7 @@ hlintJobVersionRange vs HLintJobLatest = case S.maxView vs of
hlintJobVersionRange _ (HLintJob v) = thisVersion v

hlintArgs :: GenericPackageDescription -> [[String]]
hlintArgs gpd =
hlintArgs gpd = nub $
[ libraryModuleArgs c
| c <- flattenPackageDescription gpd ^.. L.library . traverse
] ++
Expand Down
6 changes: 5 additions & 1 deletion src/HaskellCI/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ data Config = Config
, cfgInstallDeps :: !Bool
, cfgInstalled :: [Installed]
, cfgTests :: !VersionRange
, cfgRunTests :: !VersionRange
, cfgBenchmarks :: !VersionRange
, cfgHaddock :: !VersionRange
, cfgNoTestsNoBench :: !VersionRange
Expand Down Expand Up @@ -106,6 +107,7 @@ emptyConfig = Config
, cfgInstalled = []
, cfgInstallDeps = True
, cfgTests = anyVersion
, cfgRunTests = anyVersion
, cfgBenchmarks = anyVersion
, cfgHaddock = anyVersion
, cfgNoTestsNoBench = anyVersion
Expand Down Expand Up @@ -152,7 +154,9 @@ configGrammar = Config
<*> C.monoidalFieldAla "installed" (C.alaList C.FSep) #cfgInstalled
^^^ metahelp "+/-PKG" "Specify 'constraint: ... installed' packages"
<*> rangeField "tests" #cfgTests anyVersion
^^^ metahelp "RANGE" "Build and run tests with"
^^^ metahelp "RANGE" "Build tests with"
<*> rangeField "run-tests" #cfgRunTests anyVersion
^^^ metahelp "RANGE" "Run tests with (note: only built tests are run)"
<*> rangeField "benchmarks" #cfgBenchmarks anyVersion
^^^ metahelp "RANGE" "Build benchmarks"
<*> rangeField "haddock" #cfgHaddock anyVersion
Expand Down
8 changes: 7 additions & 1 deletion src/HaskellCI/Config/ConstraintSet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ data ConstraintSet = ConstraintSet
{ csName :: String
, csGhcVersions :: VersionRange
, csConstraints :: [String] -- we parse these simply as strings
, csTests :: Bool
, csRunTests :: Bool
, csBenchmarks :: Bool
, csHaddock :: Bool
}
deriving (Show, Generic)

emptyConstraintSet :: String -> ConstraintSet
emptyConstraintSet n = ConstraintSet n anyVersion [] False
emptyConstraintSet n = ConstraintSet n anyVersion [] False False False False

-------------------------------------------------------------------------------
-- Grammar
Expand All @@ -32,4 +35,7 @@ constraintSetGrammar
constraintSetGrammar name = ConstraintSet name
<$> C.optionalFieldDef "ghc" #csGhcVersions anyVersion
<*> C.monoidalFieldAla "constraints" (C.alaList' C.CommaVCat NoCommas) #csConstraints
<*> C.booleanFieldDef "tests" #csTests False
<*> C.booleanFieldDef "run-tests" #csRunTests False
<*> C.booleanFieldDef "benchmarks" #csBenchmarks False
<*> C.booleanFieldDef "haddock" #csHaddock False

0 comments on commit e7cc74a

Please sign in to comment.