git.iko.soy/typeable/cabal2nix
on master help sign in
Hackage4Nix.hs: replace the old regex-parser with the BNFC-generated one
commit172ad4a312b77621529b78a7bc3c89d521530049 authorPeter Simons <simons@cryp.to> dateFri 12 Aug 2011, 12:18 (15 years ago) parent6bd1f35
1 file changed+21−27
src/Hackage4Nix.hs+21−27
src/Hackage4Nix.hs+21−27
@@ -19,6 +19,8 @@ import Distribution.PackageDescription.Parse ( parsePackageDescription, ParseRes
1919import Distribution.PackageDescription ( GenericPackageDescription() )
2020import System.Console.GetOpt ( OptDescr(..), ArgDescr(..), ArgOrder(..), usageInfo, getOpt )
2121import Cabal2Nix.Package ( cabal2nix, showNixPkg, PkgName, PkgSHA256, PkgPlatforms, PkgMaintainers )
22+import qualified Cabal2Nix.Package ( Pkg(..) )
23+import Hackage4Nix.Nix
2224
2325type ByteString = BS.ByteString
2426
@@ -101,33 +103,20 @@ normalizeMaintainer x
101103 | otherwise = x
102104
103105parseNixFile :: FilePath -> ByteString -> Hackage4Nix (Maybe Pkg)
104−parseNixFile path buf
105− | True <- (pack path) `regmatch` (concat (intersperse "|" badPackages))
106− = msgDebug ("ignore known bad package " ++ path) >> return Nothing
107− | True <- buf `regmatch` "src = (fetchgit|sourceFromHead)"
108− = msgDebug ("ignore non-hackage package " ++ path) >> return Nothing
109− | True <- buf `regmatch` "(patchPhase|configureFlags) ="
110− = msgDebug ("ignore patched package " ++ path) >> return Nothing
111− | True <- buf `regmatch` "noHaddock"
112− = msgDebug ("ignore non-haddock package " ++ path) >> return Nothing
113− | True <- buf =~ pack "cabal.mkDerivation"
114− , [name] <- buf `regsubmatch` "name *= *\"([^\"]+)\""
115− , [vers] <- buf `regsubmatch` "version *= *\"([^\"]+)\""
116− , [sha] <- buf `regsubmatch` "sha256 *= *\"([^\"]+)\""
117− , plats <- buf `regsubmatch` "platforms *= *([^;]+);"
118− , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
119− = let plats' = concatMap BS.words (map (BS.map (\c -> if c == '+' then ' ' else c)) plats)
120− maint' = concatMap BS.words maint
121− in
122− return $ Just $ Pkg (unpack name)
123− (unpack vers)
124− (unpack sha)
125− (map unpack plats')
126− (map (normalizeMaintainer . unpack) maint')
127− (path)
128− | True <- buf `regmatch` "cabal.mkDerivation"
129− = msgInfo ("failed to parse file " ++ path) >> return Nothing
130− | otherwise = return Nothing
106+parseNixFile path buf'
107+ | not (buf' `regmatch` "cabal.mkDerivation")
108+ = msgDebug ("ignore non-cabal package " ++ path) >> return Nothing
109+ | (pack path) `regmatch` (concat (intersperse "|" badPackages))
110+ = msgDebug ("ignore known bad package " ++ path) >> return Nothing
111+ | otherwise = do
112+ let buf = BS.unpack buf'
113+ tree <- parseNixExpr buf
114+ let pkg' = nixExpr2CabalExpr tree
115+ Cabal2Nix.Package.Pkg pkgname pkgver sha256 url desc lic isLib isExe deps tools libs pcs plats maints = pkg'
116+ pkg = Pkg pkgname pkgver sha256 plats (map normalizeMaintainer maints) path
117+ msgDebug ("pkg = " ++ show pkg')
118+ msgDebug ("pkg = " ++ show pkg)
119+ return (Just pkg)
131120
132121readVersion :: String -> Version
133122readVersion str =
@@ -252,6 +241,11 @@ badPackages :: [String]
252241badPackages = [ "/"++p++"/" | p <- names ]
253242 where names =
254243 [ "alex"
244+ , "CS173Tourney"
245+ , "get-options"
246+ , "WebServer"
247+ , "WebServer-Extras"
248+ , "cabal"
255249 , "cairo"
256250 , "citeproc"
257251 , "citeproc-hs"