@@ -9,6 +9,7 @@ module Distribution.Nixpkgs.Haskell.Derivation
99 , cabalFlags , runHaddock , jailbreak , doCheck , doBenchmark , testFlags , testTargets , hyperlinkSource
1010 , enableLibraryProfiling , enableExecutableProfiling , phaseOverrides , editedCabalFile , metaSection
1111 , dependencies , setupDepends , benchmarkDepends , enableSeparateDataOutput , extraAttributes
12+ , subLibraryDepends , subLibraryDependencies
1213 )
1314 where
1415
@@ -50,6 +51,8 @@ data Derivation = MkDerivation
5051 , _executableDepends :: BuildInfo
5152 , _testDepends :: BuildInfo
5253 , _benchmarkDepends :: BuildInfo
54+ , _subLibraryDepends :: Map String BuildInfo
55+ , _subLibraryDependencies :: Map String [String ]
5356 , _configureFlags :: Set String
5457 , _cabalFlags :: FlagAssignment
5558 , _runHaddock :: Bool
@@ -83,6 +86,8 @@ nullDerivation = MkDerivation
8386 , _executableDepends = error " undefined Derivation.executableDepends"
8487 , _testDepends = error " undefined Derivation.testDepends"
8588 , _benchmarkDepends = error " undefined Derivation.benchmarkDepends"
89+ , _subLibraryDepends = mempty
90+ , _subLibraryDependencies = mempty
8691 , _configureFlags = error " undefined Derivation.configureFlags"
8792 , _cabalFlags = error " undefined Derivation.cabalFlags"
8893 , _runHaddock = error " undefined Derivation.runHaddock"
@@ -102,15 +107,26 @@ nullDerivation = MkDerivation
102107
103108makeLenses ''Derivation
104109
105- makeLensesFor [(" _setupDepends" , " dependencies" ), (" _libraryDepends" , " dependencies" ), (" _executableDepends" , " dependencies" ), (" _testDepends" , " dependencies" ), (" _benchmarkDepends" , " dependencies" )] ''Derivation
110+ -- | Traversal over all 'BuildInfo' values in a 'Derivation', including
111+ -- the setup, library, executable, test, benchmark, and sub-library depends.
112+ dependencies :: Traversal' Derivation BuildInfo
113+ dependencies f drv =
114+ (\ s l e t b sl -> drv { _setupDepends = s, _libraryDepends = l, _executableDepends = e
115+ , _testDepends = t, _benchmarkDepends = b, _subLibraryDepends = sl })
116+ <$> f (_setupDepends drv)
117+ <*> f (_libraryDepends drv)
118+ <*> f (_executableDepends drv)
119+ <*> f (_testDepends drv)
120+ <*> f (_benchmarkDepends drv)
121+ <*> traverse f (_subLibraryDepends drv)
106122
107123instance Package Derivation where
108124 packageId = view pkgid
109125
110126instance NFData Derivation
111127
112128instance Pretty Derivation where
113- pPrint drv@ MkDerivation {.. } = funargs (map text (" mkDerivation" : toAscList inputs)) $$ vcat
129+ pPrint drv@ MkDerivation {_subLibraryDepends = subLibDeps, _subLibraryDependencies = subLibConsumerDeps, .. } = funargs (map text (" mkDerivation" : toAscList inputs)) $$ vcat
114130 [ text " mkDerivation" <+> lbrace
115131 , nest 2 $ vcat
116132 [ attr " pname" $ doubleQuotes $ pPrint (packageName _pkgid)
@@ -124,10 +140,12 @@ instance Pretty Derivation where
124140 , boolattr " isExecutable" (not _isLibrary || _isExecutable) _isExecutable
125141 , boolattr " enableSeparateDataOutput" _enableSeparateDataOutput _enableSeparateDataOutput
126142 , onlyIf (_setupDepends /= mempty ) $ pPrintBuildInfo " setup" _setupDepends
127- , onlyIf (_libraryDepends /= mempty ) $ pPrintBuildInfo " library" _libraryDepends
143+ , onlyIf (mergedLibraryDepends /= mempty ) $ pPrintBuildInfo " library" mergedLibraryDepends
144+ , onlyIf (not (Map. null subLibDeps)) $ pPrintSubLibraryDepends subLibDeps
128145 , onlyIf (_executableDepends /= mempty ) $ pPrintBuildInfo " executable" _executableDepends
129146 , onlyIf (_testDepends /= mempty ) $ pPrintBuildInfo " test" _testDepends
130147 , onlyIf (_benchmarkDepends /= mempty ) $ pPrintBuildInfo " benchmark" _benchmarkDepends
148+ , onlyIf (not (Map. null subLibConsumerDeps)) $ pPrintSubLibraryDependencies subLibConsumerDeps
131149 , boolattr " enableLibraryProfiling" _enableLibraryProfiling _enableLibraryProfiling
132150 , boolattr " enableExecutableProfiling" _enableExecutableProfiling _enableExecutableProfiling
133151 , boolattr " doHaddock" (not _runHaddock) _runHaddock
@@ -152,8 +170,39 @@ instance Pretty Derivation where
152170 Just derivKind' -> Set. fromList [derivKindFunction derivKind' | not isHackagePackage]
153171 ]
154172
173+ -- For backwards compatibility, libraryHaskellDepends is emitted as the
174+ -- union of the main library deps and all sub-library deps. New consumers
175+ -- should prefer the separate subLibraryDepends attrset.
176+ mergedLibraryDepends = _libraryDepends `mappend` foldMap id (Map. elems subLibDeps)
177+
155178 renderedFlags = [ text " -f" <> (if enable then empty else char ' -' ) <> text (unFlagName f) | (f, enable) <- unFlagAssignment _cabalFlags ]
156179 ++ map text (toAscList _configureFlags)
157180 isHackagePackage = " mirror://hackage/" `isPrefixOf` derivUrl _src
158181
159182 postUnpack = string $ " sourceRoot+=/" ++ _subpath ++ " ; echo source root reset to $sourceRoot"
183+
184+ pPrintSubLibraryDepends :: Map String BuildInfo -> Doc
185+ pPrintSubLibraryDepends libs = vcat
186+ [ text " subLibraryDepends" <+> equals <+> lbrace
187+ , nest 2 $ vcat entries
188+ , rbrace <> semi
189+ ]
190+ where
191+ entries = [ vcat [ text (show name) <+> equals <+> lbrace
192+ , nest 2 $ pPrintBuildInfo " " bi
193+ , rbrace <> semi
194+ ]
195+ | (name, bi) <- Map. toAscList libs
196+ , bi /= mempty
197+ ]
198+
199+ pPrintSubLibraryDependencies :: Map String [String ] -> Doc
200+ pPrintSubLibraryDependencies deps = vcat
201+ [ text " subLibraryDependencies" <+> equals <+> lbrace
202+ , nest 2 $ vcat entries
203+ , rbrace <> semi
204+ ]
205+ where
206+ entries = [ listattrDoc (show pkgName) empty (map (doubleQuotes . text) subLibs)
207+ | (pkgName, subLibs) <- Map. toAscList deps
208+ ]
0 commit comments