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 v2-run ... source.temeplate.ext target.ext"
72 main
= withIO
$ \src tgt
-> do
73 mdl
<- parseAndCompileModuleIO config src
76 config
:: ModuleConfig Z
80 [ "{-# LANGUAGE DeriveGeneric #-}"
81 , "module Distribution.Simple.Build.Macros.Z (render, Z(..), ZPackage (..), ZTool (..)) where"
82 , "import Distribution.ZinzaPrelude"
84 , "render :: Z -> String"
88 -------------------------------------------------------------------------------
90 -------------------------------------------------------------------------------
92 instance Zinza Z
where
93 toType
= genericToTypeSFP
94 toValue
= genericToValueSFP
95 fromValue
= genericFromValueSFP
97 instance Zinza ZPackage
where
98 toType
= genericToTypeSFP
99 toValue
= genericToValueSFP
100 fromValue
= genericFromValueSFP
102 instance Zinza ZTool
where
103 toType
= genericToTypeSFP
104 toValue
= genericToValueSFP
105 fromValue
= genericFromValueSFP
107 -------------------------------------------------------------------------------
109 -------------------------------------------------------------------------------
111 instance Zinza PackageName
where
112 toType _
= TyString
(Just
"prettyShow")
113 toValue _
= error "not needed"
114 fromValue _
= error "not needed"
116 instance Zinza Version
where
117 toType _
= TyString
(Just
"prettyShow")
118 toValue _
= error "not needed"
119 fromValue _
= error "not needed"