Lens.hs 9.75 KB
Newer Older
1 2 3 4 5
module Distribution.Types.BuildInfo.Lens (
    BuildInfo,
    HasBuildInfo (..),
    ) where

Oleg Grenrus's avatar
Oleg Grenrus committed
6
import Prelude ()
7 8 9
import Distribution.Compat.Prelude
import Distribution.Compat.Lens

Oleg Grenrus's avatar
Oleg Grenrus committed
10 11 12 13 14 15 16 17 18 19
import Distribution.Compiler                  (CompilerFlavor)
import Distribution.ModuleName                (ModuleName)
import Distribution.Types.BuildInfo           (BuildInfo)
import Distribution.Types.Dependency          (Dependency)
import Distribution.Types.ExeDependency       (ExeDependency)
import Distribution.Types.LegacyExeDependency (LegacyExeDependency)
import Distribution.Types.Mixin               (Mixin)
import Distribution.Types.PkgconfigDependency (PkgconfigDependency)
import Language.Haskell.Extension             (Extension, Language)

20 21 22 23
import qualified Distribution.Types.BuildInfo as T

-- | Classy lenses for 'BuildInfo'.
class HasBuildInfo a where
Oleg Grenrus's avatar
Oleg Grenrus committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
   buildInfo :: Lens' a BuildInfo

   buildable :: Lens' a Bool
   buildable = buildInfo . buildable
   {-# INLINE buildable #-}

   buildTools :: Lens' a [LegacyExeDependency]
   buildTools = buildInfo . buildTools
   {-# INLINE buildTools #-}

   buildToolDepends :: Lens' a [ExeDependency]
   buildToolDepends = buildInfo . buildToolDepends
   {-# INLINE buildToolDepends #-}

   cppOptions :: Lens' a [String]
   cppOptions = buildInfo . cppOptions
   {-# INLINE cppOptions #-}

42 43 44 45 46 47 48 49
   asmOptions :: Lens' a [String]
   asmOptions = buildInfo . asmOptions
   {-# INLINE asmOptions #-}

   cmmOptions :: Lens' a [String]
   cmmOptions = buildInfo . cmmOptions
   {-# INLINE cmmOptions #-}

Oleg Grenrus's avatar
Oleg Grenrus committed
50 51 52 53
   ccOptions :: Lens' a [String]
   ccOptions = buildInfo . ccOptions
   {-# INLINE ccOptions #-}

54 55 56 57
   cxxOptions :: Lens' a [String]
   cxxOptions = buildInfo . cxxOptions
   {-# INLINE cxxOptions #-}

Oleg Grenrus's avatar
Oleg Grenrus committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
   ldOptions :: Lens' a [String]
   ldOptions = buildInfo . ldOptions
   {-# INLINE ldOptions #-}

   pkgconfigDepends :: Lens' a [PkgconfigDependency]
   pkgconfigDepends = buildInfo . pkgconfigDepends
   {-# INLINE pkgconfigDepends #-}

   frameworks :: Lens' a [String]
   frameworks = buildInfo . frameworks
   {-# INLINE frameworks #-}

   extraFrameworkDirs :: Lens' a [String]
   extraFrameworkDirs = buildInfo . extraFrameworkDirs
   {-# INLINE extraFrameworkDirs #-}

74 75 76 77 78 79 80 81
   asmSources :: Lens' a [FilePath]
   asmSources = buildInfo . asmSources
   {-# INLINE asmSources #-}

   cmmSources :: Lens' a [FilePath]
   cmmSources = buildInfo . cmmSources
   {-# INLINE cmmSources #-}

Oleg Grenrus's avatar
Oleg Grenrus committed
82
   cSources :: Lens' a [FilePath]
Oleg Grenrus's avatar
Oleg Grenrus committed
83 84 85
   cSources = buildInfo . cSources
   {-# INLINE cSources #-}

86 87 88 89
   cxxSources :: Lens' a [FilePath]
   cxxSources = buildInfo . cxxSources
   {-# INLINE cxxSources #-}

Oleg Grenrus's avatar
Oleg Grenrus committed
90
   jsSources :: Lens' a [FilePath]
Oleg Grenrus's avatar
Oleg Grenrus committed
91 92 93
   jsSources = buildInfo . jsSources
   {-# INLINE jsSources #-}

Oleg Grenrus's avatar
Oleg Grenrus committed
94
   hsSourceDirs :: Lens' a [FilePath]
Oleg Grenrus's avatar
Oleg Grenrus committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
   hsSourceDirs = buildInfo . hsSourceDirs
   {-# INLINE hsSourceDirs #-}

   otherModules :: Lens' a [ModuleName]
   otherModules = buildInfo . otherModules
   {-# INLINE otherModules #-}

   autogenModules :: Lens' a [ModuleName]
   autogenModules = buildInfo . autogenModules
   {-# INLINE autogenModules #-}

   defaultLanguage :: Lens' a (Maybe Language)
   defaultLanguage = buildInfo . defaultLanguage
   {-# INLINE defaultLanguage #-}

   otherLanguages :: Lens' a [Language]
   otherLanguages = buildInfo . otherLanguages
   {-# INLINE otherLanguages #-}

   defaultExtensions :: Lens' a [Extension]
   defaultExtensions = buildInfo . defaultExtensions
   {-# INLINE defaultExtensions #-}

   otherExtensions :: Lens' a [Extension]
   otherExtensions = buildInfo . otherExtensions
   {-# INLINE otherExtensions #-}

   oldExtensions :: Lens' a [Extension]
   oldExtensions = buildInfo . oldExtensions
   {-# INLINE oldExtensions #-}

   extraLibs :: Lens' a [String]
   extraLibs = buildInfo . extraLibs
   {-# INLINE extraLibs #-}

   extraGHCiLibs :: Lens' a [String]
   extraGHCiLibs = buildInfo . extraGHCiLibs
   {-# INLINE extraGHCiLibs #-}

134 135 136 137
   extraBundledLibs :: Lens' a [String]
   extraBundledLibs = buildInfo . extraBundledLibs
   {-# INLINE extraBundledLibs #-}

Oleg Grenrus's avatar
Oleg Grenrus committed
138 139 140 141
   extraLibDirs :: Lens' a [String]
   extraLibDirs = buildInfo . extraLibDirs
   {-# INLINE extraLibDirs #-}

Oleg Grenrus's avatar
Oleg Grenrus committed
142
   includeDirs :: Lens' a [FilePath]
Oleg Grenrus's avatar
Oleg Grenrus committed
143 144 145
   includeDirs = buildInfo . includeDirs
   {-# INLINE includeDirs #-}

Oleg Grenrus's avatar
Oleg Grenrus committed
146
   includes :: Lens' a [FilePath]
Oleg Grenrus's avatar
Oleg Grenrus committed
147 148 149
   includes = buildInfo . includes
   {-# INLINE includes #-}

Oleg Grenrus's avatar
Oleg Grenrus committed
150
   installIncludes :: Lens' a [FilePath]
Oleg Grenrus's avatar
Oleg Grenrus committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
   installIncludes = buildInfo . installIncludes
   {-# INLINE installIncludes #-}

   options :: Lens' a [(CompilerFlavor,[String])]
   options = buildInfo . options
   {-# INLINE options #-}

   profOptions :: Lens' a [(CompilerFlavor,[String])]
   profOptions = buildInfo . profOptions
   {-# INLINE profOptions #-}

   sharedOptions :: Lens' a [(CompilerFlavor,[String])]
   sharedOptions = buildInfo . sharedOptions
   {-# INLINE sharedOptions #-}

   staticOptions :: Lens' a [(CompilerFlavor,[String])]
   staticOptions = buildInfo . staticOptions
   {-# INLINE staticOptions #-}

   customFieldsBI :: Lens' a [(String,String)]
   customFieldsBI = buildInfo . customFieldsBI
   {-# INLINE customFieldsBI #-}

   targetBuildDepends :: Lens' a [Dependency]
   targetBuildDepends = buildInfo . targetBuildDepends
   {-# INLINE targetBuildDepends #-}
177

Oleg Grenrus's avatar
Oleg Grenrus committed
178 179 180
   mixins :: Lens' a [Mixin]
   mixins = buildInfo . mixins
   {-# INLINE mixins #-}
181

182

183 184
instance HasBuildInfo BuildInfo where
    buildInfo = id
Oleg Grenrus's avatar
Oleg Grenrus committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198
    {-# INLINE buildInfo #-}

    buildable f s = fmap (\x -> s { T.buildable = x }) (f (T.buildable s))
    {-# INLINE buildable #-}

    buildTools f s = fmap (\x -> s { T.buildTools = x }) (f (T.buildTools s))
    {-# INLINE buildTools #-}

    buildToolDepends f s = fmap (\x -> s { T.buildToolDepends = x }) (f (T.buildToolDepends s))
    {-# INLINE buildToolDepends #-}

    cppOptions f s = fmap (\x -> s { T.cppOptions = x }) (f (T.cppOptions s))
    {-# INLINE cppOptions #-}

199 200 201 202 203 204
    asmOptions f s = fmap (\x -> s { T.asmOptions = x }) (f (T.asmOptions s))
    {-# INLINE asmOptions #-}

    cmmOptions f s = fmap (\x -> s { T.cmmOptions = x }) (f (T.cmmOptions s))
    {-# INLINE cmmOptions #-}

Oleg Grenrus's avatar
Oleg Grenrus committed
205 206 207
    ccOptions f s = fmap (\x -> s { T.ccOptions = x }) (f (T.ccOptions s))
    {-# INLINE ccOptions #-}

208 209 210
    cxxOptions f s = fmap (\x -> s { T.cxxOptions = x }) (f (T.cxxOptions s))
    {-# INLINE cxxOptions #-}

Oleg Grenrus's avatar
Oleg Grenrus committed
211 212 213 214 215 216 217 218 219 220 221 222
    ldOptions f s = fmap (\x -> s { T.ldOptions = x }) (f (T.ldOptions s))
    {-# INLINE ldOptions #-}

    pkgconfigDepends f s = fmap (\x -> s { T.pkgconfigDepends = x }) (f (T.pkgconfigDepends s))
    {-# INLINE pkgconfigDepends #-}

    frameworks f s = fmap (\x -> s { T.frameworks = x }) (f (T.frameworks s))
    {-# INLINE frameworks #-}

    extraFrameworkDirs f s = fmap (\x -> s { T.extraFrameworkDirs = x }) (f (T.extraFrameworkDirs s))
    {-# INLINE extraFrameworkDirs #-}

223 224 225 226 227 228
    asmSources f s = fmap (\x -> s { T.asmSources = x }) (f (T.asmSources s))
    {-# INLINE asmSources #-}

    cmmSources f s = fmap (\x -> s { T.cmmSources = x }) (f (T.cmmSources s))
    {-# INLINE cmmSources #-}

Oleg Grenrus's avatar
Oleg Grenrus committed
229 230 231
    cSources f s = fmap (\x -> s { T.cSources = x }) (f (T.cSources s))
    {-# INLINE cSources #-}

232 233 234
    cxxSources f s = fmap (\x -> s { T.cSources = x }) (f (T.cxxSources s))
    {-# INLINE cxxSources #-}

Oleg Grenrus's avatar
Oleg Grenrus committed
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
    jsSources f s = fmap (\x -> s { T.jsSources = x }) (f (T.jsSources s))
    {-# INLINE jsSources #-}

    hsSourceDirs f s = fmap (\x -> s { T.hsSourceDirs = x }) (f (T.hsSourceDirs s))
    {-# INLINE hsSourceDirs #-}

    otherModules f s = fmap (\x -> s { T.otherModules = x }) (f (T.otherModules s))
    {-# INLINE otherModules #-}

    autogenModules f s = fmap (\x -> s { T.autogenModules = x }) (f (T.autogenModules s))
    {-# INLINE autogenModules #-}

    defaultLanguage f s = fmap (\x -> s { T.defaultLanguage = x }) (f (T.defaultLanguage s))
    {-# INLINE defaultLanguage #-}

    otherLanguages f s = fmap (\x -> s { T.otherLanguages = x }) (f (T.otherLanguages s))
    {-# INLINE otherLanguages #-}

    defaultExtensions f s = fmap (\x -> s { T.defaultExtensions = x }) (f (T.defaultExtensions s))
    {-# INLINE defaultExtensions #-}

    otherExtensions f s = fmap (\x -> s { T.otherExtensions = x }) (f (T.otherExtensions s))
    {-# INLINE otherExtensions #-}

    oldExtensions f s = fmap (\x -> s { T.oldExtensions = x }) (f (T.oldExtensions s))
    {-# INLINE oldExtensions #-}

    extraLibs f s = fmap (\x -> s { T.extraLibs = x }) (f (T.extraLibs s))
    {-# INLINE extraLibs #-}

    extraGHCiLibs f s = fmap (\x -> s { T.extraGHCiLibs = x }) (f (T.extraGHCiLibs s))
    {-# INLINE extraGHCiLibs #-}

268 269 270
    extraBundledLibs f s = fmap (\x -> s { T.extraBundledLibs = x }) (f (T.extraBundledLibs s))
    {-# INLINE extraBundledLibs #-}

Oleg Grenrus's avatar
Oleg Grenrus committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
    extraLibDirs f s = fmap (\x -> s { T.extraLibDirs = x }) (f (T.extraLibDirs s))
    {-# INLINE extraLibDirs #-}

    includeDirs f s = fmap (\x -> s { T.includeDirs = x }) (f (T.includeDirs s))
    {-# INLINE includeDirs #-}

    includes f s = fmap (\x -> s { T.includes = x }) (f (T.includes s))
    {-# INLINE includes #-}

    installIncludes f s = fmap (\x -> s { T.installIncludes = x }) (f (T.installIncludes s))
    {-# INLINE installIncludes #-}

    options f s = fmap (\x -> s { T.options = x }) (f (T.options s))
    {-# INLINE options #-}

    profOptions f s = fmap (\x -> s { T.profOptions = x }) (f (T.profOptions s))
    {-# INLINE profOptions #-}

    sharedOptions f s = fmap (\x -> s { T.sharedOptions = x }) (f (T.sharedOptions s))
    {-# INLINE sharedOptions #-}

    staticOptions f s = fmap (\x -> s { T.staticOptions = x }) (f (T.staticOptions s))
    {-# INLINE staticOptions #-}

    customFieldsBI f s = fmap (\x -> s { T.customFieldsBI = x }) (f (T.customFieldsBI s))
    {-# INLINE customFieldsBI #-}

    targetBuildDepends f s = fmap (\x -> s { T.targetBuildDepends = x }) (f (T.targetBuildDepends s))
    {-# INLINE targetBuildDepends #-}
300

Oleg Grenrus's avatar
Oleg Grenrus committed
301 302
    mixins f s = fmap (\x -> s { T.mixins = x }) (f (T.mixins s))
    {-# INLINE mixins #-}