packages feed

cabal-toolkit 0.0.1 → 0.0.2

raw patch · 4 files changed

+39/−7 lines, 4 filesdep +ghc

Dependencies added: ghc

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # CHANGELOG for cabal-toolkit +## 0.0.2++* Add `getGHCPackageDBFlags` for users working with GHC API.+ ## 0.0.1  * Initial commit.
README.md view
@@ -1,5 +1,8 @@ # cabal-toolkit -[![Build Status](https://ci.appveyor.com/api/projects/status/github/TerrorJack/cabal-toolkit?branch=master&svg=true)](https://ci.appveyor.com/project/TerrorJack/cabal-toolkit?branch=master)+[![CircleCI](https://circleci.com/gh/TerrorJack/cabal-toolkit/tree/master.svg?style=shield)](https://circleci.com/gh/TerrorJack/cabal-toolkit/tree/master)+[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/TerrorJack/cabal-toolkit?branch=master&svg=true)](https://ci.appveyor.com/project/TerrorJack/cabal-toolkit?branch=master)+[![Hackage](https://img.shields.io/hackage/v/cabal-toolkit.svg)](https://hackage.haskell.org/package/cabal-toolkit)+[![Stackage Nightly](https://www.stackage.org/package/cabal-toolkit/badge/nightly)](https://www.stackage.org/nightly/package/cabal-toolkit)  Helper functions for writing custom `Setup.hs` scripts. See haddock documentation for details.
cabal-toolkit.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           cabal-toolkit-version:        0.0.1+version:        0.0.2 synopsis:       Helper functions for writing custom Setup.hs scripts. category:       Distribution stability:      alpha@@ -36,6 +36,7 @@     , bytestring     , containers     , Cabal >= 2.0 && < 2.2+    , ghc     , template-haskell   exposed-modules:       Distribution.Simple.Toolkit
src/Distribution/Simple/Toolkit.hs view
@@ -13,8 +13,8 @@ This module provides helper functions for writing custom @Setup.hs@ scripts. -} -module Distribution.Simple.Toolkit-  ( -- * Writing build metadata in @Setup.hs@+module Distribution.Simple.Toolkit (+  -- * Writing build metadata in @Setup.hs@     userHooksWithBuildInfo   , simpleUserHooksWithBuildInfo   , defaultMainWithBuildInfo@@ -29,6 +29,8 @@   , getGHCLibDir   , runLBIProgram   , getLBIProgramOutput+  -- * Convenient functions for working with GHC API+  , getGHCPackageDBFlags   ) where  import Data.Binary@@ -42,6 +44,7 @@ import Distribution.Types.BuildInfo import Distribution.Types.PackageDescription import Distribution.Verbosity+import DynFlags import Language.Haskell.TH.Syntax import System.IO.Unsafe @@ -51,15 +54,16 @@ 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+userHooksWithBuildInfo h =+  h   { postConf =       \args flags pkg_descr lbi -> do         encodeFile ".pkg_descr.buildinfo" pkg_descr         encodeFile ".lbi.buildinfo" lbi-        postConf hooks args flags pkg_descr lbi+        postConf h args flags pkg_descr lbi   } + simpleUserHooksWithBuildInfo :: UserHooks simpleUserHooksWithBuildInfo = userHooksWithBuildInfo simpleUserHooks @@ -141,3 +145,23 @@     (fromFlagOrDefault normal $ configVerbosity $ configFlags lbi)     prog     (withPrograms lbi)++{-|+Extract 'PackageDBFlag's from 'LocalBuildInfo' to put into the 'packageDBFlags' field of 'DynFlags'. This is useful to ensure the invocation of GHC API shares the same package databases (e.g. a @stack@ snapshot)+-}+getGHCPackageDBFlags :: LocalBuildInfo -> [PackageDBFlag]+getGHCPackageDBFlags lbi =+  reverse $+  case withPackageDB lbi of+    (GlobalPackageDB:UserPackageDB:dbs)+      | all isSpecific dbs -> fmap single dbs+    (GlobalPackageDB:dbs)+      | all isSpecific dbs -> NoUserPackageDB : fmap single dbs+    dbs -> ClearPackageDBs : fmap single dbs+  where+    single (SpecificPackageDB db) = PackageDB $ PkgConfFile db+    single GlobalPackageDB = PackageDB GlobalPkgConf+    single UserPackageDB = PackageDB UserPkgConf+    isSpecific (SpecificPackageDB _) = True+    isSpecific _ = False+