cabal-meta 0.2.2 → 0.2.3
raw patch · 4 files changed
+47/−39 lines, 4 filesdep +system-fileio
Dependencies added: system-fileio
Files
- CabalMeta.hs +5/−5
- cabal-meta.cabal +3/−3
- main.hs +37/−29
- test/main.hs +2/−2
CabalMeta.hs view
@@ -34,7 +34,7 @@ pLocation :: Text , pFlags :: [Text] } | GitPackage {- gLocation :: Text+ gitLocation :: Text , pFlags :: [Text] , gTag :: Maybe Text } deriving (Show, Eq)@@ -78,7 +78,7 @@ readPackages :: Bool -> FilePath -> ShIO PackageSources readPackages allowCabals startDir = do- fullDir <- absPath startDir+ fullDir <- canonic startDir chdir fullDir $ do cabalPresent <- if allowCabals then return False else isCabalPresent if cabalPresent then return mempty else do@@ -90,7 +90,7 @@ mkdir_p vendor_dir chdir vendor_dir $ forM git_pkgs $ \pkg -> do- let repo = gLocation pkg + let repo = gitLocation pkg let d = filename $ fromText repo e <- test_d d if not e@@ -102,7 +102,7 @@ readPackages False d child_dir_pkgs <- forM (dirs psources) $ \dir -> do- b <- fmap (== fullDir) (absPath $ dLocation dir)+ b <- fmap (== fullDir) (canonic $ dLocation dir) if b then return mempty else readPackages False (dLocation dir) let child_pkgs = child_dir_pkgs ++ child_vendor_pkgs@@ -136,7 +136,7 @@ return $ sources { dirs = ds } where fullPath package = do- fp <- absPath $ dLocation package+ fp <- canonic $ dLocation package return package { dLocation = fp } paritionSources :: [[Text]] -> PackageSources
cabal-meta.cabal view
@@ -1,5 +1,5 @@ name: cabal-meta-version: 0.2.2+version: 0.2.3 license: BSD3 license-file: LICENSE author: Greg Weber <greg@gregweber.info>@@ -36,7 +36,7 @@ else build-depends: base >= 4 && < 4.3 build-depends: shelly >= 0.9- , text, system-filepath+ , text, system-filepath, system-fileio -- , file-location ghc-options: -Wall@@ -50,7 +50,7 @@ build-depends: shelly >= 0.9 , hspec, HUnit, unix, base, text, system-filepath- -- , file-location+ -- , file-location extensions: OverloadedStrings source-repository head
main.hs view
@@ -1,12 +1,12 @@ {-# LANGUAGE OverloadedStrings, CPP #-} import CabalMeta+import OmniConfig import Shelly-import System.Environment (getArgs) -import qualified Data.Text.Lazy as T+import qualified Data.Text.Lazy as LT import Control.Monad (forM_) import Data.Maybe (isNothing)-import Data.Text.Lazy (Text, pack)+import Data.Text.Lazy (Text) import Filesystem.Path.CurrentOS (filename) import Prelude hiding (FilePath)@@ -16,69 +16,77 @@ headDef _ (x:_) = x help :: Text-help = T.intercalate "\n" [- "cabal-meta is a cabal wrapper for packages not on hackage"+help = LT.intercalate "\n" [+ "cabal-meta is a cabal wrapper for installing multiple packages at once that may not be on hackage" ,"run with:" ,""- ," cabal-meta [--dev] install [Cabal install arguments]"+ ," cabal-meta [--[no-]dev] install [cabal install arguments]" ,"" ," --dev means use cabal-dev instead of cabal"+ ,""+ ,"You can also set options through the CABAL_META_OPTS environment variable or the ~/.cabal-meta/opts file" ] cabal_install_ :: CabalExe -> [Text] -> ShIO () cabal_install_ cabal = command_ (progName cabal) ["install"] -data CabalExe = Cabal | CabalDev+data CabalExe = Cabal | CabalDev deriving Show progName :: CabalExe -> FilePath progName Cabal = "cabal" progName CabalDev = "cabal-dev" -assertCabalDevInstalled :: CabalExe -> ShIO ()-assertCabalDevInstalled Cabal = return ()-assertCabalDevInstalled CabalDev = do- mcd <- which "cabal-dev"+assertCabalDependencies :: CabalExe -> IO ()+assertCabalDependencies Cabal = shelly $ do+ mPath <- which "cabal-src-install"+ when (isNothing mPath) $+ errorExit "please run: cabal install cabal-src"++assertCabalDependencies CabalDev = do+ mcd <- shelly $ which "cabal-dev" case mcd of Just _ -> return () Nothing -> error "--dev requires cabal-dev to be installed" +nothingToFalse :: Maybe Bool -> Bool+nothingToFalse Nothing = False+nothingToFalse (Just b) = b+ main :: IO () main = do- cmdArgs <- fmap (map pack) getArgs- shelly $ verbosely $ do- let isDev = elem "--dev" cmdArgs- noDevArgs = filter (/= "--dev") cmdArgs- cabal = if isDev then CabalDev else Cabal+ allArgs <- allProgramOpts [commandLine, environment "cabal-meta", homeOptFile "cabal-meta"]+ let (mDev, noDevArgs) = checkNegatedOpt "dev" allArgs+ let isDev = nothingToFalse mDev - assertCabalDevInstalled cabal- unless (headDef "" noDevArgs == "install") $- errorExit help+ let cabal = if isDev then CabalDev else Cabal+ assertCabalDependencies cabal - let (_:args) = noDevArgs+ unless (headDef "" noDevArgs == "install") $ do+ putStrLn $ LT.unpack help+ putStrLn $ "using cabal: " ++ show cabal+ shelly $ exit 1 - packageSources <- readPackages True "."- ifCabal cabal $ do- mPath <- which "cabal-src-install"- when (isNothing mPath) $- errorExit "please run: cabal install cabal-src"+ let (_:args) = map LT.fromStrict noDevArgs + shelly $ verbosely $ do+ packageSources <- readPackages True "." let installs = packageList packageSources echo "Installing packages:"- mapM_ echo $ map (T.intercalate " ") installs+ mapM_ echo $ map (LT.intercalate " ") installs cabal_install_ cabal $ args ++ concat installs- ifCabal cabal $ do+ whenCabal cabal $ do forM_ (dirs packageSources) $ \pkg -> chdir (dLocation pkg) $ run "cabal-src-install" ["--src-only"] forM_ (gitPackages packageSources) $ \pkg -> chdir vendor_dir $ do- let repo = gLocation pkg + let repo = gitLocation pkg let d = filename $ fromText repo chdir d $ run "cabal-src-install" ["--src-only"] return () where- ifCabal cabal a =+ whenCabal cabal a = case cabal of CabalDev -> return () Cabal -> a
test/main.hs view
@@ -12,9 +12,9 @@ main = hspec $ it "gets the packages" $ do (psources, wd) <- shelly $ verbosely $ do- ps <- readPackages True "test" d <- pwd+ ps <- readPackages True "test" return (ps, d) let localize = (\p-> toTextIgnore $ wd </> fromText p)- concatMap asList (packages psources) @?= [localize "test/child", localize "test/vendor/yesod/yesod", "sphinx", "-fone-one-beta", "fake-package"]+ concatMap asList (packages psources) @?= [localize "test/child/grandchild", "top-package", "sphinx", "-fone-one-beta", "child-package"]