forked from haskell/cabal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Zinza to generate
.../PackageInfoModule/z.hs
- Loading branch information
Showing
6 changed files
with
188 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
module Main (main) where | ||
|
||
import Control.Exception (SomeException (..), catch, displayException) | ||
import Distribution.Types.PackageName (PackageName) | ||
import GHC.Generics (Generic) | ||
import System.Environment (getArgs) | ||
import System.Exit (exitFailure) | ||
import Zinza | ||
(ModuleConfig (..), Ty (..), Zinza (..), genericFromValueSFP, genericToTypeSFP, | ||
genericToValueSFP, parseAndCompileModuleIO) | ||
|
||
import Capture | ||
|
||
------------------------------------------------------------------------------- | ||
-- Inputs | ||
------------------------------------------------------------------------------- | ||
|
||
$(capture "decls" [d| | ||
data Z = Z | ||
{ zPackageName :: PackageName | ||
, zVersionDigits :: String | ||
, zSynopsis :: String | ||
, zCopyright :: String | ||
, zLicense :: String | ||
, zHomepage :: String | ||
|
||
, zSupportsNoRebindableSyntax :: Bool | ||
|
||
, zManglePkgName :: PackageName -> String | ||
, zShow :: String -> String | ||
} | ||
deriving (Generic) | ||
|]) | ||
|
||
------------------------------------------------------------------------------- | ||
-- Main | ||
------------------------------------------------------------------------------- | ||
|
||
withIO :: (FilePath -> FilePath -> IO a) -> IO a | ||
withIO k = do | ||
args <- getArgs | ||
case args of | ||
[src,tgt] -> k src tgt `catch` \(SomeException e) -> do | ||
putStrLn $ "Exception: " ++ displayException e | ||
exitFailure | ||
_ -> do | ||
putStrLn "Usage cabal run ... source.temeplate.ext target.ext" | ||
exitFailure | ||
|
||
main :: IO () | ||
main = withIO $ \src tgt -> do | ||
mdl <- parseAndCompileModuleIO config src | ||
writeFile tgt mdl | ||
|
||
config :: ModuleConfig Z | ||
config = ModuleConfig | ||
{ mcRender = "render" | ||
, mcHeader = | ||
[ "{- FOURMOLU_DISABLE -}" | ||
, "{-# LANGUAGE DeriveGeneric #-}" | ||
, "module Distribution.Simple.Build.PackageInfoModule.Z (render, Z(..)) where" | ||
, "import Distribution.ZinzaPrelude" | ||
, decls | ||
, "render :: Z -> String" | ||
] | ||
} | ||
|
||
------------------------------------------------------------------------------- | ||
-- Zinza instances | ||
------------------------------------------------------------------------------- | ||
|
||
instance Zinza Z where | ||
toType = genericToTypeSFP | ||
toValue = genericToValueSFP | ||
fromValue = genericFromValueSFP | ||
|
||
------------------------------------------------------------------------------- | ||
-- Orphans | ||
------------------------------------------------------------------------------- | ||
|
||
instance Zinza PackageName where | ||
toType _ = TyString (Just "prettyShow") | ||
toValue _ = error "not needed" | ||
fromValue _ = error "not needed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{% if supportsNoRebindableSyntax %} | ||
{-# LANGUAGE NoRebindableSyntax #-} | ||
{% endif %} | ||
{-# OPTIONS_GHC -fno-warn-missing-import-lists #-} | ||
{-# OPTIONS_GHC -w #-} | ||
module PackageInfo_{{ manglePkgName packageName }} | ||
( name | ||
, version | ||
, synopsis | ||
, copyright | ||
, license | ||
, homepage | ||
) where | ||
|
||
import Data.Version (Version(..)) | ||
import Prelude | ||
|
||
name :: String | ||
name = {{ show (manglePkgName packageName) }} | ||
|
||
version :: Version | ||
version = Version {{ versionDigits }} [] | ||
|
||
synopsis :: String | ||
synopsis = {{ synopsis }} | ||
|
||
copyright :: String | ||
copyright = {{ copyright }} | ||
|
||
license :: String | ||
license = {{ license }} | ||
|
||
homepage :: String | ||
homepage = {{ homepage }} | ||
|