summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorryanglscott <>2017-04-27 01:16:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2017-04-27 01:16:00 (GMT)
commite98d468033d7dc4707d532e73adcf1303440756e (patch)
tree709fcc766af2c2048fafd743fc6f9d6e885093bf
parent95132dc1f30f9f33c6ec8a35895b9a2c79a74f5b (diff)
version 0.15.3HEAD0.15.3master
-rw-r--r--.travis.yml32
-rw-r--r--CHANGELOG.markdown7
-rw-r--r--Setup.lhs205
-rw-r--r--bytes.cabal23
-rw-r--r--src/Data/Bytes/Get.hs3
-rw-r--r--tests/doctests.hs25
-rw-r--r--tests/doctests.hsc75
7 files changed, 233 insertions, 137 deletions
diff --git a/.travis.yml b/.travis.yml
index 479a658..14e76f6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -22,12 +22,20 @@ matrix:
- env: CABALVER=1.18 GHCVER=7.8.4
compiler: ": #GHC 7.8.4"
addons: {apt: {packages: [cabal-install-1.18,ghc-7.8.4], sources: [hvr-ghc]}}
- - env: CABALVER=1.22 GHCVER=7.10.2
- compiler: ": #GHC 7.10.2"
- addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.2], sources: [hvr-ghc]}}
- - env: CABALVER=1.24 GHCVER=8.0.1
- compiler: ": #GHC 8.0.1"
- addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.1], sources: [hvr-ghc]}}
+ - env: CABALVER=1.22 GHCVER=7.10.3
+ compiler: ": #GHC 7.10.3"
+ addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.3], sources: [hvr-ghc]}}
+ - env: CABALVER=1.24 GHCVER=8.0.2
+ compiler: ": #GHC 8.0.2"
+ addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.2], sources: [hvr-ghc]}}
+ - env: CABALVER=1.24 GHCVER=8.2.1
+ compiler: ": #GHC 8.2.1"
+ addons: {apt: {packages: [cabal-install-1.24,ghc-8.2.1], sources: [hvr-ghc]}}
+ - env: CABALVER=head GHCVER=head CABALFLAGS="--allow-newer"
+ compiler: ": #GHC head"
+ addons: {apt: {packages: [cabal-install-head,ghc-head], sources: [hvr-ghc]}}
+ allow_failures:
+ - env: CABALVER=head GHCVER=head CABALFLAGS="--allow-newer"
before_install:
- unset CC
@@ -43,7 +51,7 @@ install:
fi
- travis_retry cabal update -v
- sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config
- - cabal install --only-dependencies --enable-tests --enable-benchmarks --dry -v > installplan.txt
+ - cabal install --only-dependencies --enable-tests --enable-benchmarks --dry -v $CABALFLAGS > installplan.txt
- sed -i -e '1,/^Resolving /d' installplan.txt; cat installplan.txt
# check whether current requested install-plan matches cached package-db snapshot
@@ -57,9 +65,9 @@ install:
echo "cabal build-cache MISS";
rm -rf $HOME/.cabsnap;
mkdir -p $HOME/.ghc $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin;
- cabal install --only-dependencies --enable-tests --enable-benchmarks;
+ cabal install -j --only-dependencies --enable-tests --enable-benchmarks $CABALFLAGS;
fi
-
+
# snapshot package-db on cache miss
- if [ ! -d $HOME/.cabsnap ];
then
@@ -73,16 +81,16 @@ install:
# any command which exits with a non-zero exit code causes the build to fail.
script:
- if [ -f configure.ac ]; then autoreconf -i; fi
- - cabal configure --enable-tests --enable-benchmarks -v2 # -v2 provides useful information for debugging
+ - cabal configure --enable-tests --enable-benchmarks -v2 $CABALFLAGS # -v2 provides useful information for debugging
- cabal build # this builds all libraries and executables (including tests/benchmarks)
- - cabal test
+ - cabal test --show-details=always
- cabal sdist # tests that a source-distribution can be generated
# Check that the resulting source distribution can be built & installed.
# If there are no other `.tar.gz` files in `dist`, this can be even simpler:
# `cabal install --force-reinstalls dist/*-*.tar.gz`
- SRC_TGZ=$(cabal info . | awk '{print $2;exit}').tar.gz &&
- (cd dist && cabal install --force-reinstalls "$SRC_TGZ")
+ (cd dist && cabal install $CABALFLAGS --force-reinstalls "$SRC_TGZ")
notifications:
irc:
diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown
index f6e9199..5f28c65 100644
--- a/CHANGELOG.markdown
+++ b/CHANGELOG.markdown
@@ -1,3 +1,10 @@
+0.15.3
+------
+* Support GHC 8.2
+* Revamp `Setup.hs` to use `cabal-doctest`. This makes it build
+ with `Cabal-2.0`, and makes the `doctest`s work with `cabal new-build` and
+ sandboxes.
+
0.15.2
------
* Support ghc 8
diff --git a/Setup.lhs b/Setup.lhs
index f459974..5555bb3 100644
--- a/Setup.lhs
+++ b/Setup.lhs
@@ -1,55 +1,182 @@
-#!/usr/bin/runhaskell
\begin{code}
-{-# OPTIONS_GHC -Wall #-}
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
+#ifndef MIN_VERSION_cabal_doctest
+#define MIN_VERSION_cabal_doctest(x,y,z) 0
+#endif
+
+
+#if MIN_VERSION_cabal_doctest(1,0,0)
+import Distribution.Extra.Doctest ( defaultMainWithDoctests )
+#else
+
+-- Otherwise we provide a shim
+
+#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
+
+import Control.Monad ( when )
import Data.List ( nub )
-import Data.Version ( showVersion )
-import Distribution.Package ( PackageName(PackageName), Package, PackageId, InstalledPackageId, packageVersion, packageName )
-import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) )
+import Data.String ( fromString )
+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, copyFiles )
+import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose )
import Distribution.Simple.BuildPaths ( autogenModulesDir )
-import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), Flag(..), fromFlag, HaddockFlags(haddockDistPref))
-import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) )
-import Distribution.Text ( display )
-import Distribution.Verbosity ( Verbosity, normal )
+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 ( (</>) )
-main :: IO ()
-main = defaultMainWithHooks simpleUserHooks
- { buildHook = \pkg lbi hooks flags -> do
- generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi
- buildHook simpleUserHooks pkg lbi hooks flags
- , postHaddock = \args flags pkg lbi -> do
- copyFiles normal (haddockOutputDir flags pkg) []
- postHaddock simpleUserHooks args flags pkg lbi
- }
+#if MIN_VERSION_Cabal(1,25,0)
+import Distribution.Simple.BuildPaths ( autogenComponentModulesDir )
+#endif
+
+#if MIN_VERSION_directory(1,2,2)
+import System.Directory (makeAbsolute)
+#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
+#endif
+
+generateBuildModule :: String -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
+generateBuildModule testsuiteName 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
-haddockOutputDir :: Package p => HaddockFlags -> p -> FilePath
-haddockOutputDir flags pkg = destDir where
- baseDir = case haddockDistPref flags of
- NoFlag -> "."
- Flag x -> x
- destDir = baseDir </> "doc" </> "html" </> display (packageName pkg)
-
-generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO ()
-generateBuildModule verbosity pkg lbi = do
- let dir = autogenModulesDir lbi
- createDirectoryIfMissingVerbose verbosity True dir
- withLibLBI pkg lbi $ \_ libcfg -> do
- withTestLBI pkg lbi $ \suite suitecfg -> do
- rewriteFile (dir </> "Build_" ++ testName suite ++ ".hs") $ unlines
- [ "module Build_" ++ testName suite ++ " where"
- , "deps :: [String]"
- , "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg))
+ -- 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
+
+ withTestLBI pkg lbi $ \suite suitecfg -> when (testName suite == fromString testsuiteName) $ 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
- formatdeps = map (formatone . snd)
- formatone p = case packageName p of
- PackageName n -> n ++ "-" ++ showVersion (packageVersion p)
+ -- 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
+defaultMainWithDoctests :: String -> IO ()
+defaultMainWithDoctests testSuiteName = defaultMainWithHooks simpleUserHooks
+ { buildHook = \pkg lbi hooks flags -> do
+ generateBuildModule testSuiteName flags pkg lbi
+ buildHook simpleUserHooks pkg lbi hooks flags
+ }
+
+#endif
+
+main :: IO ()
+main = defaultMainWithDoctests "doctests"
+
\end{code}
diff --git a/bytes.cabal b/bytes.cabal
index debb7ea..98ca056 100644
--- a/bytes.cabal
+++ b/bytes.cabal
@@ -1,6 +1,6 @@
name: bytes
category: Data, Serialization
-version: 0.15.2
+version: 0.15.3
license: BSD3
cabal-version: >= 1.8
license-file: LICENSE
@@ -11,7 +11,7 @@ homepage: https://github.com/ekmett/bytes
bug-reports: https://github.com/ekmett/bytes/issues
copyright: Copyright (C) 2013-2015 Edward A. Kmett
build-type: Custom
-tested-with: GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.2
+tested-with: GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.1
synopsis: Sharing code for serialization between binary and cereal
description: Sharing code for serialization between binary and cereal
@@ -37,6 +37,14 @@ flag test-doctests
default: True
manual: True
+custom-setup
+ -- any should do
+ setup-depends:
+ base >= 4.5 && <5,
+ Cabal >= 1.14,
+ cabal-doctest >= 1 && <1.1
+
+
library
build-depends:
base >= 4.5 && < 5,
@@ -47,7 +55,7 @@ library
hashable >= 1.0.1.1 && < 1.4,
mtl >= 2.0 && < 2.3,
text >= 0.2 && < 1.3,
- time >= 1.2 && < 1.7,
+ time >= 1.2 && < 1.9,
transformers >= 0.2 && < 0.6,
transformers-compat >= 0.3 && < 1,
unordered-containers >= 0.2 && < 0.3,
@@ -57,11 +65,6 @@ library
if impl(ghc >= 7.4 && < 7.6)
build-depends: ghc-prim
- -- hack around the buggy unused matches check for class associated types in ghc 8 rc1
- if impl(ghc >= 8)
- ghc-options: -fno-warn-unused-matches
-
-
exposed-modules:
Data.Bytes.Get
Data.Bytes.Put
@@ -79,12 +82,12 @@ test-suite doctests
ghc-options: -Wall -threaded
hs-source-dirs: tests
- if !flag(test-doctests) || impl(ghc >= 8)
+ if !flag(test-doctests)
buildable: False
else
build-depends:
base,
bytes,
directory >= 1.0,
- doctest >= 0.9.1,
+ doctest >= 0.11.1 && <0.12,
filepath >= 1.2
diff --git a/src/Data/Bytes/Get.hs b/src/Data/Bytes/Get.hs
index 816a6be..ede0304 100644
--- a/src/Data/Bytes/Get.hs
+++ b/src/Data/Bytes/Get.hs
@@ -89,7 +89,8 @@ class (Integral (Remaining m), Monad m, Applicative m) => MonadGet m where
-- Note that this forces the rest of the input.
remaining :: m (Remaining m)
#ifndef HLINT
- default remaining :: (MonadTrans t, MonadGet n, m ~ t n) => m (Remaining n)
+ default remaining :: (MonadTrans t, MonadGet n, m ~ t n, Remaining m ~ Remaining n)
+ => m (Remaining m)
remaining = lift remaining
#endif
diff --git a/tests/doctests.hs b/tests/doctests.hs
new file mode 100644
index 0000000..2d080e7
--- /dev/null
+++ b/tests/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 <ekmett@gmail.com>
+-- 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/tests/doctests.hsc b/tests/doctests.hsc
deleted file mode 100644
index 7f967b9..0000000
--- a/tests/doctests.hsc
+++ /dev/null
@@ -1,75 +0,0 @@
-{-# LANGUAGE CPP #-}
-{-# LANGUAGE ForeignFunctionInterface #-}
------------------------------------------------------------------------------
--- |
--- Module : Main (doctests)
--- Copyright : (C) 2012-13 Edward Kmett
--- License : BSD-style (see the file LICENSE)
--- Maintainer : Edward Kmett <ekmett@gmail.com>
--- 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 (deps)
-import Control.Applicative
-import Control.Monad
-import Data.List
-import System.Directory
-import System.FilePath
-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 $ getSources >>= \sources -> doctest $
- "-isrc"
- : "-idist/build/autogen"
- : "-optP-include"
- : "-optPdist/build/autogen/cabal_macros.h"
- : "-hide-all-packages"
- : "-Iincludes"
- : "dist/build/cbits/i2d.o"
- : map ("-package="++) (filter (not . ("bytes-" `isPrefixOf`)) deps) ++ sources
-
-getSources :: IO [FilePath]
-getSources = filter (isSuffixOf ".hs") <$> go "src"
- where
- go dir = do
- (dirs, files) <- getFilesAndDirectories dir
- (files ++) . concat <$> mapM go dirs
-
-getFilesAndDirectories :: FilePath -> IO ([FilePath], [FilePath])
-getFilesAndDirectories dir = do
- c <- map (dir </>) . filter (`notElem` ["..", "."]) <$> getDirectoryContents dir
- (,) <$> filterM doesDirectoryExist c <*> filterM doesFileExist c