@@ -11,7 +11,6 @@ import Data.List
11import qualified Data.Set as Set
11import qualified Data.Set as Set
12import Control.Monad.State
12import Control.Monad.State
13import Control.Exception ( bracket )
13import Control.Exception ( bracket )
14−import qualified Data.ByteString.Char8 as BS
15import Text.Regex.Posix
14import Text.Regex.Posix
16import Data.Version
15import Data.Version
17import Text.ParserCombinators.ReadP ( readP_to_S )
16import Text.ParserCombinators.ReadP ( readP_to_S )
@@ -22,14 +21,6 @@ import Cabal2Nix.Package ( cabal2nix, showNixPkg, PkgName, PkgSHA256, PkgPlatfor
22 , PkgNoHaddock )
21 , PkgNoHaddock )
23import qualified Cabal2Nix.Package ( Pkg(..) )
22import qualified Cabal2Nix.Package ( Pkg(..) )
25−type ByteString = BS.ByteString
27−pack :: String -> ByteString
30−unpack :: ByteString -> String
33type PkgSet = Set.Set Pkg
24type PkgSet = Set.Set Pkg
35data Configuration = Configuration
26data Configuration = Configuration
@@ -89,49 +80,49 @@ type PkgVersion = String
89data Pkg = Pkg PkgName PkgVersion PkgSHA256 PkgNoHaddock PkgPlatforms PkgMaintainers FilePath
80data Pkg = Pkg PkgName PkgVersion PkgSHA256 PkgNoHaddock PkgPlatforms PkgMaintainers FilePath
90 deriving (Show, Eq, Ord)
81 deriving (Show, Eq, Ord)
92−regmatch :: ByteString -> String -> Bool
83+regmatch :: String -> String -> Bool
93−regmatch buf patt = match (makeRegexOpts compExtended execBlank (pack patt)) buf
84+regmatch buf patt = match (makeRegexOpts compExtended execBlank patt) buf
95−regsubmatch :: ByteString -> String -> [ByteString]
86+regsubmatch :: String -> String -> [String]
96regsubmatch buf patt = let (_,_,_,x) = f in x
87regsubmatch buf patt = let (_,_,_,x) = f in x
97− where f :: (ByteString,ByteString,ByteString,[ByteString])
88+ where f :: (String,String,String,[String])
98− f = match (makeRegexOpts compExtended execBlank (pack patt)) buf
89+ f = match (makeRegexOpts compExtended execBlank patt) buf
100normalizeMaintainer :: String -> String
91normalizeMaintainer :: String -> String
101normalizeMaintainer x
92normalizeMaintainer x
102 | "self.stdenv.lib.maintainers." `isPrefixOf` x = drop 28 x
93 | "self.stdenv.lib.maintainers." `isPrefixOf` x = drop 28 x
103 | otherwise = x
94 | otherwise = x
105−parseNixFile :: FilePath -> ByteString -> Hackage4Nix (Maybe Pkg)
96+parseNixFile :: FilePath -> String -> Hackage4Nix (Maybe Pkg)
106parseNixFile path buf
97parseNixFile path buf
107 | not (buf `regmatch` "cabal.mkDerivation")
98 | not (buf `regmatch` "cabal.mkDerivation")
108 = msgDebug ("ignore non-cabal package " ++ path) >> return Nothing
99 = msgDebug ("ignore non-cabal package " ++ path) >> return Nothing
109− | True <- (pack path) `regmatch` (concat (intersperse "|" badPackages))
100+ | True <- path `regmatch` (concat (intersperse "|" badPackages))
110 = msgDebug ("ignore known bad package " ++ path) >> return Nothing
101 = msgDebug ("ignore known bad package " ++ path) >> return Nothing
111 | True <- buf `regmatch` "src = (fetchgit|sourceFromHead)"
102 | True <- buf `regmatch` "src = (fetchgit|sourceFromHead)"
112 = msgDebug ("ignore non-hackage package " ++ path) >> return Nothing
103 = msgDebug ("ignore non-hackage package " ++ path) >> return Nothing
113 | buf `regmatch` "preConfigure|configureFlags|postInstall|patchPhase"
104 | buf `regmatch` "preConfigure|configureFlags|postInstall|patchPhase"
114 = msgInfo ("ignore patched package " ++ path) >> return Nothing
105 = msgInfo ("ignore patched package " ++ path) >> return Nothing
115− | True <- buf =~ pack "cabal.mkDerivation"
106+ | True <- buf =~ "cabal.mkDerivation"
116 , [name] <- buf `regsubmatch` "name *= *\"([^\"]+)\""
107 , [name] <- buf `regsubmatch` "name *= *\"([^\"]+)\""
117 , [vers] <- buf `regsubmatch` "version *= *\"([^\"]+)\""
108 , [vers] <- buf `regsubmatch` "version *= *\"([^\"]+)\""
118 , [sha] <- buf `regsubmatch` "sha256 *= *\"([^\"]+)\""
109 , [sha] <- buf `regsubmatch` "sha256 *= *\"([^\"]+)\""
119 , plats <- buf `regsubmatch` "platforms *= *([^;]+);"
110 , plats <- buf `regsubmatch` "platforms *= *([^;]+);"
120 , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
111 , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
121 , haddock <- buf `regsubmatch` "noHaddock *= *(true|false) *;"
112 , haddock <- buf `regsubmatch` "noHaddock *= *(true|false) *;"
122− = let plats' = concatMap BS.words (map (BS.map (\c -> if c == '+' then ' ' else c)) plats)
113+ = let plats' = concatMap words (map (map (\c -> if c == '+' then ' ' else c)) plats)
123− maint' = concatMap BS.words maint
114+ maint' = concatMap words maint
124 noHaddock
115 noHaddock
125− | b:[] <- haddock, unpack b == "true" = True
116+ | "true":[] <- haddock = True
126− | otherwise = False
117+ | otherwise = False
128− return $ Just $ Pkg (unpack name)
119+ return $ Just $ Pkg name
129− (unpack vers)
120+ vers
130− (unpack sha)
121+ sha
131 noHaddock
122 noHaddock
132− (map unpack plats')
123+ plats'
133− (map (normalizeMaintainer . unpack) maint')
124+ (map normalizeMaintainer maint')
135 | True <- buf `regmatch` "cabal.mkDerivation"
126 | True <- buf `regmatch` "cabal.mkDerivation"
136 = msgInfo ("failed to parse file " ++ path) >> return Nothing
127 = msgInfo ("failed to parse file " ++ path) >> return Nothing
137 | otherwise = return Nothing
128 | otherwise = return Nothing
@@ -163,7 +154,7 @@ updateNixPkgs paths = do
163 msgDebug $ "updating = " ++ show paths
154 msgDebug $ "updating = " ++ show paths
164 flip mapM_ paths $ \fileOrDir ->
155 flip mapM_ paths $ \fileOrDir ->
165 flip discoverNixFiles fileOrDir $ \file -> do
156 flip discoverNixFiles fileOrDir $ \file -> do
166− nix' <- io (BS.readFile file) >>= parseNixFile file
157+ nix' <- io (readFile file) >>= parseNixFile file
167 flip (maybe (return ())) nix' $ \nix -> do
158 flip (maybe (return ())) nix' $ \nix -> do
168 let Pkg name vers sha noHaddock plats maints path = nix
159 let Pkg name vers sha noHaddock plats maints path = nix
169 maints' = nub (sort (maints ++ ["andres","simons"]))
160 maints' = nub (sort (maints ++ ["andres","simons"]))
@@ -201,8 +192,8 @@ genCabal2NixCmdline (Pkg name vers _ noHaddock plats maints path) = unwords $ ["
201 | ["self.ghc.meta.platforms"] == plats = []
192 | ["self.ghc.meta.platforms"] == plats = []
202 | otherwise = [ "--platform=" ++ p | p <- plats ]
193 | otherwise = [ "--platform=" ++ p | p <- plats ]
204− | pack path `regmatch` "/[0-9\\.]+\\.nix$" = replaceFileName path (vers <.> "nix")
195+ | path `regmatch` "/[0-9\\.]+\\.nix$" = replaceFileName path (vers <.> "nix")
205− | otherwise = path
196+ | otherwise = path
207data CliOption = PrintHelp | Verbose | HackageDB FilePath
198data CliOption = PrintHelp | Verbose | HackageDB FilePath
208 deriving (Eq)
199 deriving (Eq)