Skip to content

Commit

Permalink
Remove references to Derive code
Browse files Browse the repository at this point in the history
* Also remove CPP for __HADDOCK__ from code and Setup.lhs
  • Loading branch information
spl committed Apr 22, 2010
1 parent 70baee6 commit 695bf39
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 198 deletions.
99 changes: 3 additions & 96 deletions Setup.lhs
@@ -1,7 +1,6 @@
#! /usr/bin/env runhaskell

\begin{code}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS -Wall #-}

-----------------------------------------------------------------------------
Expand All @@ -23,46 +22,26 @@ import System.FilePath
( (</>)
)

import Data.Version
( Version(..)
)

import Distribution.Simple
( defaultMainWithHooks
, simpleUserHooks
, UserHooks(runTests, haddockHook, buildHook)
, UserHooks(runTests)
, Args
)

import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo(..)
)

import Distribution.Simple.Program
( userSpecifyArgs
)

import Distribution.Simple.Setup
( HaddockFlags
, BuildFlags
( LocalBuildInfo
)

import Distribution.Package

import Distribution.PackageDescription
( PackageDescription(..)
, BuildInfo(..)
, Library(..)
, Executable(..)
( PackageDescription
)

main :: IO ()
main = defaultMainWithHooks hooks
where
hooks = simpleUserHooks
{ runTests = runTests'
, haddockHook = haddockHook'
, buildHook = buildHook'
}

-- Run a 'test' binary that gets built when configured with '-ftest'.
Expand All @@ -72,77 +51,5 @@ runTests' _ _ _ _ = system cmd >> return ()
testcmd = "." </> "test"
cmd = "cd " ++ testdir ++ " && " ++ testcmd

-- Define __HADDOCK__ for CPP when running haddock. This is a workaround for
-- Haddock not building the documentation due to some issue with Template
-- Haskell.
haddockHook' :: PackageDescription -> LocalBuildInfo -> UserHooks -> HaddockFlags -> IO ()
haddockHook' pkg lbi =
haddockHook simpleUserHooks pkg (lbi { withPrograms = p })
where
p = userSpecifyArgs "haddock" ["--optghc=-D__HADDOCK__"] (withPrograms lbi)

-- Insert CPP flag for building with template-haskell versions >= 2.3. This was
-- previously done in the .cabal file, but it was not backwards compatible with
-- Cabal 1.2. This should work with Cabal from 1.2 to 1.6 at least.
buildHook' :: PackageDescription -> LocalBuildInfo -> UserHooks -> BuildFlags -> IO ()
buildHook' pkg lbi hooks flags = do
buildHook simpleUserHooks pkg (lbi { localPkgDescr = newPkgDescr }) hooks flags
where

-- Old local package description
oldPkgDescr = localPkgDescr lbi

-- New local package description
newPkgDescr =
case thVersion of
Nothing ->
oldPkgDescr
Just version ->
if version >= Version [2,3] []
then
oldPkgDescr
{ library = addThCppToLibrary (library oldPkgDescr)
, executables = map addThCppToExec (executables oldPkgDescr)
}
else
oldPkgDescr

-- Template Haskell package name
thPackageName = mkPackageName "template-haskell"

mkPackageName :: (Read a) => String -> a
mkPackageName nm =
fst $ head $ reads shownNm ++ reads ("PackageName " ++ shownNm)
where
shownNm = show nm

-- template-haskell version
thVersion = findThVersion (packageDeps lbi)

-- CPP options for template-haskell >= 2.3
thCppOpt = "-DTH_LOC_DERIVEREP"

-- Find the version of the template-haskell package
findThVersion [] = Nothing
findThVersion (PackageIdentifier name version:ps)
| name == thPackageName = Just version
| otherwise = findThVersion ps

-- Add the template-haskell CPP flag to a BuildInfo
addThCppToBuildInfo :: BuildInfo -> BuildInfo
addThCppToBuildInfo bi =
bi { cppOptions = thCppOpt : cppOptions bi }

-- Add the template-haskell CPP flag to a library package description
addThCppToLibrary :: Maybe Library -> Maybe Library
addThCppToLibrary ml = do
lib <- ml
return (lib { libBuildInfo = addThCppToBuildInfo (libBuildInfo lib) })

-- Add the template-haskell CPP flag to an executable package description
addThCppToExec :: Executable -> Executable
addThCppToExec exec =
exec { buildInfo = addThCppToBuildInfo (buildInfo exec) }

\end{code}

40 changes: 1 addition & 39 deletions emgm.cabal
Expand Up @@ -62,7 +62,6 @@ extra-source-files: README,
tests/Collect.hs,
tests/Compare.hs,
tests/Crush.hs,
tests/Derive.hs,
tests/Enum.hs,
tests/Everywhere.hs,
tests/Main.hs,
Expand Down Expand Up @@ -129,20 +128,8 @@ Library
Generics.EMGM.Data.List
Generics.EMGM.Data.Maybe
Generics.EMGM.Data.Tuple
Generics.EMGM.Data.TH

-- Deriving
Generics.EMGM.Derive

other-modules: Generics.EMGM.Derive.Common
Generics.EMGM.Derive.ConDescr
Generics.EMGM.Derive.EP
Generics.EMGM.Derive.Functions
Generics.EMGM.Derive.Instance
Generics.EMGM.Derive.Internal

build-depends: base >= 3.0 && < 4.0,
template-haskell >= 2.2 && < 2.4
build-depends: base >= 3.0 && < 5.0

extensions: CPP

Expand All @@ -162,28 +149,3 @@ Library
if flag(nolib)
buildable: False

--------------------------------------------------------------------------------

Executable test
hs-source-dirs: src, tests, examples
other-modules: Generics.EMGM
extensions: CPP
main-is: Main.hs

build-depends: base >= 3.0 && < 4.0,
template-haskell >= 2.2 && < 2.4

-- Only enable the build-depends here if configured with "-ftest". This
-- allows users to use EMGM without having to install QuickCheck.
if flag(test)
build-depends: QuickCheck >= 2.1 && < 2.2,
HUnit >= 1.2 && < 1.3
else
buildable: False

ghc-options: -Wall -O0 -fno-warn-missing-signatures

-- Add program coverage if configured with "-fhpc".
if flag(hpc)
ghc-options: -fhpc

13 changes: 0 additions & 13 deletions src/Generics/EMGM.hs
@@ -1,4 +1,3 @@
{-# LANGUAGE CPP #-}

-----------------------------------------------------------------------------
-- |
Expand All @@ -23,8 +22,6 @@
-- defining functions.
--
-- * "Generics.EMGM.Functions" - Generic functions included with EMGM.
--
-- * "Generics.EMGM.Derive" - Generating the EMGM representation for a datatype.
-----------------------------------------------------------------------------

module Generics.EMGM (
Expand Down Expand Up @@ -119,16 +116,6 @@ module Generics.EMGM (
Generic2(..),
Generic3(..),

-- ** Deriving Representation
--
-- | The necessary values and instances for using EMGM with a user-defined
-- datatype can be generated automatically using Template Haskell. By
-- necessity, there are a number of exported values for this process that are
-- unrelated to other uses of the EMGM library. In order to not export these
-- signatures more than necessary, you should import "Generics.EMGM.Derive"
-- for deriving the representation. Note that "Generics.EMGM" does not export
-- anything in "Generics.EMGM.Derive".

-- * Generic Functions
--
-- | The following collection of functions use the common EMGM infrastructure
Expand Down
18 changes: 4 additions & 14 deletions src/Generics/EMGM/Data/Bool.hs
@@ -1,10 +1,8 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS -fno-warn-orphans #-}
{- OPTIONS -ddump-splices -}

Expand Down Expand Up @@ -32,15 +30,9 @@ module Generics.EMGM.Data.Bool (
bifrep2Bool,
) where

import Generics.EMGM.Derive.Internal

#ifndef __HADDOCK__

$(derive ''Bool)

#else
-- The following code is used by Haddock to generate documentation. It may be
-- useful to keep around for debugging TH, so don't remove it.
import Generics.EMGM.Common
import Generics.EMGM.Functions.Collect
import Generics.EMGM.Functions.Everywhere

-----------------------------------------------------------------------------
-- Embedding-projection pair
Expand Down Expand Up @@ -117,5 +109,3 @@ instance Rep (Everywhere Bool) Bool where
instance Rep (Everywhere' Bool) Bool where
rep = Everywhere' ($)

#endif

18 changes: 4 additions & 14 deletions src/Generics/EMGM/Data/Either.hs
@@ -1,10 +1,8 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS -fno-warn-orphans #-}
{- OPTIONS -ddump-splices -}

Expand Down Expand Up @@ -32,15 +30,9 @@ module Generics.EMGM.Data.Either (
bifrep2Either,
) where

import Generics.EMGM.Derive.Internal

#ifndef __HADDOCK__

$(derive ''Either)

#else
-- The following code is used by Haddock to generate documentation. It may be
-- useful to keep around for debugging TH, so don't remove it.
import Generics.EMGM.Common
import Generics.EMGM.Functions.Collect
import Generics.EMGM.Functions.Everywhere

-----------------------------------------------------------------------------
-- Embedding-projection pair
Expand Down Expand Up @@ -126,5 +118,3 @@ instance (Rep (Everywhere (Either a b)) a, Rep (Everywhere (Either a b)) b)
instance Rep (Everywhere' (Either a b)) (Either a b) where
rep = Everywhere' ($)

#endif

4 changes: 3 additions & 1 deletion src/Generics/EMGM/Data/List.hs
Expand Up @@ -29,7 +29,9 @@ module Generics.EMGM.Data.List (
bifrep2List,
) where

import Generics.EMGM.Derive.Internal
import Generics.EMGM.Common
import Generics.EMGM.Functions.Collect
import Generics.EMGM.Functions.Everywhere

-----------------------------------------------------------------------------
-- Embedding-projection pair
Expand Down
18 changes: 4 additions & 14 deletions src/Generics/EMGM/Data/Maybe.hs
@@ -1,10 +1,8 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS -fno-warn-orphans #-}
{- OPTIONS -ddump-splices -}

Expand Down Expand Up @@ -32,15 +30,9 @@ module Generics.EMGM.Data.Maybe (
bifrep2Maybe,
) where

import Generics.EMGM.Derive.Internal

#ifndef __HADDOCK__

$(derive ''Maybe)

#else
-- The following code is used by Haddock to generate documentation. It may be
-- useful to keep around for debugging TH, so don't remove it.
import Generics.EMGM.Common
import Generics.EMGM.Functions.Collect
import Generics.EMGM.Functions.Everywhere

-----------------------------------------------------------------------------
-- Embedding-projection pair
Expand Down Expand Up @@ -131,5 +123,3 @@ instance (Rep (Everywhere (Maybe a)) a) => Rep (Everywhere (Maybe a)) (Maybe a)
instance Rep (Everywhere' (Maybe a)) (Maybe a) where
rep = Everywhere' ($)

#endif

4 changes: 3 additions & 1 deletion src/Generics/EMGM/Data/Tuple.hs
Expand Up @@ -86,7 +86,9 @@ module Generics.EMGM.Data.Tuple (

) where

import Generics.EMGM.Derive.Internal
import Generics.EMGM.Common
import Generics.EMGM.Functions.Collect
import Generics.EMGM.Functions.Everywhere

-----------------------------------------------------------------------------
-- 0: ()
Expand Down
7 changes: 1 addition & 6 deletions src/Generics/EMGM/Functions/Everywhere.hs
@@ -1,4 +1,3 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
Expand Down Expand Up @@ -31,7 +30,7 @@
--
-- @
-- -- SYB
-- everywhere :: (forall a. 'Data' a => a -> a) -> forall a. 'Data' a => a -> a
-- everywhere :: (forall a. Data a => a -> a) -> forall a. Data a => a -> a
-- @
--
-- @
Expand All @@ -50,10 +49,6 @@ module Generics.EMGM.Functions.Everywhere (
import Generics.EMGM.Common.Base
import Generics.EMGM.Common.Representation

#ifdef __HADDOCK__
import Data.Generics (Data)
#endif

--------------------------------------------------------------------------------
-- Types
--------------------------------------------------------------------------------
Expand Down

0 comments on commit 695bf39

Please sign in to comment.