cabal-progdeps (empty) → 1.0
raw patch · 4 files changed
+134/−0 lines, 4 filesdep +Cabaldep +basedep +directorysetup-changed
Dependencies added: Cabal, base, directory, filepath
Files
- LICENSE +30/−0
- Setup.hs +3/−0
- cabal-progdeps.cabal +40/−0
- progdeps.hs +61/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2012, Kevin Quick+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 Kevin Quick 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.
+ Setup.hs view
@@ -0,0 +1,3 @@+import Distribution.Simple+main :: IO ()+main = defaultMain
+ cabal-progdeps.cabal view
@@ -0,0 +1,40 @@+name: cabal-progdeps+version: 1.0+synopsis: Show dependencies of program being built in current directory++description:++ This utility can be used to display the version dependency+ information for the program being built in the current directory.+ Essentially it parses the dist/setup-config and displays the+ information in a readable format. This can be very helpful when+ adding version constraints to your package's dependencies in that it+ shows what your package is currently built (or configured to be+ built) with.+ .+ n.b. It's called "progdeps" instead of "pkgdeps" because it's+ examining the build information in the current directory and not+ actual packages.+ .+ Usage: cabal-progdeps+ .+ Works with cabal-dev and cabal.+ .++category: Distribution+license: BSD3+license-file: LICENSE+author: Kevin Quick+maintainer: quick@sparq.org+build-type: Simple+cabal-version: >= 1.2+++Executable cabal-progdeps+ Main-is: progdeps.hs+ Build-Depends:+ base >= 4 && < 5,+ Cabal > 1.10 && < 2,+ filepath >= 1.2 && < 1.3,+ directory >= 1.1 && < 1.2+ ghc-options: -Wall
+ progdeps.hs view
@@ -0,0 +1,61 @@+module Main where++import System.Directory (getCurrentDirectory)+import System.FilePath ( (</>) )+import System.Exit (exitSuccess, exitWith, ExitCode(..))+import System.Environment (getArgs, getProgName)+import Data.List (intercalate)+import Data.Char (toUpper)+import Control.Applicative ( (<$>) )+import Control.Monad (when)+import Distribution.Simple.LocalBuildInfo+import Distribution.InstalledPackageInfo (showInstalledPackageInfoField+ -- ,showInstalledPackageInfo+ )+import Distribution.Simple.PackageIndex (topologicalOrder)++exitUsage :: IO ()+exitUsage = do putStr "Usage: "+ putStr =<< getProgName+ putStrLn " [progdir]"+ putStrLn ""+ putStrLn " Shows the current package dependency versions for the"+ putStrLn " cabal-built program in progdir (default=current directory)."+ exitWith $ ExitFailure 2++mktable :: [[String]] -> [String]+mktable cols = zipLists "" (mkcol widths) cols+ where zipLists e f ls = if all null ls then []+ else f (map (headOr e) ls) : zipLists e f (map (tailOr []) ls)+ headOr d = head . \l -> l ++ [d]+ tailOr d = tail . \l -> l ++ d+ widths = [ maximum (map length c) | c <- cols ]+ mkcol _ [] = ""+ mkcol s (a:bs) = let (sz:szs) = s+ fillsz = if length a < sz then sz - length a else 0+ fill = replicate fillsz ' '+ in a ++ fill ++ "| " ++ mkcol szs bs++main :: IO ()+main = do args <- getArgs+ when ("-h" `elem` args) exitUsage+ when ("--help" `elem` args) exitUsage+ when (length args > 1) exitUsage+ curdir <- return . head . (++) args . flip (:) [] =<< getCurrentDirectory+ let progcfgName = curdir </> "dist" </> "setup-config"+ progcfg <- lines <$> readFile progcfgName+ -- always 2 lines: a version declaration followed by the LocalBuildInfo `show'+ let cdata = (read . head . tail $ progcfg) :: LocalBuildInfo+ showfld f = blnkOrVal f . showInstalledPackageInfoField $ f+ blnkOrVal f = maybe (const " ") (\g -> drop (2 + length f) . g)+ pkglist = topologicalOrder . installedPkgs $ cdata+ fldcol n = (:) (map toUpper n) . map (showfld n)+ putStrLn $ head progcfg+ -- putStrLn . show . withPrograms $ cdata+ putStrLn . intercalate "\n" $ mktable [ fldcol "name" pkglist+ , fldcol "version" pkglist+ , fldcol "stability" pkglist+ , fldcol "category" pkglist+ ]+ -- putStrLn . intercalate "\n\n" . map showInstalledPackageInfo $ pkglist+ exitSuccess