Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

code drop

  • Loading branch information...
commit 6e84a89a2903618fea6457beb2c6ef2d6aa1c2d9 0 parents
Greg Weber gregwebs authored
1  .gitignore
... ... @@ -0,0 +1 @@
  1 +dist/
25 LICENSE
... ... @@ -0,0 +1,25 @@
  1 +The following license covers this documentation, and the source code, except
  2 +where otherwise indicated.
  3 +
  4 +Copyright 2010, Michael Snoyman. All rights reserved.
  5 +
  6 +Redistribution and use in source and binary forms, with or without
  7 +modification, are permitted provided that the following conditions are met:
  8 +
  9 +* Redistributions of source code must retain the above copyright notice, this
  10 + list of conditions and the following disclaimer.
  11 +
  12 +* Redistributions in binary form must reproduce the above copyright notice,
  13 + this list of conditions and the following disclaimer in the documentation
  14 + and/or other materials provided with the distribution.
  15 +
  16 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR
  17 +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18 +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19 +EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21 +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  24 +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25 +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 README.md
Source Rendered
... ... @@ -0,0 +1,38 @@
  1 +If you run this command, you can easily get a failure:
  2 +
  3 + cabal install foo && cabal install bar
  4 +
  5 + Whereas if you run this command it should almost always work:
  6 +
  7 + cabal install foo bar
  8 +
  9 +cabal-meta facilitates installing everything at once.
  10 +When invoked, it looks for a file `sources.txt`.
  11 +Each line of `sources.txt` is either a directory to install or contains another `sources.txt` to recurse into.
  12 +cabal-meta won't continue to recurse if a cabal file is found.
  13 +cabal-meta automatically uses cabal-src-install also.
  14 +
  15 +
  16 +# Example
  17 +
  18 +To build a Yesod web application using the source from github, I have a sources.txt in my project consisting of
  19 +
  20 + ./
  21 + path/to/yesod/sources
  22 +
  23 +`./` means the current project
  24 +`path/to/yesod/sources` contains a `sources.txt` with:
  25 +
  26 + hamlet
  27 + persistent
  28 + wai
  29 + yesod
  30 +
  31 +Each of these directories have a `sources.txt` listing several dirctories containing cabal packages.
  32 +
  33 +Confused? It is just recursion, although we are interleaving IO :)
  34 +
  35 +
  36 +# TODO
  37 +
  38 +* support github and tar.gz urls: this lets us do beta releases and work with hackage
28 cabal-meta.cabal
... ... @@ -0,0 +1,28 @@
  1 +name: cabal-meta
  2 +version: 0.0
  3 +license: BSD3
  4 +license-file: LICENSE
  5 +author: Greg Weber <greg@gregweber.info>
  6 +maintainer: Greg Weber <greg@gregweber.info>
  7 +synopsis: build multiple packages at once
  8 +description: build multiple packages at once
  9 +
  10 +stability: Beta
  11 +cabal-version: >= 1.8
  12 +build-type: Simple
  13 +homepage: http://www.yesodweb.com/
  14 +
  15 +flag ghc7
  16 +
  17 +executable cabal-meta
  18 + main-is: cabal-meta.hs
  19 +
  20 + if flag(ghc7)
  21 + build-depends: base >= 4.3 && < 5
  22 + cpp-options: -DGHC7
  23 + else
  24 + build-depends: base >= 4 && < 4.3
  25 + build-depends: shelly, filepath, text
  26 +
  27 + ghc-options: -Wall
  28 +
59 cabal-meta.hs
... ... @@ -0,0 +1,59 @@
  1 +{-# LANGUAGE OverloadedStrings #-}
  2 +
  3 +-- TODO:
  4 +-- * use --only-dependencies. otherwise a simple build failure will prevent a cabal-src-install
  5 +-- support git & tar.gz urls
  6 +
  7 +import Shelly
  8 +import Data.Text.Lazy (Text, pack, unpack)
  9 +import qualified Data.Text.Lazy as LT
  10 +import Control.Monad (forM, forM_, when)
  11 +import System.Environment (getArgs)
  12 +import System.FilePath (takeExtension)
  13 +
  14 +source_file :: FilePath
  15 +source_file = "sources.txt"
  16 +
  17 +cabal_install :: [Text] -> ShIO Text
  18 +cabal_install = command "cabal" ["install"]
  19 +
  20 +headDef :: a -> [a] -> a
  21 +headDef d [] = d
  22 +headDef _ (x:_) = x
  23 +
  24 +main :: IO ()
  25 +main = do
  26 + args <- fmap (map pack) getArgs
  27 + shelly $ verbosely $ do
  28 + pkgs <- readPackages True $ headDef "." args
  29 + echo "Installing packages:"
  30 + forM_ pkgs echo
  31 + _<-cabal_install pkgs
  32 + forM_ pkgs $ \pkg ->
  33 + chdir (unpack pkg) $ "cabal-src-install" # ["--src-only"]
  34 + return ()
  35 +
  36 +readPackages :: Bool -> Text -> ShIO [Text]
  37 +readPackages allowCabals dir = do
  38 + fullDir <- path (unpack dir)
  39 + chdir fullDir $ do
  40 + cabalPresent <- if allowCabals then return False else isCabalPresent
  41 + if cabalPresent then return [] else do
  42 + pkgs <- getSources
  43 + child_pkgs <- forM pkgs $ \pkg -> do
  44 + b <- fmap (== fullDir) (path $ unpack pkg)
  45 + if b then return [] else readPackages False pkg
  46 + return $ concatMap (\(p, ps) -> if null ps then [p] else ps) $ zip pkgs child_pkgs
  47 + where
  48 + isCabalFile f = ".cabal" == takeExtension f
  49 + isCabalPresent = do
  50 + cabals <- fmap (filter isCabalFile) $ ls "."
  51 + return $ not $ null cabals
  52 +
  53 + getSources :: ShIO [Text]
  54 + getSources = do
  55 + relative_pkgs <- fmap LT.lines $ readfile source_file
  56 + when (null relative_pkgs) $ error $ "empty " ++ source_file
  57 + mapM (liftAsString path) relative_pkgs
  58 + where
  59 + liftAsString f = fmap pack . f . unpack

0 comments on commit 6e84a89

Please sign in to comment.
Something went wrong with that request. Please try again.