cabal-src (empty) → 0.1
raw patch · 4 files changed
+131/−0 lines, 4 filesdep +basedep +bytestringdep +directorysetup-changed
Dependencies added: base, bytestring, directory, process, tar
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- cabal-src-install.hs +74/−0
- cabal-src.cabal +25/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2011, Michael Snoyman++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 Michael Snoyman 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,2 @@+import Distribution.Simple+main = defaultMain
+ cabal-src-install.hs view
@@ -0,0 +1,74 @@+import System.Process (rawSystem)+import System.Environment (getArgs)+import System.Exit (ExitCode (ExitSuccess), exitWith)+import Control.Monad (unless, when)+import System.Directory+import Data.List (isSuffixOf, isPrefixOf)+import qualified Codec.Archive.Tar as Tar+import qualified Codec.Archive.Tar.Entry as TE+import Data.Monoid (mempty)+import qualified Data.ByteString as S+import qualified Data.ByteString.Lazy as L+import Control.Applicative ((<$>))++rawSystem' :: String -> [String] -> IO ()+rawSystem' a b = do+ ec <- rawSystem a b+ unless (ec == ExitSuccess) $ exitWith ec++main :: IO ()+main = do+ args <- getArgs+ unless (args == ["--src-only"]) $ rawSystem' "cabal" $ "install" : args+ putStrLn "Installing source package"+ distExists <- doesDirectoryExist "dist"+ when distExists $+ getDirectoryContents "dist" >>= mapM_ (\fp ->+ when (".tar.gz" `isSuffixOf` fp) $ removeFile $ "dist/" ++ fp)+ rawSystem' "cabal" ["sdist"]+ files <- getDirectoryContents "dist"+ case filter (".tar.gz" `isSuffixOf`) files of+ [x] -> do+ let y = drop 1 $ dropWhile (/= '.')+ $ drop 1 $ dropWhile (/= '.')+ $ reverse x+ let (ver', name') = break (== '-') y+ let ver = reverse ver'+ let name = reverse $ drop 1 name'+ addToDB name ver+ [] -> error "Missing tarball"+ _ -> error "Too many tarballs"++addToDB name ver = do+ cabal <- getAppUserDataDirectory "cabal"+ let pd = cabal ++ "/packages/cabal-src/"+ createDirectoryIfMissing True pd+ let tb = pd ++ "00-index.tar"+ e <- doesFileExist tb+ entries <-+ if e+ then Tar.foldEntries (:) [] error . Tar.read . L.fromChunks . return+ <$> S.readFile tb+ else return []+ cabalLBS <- L.readFile $ name ++ ".cabal"+ Right tarPath <- return $ TE.toTarPath False $ concat+ [name, "/", ver, "/", name, "-", ver, ".cabal"]+ let entry = TE.fileEntry tarPath cabalLBS+ let entries' = entry : filter (\e -> TE.entryTarPath e /= tarPath) entries+ L.writeFile tb $ Tar.write entries'++ let dir = pd ++ concat [name, "/", ver, "/"]+ createDirectoryIfMissing True dir+ let filename = concat [name, "-", ver, ".tar.gz"]+ copyFile ("dist/" ++ filename) (dir ++ filename)+ fixConfig $ cabal ++ "/config"++fixConfig fn = do+ ls <- lines <$> readFile fn+ let s = "remote-repo: cabal-src:http://www.haskell.org/"+ unless (s `elem` ls) $ writeFile fn $ unlines $ addRepo s ls++addRepo s [] = [s]+addRepo s (x:xs)+ | "remote-repo:" `isPrefixOf` x = s : x : xs+ | otherwise = x : addRepo s xs
+ cabal-src.cabal view
@@ -0,0 +1,25 @@+Name: cabal-src+Version: 0.1+Synopsis: Alternative install procedure to avoid the diamond dependency issue.+Description: Please see the README.md file on Github for more information: <https://github.com/yesodweb/cabal-src/blob/master/README.md>.+License: BSD3+License-file: LICENSE+Author: Michael Snoyman+Maintainer: michael@snoyman.com+Category: Distribution+Build-type: Simple+Cabal-version: >=1.6+homepage: https://github.com/+++Executable cabal-src-install+ Main-is: cabal-src-install.hs+ Build-depends: base >= 4 && < 5+ , bytestring+ , tar+ , directory+ , process++source-repository head+ type: git+ location: git://github.com/yesodweb/cabal-src.git