Skip to content

Commit cdc2846

Browse files
authored
Merge pull request #61 from phadej/servant-0.10
Support servant-0.10 & aeson-1.1
2 parents 78716f4 + 8b6e999 commit cdc2846

File tree

10 files changed

+312
-156
lines changed

10 files changed

+312
-156
lines changed

.travis.yml

Lines changed: 93 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,103 @@
1+
# This Travis job script has been generated by a script via
2+
#
3+
# make_travis_yml_2.hs 'servant-swagger.cabal'
4+
#
5+
# For more information, see https://github.com/hvr/multi-ghc-travis
6+
#
7+
language: c
18
sudo: false
29

3-
addons:
4-
apt:
5-
sources:
6-
- hvr-ghc
7-
packages:
8-
- happy-1.19.5
9-
- libgmp-dev
10+
git:
11+
submodules: false # whether to recursively clone submodules
1012

11-
env:
12-
- STACK_YAML=stack.yaml
13-
- STACK_YAML=stack-ghc-7.8.yaml
14-
- STACK_YAML=stack-ghc-7.10.yaml
13+
cache:
14+
directories:
15+
- $HOME/.cabal/packages
16+
- $HOME/.cabal/store
17+
18+
before_cache:
19+
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log
20+
# remove files that are regenerated by 'cabal update'
21+
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.*
22+
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/*.json
23+
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.cache
24+
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar
25+
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx
26+
27+
matrix:
28+
include:
29+
- compiler: "ghc-7.8.4"
30+
# env: TEST=--disable-tests BENCH=--disable-benchmarks
31+
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.8.4], sources: [hvr-ghc]}}
32+
- compiler: "ghc-7.10.3"
33+
# env: TEST=--disable-tests BENCH=--disable-benchmarks
34+
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.10.3], sources: [hvr-ghc]}}
35+
- compiler: "ghc-8.0.2"
36+
# env: TEST=--disable-tests BENCH=--disable-benchmarks
37+
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.0.2], sources: [hvr-ghc]}}
1538

1639
before_install:
17-
# Download and unpack the stack executable
18-
- mkdir -p ~/.local/bin
19-
- export PATH=$HOME/.local/bin:/opt/happy/1.19.5/bin:$PATH
20-
- travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
21-
- export PATH=~/.local/bin:$PATH
22-
- stack --version
40+
- HC=${CC}
41+
- unset CC
42+
- PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$PATH
43+
- PKGNAME='servant-swagger'
2344

2445
install:
25-
- stack setup
46+
- cabal --version
47+
- echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
48+
- BENCH=${BENCH---enable-benchmarks}
49+
- TEST=${TEST---enable-tests}
50+
- travis_retry cabal update -v
51+
- sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config
52+
# Install hspec-discover manually, before hackage accepts build-tool-depends
53+
- mkdir -p $HOME/.local/bin
54+
- export PATH=$HOME/.local/bin/:$PATH
55+
- cabal get hspec-discover
56+
- "cd hspec-discover-*; cabal new-build hspec-discover:exe:hspec-discover; cp $(find dist-newstyle -type f -name hspec-discover) $HOME/.local/bin; cd .."
57+
58+
- rm -fv cabal.project.local
59+
- "echo 'packages: .' > cabal.project"
60+
- rm -f cabal.project.freeze
61+
- cabal new-build -w ${HC} ${TEST} ${BENCH} --dep -j2
62+
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks --dep -j2
2663

64+
# Here starts the actual work to be performed for the package under test;
65+
# any command which exits with a non-zero exit code causes the build to fail.
2766
script:
28-
- stack --no-terminal build --test
67+
- if [ -f configure.ac ]; then autoreconf -i; fi
68+
- rm -rf dist/
69+
- cabal sdist # test that a source-distribution can be generated
70+
- cd dist/
71+
- SRCTAR=(${PKGNAME}-*.tar.gz)
72+
- SRC_BASENAME="${SRCTAR/%.tar.gz}"
73+
- tar -xvf "./$SRC_BASENAME.tar.gz"
74+
- cd "$SRC_BASENAME/"
75+
## from here on, CWD is inside the extracted source-tarball
76+
- rm -fv cabal.project.local
77+
- "echo 'packages: .' > cabal.project"
78+
# this builds all libraries and executables (without tests/benchmarks)
79+
- rm -f cabal.project.freeze
80+
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks
2981

30-
cache:
31-
directories:
32-
- $HOME/.stack
82+
# Build with various constraints
83+
- if [ $HC = "ghc-8.0.2" ]; then UNLESSGHC802=true; fi
84+
- $UNLESSGHC802 cabal new-build -w ${HC} --disable-tests --disable-benchmarks "--constraint=servant==0.5.*"
85+
- $UNLESSGHC802 cabal new-build -w ${HC} --disable-tests --disable-benchmarks "--constraint=servant==0.6.*"
86+
- $UNLESSGHC802 cabal new-build -w ${HC} --disable-tests --disable-benchmarks "--constraint=servant==0.7.*"
87+
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks "--constraint=servant==0.8.*"
88+
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks "--constraint=servant==0.9.*"
89+
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks "--constraint=servant==0.10.*"
90+
91+
# this builds all libraries and executables (including tests/benchmarks)
92+
# - rm -rf ./dist-newstyle
93+
- cabal new-build -w ${HC} ${TEST} ${BENCH}
94+
95+
# there's no 'cabal new-test' yet, so let's emulate for now
96+
- TESTS=( $(awk 'tolower($0) ~ /^test-suite / { print $2 }' *.cabal) )
97+
- if [ "$TEST" != "--enable-tests" ]; then TESTS=(); fi
98+
- shopt -s globstar;
99+
RC=true; for T in ${TESTS[@]}; do echo "== $T ==";
100+
if dist-newstyle/build/**/$SRC_BASENAME/**/build/$T/$T; then echo "= $T OK =";
101+
else echo "= $T FAILED ="; RC=false; fi; done; $RC
102+
103+
# EOF

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
1.1.2.1
2+
---
3+
4+
* Notes:
5+
* `servant-0.10` compatible release
6+
17
1.1.2
28
---
39

