codex 0.1.0.1 → 0.1.0.2
raw patch · 3 files changed
+25/−50 lines, 3 filesdep ~Cabal
Dependency ranges changed: Cabal
Files
- codex.cabal +2/−3
- src/Codex/Project.hs +23/−7
- src/Distribution/Utils.hs +0/−40
codex.cabal view
@@ -1,5 +1,5 @@ name: codex-version: 0.1.0.1+version: 0.1.0.2 synopsis: A ctags file generator for cabal project dependencies. description: This tool download and cache the source code of packages in your local hackage,@@ -27,12 +27,11 @@ Codex Codex.Project Codex.Internal- Distribution.Utils Distribution.Hackage.Utils build-depends: base >= 4.6.0.1 && < 5 , bytestring >= 0.10.0.2 && < 0.11- , Cabal >= 1.19 && < 1.21+ , Cabal >= 1.18 && < 1.21 , containers >= 0.5.0.0 && < 0.6 , directory >= 1.2.0.1 && < 1.3 , download-curl >= 0.1.4 && < 0.2
src/Codex/Project.hs view
@@ -4,6 +4,7 @@ import Data.Functor import Data.Function import Data.Maybe+import Data.String.Utils import Data.Traversable (traverse) import Distribution.InstalledPackageInfo import Distribution.Hackage.DB (Hackage, readHackage)@@ -15,7 +16,6 @@ import Distribution.Simple.LocalBuildInfo import Distribution.Simple.PackageIndex import Distribution.Package-import Distribution.Utils (identifier, findPackageDescription, findProjects, readProject) import Distribution.Verbosity import Distribution.Version import System.Directory@@ -32,6 +32,9 @@ type ProjectDependencies = (PackageIdentifier, [PackageIdentifier], [WorkspaceProject]) +identifier :: GenericPackageDescription -> PackageIdentifier+identifier = package . packageDescription+ allDependencies :: GenericPackageDescription -> [Dependency] allDependencies pd = List.filter (not . isCurrent) $ concat [lds, eds, tds] where lds = condTreeConstraints =<< (maybeToList $ condLibrary pd)@@ -39,6 +42,11 @@ tds = (condTreeConstraints . snd) =<< condTestSuites pd isCurrent (Dependency n _) = n == (pkgName $ identifier pd) +findPackageDescription :: FilePath -> IO (Maybe GenericPackageDescription)+findPackageDescription root = do+ files <- getDirectoryContents root+ traverse (readPackageDescription silent) $ fmap (\x -> root </> x) $ List.find (endswith ".cabal") files+ resolveCurrentProjectDependencies :: IO ProjectDependencies resolveCurrentProjectDependencies = do ws <- getWorkspace ".."@@ -110,11 +118,19 @@ List.find (\(WorkspaceProject (PackageIdentifier n v) _) -> n == name && withinRange v versionRange) ws readWorkspaceProject :: FilePath -> IO (Maybe WorkspaceProject)-readWorkspaceProject fp = do- maybePrj <- readProject fp- return $ (\(path, id) -> WorkspaceProject id path) <$> maybePrj+readWorkspaceProject path = do+ pd <- findPackageDescription path+ return $ fmap (\x -> WorkspaceProject (identifier x) path) pd getWorkspace :: FilePath -> IO Workspace-getWorkspace fp = do- prjs <- findProjects fp- return $ Workspace $ (\(path, id) -> WorkspaceProject id path) <$> prjs+getWorkspace _root = do+ root <- canonicalizePath _root+ xs <- listDirectory root+ ys <- traverse find xs+ return . Workspace $ ys >>= maybeToList where+ find path = do+ isDirectory <- doesDirectoryExist path+ if isDirectory then readWorkspaceProject path else return Nothing+ listDirectory fp = do+ xs <- getDirectoryContents fp+ return . fmap (fp </>) $ filter (not . startswith ".") xs
− src/Distribution/Utils.hs
@@ -1,40 +0,0 @@-module Distribution.Utils where--import Data.List (isPrefixOf, isSuffixOf)-import Data.Maybe (maybeToList)-import Data.Traversable (traverse)-import Distribution.Package-import Distribution.PackageDescription-import Distribution.PackageDescription.Parse (readPackageDescription)-import Distribution.Verbosity (silent)-import System.Directory-import System.FilePath--import qualified Data.List as List--identifier :: GenericPackageDescription -> PackageIdentifier-identifier = package . packageDescription--findPackageDescription :: FilePath -> IO (Maybe GenericPackageDescription)-findPackageDescription root = do- files <- getDirectoryContents root- traverse (readPackageDescription silent) $ fmap (\x -> root </> x) $ List.find (isSuffixOf ".cabal") files--findProjects :: FilePath -> IO [(FilePath, PackageIdentifier)]-findProjects fp = do- root <- canonicalizePath fp- xs <- listDirectory root- ys <- traverse find xs- return $ ys >>= maybeToList where- find path = do- isDirectory <- doesDirectoryExist path- if isDirectory then readProject path else return Nothing- listDirectory fp = do- xs <- getDirectoryContents fp- return . fmap (fp </>) $ filter (not . isPrefixOf ".") xs--readProject :: FilePath -> IO (Maybe (FilePath, PackageIdentifier))-readProject path = do- pd <- findPackageDescription path- return $ fmap (\x -> (path, identifier x)) pd-