1+ {-# LANGUAGE CPP #-}
12{-# LANGUAGE DeriveGeneric #-}
3+ {-# LANGUAGE RankNTypes #-}
24{-# LANGUAGE RecordWildCards #-}
35{-# LANGUAGE TemplateHaskell #-}
46{-# LANGUAGE TupleSections #-}
@@ -10,11 +12,15 @@ module Distribution.Nixpkgs.Haskell.Derivation
1012 , cabalFlags , runHaddock , jailbreak , doCheck , doBenchmark , testFlags , testTargets , hyperlinkSource
1113 , enableLibraryProfiling , enableExecutableProfiling , phaseOverrides , editedCabalFile , metaSection
1214 , dependencies , setupDepends , benchmarkDepends , enableSeparateDataOutput , extraAttributes
15+ , focusBuildInfo
1316 )
1417 where
1518
1619import Prelude hiding ((<>) )
1720
21+ #if !MIN_VERSION_base(4,18,0)
22+ import Control.Applicative (liftA2 )
23+ #endif
1824import Control.DeepSeq
1925import Control.Lens
2026import Data.List ( isPrefixOf )
@@ -47,10 +53,10 @@ data Derivation = MkDerivation
4753 , _extraFunctionArgs :: Set Binding
4854 , _extraAttributes :: Map String String
4955 , _setupDepends :: BuildInfo
50- , _libraryDepends :: BuildInfo
51- , _executableDepends :: BuildInfo
52- , _testDepends :: BuildInfo
53- , _benchmarkDepends :: BuildInfo
56+ , _libraryDepends :: [( BuildInfo , Bool )]
57+ , _executableDepends :: [( BuildInfo , Bool )]
58+ , _testDepends :: [( BuildInfo , Bool )]
59+ , _benchmarkDepends :: [( BuildInfo , Bool )]
5460 , _configureFlags :: Set String
5561 , _cabalFlags :: FlagAssignment
5662 , _runHaddock :: Bool
@@ -103,7 +109,14 @@ nullDerivation = MkDerivation
103109
104110makeLenses ''Derivation
105111
106- makeLensesFor (fmap (," dependencies" ) [" _setupDepends" , " _libraryDepends" , " _executableDepends" , " _testDepends" , " _benchmarkDepends" ]) ''Derivation
112+ makeLensesFor (fmap (," nonSetupDependencies" ) [" _libraryDepends" , " _executableDepends" , " _testDepends" , " _benchmarkDepends" ]) ''Derivation
113+
114+ dependencies :: Traversal' Derivation BuildInfo
115+ dependencies = traversal $ \ focus drv ->
116+ liftA2 (set setupDepends) (focus $ view setupDepends drv) ((nonSetupDependencies . traverse . _1) focus drv)
117+
118+ focusBuildInfo :: Lens' Derivation [(BuildInfo , Bool )] -> Traversal' Derivation BuildInfo
119+ focusBuildInfo l = l . traverse . _1
107120
108121instance Package Derivation where
109122 packageId = view pkgid
@@ -125,10 +138,10 @@ instance Pretty Derivation where
125138 , boolattr " isExecutable" (not _isLibrary || _isExecutable) _isExecutable
126139 , boolattr " enableSeparateDataOutput" _enableSeparateDataOutput _enableSeparateDataOutput
127140 , pPrintBuildInfo " setup" _setupDepends
128- , pPrintBuildInfo " library" _libraryDepends
129- , pPrintBuildInfo " executable" _executableDepends
130- , pPrintBuildInfo " test" _testDepends
131- , pPrintBuildInfo " benchmark" _benchmarkDepends
141+ , pPrintBuildInfo' " library" _libraryDepends
142+ , pPrintBuildInfo' " executable" _executableDepends
143+ , pPrintBuildInfo' " test" _testDepends
144+ , pPrintBuildInfo' " benchmark" _benchmarkDepends
132145 , boolattr " enableLibraryProfiling" _enableLibraryProfiling _enableLibraryProfiling
133146 , boolattr " enableExecutableProfiling" _enableExecutableProfiling _enableExecutableProfiling
134147 , boolattr " doHaddock" (not _runHaddock) _runHaddock
@@ -145,6 +158,9 @@ instance Pretty Derivation where
145158 , rbrace
146159 ]
147160 where
161+ pPrintBuildInfo' :: String -> [(BuildInfo , Bool )] -> Doc
162+ pPrintBuildInfo' name = pPrintBuildInfo name . foldMap fst . filter snd
163+
148164 inputs :: Set String
149165 inputs = Set. unions [ Set. map (view (localName . ident)) _extraFunctionArgs
150166 , setOf (dependencies . each . folded . localName . ident) drv
0 commit comments