Setup.lhs

Lines changed: 160 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,178 @@
1-
#!/usr/bin/runhaskell
21
\begin{code}
3-
{-# OPTIONS_GHC -Wall #-}
2+
{-# LANGUAGE CPP #-}
3+
{-# LANGUAGE OverloadedStrings #-}
44
module Main (main) where
55
6-
import Data.List ( nub )
7-
import Data.Version ( showVersion )
8-
import Distribution.Package ( PackageName(PackageName), PackageId, InstalledPackageId, packageVersion, packageName )
9-
import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) )
6+
#ifndef MIN_VERSION_cabal_doctest
7+
#define MIN_VERSION_cabal_doctest(x,y,z) 0
8+
#endif
9+
1010
import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )
11+
12+
#if MIN_VERSION_cabal_doctest(1,0,0)
13+
import Distribution.Extra.Doctest ( generateBuildModule )
14+
#else
15+
16+
-- Otherwise we provide a shim
17+
18+
#ifndef MIN_VERSION_Cabal
19+
#define MIN_VERSION_Cabal(x,y,z) 0
20+
#endif
21+
#ifndef MIN_VERSION_directory
22+
#define MIN_VERSION_directory(x,y,z) 0
23+
#endif
24+
#if MIN_VERSION_Cabal(1,24,0)
25+
#define InstalledPackageId UnitId
26+
#endif
27+
28+
import Control.Monad ( when )
29+
import Data.List ( nub )
30+
import Data.String ( fromString )
31+
import Distribution.Package ( InstalledPackageId )
32+
import Distribution.Package ( PackageId, Package (..), packageVersion )
33+
import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) , Library (..), BuildInfo (..))
1134
import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose )
1235
import Distribution.Simple.BuildPaths ( autogenModulesDir )
13-
import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), fromFlag )
14-
import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) )
15-
import Distribution.Verbosity ( Verbosity )
36+
import Distribution.Simple.Setup ( BuildFlags(buildDistPref, buildVerbosity), fromFlag)
37+
import Distribution.Simple.LocalBuildInfo ( withPackageDB, withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps), compiler )
38+
import Distribution.Simple.Compiler ( showCompilerId , PackageDB (..))
39+
import Distribution.Text ( display , simpleParse )
1640
import System.FilePath ( (</>) )
1741
18-
main :: IO ()
19-
main = defaultMainWithHooks simpleUserHooks
20-
{ buildHook = \pkg lbi hooks flags -> do
21-
generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi
22-
buildHook simpleUserHooks pkg lbi hooks flags
23-
}
42+
#if MIN_VERSION_Cabal(1,25,0)
43+
import Distribution.Simple.BuildPaths ( autogenComponentModulesDir )
44+
#endif
45+
46+
#if MIN_VERSION_directory(1,2,2)
47+
import System.Directory (makeAbsolute)
48+
#else
49+
import System.Directory (getCurrentDirectory)
50+
import System.FilePath (isAbsolute)
51+
52+
makeAbsolute :: FilePath -> IO FilePath
53+
makeAbsolute p | isAbsolute p = return p
54+
| otherwise = do
55+
cwd <- getCurrentDirectory
56+
return $ cwd </> p
57+
#endif
58+
59+
generateBuildModule :: String -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
60+
generateBuildModule testsuiteName flags pkg lbi = do
61+
let verbosity = fromFlag (buildVerbosity flags)
62+
let distPref = fromFlag (buildDistPref flags)
63+
64+
-- Package DBs
65+
let dbStack = withPackageDB lbi ++ [ SpecificPackageDB $ distPref </> "package.conf.inplace" ]
66+
let dbFlags = "-hide-all-packages" : packageDbArgs dbStack
67+
68+
withLibLBI pkg lbi $ \lib libcfg -> do
69+
let libBI = libBuildInfo lib
2470
25-
generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO ()
26-
generateBuildModule verbosity pkg lbi = do
27-
let dir = autogenModulesDir lbi
28-
createDirectoryIfMissingVerbose verbosity True dir
29-
withLibLBI pkg lbi $ \_ libcfg -> do
30-
withTestLBI pkg lbi $ \suite suitecfg -> do
31-
rewriteFile (dir </> "Build_" ++ testName suite ++ ".hs") $ unlines
32-
[ "module Build_" ++ testName suite ++ " where"
71+
-- modules
72+
let modules = exposedModules lib ++ otherModules libBI
73+
-- it seems that doctest is happy to take in module names, not actual files!
74+
let module_sources = modules
75+
76+
-- We need the directory with library's cabal_macros.h!
77+
#if MIN_VERSION_Cabal(1,25,0)
78+
let libAutogenDir = autogenComponentModulesDir lbi libcfg
79+
#else
80+
let libAutogenDir = autogenModulesDir lbi
81+
#endif
82+
83+
-- Lib sources and includes
84+
iArgs <- mapM (fmap ("-i"++) . makeAbsolute) $ libAutogenDir : hsSourceDirs libBI
85+
includeArgs <- mapM (fmap ("-I"++) . makeAbsolute) $ includeDirs libBI
86+
87+
-- CPP includes, i.e. include cabal_macros.h
88+
let cppFlags = map ("-optP"++) $
89+
[ "-include", libAutogenDir ++ "/cabal_macros.h" ]
90+
++ cppOptions libBI
91+
92+
withTestLBI pkg lbi $ \suite suitecfg -> when (testName suite == fromString testsuiteName) $ do
93+
94+
-- get and create autogen dir
95+
#if MIN_VERSION_Cabal(1,25,0)
96+
let testAutogenDir = autogenComponentModulesDir lbi suitecfg
97+
#else
98+
let testAutogenDir = autogenModulesDir lbi
99+
#endif
100+
createDirectoryIfMissingVerbose verbosity True testAutogenDir
101+
102+
-- write autogen'd file
103+
rewriteFile (testAutogenDir </> "Build_doctests.hs") $ unlines
104+
[ "module Build_doctests where"
105+
, ""
106+
-- -package-id etc. flags
107+
, "pkgs :: [String]"
108+
, "pkgs = " ++ (show $ formatDeps $ testDeps libcfg suitecfg)
33109
, ""
34-
, "autogen_dir :: String"
35-
, "autogen_dir = " ++ show dir
110+
, "flags :: [String]"
111+
, "flags = " ++ show (iArgs ++ includeArgs ++ dbFlags ++ cppFlags)
36112
, ""
37-
, "deps :: [String]"
38-
, "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg))
113+
, "module_sources :: [String]"
114+
, "module_sources = " ++ show (map display module_sources)
39115
]
40116
where
41-
formatdeps = map (formatone . snd)
42-
formatone p = case packageName p of
43-
PackageName n -> n ++ "-" ++ showVersion (packageVersion p)
117+
-- we do this check in Setup, as then doctests don't need to depend on Cabal
118+
isOldCompiler = maybe False id $ do
119+
a <- simpleParse $ showCompilerId $ compiler lbi
120+
b <- simpleParse "7.5"
121+
return $ packageVersion (a :: PackageId) < b
122+
123+
formatDeps = map formatOne
124+
formatOne (installedPkgId, pkgId)
125+
-- The problem is how different cabal executables handle package databases
126+
-- when doctests depend on the library
127+
| packageId pkg == pkgId = "-package=" ++ display pkgId
128+
| otherwise = "-package-id=" ++ display installedPkgId
129+
130+
-- From Distribution.Simple.Program.GHC
131+
packageDbArgs :: [PackageDB] -> [String]
132+
packageDbArgs | isOldCompiler = packageDbArgsConf
133+
| otherwise = packageDbArgsDb
134+
135+
-- GHC <7.6 uses '-package-conf' instead of '-package-db'.
136+
packageDbArgsConf :: [PackageDB] -> [String]
137+
packageDbArgsConf dbstack = case dbstack of
138+
(GlobalPackageDB:UserPackageDB:dbs) -> concatMap specific dbs
139+
(GlobalPackageDB:dbs) -> ("-no-user-package-conf")
140+
: concatMap specific dbs
141+
_ -> ierror
142+
where
143+
specific (SpecificPackageDB db) = [ "-package-conf=" ++ db ]
144+
specific _ = ierror
145+
ierror = error $ "internal error: unexpected package db stack: "
146+
++ show dbstack
147+
148+
-- GHC >= 7.6 uses the '-package-db' flag. See
149+
-- https://ghc.haskell.org/trac/ghc/ticket/5977.
150+
packageDbArgsDb :: [PackageDB] -> [String]
151+
-- special cases to make arguments prettier in common scenarios
152+
packageDbArgsDb dbstack = case dbstack of
153+
(GlobalPackageDB:UserPackageDB:dbs)
154+
| all isSpecific dbs -> concatMap single dbs
155+
(GlobalPackageDB:dbs)
156+
| all isSpecific dbs -> "-no-user-package-db"
157+
: concatMap single dbs
158+
dbs -> "-clear-package-db"
159+
: concatMap single dbs
160+
where
161+
single (SpecificPackageDB db) = [ "-package-db=" ++ db ]
162+
single GlobalPackageDB = [ "-global-package-db" ]
163+
single UserPackageDB = [ "-user-package-db" ]
164+
isSpecific (SpecificPackageDB _) = True
165+
isSpecific _ = False
44166
45167
testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)]
46168
testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys
169+
#endif
170+
171+
main :: IO ()
172+
main = defaultMainWithHooks simpleUserHooks
173+
{ buildHook = \pkg lbi hooks flags -> do
174+
generateBuildModule "doctests" flags pkg lbi
175+
buildHook simpleUserHooks pkg lbi hooks flags
176+
}
47177
48178
\end{code}

0 commit comments

Comments
 (0)