Skip to content

Commit

Permalink
Merge pull request #19 from obsidiansystems/aa-travis
Browse files Browse the repository at this point in the history
Add travis CI and fix for GHC802
  • Loading branch information
ali-abrar authored Oct 10, 2019
2 parents 65df0b0 + bb1ad0f commit 050f8ef
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 15 deletions.
146 changes: 146 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# This Travis job script has been generated by a script via
#
# haskell-ci 'aeson-gadt-th.cabal' '--output' '.travis.yml'
#
# For more information, see https://github.com/haskell-CI/haskell-ci
#
# version: 0.3.20190814
#
language: c
dist: xenial
sudo: required
git:
# whether to recursively clone submodules
submodules: false
cache:
directories:
- $HOME/.cabal/packages
- $HOME/.cabal/store
before_cache:
- rm -fv $CABALHOME/packages/hackage.haskell.org/build-reports.log
# remove files that are regenerated by 'cabal update'
- rm -fv $CABALHOME/packages/hackage.haskell.org/00-index.*
- rm -fv $CABALHOME/packages/hackage.haskell.org/*.json
- rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.cache
- rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.tar
- rm -fv $CABALHOME/packages/hackage.haskell.org/01-index.tar.idx
- rm -rfv $CABALHOME/packages/head.hackage
matrix:
include:
- compiler: ghc-8.6.5
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.6.5","cabal-install-2.4"]}}
- compiler: ghc-8.4.4
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.4.4","cabal-install-2.4"]}}
- compiler: ghc-8.2.2
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.2.2","cabal-install-2.4"]}}
- compiler: ghc-8.0.2
addons: {"apt":{"sources":["hvr-ghc"],"packages":["ghc-8.0.2","cabal-install-2.4"]}}
before_install:
- HC=$(echo "/opt/$CC/bin/ghc" | sed 's/-/\//')
- WITHCOMPILER="-w $HC"
- HCPKG="$HC-pkg"
- unset CC
- CABAL=/opt/ghc/bin/cabal
- CABALHOME=$HOME/.cabal
- export PATH="$CABALHOME/bin:$PATH"
- TOP=$(pwd)
- "HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\\d+)\\.(\\d+)\\.(\\d+)(\\.(\\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')"
- echo $HCNUMVER
- CABAL="$CABAL -vnormal+nowrap+markoutput"
- set -o pipefail
- |
echo 'function blue(s) { printf "\033[0;34m" s "\033[0m " }' >> .colorful.awk
echo 'BEGIN { state = "output"; }' >> .colorful.awk
echo '/^-----BEGIN CABAL OUTPUT-----$/ { state = "cabal" }' >> .colorful.awk
echo '/^-----END CABAL OUTPUT-----$/ { state = "output" }' >> .colorful.awk
echo '!/^(-----BEGIN CABAL OUTPUT-----|-----END CABAL OUTPUT-----)/ {' >> .colorful.awk
echo ' if (state == "cabal") {' >> .colorful.awk
echo ' print blue($0)' >> .colorful.awk
echo ' } else {' >> .colorful.awk
echo ' print $0' >> .colorful.awk
echo ' }' >> .colorful.awk
echo '}' >> .colorful.awk
- cat .colorful.awk
- |
color_cabal_output () {
awk -f $TOP/.colorful.awk
}
- echo text | color_cabal_output
install:
- ${CABAL} --version
- echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
- TEST=--enable-tests
- BENCH=--enable-benchmarks
- HEADHACKAGE=false
- rm -f $CABALHOME/config
- |
echo "verbose: normal +nowrap +markoutput" >> $CABALHOME/config
echo "remote-build-reporting: anonymous" >> $CABALHOME/config
echo "write-ghc-environment-files: always" >> $CABALHOME/config
echo "remote-repo-cache: $CABALHOME/packages" >> $CABALHOME/config
echo "logs-dir: $CABALHOME/logs" >> $CABALHOME/config
echo "world-file: $CABALHOME/world" >> $CABALHOME/config
echo "extra-prog-path: $CABALHOME/bin" >> $CABALHOME/config
echo "symlink-bindir: $CABALHOME/bin" >> $CABALHOME/config
echo "installdir: $CABALHOME/bin" >> $CABALHOME/config
echo "build-summary: $CABALHOME/logs/build.log" >> $CABALHOME/config
echo "store-dir: $CABALHOME/store" >> $CABALHOME/config
echo "install-dirs user" >> $CABALHOME/config
echo " prefix: $CABALHOME" >> $CABALHOME/config
echo "repository hackage.haskell.org" >> $CABALHOME/config
echo " url: http://hackage.haskell.org/" >> $CABALHOME/config
- cat $CABALHOME/config
- rm -fv cabal.project cabal.project.local cabal.project.freeze
- travis_retry ${CABAL} v2-update -v
# Generate cabal.project
- rm -rf cabal.project cabal.project.local cabal.project.freeze
- touch cabal.project
- |
echo "packages: ." >> cabal.project
- |
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(aeson-gadt-th)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
- cat cabal.project || true
- cat cabal.project.local || true
- if [ -f "./configure.ac" ]; then (cd "." && autoreconf -i); fi
- ${CABAL} v2-freeze $WITHCOMPILER ${TEST} ${BENCH} | color_cabal_output
- "cat cabal.project.freeze | sed -E 's/^(constraints: *| *)//' | sed 's/any.//'"
- rm cabal.project.freeze
- ${CABAL} v2-build $WITHCOMPILER ${TEST} ${BENCH} --dep -j2 all | color_cabal_output
- ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks --dep -j2 all | color_cabal_output
script:
- DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)
# Packaging...
- ${CABAL} v2-sdist all | color_cabal_output
# Unpacking...
- mv dist-newstyle/sdist/*.tar.gz ${DISTDIR}/
- cd ${DISTDIR} || false
- find . -maxdepth 1 -type f -name '*.tar.gz' -exec tar -xvf '{}' \;
- find . -maxdepth 1 -type f -name '*.tar.gz' -exec rm '{}' \;
- PKGDIR_aeson_gadt_th="$(find . -maxdepth 1 -type d -regex '.*/aeson-gadt-th-[0-9.]*')"
# Generate cabal.project
- rm -rf cabal.project cabal.project.local cabal.project.freeze
- touch cabal.project
- |
echo "packages: ${PKGDIR_aeson_gadt_th}" >> cabal.project
- |
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(aeson-gadt-th)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
- cat cabal.project || true
- cat cabal.project.local || true
# Building...
# this builds all libraries and executables (without tests/benchmarks)
- ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks all | color_cabal_output
# Building with tests and benchmarks...
# build & run tests, build benchmarks
- ${CABAL} v2-build $WITHCOMPILER ${TEST} ${BENCH} all | color_cabal_output
# Testing...
- ${CABAL} v2-test $WITHCOMPILER ${TEST} ${BENCH} all | color_cabal_output
# cabal check...
- (cd ${PKGDIR_aeson_gadt_th} && ${CABAL} -vnormal check)
# haddock...
- ${CABAL} v2-haddock $WITHCOMPILER ${TEST} ${BENCH} all | color_cabal_output
# Building without installed constraints for packages in global-db...
- rm -f cabal.project.local
- ${CABAL} v2-build $WITHCOMPILER --disable-tests --disable-benchmarks all | color_cabal_output

