From ec930ac9a8f7da2c8ece100c698b3201209b7faf Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Sun, 14 May 2017 21:41:39 +0300 Subject: [PATCH 1/3] Release 0.11 --- README.md | 26 +++++++++++----------- doc/tutorial/tutorial.cabal | 6 ++--- servant-client/CHANGELOG.md | 12 ++++++++++ servant-client/servant-client.cabal | 8 +++---- servant-docs/servant-docs.cabal | 4 ++-- servant-foreign/CHANGELOG.md | 9 ++++++++ servant-foreign/servant-foreign.cabal | 4 ++-- servant-server/CHANGELOG.md | 10 +++++++++ servant-server/servant-server.cabal | 4 ++-- servant/CHANGELOG.md | 32 ++++++++++++++++++++++++++- servant/servant.cabal | 2 +- 11 files changed, 89 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 4b56434c..e081ab4d 100644 --- a/README.md +++ b/README.md @@ -21,19 +21,19 @@ list](https://groups.google.com/forum/#!forum/haskell-servant). This table lists the versions of some `servant-` libraries at the point of release of `servant` package. -| | **0.10** | -| ------------------- | -------- | -| servant | 0.10 | -| servant-blaze | 0.7.1 | -| servant-cassava | 0.7 | -| servant-client | 0.10 | -| servant-docs | 0.10 | -| servant-foreign | 0.10 | -| servant-js | 0.9.1 | -| servant-lucid | 0.7.1 | -| servant-mock | 0.8.1.1 | -| servant-server | 0.10 | -| servant-swagger | 1.1.2.1 | +| | **0.10** | **0.11** | +| ------------------- | -------- |----------- +| servant | 0.10 | 0.11 | +| servant-blaze | 0.7.1 | ? | +| servant-cassava | 0.7 | ? | +| servant-client | 0.10 | 0.11 | +| servant-docs | 0.10 | 0.10.1 | +| servant-foreign | 0.10 | 0.10.0.1 | +| servant-js | 0.9.1 | ? | +| servant-lucid | 0.7.1 | ? | +| servant-mock | 0.8.1.1 | ? | +| servant-server | 0.10 | 0.11 | +| servant-swagger | 1.1.2.1 | ? | ## Contributing diff --git a/doc/tutorial/tutorial.cabal b/doc/tutorial/tutorial.cabal index 13ab0e75..7b854f2f 100644 --- a/doc/tutorial/tutorial.cabal +++ b/doc/tutorial/tutorial.cabal @@ -25,9 +25,9 @@ library , directory , blaze-markup , containers - , servant == 0.10.* - , servant-server == 0.10.* - , servant-client == 0.10.* + , servant == 0.11.* + , servant-server == 0.11.* + , servant-client == 0.11.* , servant-docs == 0.10.* , servant-js >= 0.9 && <0.10 , warp diff --git a/servant-client/CHANGELOG.md b/servant-client/CHANGELOG.md index 45cf0377..d9a340ff 100644 --- a/servant-client/CHANGELOG.md +++ b/servant-client/CHANGELOG.md @@ -1,3 +1,15 @@ +0.11 +---- + +### Other changes + +- Path components are escaped + ([#696](https://github.com/haskell-servant/servant/pull/696)) +- `Req` `reqPath` field changed from `String` to `BS.Builder` + ([#696](https://github.com/haskell-servant/servant/pull/696)) +- Include `Req` in failure errors + ([#740](https://github.com/haskell-servant/servant/pull/740)) + 0.10 ----- diff --git a/servant-client/servant-client.cabal b/servant-client/servant-client.cabal index d3b79c57..2c5471ec 100644 --- a/servant-client/servant-client.cabal +++ b/servant-client/servant-client.cabal @@ -1,5 +1,5 @@ name: servant-client -version: 0.10 +version: 0.11 synopsis: automatical derivation of querying functions for servant webservices description: This library lets you derive automatically Haskell functions that @@ -53,7 +53,7 @@ library , network-uri >= 2.6 && < 2.7 , safe >= 0.3.9 && < 0.4 , semigroupoids >= 4.3 && < 5.3 - , servant == 0.10.* + , servant == 0.11.* , string-conversions >= 0.3 && < 0.5 , text >= 1.2 && < 1.3 , transformers >= 0.3 && < 0.6 @@ -94,9 +94,9 @@ test-suite spec , mtl , network >= 2.6 , QuickCheck >= 2.7 - , servant == 0.10.* + , servant , servant-client - , servant-server == 0.10.* + , servant-server == 0.11.* , text , transformers , transformers-compat diff --git a/servant-docs/servant-docs.cabal b/servant-docs/servant-docs.cabal index 29c4bee5..a3871886 100644 --- a/servant-docs/servant-docs.cabal +++ b/servant-docs/servant-docs.cabal @@ -1,5 +1,5 @@ name: servant-docs -version: 0.10 +version: 0.10.0.1 synopsis: generate API docs for your servant webservice description: Library for generating API docs from a servant API definition. @@ -42,7 +42,7 @@ library , http-media >= 0.6 , http-types >= 0.7 , lens - , servant == 0.10.* + , servant == 0.11.* , string-conversions , text , unordered-containers diff --git a/servant-foreign/CHANGELOG.md b/servant-foreign/CHANGELOG.md index e6cff9ad..d1ab33fb 100644 --- a/servant-foreign/CHANGELOG.md +++ b/servant-foreign/CHANGELOG.md @@ -1,3 +1,12 @@ +0.10.1 +------ + +### Changes + +* Don't drop samples in `HasDocs ReqBody` instance + ([#755](https://github.com/haskell-servant/servant/pull/755/files)). + *Breaking change in an `Internal` module*. + 0.10 ---- diff --git a/servant-foreign/servant-foreign.cabal b/servant-foreign/servant-foreign.cabal index 703d20a7..17f2e1a7 100644 --- a/servant-foreign/servant-foreign.cabal +++ b/servant-foreign/servant-foreign.cabal @@ -1,5 +1,5 @@ name: servant-foreign -version: 0.10 +version: 0.10.1 synopsis: Helpers for generating clients for servant APIs in any programming language description: Helper types and functions for generating client functions for servant APIs in any programming language @@ -32,7 +32,7 @@ library , Servant.Foreign.Inflections build-depends: base == 4.* , lens == 4.* - , servant == 0.10.* + , servant == 0.11.* , text >= 1.2 && < 1.3 , http-types hs-source-dirs: src diff --git a/servant-server/CHANGELOG.md b/servant-server/CHANGELOG.md index 8381fabb..5b55cb7e 100644 --- a/servant-server/CHANGELOG.md +++ b/servant-server/CHANGELOG.md @@ -1,7 +1,17 @@ 0.11 ---- + +### Breaking changes + * Changed `HasServer` instances for `Header` to throw 400 when parsing fails + ([#724](https://github.com/haskell-servant/servant/pull/724)) * Added `headersD` block to `Delayed` + ([#724](https://github.com/haskell-servant/servant/pull/724)) + +### Other changes + +* Add `err418`, `err422` error codes + ([#739](https://github.com/haskell-servant/servant/pull/739)) 0.10 ---- diff --git a/servant-server/servant-server.cabal b/servant-server/servant-server.cabal index 11c80a6b..5338e00b 100644 --- a/servant-server/servant-server.cabal +++ b/servant-server/servant-server.cabal @@ -1,5 +1,5 @@ name: servant-server -version: 0.10 +version: 0.11 synopsis: A family of combinators for defining webservices APIs and serving them description: A family of combinators for defining webservices APIs and serving them @@ -64,7 +64,7 @@ library , mtl >= 2 && < 2.3 , network >= 2.6 && < 2.7 , safe >= 0.3 && < 0.4 - , servant == 0.10.* + , servant == 0.11.* , split >= 0.2 && < 0.3 , string-conversions >= 0.3 && < 0.5 , system-filepath >= 0.4 && < 0.5 diff --git a/servant/CHANGELOG.md b/servant/CHANGELOG.md index 1b099e0a..a2f9cec5 100644 --- a/servant/CHANGELOG.md +++ b/servant/CHANGELOG.md @@ -1,5 +1,35 @@ +0.11 +---- + +### Breaking changes + +- `Enter` refactored + ([#734](https://github.com/haskell-servant/servant/issues/734) + , [#736](https://github.com/haskell-servant/servant/pull/736)) + +### Other changes + +- Add a type representing an empty API + ([#753](https://github.com/haskell-servant/servant/pull/753)) +- Add `linkURI'` and `Link` accessors + ([#745](https://github.com/haskell-servant/servant/pull/745) + , [#717](https://github.com/haskell-servant/servant/pull/717) + , [#715](https://github.com/haskell-servant/servant/issues/715)) +- Prepare for GHC-8.2 + ([#722](https://github.com/haskell-servant/servant/pull/722)) +- Add `HasLink AuthProtect` instance + ([#720](https://github.com/haskell-servant/servant/pull/720)) +- `AllCTRender [] ()` `TypeError` (use `NoContent`) + ([#671](https://github.com/haskell-servant/servant/pull/671)) +- Documentation improvements and typo fixes + ([#702](https://github.com/haskell-servant/servant/pull/702) + , [#709](https://github.com/haskell-servant/servant/pull/709) + , [#716](https://github.com/haskell-servant/servant/pull/716) + , [#725](https://github.com/haskell-servant/servant/pull/725) + , [#727](https://github.com/haskell-servant/servant/pull/727)) + 0.10 ------- +---- ### Breaking changes diff --git a/servant/servant.cabal b/servant/servant.cabal index 1f4f9fa7..af6b9b30 100644 --- a/servant/servant.cabal +++ b/servant/servant.cabal @@ -1,5 +1,5 @@ name: servant -version: 0.10 +version: 0.11 synopsis: A family of combinators for defining webservices APIs description: A family of combinators for defining webservices APIs and serving them From b6cfd64b5a2812dd76b5f81de10faa708562c10e Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Mon, 15 May 2017 15:52:22 +0300 Subject: [PATCH 2/3] GHC-8.2 readyness --- servant-server/Setup.lhs | 169 +++--------------------- servant-server/servant-server.cabal | 6 +- servant-server/src/Servant/Server.hs | 2 + servant-server/test/doctests.hs | 25 ++++ servant-server/test/doctests.hsc | 61 --------- servant/Setup.lhs | 169 +++--------------------- servant/servant.cabal | 9 +- servant/src/Servant/API/ContentTypes.hs | 3 + servant/test/doctests.hs | 25 ++++ servant/test/doctests.hsc | 59 --------- stack-ghc-7.8.4.yaml | 8 +- stack-ghc-8.0.2.yaml | 2 + stack.yaml | 12 +- 13 files changed, 119 insertions(+), 431 deletions(-) create mode 100644 servant-server/test/doctests.hs delete mode 100644 servant-server/test/doctests.hsc create mode 100644 servant/test/doctests.hs delete mode 100644 servant/test/doctests.hsc diff --git a/servant-server/Setup.lhs b/servant-server/Setup.lhs index 0f89abf8..faedcd30 100644 --- a/servant-server/Setup.lhs +++ b/servant-server/Setup.lhs @@ -1,165 +1,34 @@ \begin{code} {-# LANGUAGE CPP #-} -#ifndef MIN_VERSION_Cabal -#define MIN_VERSION_Cabal(x,y,z) 0 -#endif -#ifndef MIN_VERSION_directory -#define MIN_VERSION_directory(x,y,z) 0 -#endif -#if MIN_VERSION_Cabal(1,24,0) -#define InstalledPackageId UnitId -#endif +{-# OPTIONS_GHC -Wall #-} module Main (main) where -import Control.Monad ( when ) -import Data.List ( nub ) -import Distribution.Package ( InstalledPackageId ) -import Distribution.Package ( PackageId, Package (..), packageVersion ) -import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) , Library (..), BuildInfo (..)) -import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks ) -import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose ) -import Distribution.Simple.BuildPaths ( autogenModulesDir ) -import Distribution.Simple.Setup ( BuildFlags(buildDistPref, buildVerbosity), fromFlag) -import Distribution.Simple.LocalBuildInfo ( withPackageDB, withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps), compiler ) -import Distribution.Simple.Compiler ( showCompilerId , PackageDB (..)) -import Distribution.Text ( display , simpleParse ) -import System.FilePath ( () ) - -#if MIN_VERSION_Cabal(1,25,0) -import Distribution.Simple.BuildPaths ( autogenComponentModulesDir ) +#ifndef MIN_VERSION_cabal_doctest +#define MIN_VERSION_cabal_doctest(x,y,z) 0 #endif -#if MIN_VERSION_directory(1,2,2) -import System.Directory (makeAbsolute) +#if MIN_VERSION_cabal_doctest(1,0,0) + +import Distribution.Extra.Doctest ( defaultMainWithDoctests ) +main :: IO () +main = defaultMainWithDoctests "doctests" + #else -import System.Directory (getCurrentDirectory) -import System.FilePath (isAbsolute) -makeAbsolute :: FilePath -> IO FilePath -makeAbsolute p | isAbsolute p = return p - | otherwise = do - cwd <- getCurrentDirectory - return $ cwd p +#ifdef MIN_VERSION_Cabal +-- If the macro is defined, we have new cabal-install, +-- but for some reason we don't have cabal-doctest in package-db +-- +-- Probably we are running cabal sdist, when otherwise using new-build +-- workflow +import Warning () #endif +import Distribution.Simple + main :: IO () -main = defaultMainWithHooks simpleUserHooks - { buildHook = \pkg lbi hooks flags -> do - generateBuildModule flags pkg lbi - buildHook simpleUserHooks pkg lbi hooks flags - } +main = defaultMain -generateBuildModule :: BuildFlags -> PackageDescription -> LocalBuildInfo -> IO () -generateBuildModule flags pkg lbi = do - let verbosity = fromFlag (buildVerbosity flags) - let distPref = fromFlag (buildDistPref flags) - - -- Package DBs - let dbStack = withPackageDB lbi ++ [ SpecificPackageDB $ distPref "package.conf.inplace" ] - let dbFlags = "-hide-all-packages" : packageDbArgs dbStack - - withLibLBI pkg lbi $ \lib libcfg -> do - let libBI = libBuildInfo lib - - -- modules - let modules = exposedModules lib ++ otherModules libBI - -- it seems that doctest is happy to take in module names, not actual files! - let module_sources = modules - - -- We need the directory with library's cabal_macros.h! -#if MIN_VERSION_Cabal(1,25,0) - let libAutogenDir = autogenComponentModulesDir lbi libcfg -#else - let libAutogenDir = autogenModulesDir lbi #endif - -- Lib sources and includes - iArgs <- mapM (fmap ("-i"++) . makeAbsolute) $ libAutogenDir : hsSourceDirs libBI - includeArgs <- mapM (fmap ("-I"++) . makeAbsolute) $ includeDirs libBI - - -- CPP includes, i.e. include cabal_macros.h - let cppFlags = map ("-optP"++) $ - [ "-include", libAutogenDir ++ "/cabal_macros.h" ] - ++ cppOptions libBI - - -- Actually we need to check whether testName suite == "doctests" - -- pending https://github.com/haskell/cabal/pull/4229 getting into GHC HEAD tree - withTestLBI pkg lbi $ \suite suitecfg -> when (testName suite == "doctests") $ do - - -- get and create autogen dir -#if MIN_VERSION_Cabal(1,25,0) - let testAutogenDir = autogenComponentModulesDir lbi suitecfg -#else - let testAutogenDir = autogenModulesDir lbi -#endif - createDirectoryIfMissingVerbose verbosity True testAutogenDir - - -- write autogen'd file - rewriteFile (testAutogenDir "Build_doctests.hs") $ unlines - [ "module Build_doctests where" - , "" - -- -package-id etc. flags - , "pkgs :: [String]" - , "pkgs = " ++ (show $ formatDeps $ testDeps libcfg suitecfg) - , "" - , "flags :: [String]" - , "flags = " ++ show (iArgs ++ includeArgs ++ dbFlags ++ cppFlags) - , "" - , "module_sources :: [String]" - , "module_sources = " ++ show (map display module_sources) - ] - where - -- we do this check in Setup, as then doctests don't need to depend on Cabal - isOldCompiler = maybe False id $ do - a <- simpleParse $ showCompilerId $ compiler lbi - b <- simpleParse "7.5" - return $ packageVersion (a :: PackageId) < b - - formatDeps = map formatOne - formatOne (installedPkgId, pkgId) - -- The problem is how different cabal executables handle package databases - -- when doctests depend on the library - | packageId pkg == pkgId = "-package=" ++ display pkgId - | otherwise = "-package-id=" ++ display installedPkgId - - -- From Distribution.Simple.Program.GHC - packageDbArgs :: [PackageDB] -> [String] - packageDbArgs | isOldCompiler = packageDbArgsConf - | otherwise = packageDbArgsDb - - -- GHC <7.6 uses '-package-conf' instead of '-package-db'. - packageDbArgsConf :: [PackageDB] -> [String] - packageDbArgsConf dbstack = case dbstack of - (GlobalPackageDB:UserPackageDB:dbs) -> concatMap specific dbs - (GlobalPackageDB:dbs) -> ("-no-user-package-conf") - : concatMap specific dbs - _ -> ierror - where - specific (SpecificPackageDB db) = [ "-package-conf=" ++ db ] - specific _ = ierror - ierror = error $ "internal error: unexpected package db stack: " - ++ show dbstack - - -- GHC >= 7.6 uses the '-package-db' flag. See - -- https://ghc.haskell.org/trac/ghc/ticket/5977. - packageDbArgsDb :: [PackageDB] -> [String] - -- special cases to make arguments prettier in common scenarios - packageDbArgsDb dbstack = case dbstack of - (GlobalPackageDB:UserPackageDB:dbs) - | all isSpecific dbs -> concatMap single dbs - (GlobalPackageDB:dbs) - | all isSpecific dbs -> "-no-user-package-db" - : concatMap single dbs - dbs -> "-clear-package-db" - : concatMap single dbs - where - single (SpecificPackageDB db) = [ "-package-db=" ++ db ] - single GlobalPackageDB = [ "-global-package-db" ] - single UserPackageDB = [ "-user-package-db" ] - isSpecific (SpecificPackageDB _) = True - isSpecific _ = False - -testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)] -testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys - \end{code} diff --git a/servant-server/servant-server.cabal b/servant-server/servant-server.cabal index 5338e00b..70445d08 100644 --- a/servant-server/servant-server.cabal +++ b/servant-server/servant-server.cabal @@ -33,7 +33,9 @@ source-repository head custom-setup setup-depends: - Cabal >=1.14, base, filepath, directory + base >= 4 && <5, + Cabal, + cabal-doctest >= 1.0.1 && <1.1 library exposed-modules: @@ -159,4 +161,6 @@ test-suite doctests buildable: True default-language: Haskell2010 ghc-options: -Wall -threaded + if impl(ghc >= 8.2) + x-doctest-options: -fdiagnostics-color=never include-dirs: include diff --git a/servant-server/src/Servant/Server.hs b/servant-server/src/Servant/Server.hs index 66e0ef9b..056ca28f 100644 --- a/servant-server/src/Servant/Server.hs +++ b/servant-server/src/Servant/Server.hs @@ -228,5 +228,7 @@ layoutWithContext p context = -- -- $setup +-- >>> :set -XDataKinds +-- >>> :set -XTypeOperators -- >>> import Servant.API -- >>> import Servant.Server diff --git a/servant-server/test/doctests.hs b/servant-server/test/doctests.hs new file mode 100644 index 00000000..2d080e7f --- /dev/null +++ b/servant-server/test/doctests.hs @@ -0,0 +1,25 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Main (doctests) +-- Copyright : (C) 2012-14 Edward Kmett +-- License : BSD-style (see the file LICENSE) +-- Maintainer : Edward Kmett +-- Stability : provisional +-- Portability : portable +-- +-- This module provides doctests for a project based on the actual versions +-- of the packages it was built with. It requires a corresponding Setup.lhs +-- to be added to the project +----------------------------------------------------------------------------- +module Main where + +import Build_doctests (flags, pkgs, module_sources) +import Data.Foldable (traverse_) +import Test.DocTest + +main :: IO () +main = do + traverse_ putStrLn args + doctest args + where + args = flags ++ pkgs ++ module_sources diff --git a/servant-server/test/doctests.hsc b/servant-server/test/doctests.hsc deleted file mode 100644 index 8bf2033b..00000000 --- a/servant-server/test/doctests.hsc +++ /dev/null @@ -1,61 +0,0 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE ForeignFunctionInterface #-} ------------------------------------------------------------------------------ --- | --- Module : Main (doctests) --- Copyright : (C) 2012-14 Edward Kmett --- License : BSD-style (see the file LICENSE) --- Maintainer : Edward Kmett --- Stability : provisional --- Portability : portable --- --- This module provides doctests for a project based on the actual versions --- of the packages it was built with. It requires a corresponding Setup.lhs --- to be added to the project ------------------------------------------------------------------------------ -module Main where - -import Build_doctests (flags, pkgs, module_sources) -import Data.Foldable (traverse_) -import Test.DocTest - -##if defined(mingw32_HOST_OS) -##if defined(i386_HOST_ARCH) -##define USE_CP -import Control.Applicative -import Control.Exception -import Foreign.C.Types -foreign import stdcall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool -foreign import stdcall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt -##elif defined(x86_64_HOST_ARCH) -##define USE_CP -import Control.Applicative -import Control.Exception -import Foreign.C.Types -foreign import ccall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool -foreign import ccall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt -##endif -##endif - --- | Run in a modified codepage where we can print UTF-8 values on Windows. -withUnicode :: IO a -> IO a -##ifdef USE_CP -withUnicode m = do - cp <- c_GetConsoleCP - (c_SetConsoleCP 65001 >> m) `finally` c_SetConsoleCP cp -##else -withUnicode m = m -##endif - -main :: IO () -main = withUnicode $ do - traverse_ putStrLn args - doctest args - where - args = - "-XOverloadedStrings" : - "-XFlexibleInstances" : - "-XMultiParamTypeClasses" : - "-XDataKinds" : - "-XTypeOperators" : - flags ++ pkgs ++ module_sources diff --git a/servant/Setup.lhs b/servant/Setup.lhs index 0e04e46c..faedcd30 100644 --- a/servant/Setup.lhs +++ b/servant/Setup.lhs @@ -1,165 +1,34 @@ \begin{code} {-# LANGUAGE CPP #-} -#ifndef MIN_VERSION_Cabal -#define MIN_VERSION_Cabal(x,y,z) 0 -#endif -#ifndef MIN_VERSION_directory -#define MIN_VERSION_directory(x,y,z) 0 -#endif -#if MIN_VERSION_Cabal(1,24,0) -#define InstalledPackageId UnitId -#endif +{-# OPTIONS_GHC -Wall #-} module Main (main) where -import Control.Monad ( when ) -import Data.List ( nub ) -import Distribution.Package ( InstalledPackageId ) -import Distribution.Package ( PackageId, Package (..), packageVersion ) -import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) , Library (..), BuildInfo (..)) -import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks ) -import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose ) -import Distribution.Simple.BuildPaths ( autogenModulesDir ) -import Distribution.Simple.Setup ( BuildFlags(buildDistPref, buildVerbosity), fromFlag) -import Distribution.Simple.LocalBuildInfo ( withPackageDB, withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps), compiler ) -import Distribution.Simple.Compiler ( showCompilerId , PackageDB (..)) -import Distribution.Text ( display , simpleParse ) -import System.FilePath ( () ) - -#if MIN_VERSION_Cabal(1,25,0) -import Distribution.Simple.BuildPaths ( autogenComponentModulesDir ) +#ifndef MIN_VERSION_cabal_doctest +#define MIN_VERSION_cabal_doctest(x,y,z) 0 #endif -#if MIN_VERSION_directory(1,2,2) -import System.Directory (makeAbsolute) +#if MIN_VERSION_cabal_doctest(1,0,0) + +import Distribution.Extra.Doctest ( defaultMainWithDoctests ) +main :: IO () +main = defaultMainWithDoctests "doctests" + #else -import System.Directory (getCurrentDirectory) -import System.FilePath (isAbsolute) -makeAbsolute :: FilePath -> IO FilePath -makeAbsolute p | isAbsolute p = return p - | otherwise = do - cwd <- getCurrentDirectory - return $ cwd p +#ifdef MIN_VERSION_Cabal +-- If the macro is defined, we have new cabal-install, +-- but for some reason we don't have cabal-doctest in package-db +-- +-- Probably we are running cabal sdist, when otherwise using new-build +-- workflow +import Warning () #endif +import Distribution.Simple + main :: IO () -main = defaultMainWithHooks simpleUserHooks - { buildHook = \pkg lbi hooks flags -> do - generateBuildModule flags pkg lbi - buildHook simpleUserHooks pkg lbi hooks flags - } +main = defaultMain -generateBuildModule :: BuildFlags -> PackageDescription -> LocalBuildInfo -> IO () -generateBuildModule flags pkg lbi = do - let verbosity = fromFlag (buildVerbosity flags) - let distPref = fromFlag (buildDistPref flags) - - -- Package DBs - let dbStack = withPackageDB lbi ++ [ SpecificPackageDB $ distPref "package.conf.inplace" ] - let dbFlags = "-hide-all-packages" : packageDbArgs dbStack - - withLibLBI pkg lbi $ \lib libcfg -> do - let libBI = libBuildInfo lib - - -- modules - let modules = exposedModules lib ++ otherModules libBI - -- it seems that doctest is happy to take in module names, not actual files! - let module_sources = modules - - -- We need the directory with library's cabal_macros.h! -#if MIN_VERSION_Cabal(1,25,0) - let libAutogenDir = autogenComponentModulesDir lbi libcfg -#else - let libAutogenDir = autogenModulesDir lbi #endif - -- Lib sources and includes - iArgs <- mapM (fmap ("-i"++) . makeAbsolute) $ "test" : libAutogenDir : hsSourceDirs libBI - includeArgs <- mapM (fmap ("-I"++) . makeAbsolute) $ includeDirs libBI - - -- CPP includes, i.e. include cabal_macros.h - let cppFlags = map ("-optP"++) $ - [ "-include", libAutogenDir ++ "/cabal_macros.h" ] - ++ cppOptions libBI - - -- Actually we need to check whether testName suite == "doctests" - -- pending https://github.com/haskell/cabal/pull/4229 getting into GHC HEAD tree - withTestLBI pkg lbi $ \suite suitecfg -> when (testName suite == "doctests") $ do - - -- get and create autogen dir -#if MIN_VERSION_Cabal(1,25,0) - let testAutogenDir = autogenComponentModulesDir lbi suitecfg -#else - let testAutogenDir = autogenModulesDir lbi -#endif - createDirectoryIfMissingVerbose verbosity True testAutogenDir - - -- write autogen'd file - rewriteFile (testAutogenDir "Build_doctests.hs") $ unlines - [ "module Build_doctests where" - , "" - -- -package-id etc. flags - , "pkgs :: [String]" - , "pkgs = " ++ (show $ formatDeps $ testDeps libcfg suitecfg) - , "" - , "flags :: [String]" - , "flags = " ++ show (iArgs ++ includeArgs ++ dbFlags ++ cppFlags) - , "" - , "module_sources :: [String]" - , "module_sources = " ++ show ("Servant.Utils.LinksSpec" : map display module_sources) - ] - where - -- we do this check in Setup, as then doctests don't need to depend on Cabal - isOldCompiler = maybe False id $ do - a <- simpleParse $ showCompilerId $ compiler lbi - b <- simpleParse "7.5" - return $ packageVersion (a :: PackageId) < b - - formatDeps = map formatOne - formatOne (installedPkgId, pkgId) - -- The problem is how different cabal executables handle package databases - -- when doctests depend on the library - | packageId pkg == pkgId = "-package=" ++ display pkgId - | otherwise = "-package-id=" ++ display installedPkgId - - -- From Distribution.Simple.Program.GHC - packageDbArgs :: [PackageDB] -> [String] - packageDbArgs | isOldCompiler = packageDbArgsConf - | otherwise = packageDbArgsDb - - -- GHC <7.6 uses '-package-conf' instead of '-package-db'. - packageDbArgsConf :: [PackageDB] -> [String] - packageDbArgsConf dbstack = case dbstack of - (GlobalPackageDB:UserPackageDB:dbs) -> concatMap specific dbs - (GlobalPackageDB:dbs) -> ("-no-user-package-conf") - : concatMap specific dbs - _ -> ierror - where - specific (SpecificPackageDB db) = [ "-package-conf=" ++ db ] - specific _ = ierror - ierror = error $ "internal error: unexpected package db stack: " - ++ show dbstack - - -- GHC >= 7.6 uses the '-package-db' flag. See - -- https://ghc.haskell.org/trac/ghc/ticket/5977. - packageDbArgsDb :: [PackageDB] -> [String] - -- special cases to make arguments prettier in common scenarios - packageDbArgsDb dbstack = case dbstack of - (GlobalPackageDB:UserPackageDB:dbs) - | all isSpecific dbs -> concatMap single dbs - (GlobalPackageDB:dbs) - | all isSpecific dbs -> "-no-user-package-db" - : concatMap single dbs - dbs -> "-clear-package-db" - : concatMap single dbs - where - single (SpecificPackageDB db) = [ "-package-db=" ++ db ] - single GlobalPackageDB = [ "-global-package-db" ] - single UserPackageDB = [ "-user-package-db" ] - isSpecific (SpecificPackageDB _) = True - isSpecific _ = False - -testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)] -testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys - \end{code} diff --git a/servant/servant.cabal b/servant/servant.cabal index af6b9b30..49b176e0 100644 --- a/servant/servant.cabal +++ b/servant/servant.cabal @@ -27,7 +27,9 @@ source-repository head custom-setup setup-depends: - Cabal >=1.14, base, filepath, directory + base >= 4 && <5, + Cabal, + cabal-doctest >= 1.0.2 && <1.1 library exposed-modules: @@ -147,5 +149,8 @@ test-suite doctests buildable: True default-language: Haskell2010 ghc-options: -Wall -threaded - build-tools: hsc2hs + if impl(ghc >= 8.2) + x-doctest-options: -fdiagnostics-color=never include-dirs: include + x-doctest-source-dirs: test + x-doctest-modules: Servant.Utils.LinksSpec diff --git a/servant/src/Servant/API/ContentTypes.hs b/servant/src/Servant/API/ContentTypes.hs index 446f0276..05839e59 100644 --- a/servant/src/Servant/API/ContentTypes.hs +++ b/servant/src/Servant/API/ContentTypes.hs @@ -419,6 +419,9 @@ instance MimeUnrender OctetStream BS.ByteString where -- $setup +-- >>> :set -XFlexibleInstances +-- >>> :set -XMultiParamTypeClasses +-- >>> :set -XOverloadedStrings -- >>> import Servant.API -- >>> import Data.Aeson -- >>> import Data.Text diff --git a/servant/test/doctests.hs b/servant/test/doctests.hs new file mode 100644 index 00000000..2d080e7f --- /dev/null +++ b/servant/test/doctests.hs @@ -0,0 +1,25 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Main (doctests) +-- Copyright : (C) 2012-14 Edward Kmett +-- License : BSD-style (see the file LICENSE) +-- Maintainer : Edward Kmett +-- Stability : provisional +-- Portability : portable +-- +-- This module provides doctests for a project based on the actual versions +-- of the packages it was built with. It requires a corresponding Setup.lhs +-- to be added to the project +----------------------------------------------------------------------------- +module Main where + +import Build_doctests (flags, pkgs, module_sources) +import Data.Foldable (traverse_) +import Test.DocTest + +main :: IO () +main = do + traverse_ putStrLn args + doctest args + where + args = flags ++ pkgs ++ module_sources diff --git a/servant/test/doctests.hsc b/servant/test/doctests.hsc deleted file mode 100644 index 4956d631..00000000 --- a/servant/test/doctests.hsc +++ /dev/null @@ -1,59 +0,0 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE ForeignFunctionInterface #-} ------------------------------------------------------------------------------ --- | --- Module : Main (doctests) --- Copyright : (C) 2012-14 Edward Kmett --- License : BSD-style (see the file LICENSE) --- Maintainer : Edward Kmett --- Stability : provisional --- Portability : portable --- --- This module provides doctests for a project based on the actual versions --- of the packages it was built with. It requires a corresponding Setup.lhs --- to be added to the project ------------------------------------------------------------------------------ -module Main where - -import Build_doctests (flags, pkgs, module_sources) -import Data.Foldable (traverse_) -import Test.DocTest - -##if defined(mingw32_HOST_OS) -##if defined(i386_HOST_ARCH) -##define USE_CP -import Control.Applicative -import Control.Exception -import Foreign.C.Types -foreign import stdcall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool -foreign import stdcall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt -##elif defined(x86_64_HOST_ARCH) -##define USE_CP -import Control.Applicative -import Control.Exception -import Foreign.C.Types -foreign import ccall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool -foreign import ccall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt -##endif -##endif - --- | Run in a modified codepage where we can print UTF-8 values on Windows. -withUnicode :: IO a -> IO a -##ifdef USE_CP -withUnicode m = do - cp <- c_GetConsoleCP - (c_SetConsoleCP 65001 >> m) `finally` c_SetConsoleCP cp -##else -withUnicode m = m -##endif - -main :: IO () -main = withUnicode $ do - traverse_ putStrLn args - doctest args - where - args = - "-XOverloadedStrings" : - "-XFlexibleInstances" : - "-XMultiParamTypeClasses" : - flags ++ pkgs ++ module_sources diff --git a/stack-ghc-7.8.4.yaml b/stack-ghc-7.8.4.yaml index b7b7c93b..01bb6420 100644 --- a/stack-ghc-7.8.4.yaml +++ b/stack-ghc-7.8.4.yaml @@ -8,18 +8,20 @@ packages: extra-deps: - aeson-compat-0.3.6 - base-compat-0.9.1 +- cabal-doctest-1.0.2 +- call-stack-0.1.0 - control-monad-omega-0.3.1 - cryptonite-0.6 - doctest-0.11.0 - hspec-2.3.2 -- hspec-discover-2.3.2 - hspec-core-2.3.2 -- hspec-wai-0.8.0 +- hspec-discover-2.3.2 - hspec-expectations-0.8.2 -- call-stack-0.1.0 +- hspec-wai-0.8.0 - http-api-data-0.3.6 - natural-transformation-0.4 - primitive-0.6.1.0 +- servant-js-0.9.3 - should-not-typecheck-2.1.0 - time-locale-compat-0.1.1.1 - uri-bytestring-0.2.2.0 diff --git a/stack-ghc-8.0.2.yaml b/stack-ghc-8.0.2.yaml index c6288550..0865ecdc 100644 --- a/stack-ghc-8.0.2.yaml +++ b/stack-ghc-8.0.2.yaml @@ -9,4 +9,6 @@ packages: extra-deps: - aeson-1.2.0.0 - attoparsec-iso8601-1.0.0.0 +- cabal-doctest-1.0.2 - http-api-data-0.3.7 +- servant-js-0.9.3 diff --git a/stack.yaml b/stack.yaml index b3161b8c..525a46d9 100644 --- a/stack.yaml +++ b/stack.yaml @@ -8,12 +8,14 @@ packages: - doc/tutorial extra-deps: - attoparsec-iso8601-1.0.0.0 -- http-api-data-0.3.7 -- servant-js-0.9.1 -- natural-transformation-0.4 +- cabal-doctest-1.0.2 - hspec-2.3.2 -- hspec-discover-2.3.2 - hspec-core-2.3.2 -- hspec-wai-0.8.0 +- hspec-discover-2.3.2 - hspec-expectations-0.8.2 +- hspec-wai-0.8.0 +- http-api-data-0.3.7 +- natural-transformation-0.4 +- servant-js-0.9.1 +- servant-js-0.9.3 resolver: lts-6.27 From 22d0f6ccb902bbd62cf5b7f07ecfd417ae256638 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Tue, 16 May 2017 17:17:03 +0300 Subject: [PATCH 3/3] Make GHC-8.0.2 stack.yaml the default --- .travis.yml | 2 +- stack-ghc-8.0.2.yaml => stack-ghc-7.10.3.yaml | 10 ++++++++-- stack.yaml | 11 ++--------- 3 files changed, 11 insertions(+), 12 deletions(-) rename stack-ghc-8.0.2.yaml => stack-ghc-7.10.3.yaml (57%) diff --git a/.travis.yml b/.travis.yml index aa33923a..235acaf7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,8 @@ language: c env: - STACK_YAML=stack-ghc-7.8.4.yaml + - STACK_YAML=stack-ghc-7.10.3.yaml - STACK_YAML=stack.yaml - - STACK_YAML=stack-ghc-8.0.2.yaml addons: apt: diff --git a/stack-ghc-8.0.2.yaml b/stack-ghc-7.10.3.yaml similarity index 57% rename from stack-ghc-8.0.2.yaml rename to stack-ghc-7.10.3.yaml index 0865ecdc..fb18aac7 100644 --- a/stack-ghc-8.0.2.yaml +++ b/stack-ghc-7.10.3.yaml @@ -1,4 +1,4 @@ -resolver: nightly-2017-04-01 +flags: {} packages: - servant/ - servant-client/ @@ -7,8 +7,14 @@ packages: - servant-server/ - doc/tutorial extra-deps: -- aeson-1.2.0.0 - attoparsec-iso8601-1.0.0.0 - cabal-doctest-1.0.2 +- hspec-2.3.2 +- hspec-core-2.3.2 +- hspec-discover-2.3.2 +- hspec-expectations-0.8.2 +- hspec-wai-0.8.0 - http-api-data-0.3.7 +- natural-transformation-0.4 - servant-js-0.9.3 +resolver: lts-6.27 diff --git a/stack.yaml b/stack.yaml index 525a46d9..0865ecdc 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -flags: {} +resolver: nightly-2017-04-01 packages: - servant/ - servant-client/ @@ -7,15 +7,8 @@ packages: - servant-server/ - doc/tutorial extra-deps: +- aeson-1.2.0.0 - attoparsec-iso8601-1.0.0.0 - cabal-doctest-1.0.2 -- hspec-2.3.2 -- hspec-core-2.3.2 -- hspec-discover-2.3.2 -- hspec-expectations-0.8.2 -- hspec-wai-0.8.0 - http-api-data-0.3.7 -- natural-transformation-0.4 -- servant-js-0.9.1 - servant-js-0.9.3 -resolver: lts-6.27