@@ -1,127 +0,0 @@
1−{-# LANGUAGE PatternGuards, CPP #-}
2−{- |
3− Module : Distribution.NixOS.Derivation.Cabal
4− License : BSD3
5−
6− Maintainer : nix-dev@cs.uu.nl
7− Stability : provisional
8− Portability : PatternGuards
9−
10− A represtation of Nix expressions based on Cabal builder defined in
11− @pkgs\/development\/libraries\/haskell\/cabal\/cabal.nix@.
12−-}
13−
14−module Distribution.NixOS.Derivation.Cabal
15− ( Derivation(..)
16− , parseDerivation
17− , module Distribution.NixOS.Derivation.Meta
18− , module Data.Version
19− )
20− where
21−
22−import Distribution.NixOS.Derivation.Meta
23−import Distribution.NixOS.PrettyPrinting
24−import Distribution.Text
25−import Distribution.Package
26−#ifdef __HADDOCK__
27−import Distribution.PackageDescription ( PackageDescription )
28−#endif
29−import Data.Version
30−import Data.List
31−import Data.Char
32−import Text.Regex.Posix
33−
34−-- | A represtation of Nix expressions for building Haskell packages.
35−-- The data type correspond closely to the definition of
36−-- 'PackageDescription' from Cabal.
37−--
38−-- Note that the "Text" instance definition provides pretty-printing,
39−-- but no parsing as of now!
40−
41−data Derivation = MkDerivation
42− { pname :: String
43− , version :: Version
44− , sha256 :: String
45− , isLibrary :: Bool
46− , isExecutable :: Bool
47− , buildDepends :: [String]
48− , buildTools :: [String]
49− , extraLibs :: [String]
50− , pkgConfDeps :: [String]
51− , runHaddock :: Bool
52− , metaSection :: Meta
53− }
54− deriving (Show, Eq, Ord)
55−
56−instance Text Derivation where
57− disp = renderDerivation
58− parse = error "parsing Distribution.NixOS.Derivation.Cabal.Derivation is not supported yet"
59−
60−instance Package Derivation where
61− packageId deriv = PackageIdentifier (PackageName (pname deriv)) (version deriv)
62−
63−renderDerivation :: Derivation -> Doc
64−renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
65− [ text ""
66− , text "cabal.mkDerivation" <+> lparen <> text "self" <> colon <+> lbrace
67− , nest 2 $ vcat
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)
79− ]
80− , rbrace <> rparen
81− , text ""
82− ]
83− where
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
87−
88−-- | A very incomplete parser that extracts 'pname', 'version',
89−-- 'sha256', 'platforms', 'maintainers', and 'runHaddock' from the given
90−-- Nix expression.
91−
92−parseDerivation :: String -> Maybe Derivation
93−parseDerivation buf
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
103− { pname = name
104− , version = vers
105− , sha256 = sha
106− , isLibrary = False
107− , isExecutable = False
108− , buildDepends = []
109− , buildTools = []
110− , extraLibs = []
111− , pkgConfDeps = []
112− , runHaddock = case noHaddock of "true":[] -> False
113− _ -> True
114− , metaSection = Meta
115− { homepage = ""
116− , description = ""
117− , license = Unknown Nothing
118− , maintainers = concatMap words maint
119− , platforms = concatMap words (map (map (\c -> if c == '+' then ' ' else c)) plats)
120− }
121− }
122− | otherwise = Nothing
123−
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