# REGENDATA ["aeson-gadt-th.cabal","--output",".travis.yml"]
# EOF
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for aeson-gadt-th

## 0.2.1.2

* Add version bounds to cabal file

## 0.2.1.1

* Drop markdown-unlit in favor of "Bird"-style LHS to avoid some cross-compilation issues.
Expand Down
20 changes: 11 additions & 9 deletions aeson-gadt-th.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: >=2.0
cabal-version: 2.0
name: aeson-gadt-th
version: 0.2.1.1
version: 0.2.1.2
synopsis: Derivation of Aeson instances for GADTs
category: JSON
description: Template Haskell for generating ToJSON and FromJSON instances for GADTs. See <https://github.com/obsidiansystems/aeson-gadt-th/blob/master/README.md README.md> for examples.
Expand All @@ -10,6 +10,8 @@ author: Obsidian Systems LLC
maintainer: [email protected]
copyright: 2019 Obsidian Systems LLC
build-type: Simple
tested-with:
GHC ==8.0.2 || ==8.2.2 || ==8.4.4 || ==8.6.5
extra-source-files: README.md
ChangeLog.md

Expand All @@ -19,11 +21,11 @@ flag build-readme
library
exposed-modules: Data.Aeson.GADT.TH
build-depends: base >= 4.8 && < 4.13
, aeson
, containers
, dependent-sum
, transformers
, template-haskell
, aeson >= 1.4 && < 1.5
, containers >= 0.5 && < 0.7
, dependent-sum >= 0.6.2 && < 0.7
, transformers >= 0.5 && < 0.6
, template-haskell >= 2.11.0 && < 2.15
hs-source-dirs: src
default-language: Haskell2010

