shake-cabal (empty) → 0.1.0.0
raw patch · 5 files changed
+153/−0 lines, 5 filesdep +Cabaldep +basedep +composition-preludesetup-changed
Dependencies added: Cabal, base, composition-prelude, directory, shake
Files
- LICENSE +11/−0
- README.md +4/−0
- Setup.hs +2/−0
- shake-cabal.cabal +47/−0
- src/Development/Shake/Cabal.hs +89/−0
+ LICENSE view
@@ -0,0 +1,11 @@+Copyright Vanessa McHale (c) 2018++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.++2. 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.++3. Neither the name of the copyright holder nor the names of its 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 HOLDER 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,4 @@+# shake-cabal++A library for using [shake](http://hackage.haskell.org/package/shake) with+[cabal](https://www.haskell.org/cabal/download.html).
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ shake-cabal.cabal view
@@ -0,0 +1,47 @@+cabal-version: 1.18+name: shake-cabal+version: 0.1.0.0+license: BSD3+license-file: LICENSE+copyright: Copyright: (c) 2018 Vanessa McHale+maintainer: vanessa.mchale@iohk.io+author: Vanessa McHale+synopsis: Shake library for use with cabal+description:+ A library for using [shake](http://hackage.haskell.org/package/shake) alongside [cabal](https://www.haskell.org/cabal/).+category: Development+build-type: Simple+extra-doc-files: README.md++source-repository head+ type: darcs+ location: https://hub.darcs.net/vmchale/ats++flag development+ description:+ Enable `-Werror`+ default: False+ manual: True++library+ exposed-modules:+ Development.Shake.Cabal+ hs-source-dirs: src+ default-language: Haskell2010+ ghc-options: -Wall+ build-depends:+ base >=4.3 && <5,+ shake -any,+ Cabal >=2.2,+ directory -any,+ composition-prelude -any+ + if flag(development)+ ghc-options: -Werror+ + if impl(ghc >=8.0)+ ghc-options: -Wincomplete-uni-patterns -Wincomplete-record-updates+ -Wredundant-constraints -Wnoncanonical-monad-instances+ + if impl(ghc >=8.4)+ ghc-options: -Wmissing-export-lists
+ src/Development/Shake/Cabal.hs view
@@ -0,0 +1,89 @@+module Development.Shake.Cabal ( getCabalDeps+ , getCabalDepsV+ , getCabalDepsA+ , shakeVerbosityToCabalVerbosity+ -- * Types+ , HsCompiler (..)+ -- * Helper functions+ , platform+ , hsCompiler+ -- * Reëxports from "Distribution.Version"+ , prettyShow+ ) where++import Control.Arrow+import Control.Composition+import Control.Monad+import Data.Foldable (toList)+import Data.Maybe (catMaybes)+import Development.Shake hiding (doesFileExist)+import qualified Development.Shake as Shake+import Distribution.ModuleName+import Distribution.PackageDescription+import Distribution.PackageDescription.Parsec+import Distribution.Pretty+import Distribution.Types.CondTree+import Distribution.Types.PackageId+import Distribution.Verbosity as Distribution+import Distribution.Version+import System.Directory (doesFileExist)+import System.Info (arch, os)++data HsCompiler = GHC { _suff :: Maybe String -- ^ Compiler version+ }+ | GHCJS { _suff :: Maybe String -- ^ Compiler version+ }++hsCompiler :: HsCompiler -> String+hsCompiler (GHC Nothing) = "ghc"+hsCompiler (GHC (Just v)) = "ghc-" ++ v+hsCompiler (GHCJS Nothing) = "ghcjs"+hsCompiler (GHCJS (Just v)) = "ghcjs-" ++ v++-- | E.g. @x86_64-linux@+platform :: String+platform = arch ++ "-" ++ os++libraryToFiles :: Library -> [FilePath]+libraryToFiles lib = mconcat [cs, is, hs]+ where (cs, is) = (cSources &&& includes) $ libBuildInfo lib+ hs = (++ ".hs") . toFilePath <$> explicitLibModules lib++extract :: CondTree a b Library -> [Library]+extract (CondNode d _ []) = [d]+extract (CondNode d _ bs) = d : (g =<< bs)+ where g (CondBranch _ tb fb) = join $ catMaybes [Just $ extract tb, extract <$> fb]++-- | Assign each shake @Verbosity@ level to a Cabal @Verbosity@ level.+shakeVerbosityToCabalVerbosity :: Shake.Verbosity -> Distribution.Verbosity+shakeVerbosityToCabalVerbosity Silent = silent+shakeVerbosityToCabalVerbosity Quiet = normal+shakeVerbosityToCabalVerbosity Normal = normal+shakeVerbosityToCabalVerbosity Loud = verbose+shakeVerbosityToCabalVerbosity Chatty = verbose+shakeVerbosityToCabalVerbosity Diagnostic = deafening++-- | Get cabal dependencies, respecting verbosity level given to+-- [shake](http://shakebuild.com/).+getCabalDepsA :: FilePath -> Action (Version, [FilePath])+getCabalDepsA = join . (g <$> fmap shakeVerbosityToCabalVerbosity getVerbosity <*>) . pure+ where g = liftIO .* getCabalDepsV++-- | Get library dependencies from a @.cabal@ file. This will only work for+-- @.hs@ files; module signatures are not supported.+getCabalDeps :: FilePath -> IO (Version, [FilePath])+getCabalDeps = getCabalDepsV normal++getCabalDepsV :: Distribution.Verbosity -> FilePath -> IO (Version, [FilePath])+getCabalDepsV v p = do+ pkg <- readGenericPackageDescription v p+ let descr = packageDescription pkg+ extraSrc = extraSrcFiles descr+ vers = pkgVersion (package descr)+ libs = toList (condLibrary pkg)+ normalSrc = (libraryToFiles <=< extract) =<< libs+ dir = (fmap (++ "/") . hsSourceDirs . libBuildInfo <=< extract) =<< libs+ dirge = ((++) <$> dir <*>)+ h = filterM doesFileExist+ norms <- h (dirge normalSrc)+ pure (vers, extraSrc ++ norms)