cabal-toolkit (empty) → 0.0.1
raw patch · 6 files changed
+210/−0 lines, 6 filesdep +Cabaldep +basedep +binarysetup-changed
Dependencies added: Cabal, base, binary, bytestring, containers, template-haskell
Files
- CHANGELOG.md +5/−0
- LICENSE +13/−0
- README.md +5/−0
- Setup.hs +2/−0
- cabal-toolkit.cabal +42/−0
- src/Distribution/Simple/Toolkit.hs +143/−0
+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# CHANGELOG for cabal-toolkit++## 0.0.1++* Initial commit.
+ LICENSE view
@@ -0,0 +1,13 @@+Copyright Shao Cheng (c) 2017++All rights reserved.++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.++ * Neither the name of Shao Cheng nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,5 @@+# cabal-toolkit++[](https://ci.appveyor.com/project/TerrorJack/cabal-toolkit?branch=master)++Helper functions for writing custom `Setup.hs` scripts. See haddock documentation for details.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ cabal-toolkit.cabal view
@@ -0,0 +1,42 @@+-- This file has been generated from package.yaml by hpack version 0.17.1.+--+-- see: https://github.com/sol/hpack++name: cabal-toolkit+version: 0.0.1+synopsis: Helper functions for writing custom Setup.hs scripts.+category: Distribution+stability: alpha+homepage: https://github.com/TerrorJack/cabal-toolkit#readme+bug-reports: https://github.com/TerrorJack/cabal-toolkit/issues+maintainer: Shao Cheng <astrohavoc@gmail.com>+copyright: (c) 2017 Shao Cheng+license: BSD3+license-file: LICENSE+build-type: Simple+cabal-version: >= 1.10++extra-source-files:+ CHANGELOG.md+ LICENSE+ README.md++source-repository head+ type: git+ location: https://github.com/TerrorJack/cabal-toolkit++library+ hs-source-dirs:+ src+ other-extensions: TemplateHaskell+ ghc-options: -Wall+ build-depends:+ base >= 4.10 && < 5+ , binary+ , bytestring+ , containers+ , Cabal >= 2.0 && < 2.2+ , template-haskell+ exposed-modules:+ Distribution.Simple.Toolkit+ default-language: Haskell2010
+ src/Distribution/Simple/Toolkit.hs view
@@ -0,0 +1,143 @@+{-# LANGUAGE TemplateHaskell #-}+{-# OPTIONS_GHC -Wno-deprecations #-}+{-# OPTIONS_HADDOCK show-extensions #-}++{-|+Module: Distribution.Simple.Toolkit+Copyright: (c) 2017 Shao Cheng+License: BSD3+Maintainer: astrohavoc@gmail.com+Stability: alpha+Portability: non-portable++This module provides helper functions for writing custom @Setup.hs@ scripts.+-}++module Distribution.Simple.Toolkit+ ( -- * Writing build metadata in @Setup.hs@+ userHooksWithBuildInfo+ , simpleUserHooksWithBuildInfo+ , defaultMainWithBuildInfo+ -- * Retrieving build metadata via Template Haskell+ , packageDescriptionQ+ , packageDescriptionTypedQ+ , localBuildInfoQ+ , localBuildInfoTypedQ+ -- * Convenient functions for working with build metadata+ , getComponentInstallDirs+ , getComponentBuildInfo+ , getGHCLibDir+ , runLBIProgram+ , getLBIProgramOutput+ ) where++import Data.Binary+import qualified Data.ByteString.Lazy as LBS+import qualified Data.ByteString.Unsafe as BS+import Data.Map+import Distribution.Simple+import Distribution.Simple.LocalBuildInfo+import Distribution.Simple.Program+import Distribution.Simple.Setup+import Distribution.Types.BuildInfo+import Distribution.Types.PackageDescription+import Distribution.Verbosity+import Language.Haskell.TH.Syntax+import System.IO.Unsafe++{-|+Attach a post-configure action to a 'UserHooks' which serializes 'PackageDescription' to @.pkg_descr.buildinfo@ and 'LocalBuildInfo' to @.lbi.buildinfo@.+They should be added to your project's @.gitignore@ file.+Don't forget to edit the <https://cabal.readthedocs.io/en/latest/developing-packages.html#custom-setup-scripts custom-setup> stanza of your project's @.cabal@ file and add @cabal-toolkit@ to the dependencies.+-}+userHooksWithBuildInfo :: UserHooks -> UserHooks+userHooksWithBuildInfo hooks =+ hooks+ { postConf =+ \args flags pkg_descr lbi -> do+ encodeFile ".pkg_descr.buildinfo" pkg_descr+ encodeFile ".lbi.buildinfo" lbi+ postConf hooks args flags pkg_descr lbi+ }++simpleUserHooksWithBuildInfo :: UserHooks+simpleUserHooksWithBuildInfo = userHooksWithBuildInfo simpleUserHooks++defaultMainWithBuildInfo :: IO ()+defaultMainWithBuildInfo = defaultMainWithHooks simpleUserHooksWithBuildInfo++syringe :: FilePath -> Q Type -> Q Exp+syringe p t = do+ buf <- runIO $ LBS.readFile p+ [|unsafePerformIO $ do+ bs <-+ BS.unsafePackAddressLen+ $(lift $ LBS.length buf)+ $(pure $ LitE $ StringPrimL $ LBS.unpack buf)+ pure ((decode $ LBS.fromStrict bs) :: $(t))|]++{-|+The Template Haskell splice to retrieve 'PackageDescription'.+-}+packageDescriptionQ :: Q Exp+packageDescriptionQ = syringe ".pkg_descr.buildinfo" [t|PackageDescription|]++packageDescriptionTypedQ :: Q (TExp PackageDescription)+packageDescriptionTypedQ = unsafeTExpCoerce packageDescriptionQ++{-|+The Template Haskell splice to retrieve 'LocalBuildInfo'.+-}+localBuildInfoQ :: Q Exp+localBuildInfoQ = syringe ".lbi.buildinfo" [t|LocalBuildInfo|]++localBuildInfoTypedQ :: Q (TExp LocalBuildInfo)+localBuildInfoTypedQ = unsafeTExpCoerce localBuildInfoQ++{-|+Retrieve the 'InstallDirs' corresponding to a 'ComponentName', assuming that component does exist and is unique.+-}+getComponentInstallDirs ::+ PackageDescription+ -> LocalBuildInfo+ -> ComponentName+ -> InstallDirs FilePath+getComponentInstallDirs pkg_descr lbi k =+ absoluteComponentInstallDirs+ pkg_descr+ lbi+ (componentUnitId $ getComponentLocalBuildInfo lbi k)+ NoCopyDest++{-|+Retrieve the 'BuildInfo' corresponding to a 'ComponentName', assuming that component does exist and is unique.+-}+getComponentBuildInfo :: PackageDescription -> ComponentName -> BuildInfo+getComponentBuildInfo pkg_descr k =+ componentBuildInfo $ getComponent pkg_descr k++{-|+Equivalent to what you get from @ghc --print-libdir@.+-}+getGHCLibDir :: LocalBuildInfo -> FilePath+getGHCLibDir lbi = compilerProperties (compiler lbi) ! "LibDir"++{-|+Run a 'Program' with default 'Verbosity'.+-}+runLBIProgram :: LocalBuildInfo -> Program -> [ProgArg] -> IO ()+runLBIProgram lbi prog =+ runDbProgram+ (fromFlagOrDefault normal $ configVerbosity $ configFlags lbi)+ prog+ (withPrograms lbi)++{-|+Run a 'Program' and retrieve @stdout@ with default 'Verbosity'.+-}+getLBIProgramOutput :: LocalBuildInfo -> Program -> [ProgArg] -> IO String+getLBIProgramOutput lbi prog =+ getDbProgramOutput+ (fromFlagOrDefault normal $ configVerbosity $ configFlags lbi)+ prog+ (withPrograms lbi)