Expand All @@ -33,8 +35,8 @@ executable readme
build-depends: base
, aeson
, dependent-sum
, dependent-sum-template
, dependent-map
, dependent-sum-template >= 0.1 && < 0.2
, dependent-map >= 0.3 && < 0.4
, aeson-gadt-th
default-language: Haskell2010
main-is: README.lhs
Expand Down
13 changes: 8 additions & 5 deletions src/Data/Aeson/GADT/TH.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
Expand Down Expand Up @@ -96,8 +97,8 @@ deriveFromJSONGADTWithOptions opts n = do
wildName <- newName "s"
let wild = match (varP wildName) (normalB [e|
fail $
"Expected tag to be one of [" <> allConNames <> "] but got: "
<> $(varE wildName)
"Expected tag to be one of [" ++ allConNames ++ "] but got: "
++ $(varE wildName)
|]) []
topVars <- init <$> makeTopVars n
let n' = foldl (\c v -> AppT c (VarT v)) (ConT n) topVars
Expand Down Expand Up @@ -199,7 +200,9 @@ substVarsWith topVars resultType argType = subst Set.empty argType
ConT n -> ConT n
TupleT k -> TupleT k
UnboxedTupleT k -> UnboxedTupleT k
#if MIN_VERSION_template_haskell(2,12,0)
UnboxedSumT k -> UnboxedSumT k
#endif
ArrowT -> ArrowT
EqualityT -> EqualityT
ListT -> ListT
Expand All @@ -212,8 +215,8 @@ substVarsWith topVars resultType argType = subst Set.empty argType
WildCardT -> WildCardT
findVar v (tv:_) (AppT _ (VarT v')) | v == v' = tv
findVar v (_:tvs) (AppT t (VarT _)) = findVar v tvs t
findVar v _ _ = error $ "substVarsWith: couldn't look up variable substitution for " <> show v
<> " with topVars: " <> show topVars <> " resultType: " <> show resultType <> " argType: " <> show argType
findVar v _ _ = error $ "substVarsWith: couldn't look up variable substitution for " ++ show v
++ " with topVars: " ++ show topVars ++ " resultType: " ++ show resultType ++ " argType: " ++ show argType

-- | Determine the 'Name' being bound by a 'TyVarBndr'.
tyVarBndrName :: TyVarBndr -> Name
Expand Down Expand Up @@ -244,7 +247,7 @@ tyConArity' :: Name -> Q ([TyVarBndr], Int)
tyConArity' n = reify n >>= return . \case
TyConI (DataD _ _ ts mk _ _) -> (ts, fromMaybe 0 (fmap kindArity mk))
TyConI (NewtypeD _ _ ts mk _ _) -> (ts, fromMaybe 0 (fmap kindArity mk))
_ -> error $ "tyConArity': Supplied name reified to something other than a data declaration: " <> show n
_ -> error $ "tyConArity': Supplied name reified to something other than a data declaration: " ++ show n

-- | Determine the constructors bound by a data or newtype declaration. Errors out if supplied with another
-- sort of declaration.
Expand Down
2 changes: 1 addition & 1 deletion test/Expectations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ expectPattern f a =
try (evaluate $ f a) >>= \case
Right b -> pure b
Left (e :: PatternMatchFail) ->
throwHUnit $ "Pattern match failed, value was: " <> show a
throwHUnit $ "Pattern match failed, value was: " ++ show a

-- | Same as 'expectPattern' but with its arguments flipped.
shouldMatchPattern :: (HasCallStack, Show a) => a -> (a -> b) -> IO b
Expand Down

0 comments on commit 050f8ef

Please sign in to comment.