@@ -1,127 +0,0 @@
1−{-# LANGUAGE PatternGuards, CPP #-}
3− Module : Distribution.NixOS.Derivation.Cabal
6− Maintainer : nix-dev@cs.uu.nl
7− Stability : provisional
8− Portability : PatternGuards
10− A represtation of Nix expressions based on Cabal builder defined in
11− @pkgs\/development\/libraries\/haskell\/cabal\/cabal.nix@.
14−module Distribution.NixOS.Derivation.Cabal
17− , module Distribution.NixOS.Derivation.Meta
18− , module Data.Version
22−import Distribution.NixOS.Derivation.Meta
23−import Distribution.NixOS.PrettyPrinting
24−import Distribution.Text
25−import Distribution.Package
27−import Distribution.PackageDescription ( PackageDescription )
32−import Text.Regex.Posix
34−-- | A represtation of Nix expressions for building Haskell packages.
35−-- The data type correspond closely to the definition of
36−-- 'PackageDescription' from Cabal.
38−-- Note that the "Text" instance definition provides pretty-printing,
39−-- but no parsing as of now!
41−data Derivation = MkDerivation
46− , isExecutable :: Bool
47− , buildDepends :: [String]
48− , buildTools :: [String]
49− , extraLibs :: [String]
50− , pkgConfDeps :: [String]
52− , metaSection :: Meta
54− deriving (Show, Eq, Ord)
56−instance Text Derivation where
57− disp = renderDerivation
58− parse = error "parsing Distribution.NixOS.Derivation.Cabal.Derivation is not supported yet"
60−instance Package Derivation where
61− packageId deriv = PackageIdentifier (PackageName (pname deriv)) (version deriv)
63−renderDerivation :: Derivation -> Doc
64−renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
66− , text "cabal.mkDerivation" <+> lparen <> text "self" <> colon <+> lbrace
68− [ attr "pname" $ string (pname deriv)
69− , attr "version" $ doubleQuotes (disp (version deriv))
70− , attr "sha256" $ string (sha256 deriv)
71− , boolattr "isLibrary" (not (isLibrary deriv) || (isExecutable deriv)) (isLibrary deriv)
72− , boolattr "isExecutable" (not (isLibrary deriv) || (isExecutable deriv)) (isExecutable deriv)
73− , listattr "buildDepends" (buildDepends deriv)
74− , listattr "buildTools" (buildTools deriv)
75− , listattr "extraLibraries" (extraLibs deriv)
76− , listattr "pkgconfigDepends" (pkgConfDeps deriv)
77− , boolattr "noHaddock" (not (runHaddock deriv)) (not (runHaddock deriv))
78− , disp (metaSection deriv)
84− inputs = nub $ sortBy (\x y -> compare (map toLower x) (map toLower y)) $
85− filter (/="cabal") $ filter (/="Cabal") $
86− buildDepends deriv ++ buildTools deriv ++ extraLibs deriv ++ pkgConfDeps deriv
88−-- | A very incomplete parser that extracts 'pname', 'version',
89−-- 'sha256', 'platforms', 'maintainers', and 'runHaddock' from the given
92−parseDerivation :: String -> Maybe Derivation
94− | buf =~ "cabal.mkDerivation"
95− , [name] <- buf `regsubmatch` "pname *= *\"([^\"]+)\""
96− , [vers'] <- buf `regsubmatch` "version *= *\"([^\"]+)\""
97− , Just vers <- simpleParse vers'
98− , [sha] <- buf `regsubmatch` "sha256 *= *\"([^\"]+)\""
99− , plats <- buf `regsubmatch` "platforms *= *([^;]+);"
100− , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
101− , noHaddock <- buf `regsubmatch` "noHaddock *= *(true|false) *;"
102− = Just $ MkDerivation
107− , isExecutable = False
112− , runHaddock = case noHaddock of "true":[] -> False
114− , metaSection = Meta
117− , license = Unknown Nothing
118− , maintainers = concatMap words maint
119− , platforms = concatMap words (map (map (\c -> if c == '+' then ' ' else c)) plats)
122− | otherwise = Nothing
124−regsubmatch :: String -> String -> [String]
125−regsubmatch buf patt = let (_,_,_,x) = f in x
126− where f :: (String,String,String,[String])
127− f = match (makeRegexOpts compExtended execBlank patt) buf