git.iko.soy/typeable/cabal2nix
on master help sign in
Get latest cabal file when version is not specified
commit4f7daef6529ad369dbb0dc01164b0b9b09f0285b authorDmitry Malikov <color404051h@gmail.com> dateThu 6 Sep 2012, 22:23 (14 years ago) parentb879d4b
2 files changed+16−3
cabal2nix.cabal+1−1 src/Cabal2Nix/Hackage.hs+15−2
cabal2nix.cabal+1−1
@@ -46,7 +46,7 @@ Executable cabal2nix
4646 main-is: Cabal2Nix.hs
4747 hs-source-dirs: src
4848 Build-Depends: base >= 3 && < 5, regex-posix, pretty, Cabal >= 1.8,
49− filepath, directory, process, HTTP
49+ filepath, directory, process, HTTP, hackage-db
5050 Extensions: PatternGuards, RecordWildCards, CPP
5151 Ghc-Options: -Wall
5252 other-modules: Cabal2Nix.CorePackages
src/Cabal2Nix/Hackage.hs+15−2
@@ -2,7 +2,8 @@ module Cabal2Nix.Hackage ( hashPackage, readCabalFile ) where
22
33import Control.Monad ( unless )
44import Data.List ( isPrefixOf )
5−import Data.Version ( showVersion )
5+import Data.Maybe ( fromJust )
6+import Data.Version ( showVersion, versionBranch )
67import Distribution.Package ( PackageIdentifier(..), PackageName(..) )
78import Distribution.Text
89import Network.HTTP ( getRequest, rspBody )
@@ -11,6 +12,8 @@ import System.Directory ( doesFileExist, getHomeDirectory, createDirectoryIfMiss
1112import System.FilePath ( dropFileName, (</>), (<.>) )
1213import System.Process ( readProcess )
1314
15+import qualified Distribution.Hackage.DB as DB
16+
1417data Ext = TarGz | Cabal deriving Eq
1518
1619showExt :: Ext -> String
@@ -48,7 +51,17 @@ hashCachePath (PackageIdentifier (PackageName name) version') = do
4851
4952readCabalFile :: FilePath -> IO String
5053readCabalFile path
51− | "cabal://" `isPrefixOf` path = let Just pid = simpleParse (drop 8 path) in readCabalFile (hackagePath pid Cabal)
54+ | "cabal://" `isPrefixOf` path = do let pid p = fromJust $ simpleParse p
55+ packageName = drop 8 path
56+ case versionBranch $ pkgVersion $ pid packageName of
57+ [] -> do
58+ packageDescription <- DB.lookup packageName `fmap` DB.readHackage
59+ case packageDescription of
60+ Just d -> do
61+ let version = showVersion $ last $ DB.keys d
62+ readCabalFile $ hackagePath (pid $ packageName ++ "-" ++ version) Cabal
63+ Nothing -> error "No such package"
64+ _ -> readCabalFile $ hackagePath (pid packageName) Cabal
5265 | "http://" `isPrefixOf` path = fetchUrl path
5366 | "file://" `isPrefixOf` path = readCabalFile (drop 7 path)
5467 | otherwise = readFile path