1 {-# LANGUAGE DeriveGeneric #-}
3 {-# LANGUAGE ScopedTypeVariables #-}
4 {-# LANGUAGE TemplateHaskell #-}
5 {-# OPTIONS_GHC -Wno-orphans #-}
6 module Main
(main
) where
8 import Control
.Exception
(SomeException
(..), catch, displayException
)
9 import Distribution
.Types
.PackageName
(PackageName
)
10 import Distribution
.Types
.Version
(Version
)
11 import GHC
.Generics
(Generic
)
12 import System
.Environment
(getArgs)
13 import System
.Exit
(exitFailure)
15 (ModuleConfig
(..), Ty
(..), Zinza
(..), genericFromValueSFP
, genericToTypeSFP
,
16 genericToValueSFP
, parseAndCompileModuleIO
)
20 -------------------------------------------------------------------------------
22 -------------------------------------------------------------------------------
26 { zPackages
:: [ZPackage
]
28 , zPackageKey
:: String
29 , zComponentId
:: String
30 , zPackageVersion
:: Version
31 , zNotNull
:: String -> Bool
32 , zManglePkgName
:: PackageName
-> String
33 , zMangleStr
:: String -> String
37 data ZPackage
= ZPackage
38 { zpkgName
:: PackageName
39 , zpkgVersion
:: Version
48 , ztoolVersion
:: Version
56 -------------------------------------------------------------------------------
58 -------------------------------------------------------------------------------
60 withIO
:: (FilePath -> FilePath -> IO a
) -> IO a
64 [src
,tgt
] -> k src tgt `
catch`
\(SomeException e
) -> do
65 putStrLn $ "Exception: " ++ displayException e
68 putStrLn "Usage cabal run ... source.temeplate.ext target.ext"
72 main
= withIO
$ \src tgt
-> do
73 mdl
<- parseAndCompileModuleIO config src
76 config
:: ModuleConfig Z
80 [ "{- FOURMOLU_DISABLE -}"
81 , "{-# LANGUAGE DeriveGeneric #-}"
82 , "module Distribution.Simple.Build.Macros.Z (render, Z(..), ZPackage (..), ZTool (..)) where"
83 , "import Distribution.ZinzaPrelude"
85 , "render :: Z -> String"
89 -------------------------------------------------------------------------------
91 -------------------------------------------------------------------------------
93 instance Zinza Z
where
94 toType
= genericToTypeSFP
95 toValue
= genericToValueSFP
96 fromValue
= genericFromValueSFP
98 instance Zinza ZPackage
where
99 toType
= genericToTypeSFP
100 toValue
= genericToValueSFP
101 fromValue
= genericFromValueSFP
103 instance Zinza ZTool
where
104 toType
= genericToTypeSFP
105 toValue
= genericToValueSFP
106 fromValue
= genericFromValueSFP
108 -------------------------------------------------------------------------------
110 -------------------------------------------------------------------------------
112 instance Zinza PackageName
where
113 toType _
= TyString
(Just
"prettyShow")
114 toValue _
= error "not needed"
115 fromValue _
= error "not needed"
117 instance Zinza Version
where
118 toType _
= TyString
(Just
"prettyShow")
119 toValue _
= error "not needed"
120 fromValue _
= error "not needed"