Permalink
Browse files

trying to find the modules belonging to a package

  • Loading branch information...
phischu committed Mar 19, 2013
1 parent 4e3b2b3 commit c4fd044848329d93014da7d2ec28055b6bc06e91
Showing with 32 additions and 3 deletions.
  1. +32 −3 Master.hs
View
@@ -11,16 +11,26 @@ import Distribution.Text
import qualified Data.Version as V
import Distribution.Hackage.DB (readHackage')
+import Distribution.PackageDescription.Parse
+import Distribution.Verbosity
+import Distribution.PackageDescription.Configuration
+import Distribution.System
+import Distribution.Compiler
newtype Package = Package (Name,Version) deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
type Name = String
type Version = String
+newtype Module = Module (Name,Location) deriving (Show,Typeable,Eq,Hashable,Binary,NFData,Read)
+type Location = FilePath
+
newtype ExtractedPackage = ExtractedPackage Package deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
newtype PackageArchive = PackageArchive Package deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
-newtype PackageList = PackageList [Package] deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
newtype GetPackageList = GetPackageList () deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
+newtype PackageList = PackageList [Package] deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
+newtype GetModulesInPackage = GetModulesInPackage Package deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
+newtype ModulesList = ModulesList [Module] deriving (Show,Typeable,Eq,Hashable,Binary,NFData,Read)
instance Rule ExtractedPackage () where
storedValue (ExtractedPackage (Package (name,version))) = do
@@ -35,11 +45,22 @@ instance Rule PackageArchive () where
instance Rule GetPackageList PackageList where
storedValue (GetPackageList ()) = return Nothing
+instance Rule GetModulesInPackage ModulesList where
+ storedValue (GetModulesInPackage package) = do
+ exists <- IO.doesFileExist (moduleListFile package)
+ if exists then readFile (moduleListFile package) >>= return . Just . read else return Nothing
+
+packageIdentifier :: Package -> String
+packageIdentifier (Package (name,version)) = name++"-"++version
+
extractedDirectory :: FilePath
extractedDirectory = "Packages/"
archiveDirectory :: Package -> FilePath
-archiveDirectory (Package (name,version)) = "Archives/"++name++"-"++version++".tar.gz"
+archiveDirectory package = "Archives/"++packageIdentifier package++".tar.gz"
+
+moduleListFile :: Package -> FilePath
+moduleListFile package = "ModuleLists/"++packageIdentifier package++".modulelist"
packageUrl :: Package -> String
packageUrl (Package (name,version)) = concat ["hackage.haskell.org/packages/archive/",name,"/",version,"/",name,"-",version,".tar.gz"]
@@ -55,7 +76,7 @@ main = shakeArgs shakeOptions {shakeThreads = 4} $ do
need ["00-index.tar"]
hackage <- liftIO (readHackage' "00-index.tar")
let packages = [Package (name,renderVersion version)| name <- M.keys hackage, version <- M.keys (hackage M.! name)]
- return (PackageList (every 1 packages))))
+ return (PackageList (every 1000 packages))))
rule (\(ExtractedPackage package) -> Just $ do
liftIO (IO.createDirectoryIfMissing True extractedDirectory)
@@ -70,6 +91,14 @@ main = shakeArgs shakeOptions {shakeThreads = 4} $ do
system' "wget" ["-nv","hackage.haskell.org/packages/archive/00-index.tar.gz"]
system' "gunzip" ["-f","00-index.tar.gz"])
+ rule (\(GetModulesInPackage package@(Package (name,version))) -> Just $ do
+ let cabalfile = extractedDirectory++packageIdentifier package++"/"++name++".cabal"
+ need [cabalfile]
+ genericpackagedescription <- liftIO (readPackageDescription silent cabalfile)
+ let packagedescription = finalizePackageDescription
+ [] (const True) (Platform I386 Linux) (CompilerId GHC (V.Version [7,6,2] [])) [] genericpackagedescription
+ return (ModulesList []))
+
return ()

0 comments on commit c4fd044

Please sign in to comment.