git.iko.soy/typeable/cabal2nix
on master help sign in
Re-factoring

- Simplify pretty-printing code with a traversal over BuildInfo. - Export 'dep' parser function along with undep.

commitd32ed2ce228ba37d1f3746c7046b31ac17467734 authorPeter Simons <simons@cryp.to> dateSat 8 Aug 2015, 18:44 (11 years ago) parentd63faad
2 files changed+9−18
src/Cabal2Nix/PostProcess.hs−3 src/Distribution/Nixpkgs/Haskell.hs+9−15
src/Cabal2Nix/PostProcess.hs−3
@@ -42,9 +42,6 @@ hooks = over (mapped._1) (\str -> fromMaybe (error ("invalid constraint: " ++ sh
4242 , ("wxcore", set (libraryDepends . pkgconfig . contains (dep "wxGTK")) True)
4343 ]
4444
45−dep :: String -> Dependency
46−dep s = Dependency (PackageName s) anyVersion
47−
4845gitAnnexHook :: Derivation -> Derivation
4946gitAnnexHook = set phaseOverrides gitAnnexOverrides . over (executableDepends . system) (Set.union buildInputs)
5047 where
src/Distribution/Nixpkgs/Haskell.hs+9−15
@@ -8,8 +8,8 @@ module Distribution.Nixpkgs.Haskell
88 , cabalFlags, runHaddock, jailbreak, doCheck, testTarget, hyperlinkSource, enableSplitObjs
99 , phaseOverrides, editedCabalFile, metaSection
1010 , BuildInfo, haskell, pkgconfig, system, tool
11− , dependencies
12− , unDep
11+ , dependencies, anyDep
12+ , dep, unDep
1313 )
1414 where
1515
@@ -37,6 +37,8 @@ data BuildInfo = BuildInfo
3737
3838makeLenses ''BuildInfo
3939
40+makeLensesFor [("_haskell", "anyDep"), ("_pkgconfig", "anyDep"), ("_system", "anyDep"), ("_tool", "anyDep")] ''BuildInfo
41+
4042instance Monoid BuildInfo where
4143 mempty = BuildInfo mempty mempty mempty mempty
4244 BuildInfo w1 x1 y1 z1 `mappend` BuildInfo w2 x2 y2 z2 = BuildInfo (w1 `mappend` w2) (x1 `mappend` x2) (y1 `mappend` y2) (z1 `mappend` z2)
@@ -113,7 +115,7 @@ instance NFData VersionRange where rnf = genericRnf
113115instance NFData Dependency where rnf = genericRnf
114116
115117instance Pretty Derivation where
116− pPrint MkDerivation {..} = funargs (map text ("mkDerivation" : toAscList inputs)) $$ vcat
118+ pPrint drv@(MkDerivation {..}) = funargs (map text ("mkDerivation" : toAscList inputs)) $$ vcat
117119 [ text "mkDerivation" <+> lbrace
118120 , nest 2 $ vcat
119121 [ attr "pname" $ doubleQuotes $ disp (packageName _pkgid)
@@ -141,18 +143,7 @@ instance Pretty Derivation where
141143 where
142144 inputs :: Set String
143145 inputs = Set.unions [ _extraFunctionArgs
144− , Set.map unDep (_haskell _libraryDepends)
145− , Set.map unDep (_haskell _executableDepends)
146− , Set.map unDep (_haskell _testDepends)
147− , Set.map unDep (_system _libraryDepends)
148− , Set.map unDep (_system _executableDepends)
149− , Set.map unDep (_system _testDepends)
150− , Set.map unDep (_pkgconfig _libraryDepends)
151− , Set.map unDep (_pkgconfig _executableDepends)
152− , Set.map unDep (_pkgconfig _testDepends)
153− , Set.map unDep (_tool _libraryDepends)
154− , Set.map unDep (_tool _executableDepends)
155− , Set.map unDep (_tool _testDepends)
146+ , view (dependencies . anyDep . to (Set.map unDep)) drv
156147 , Set.fromList ["fetch" ++ derivKind _src | derivKind _src /= "" && not isHackagePackage]
157148 ]
158149
@@ -180,6 +171,9 @@ pPrintBuildInfo prefix bi = vcat
180171 , setattr (prefix++"ToolDepends") (Set.map unDep (bi^.tool))
181172 ]
182173
174+dep :: String -> Dependency
175+dep s = Dependency (PackageName s) anyVersion
176+
183177unDep :: Dependency -> String
184178unDep (Dependency (PackageName x) _) = x
185179