git.iko.soy/typeable/http-api-data
on master help sign in
Merge pull request #44 from phadej/ghc-8.2

Ghc 8.2

commitcf75536fd2ef45b5065427f5cbd23424c0d8ea66 authorNickolay Kudasov <fizruk@users.noreply.github.com> dateTue 17 Jan 2017, 20:16 (10 years ago) parentd3cc66f6b0f404
7 files changed+318−86
.gitignore+1 .travis.yml+100−26 Setup.lhs+141−24 http-api-data.cabal+16−2 stack.yaml+2−3 test/DocTest.hs−31 test/DocTest.hsc+58
.gitignore+1
@@ -1,4 +1,5 @@
11/dist/
2+/dist-newstyle/
23/.shelly/
34/tarballs/
45*.swp
.travis.yml+100−26
@@ -1,35 +1,109 @@
1+# This Travis job script has been generated by a script via
2+#
3+# make_travis_yml_2.hs 'http-api-data.cabal'
4+#
5+# For more information, see https://github.com/hvr/multi-ghc-travis
6+#
7+language: c
18sudo: false
29
3−addons:
4− apt:
5− sources:
6− - hvr-ghc
7− packages:
8− - happy-1.19.5
9− - libgmp-dev
10−
11−env:
12− - STACK_YAML=stack.yaml FLAGS="--flag http-api-data:use-text-show"
13− - STACK_YAML=stack-ghc-7.8.yaml FLAGS="--flag http-api-data:use-text-show"
14− - STACK_YAML=stack-ghc-7.10.yaml FLAGS="--flag http-api-data:use-text-show"
15− - STACK_YAML=stack.yaml FLAGS=
16− - STACK_YAML=stack-ghc-7.8.yaml FLAGS=
17− - STACK_YAML=stack-ghc-7.10.yaml FLAGS=
10+git:
11+ submodules: false # whether to recursively clone submodules
12+
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]}}
38+ - compiler: "ghc-head"
39+ env: CABALFLAGS="--allow-newer"
40+ # env: TEST=--disable-tests BENCH=--disable-benchmarks
41+ addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-head], sources: [hvr-ghc]}}
42+
43+ allow_failures:
44+ - compiler: "ghc-head"
1845
1946before_install:
20− # Download and unpack the stack executable
21− - mkdir -p ~/.local/bin
22− - export PATH=$HOME/.local/bin:/opt/happy/1.19.5/bin:$PATH
23− - travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
24− - export PATH=~/.local/bin:$PATH
25− - stack --version
47+ - HC=${CC}
48+ - unset CC
49+ - PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$PATH
50+ - PKGNAME='http-api-data'
2651
2752install:
28− - stack setup
53+ - cabal --version
54+ - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
55+ - BENCH=${BENCH---enable-benchmarks}
56+ - TEST=${TEST---enable-tests}
57+ - travis_retry cabal update -v
58+ - sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config
59+ # Soon we'll have build-tool-depends: in cabal-head
60+ - cabal get hspec-discover-2.3.2
61+ - cd hspec-discover-2.3.2
62+ - cabal new-build hspec-discover:exe:hspec-discover
63+ - mkdir -p ~/.local/bin
64+ - shopt -s globstar; cp dist-newstyle/**/hspec-discover/hspec-discover ~/.local/bin
65+ - cd ..
66+ # Continue
67+ - rm -fv cabal.project.local
68+ - "echo 'packages: .' > cabal.project"
69+ - rm -f cabal.project.freeze
70+ - cabal new-build ${CABALFLAGS} -w ${HC} ${TEST} ${BENCH} --dep -j2
71+ - cabal new-build ${CABALFLAGS} -w ${HC} --disable-tests --disable-benchmarks --dep -j2
2972
73+# Here starts the actual work to be performed for the package under test;
74+# any command which exits with a non-zero exit code causes the build to fail.
3075script:
31− - stack --no-terminal build --test $FLAGS
76+ - if [ -f configure.ac ]; then autoreconf -i; fi
77+ - rm -rf dist/
78+ - cabal sdist # test that a source-distribution can be generated
79+ - cd dist/
80+ - SRCTAR=(${PKGNAME}-*.tar.gz)
81+ - SRC_BASENAME="${SRCTAR/%.tar.gz}"
82+ - tar -xvf "./$SRC_BASENAME.tar.gz"
83+ - cd "$SRC_BASENAME/"
84+## from here on, CWD is inside the extracted source-tarball
85+ - rm -fv cabal.project.local
86+ - "echo 'packages: .' > cabal.project"
87+ # this builds all libraries and executables (without tests/benchmarks)
88+ - rm -f cabal.project.freeze
89+ - cabal new-build ${CABALFLAGS} -w ${HC} --disable-tests --disable-benchmarks
90+ - cabal new-build ${CABALFLAGS} -w ${HC} --disable-tests --disable-benchmarks --flag http-api-data:use-text-show
91+ # this builds all libraries and executables (including tests/benchmarks)
92+ # - rm -rf ./dist-newstyle
93+ - cabal new-build ${CABALFLAGS} -w ${HC} ${TEST} ${BENCH}
3294
33−cache:
34− directories:
35− - $HOME/.stack
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+ - cabal new-build ${CABALFLAGS} -w ${HC} ${TEST} ${BENCH} --flag http-api-data:use-text-show
104+ - shopt -s globstar;
105+ RC=true; for T in ${TESTS[@]}; do echo "== $T ==";
106+ if dist-newstyle/build/**/$SRC_BASENAME/**/build/$T/$T; then echo "= $T OK =";
107+ else echo "= $T FAILED ="; RC=false; fi; done; $RC
108+
109+# EOF
Setup.lhs+141−24
@@ -1,46 +1,163 @@
1−#!/usr/bin/runhaskell
21\begin{code}
3−{-# OPTIONS_GHC -Wall #-}
2+{-# LANGUAGE CPP #-}
3+#ifndef MIN_VERSION_Cabal
4+#define MIN_VERSION_Cabal(x,y,z) 0
5+#endif
6+#ifndef MIN_VERSION_directory
7+#define MIN_VERSION_directory(x,y,z) 0
8+#endif
9+#if MIN_VERSION_Cabal(1,24,0)
10+#define InstalledPackageId UnitId
11+#endif
412module Main (main) where
513
14+import Control.Monad ( when )
615import Data.List ( nub )
7−import Data.Version ( showVersion )
8−import Distribution.Package ( PackageName(PackageName), PackageId, InstalledPackageId, packageVersion, packageName )
9−import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) )
16+import Distribution.Package ( InstalledPackageId )
17+import Distribution.Package ( PackageId, Package (..), packageVersion )
18+import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) , Library (..), BuildInfo (..))
1019import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )
1120import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose )
1221import 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 )
22+import Distribution.Simple.Setup ( BuildFlags(buildDistPref, buildVerbosity), fromFlag)
23+import Distribution.Simple.LocalBuildInfo ( withPackageDB, withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps), compiler )
24+import Distribution.Simple.Compiler ( showCompilerId , PackageDB (..))
25+import Distribution.Text ( display , simpleParse )
1626import System.FilePath ( (</>) )
1727
28+#if MIN_VERSION_Cabal(1,25,0)
29+import Distribution.Simple.BuildPaths ( autogenComponentModulesDir )
30+#endif
31+
32+#if MIN_VERSION_directory(1,2,2)
33+import System.Directory (makeAbsolute)
34+#else
35+import System.Directory (getCurrentDirectory)
36+import System.FilePath (isAbsolute)
37+
38+makeAbsolute :: FilePath -> IO FilePath
39+makeAbsolute p | isAbsolute p = return p
40+ | otherwise = do
41+ cwd <- getCurrentDirectory
42+ return $ cwd </> p
43+#endif
44+
1845main :: IO ()
1946main = defaultMainWithHooks simpleUserHooks
2047 { buildHook = \pkg lbi hooks flags -> do
21− generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi
48+ generateBuildModule flags pkg lbi
2249 buildHook simpleUserHooks pkg lbi hooks flags
2350 }
2451
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"
52+generateBuildModule :: BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
53+generateBuildModule flags pkg lbi = do
54+ let verbosity = fromFlag (buildVerbosity flags)
55+ let distPref = fromFlag (buildDistPref flags)
56+
57+ -- Package DBs
58+ let dbStack = withPackageDB lbi ++ [ SpecificPackageDB $ distPref </> "package.conf.inplace" ]
59+ let dbFlags = "-hide-all-packages" : packageDbArgs dbStack
60+
61+ withLibLBI pkg lbi $ \lib libcfg -> do
62+ let libBI = libBuildInfo lib
63+
64+ -- modules
65+ let modules = exposedModules lib ++ otherModules libBI
66+ -- it seems that doctest is happy to take in module names, not actual files!
67+ let module_sources = modules
68+
69+ -- We need the directory with library's cabal_macros.h!
70+#if MIN_VERSION_Cabal(1,25,0)
71+ let libAutogenDir = autogenComponentModulesDir lbi libcfg
72+#else
73+ let libAutogenDir = autogenModulesDir lbi
74+#endif
75+
76+ -- Lib sources and includes
77+ iArgs <- mapM (fmap ("-i"++) . makeAbsolute) $ libAutogenDir : hsSourceDirs libBI
78+ includeArgs <- mapM (fmap ("-I"++) . makeAbsolute) $ includeDirs libBI
79+
80+ -- CPP includes, i.e. include cabal_macros.h
81+ let cppFlags = map ("-optP"++) $
82+ [ "-include", libAutogenDir ++ "/cabal_macros.h" ]
83+ ++ cppOptions libBI
84+
85+ -- Actually we need to check whether testName suite == "doctests"
86+ -- pending https://github.com/haskell/cabal/pull/4229 getting into GHC HEAD tree
87+ withTestLBI pkg lbi $ \suite suitecfg -> when (testName suite == testName suite) $ do
88+
89+ -- get and create autogen dir
90+#if MIN_VERSION_Cabal(1,25,0)
91+ let testAutogenDir = autogenComponentModulesDir lbi suitecfg
92+#else
93+ let testAutogenDir = autogenModulesDir lbi
94+#endif
95+ createDirectoryIfMissingVerbose verbosity True testAutogenDir
96+
97+ -- write autogen'd file
98+ rewriteFile (testAutogenDir </> "Build_doctests.hs") $ unlines
99+ [ "module Build_doctests where"
100+ , ""
101+ -- -package-id etc. flags
102+ , "pkgs :: [String]"
103+ , "pkgs = " ++ (show $ formatDeps $ testDeps libcfg suitecfg)
33104 , ""
34− , "autogen_dir :: String"
35− , "autogen_dir = " ++ show dir
105+ , "flags :: [String]"
106+ , "flags = " ++ show (iArgs ++ includeArgs ++ dbFlags ++ cppFlags)
36107 , ""
37− , "deps :: [String]"
38− , "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg))
108+ , "module_sources :: [String]"
109+ , "module_sources = " ++ show (map display module_sources)
39110 ]
40111 where
41− formatdeps = map (formatone . snd)
42− formatone p = case packageName p of
43− PackageName n -> n ++ "-" ++ showVersion (packageVersion p)
112+ -- we do this check in Setup, as then doctests don't need to depend on Cabal
113+ isOldCompiler = maybe False id $ do
114+ a <- simpleParse $ showCompilerId $ compiler lbi
115+ b <- simpleParse "7.5"
116+ return $ packageVersion (a :: PackageId) < b
117+
118+ formatDeps = map formatOne
119+ formatOne (installedPkgId, pkgId)
120+ -- The problem is how different cabal executables handle package databases
121+ -- when doctests depend on the library
122+ | packageId pkg == pkgId = "-package=" ++ display pkgId
123+ | otherwise = "-package-id=" ++ display installedPkgId
124+
125+ -- From Distribution.Simple.Program.GHC
126+ packageDbArgs :: [PackageDB] -> [String]
127+ packageDbArgs | isOldCompiler = packageDbArgsConf
128+ | otherwise = packageDbArgsDb
129+
130+ -- GHC <7.6 uses '-package-conf' instead of '-package-db'.
131+ packageDbArgsConf :: [PackageDB] -> [String]
132+ packageDbArgsConf dbstack = case dbstack of
133+ (GlobalPackageDB:UserPackageDB:dbs) -> concatMap specific dbs
134+ (GlobalPackageDB:dbs) -> ("-no-user-package-conf")
135+ : concatMap specific dbs
136+ _ -> ierror
137+ where
138+ specific (SpecificPackageDB db) = [ "-package-conf=" ++ db ]
139+ specific _ = ierror
140+ ierror = error $ "internal error: unexpected package db stack: "
141+ ++ show dbstack
142+
143+ -- GHC >= 7.6 uses the '-package-db' flag. See
144+ -- https://ghc.haskell.org/trac/ghc/ticket/5977.
145+ packageDbArgsDb :: [PackageDB] -> [String]
146+ -- special cases to make arguments prettier in common scenarios
147+ packageDbArgsDb dbstack = case dbstack of
148+ (GlobalPackageDB:UserPackageDB:dbs)
149+ | all isSpecific dbs -> concatMap single dbs
150+ (GlobalPackageDB:dbs)
151+ | all isSpecific dbs -> "-no-user-package-db"
152+ : concatMap single dbs
153+ dbs -> "-clear-package-db"
154+ : concatMap single dbs
155+ where
156+ single (SpecificPackageDB db) = [ "-package-db=" ++ db ]
157+ single GlobalPackageDB = [ "-global-package-db" ]
158+ single UserPackageDB = [ "-user-package-db" ]
159+ isSpecific (SpecificPackageDB _) = True
160+ isSpecific _ = False
44161
45162testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)]
46163testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys
http-api-data.cabal+16−2
@@ -16,15 +16,28 @@ extra-source-files:
1616 test/*.hs
1717 CHANGELOG.md
1818 README.md
19+tested-with:
20+ GHC==7.8.4,
21+ GHC==7.10.3,
22+ GHC==8.0.2,
23+ GHC==8.1.*
24+
25+custom-setup
26+ setup-depends:
27+ base >= 4.7 && <4.10,
28+ Cabal >= 1.18 && <1.26,
29+ filepath,
30+ directory
1931
2032flag use-text-show
2133 description: Use text-show library for efficient ToHttpApiData implementations.
2234 default: False
35+ manual: True
2336
2437library
2538 hs-source-dirs: src/
2639 include-dirs: include/
27− build-depends: base >= 4.6 && < 4.10
40+ build-depends: base >= 4.7 && < 4.10
2841 , bytestring
2942 , containers
3043 , hashable
@@ -68,8 +81,9 @@ test-suite spec
6881 , bytestring
6982 , uuid
7083
71−test-suite doctest
84+test-suite doctests
7285 ghc-options: -Wall
86+ build-tools: hsc2hs
7387 build-depends:
7488 base,
7589 directory >= 1.0,
stack.yaml+2−3
@@ -1,4 +1,4 @@
1−resolver: nightly-2016-07-19
1+resolver: nightly-2016-12-31
22
33packages:
44- '.'
@@ -7,6 +7,5 @@ flags:
77 http-api-data:
88 use-text-show: false
99
10−extra-deps:
11−- QuickCheck-2.9.2
10+extra-deps: []
1211extra-package-dbs: []
test/DocTest.hsdeleted−31
@@ -1,31 +0,0 @@
1−module Main where
2−
3−import Build_doctest (autogen_dir, deps)
4−import Control.Applicative
5−import Control.Monad
6−import Data.List
7−import System.Directory
8−import System.FilePath
9−import Test.DocTest
10−
11−main :: IO ()
12−main = getSources >>= \sources -> doctest $
13− "-isrc"
14− : "-Iinclude"
15− : ("-i" ++ autogen_dir)
16− : "-optP-include"
17− : ("-optP" ++ autogen_dir ++ "/cabal_macros.h")
18− : "-hide-all-packages"
19− : map ("-package="++) deps ++ sources
20−
21−getSources :: IO [FilePath]
22−getSources = filter (isSuffixOf ".hs") <$> go "src"
23− where
24− go dir = do
25− (dirs, files) <- getFilesAndDirectories dir
26− (files ++) . concat <$> mapM go dirs
27−
28−getFilesAndDirectories :: FilePath -> IO ([FilePath], [FilePath])
29−getFilesAndDirectories dir = do
30− c <- map (dir </>) . filter (`notElem` ["..", "."]) <$> getDirectoryContents dir
31− (,) <$> filterM doesDirectoryExist c <*> filterM doesFileExist c
test/DocTest.hscnew file+58
@@ -0,0 +1,58 @@
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE ForeignFunctionInterface #-}
3+-----------------------------------------------------------------------------
4+-- |
5+-- Module : Main (doctests)
6+-- Copyright : (C) 2012-14 Edward Kmett
7+-- License : BSD-style (see the file LICENSE)
8+-- Maintainer : Edward Kmett <ekmett@gmail.com>
9+-- Stability : provisional
10+-- Portability : portable
11+--
12+-- This module provides doctests for a project based on the actual versions
13+-- of the packages it was built with. It requires a corresponding Setup.lhs
14+-- to be added to the project
15+-----------------------------------------------------------------------------
16+module Main where
17+
18+import Build_doctests (flags, pkgs, module_sources)
19+#if __GLASGOW_HASKELL__ < 710
20+import Control.Applicative
21+#endif
22+import Data.Foldable (traverse_)
23+import Test.DocTest
24+
25+##if defined(mingw32_HOST_OS)
26+##if defined(i386_HOST_ARCH)
27+##define USE_CP
28+import Control.Applicative
29+import Control.Exception
30+import Foreign.C.Types
31+foreign import stdcall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool
32+foreign import stdcall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt
33+##elif defined(x86_64_HOST_ARCH)
34+##define USE_CP
35+import Control.Applicative
36+import Control.Exception
37+import Foreign.C.Types
38+foreign import ccall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool
39+foreign import ccall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt
40+##endif
41+##endif
42+
43+-- | Run in a modified codepage where we can print UTF-8 values on Windows.
44+withUnicode :: IO a -> IO a
45+##ifdef USE_CP
46+withUnicode m = do
47+ cp <- c_GetConsoleCP
48+ (c_SetConsoleCP 65001 >> m) `finally` c_SetConsoleCP cp
49+##else
50+withUnicode m = m
51+##endif
52+
53+main :: IO ()
54+main = withUnicode $ do
55+ traverse_ putStrLn args
56+ doctest args
57+ where
58+ args = flags ++ pkgs ++ module_sources