Skip to content

Commit 2ceff8f

Browse files
committed
Cleanup
1 parent aa4e16e commit 2ceff8f

5 files changed

Lines changed: 35 additions & 28 deletions

File tree

cabal2nix/src/Distribution/Nixpkgs/Haskell/BuildInfo.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ instance Monoid BuildInfo where
4242
instance NFData BuildInfo
4343

4444
pPrintBuildInfo :: String -> BuildInfo -> Doc
45-
pPrintBuildInfo prefix bi = vcat
45+
pPrintBuildInfo prefix bi = onlyIf (bi /= mempty) $ vcat
4646
[ setattr (prefix++"HaskellDepends") empty (setOf (haskell.folded.localName.ident) bi)
4747
, setattr (prefix++"SystemDepends") empty (setOf (system.folded.localName.ident) bi)
4848
, setattr (prefix++"PkgconfigDepends") empty (setOf (pkgconfig.folded.localName.ident) bi)

cabal2nix/src/Distribution/Nixpkgs/Haskell/Derivation.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE DeriveGeneric #-}
22
{-# LANGUAGE RecordWildCards #-}
33
{-# LANGUAGE TemplateHaskell #-}
4+
{-# LANGUAGE TupleSections #-}
45
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
56

67
module Distribution.Nixpkgs.Haskell.Derivation
@@ -102,7 +103,7 @@ nullDerivation = MkDerivation
102103

103104
makeLenses ''Derivation
104105

105-
makeLensesFor [("_setupDepends", "dependencies"), ("_libraryDepends", "dependencies"), ("_executableDepends", "dependencies"), ("_testDepends", "dependencies"), ("_benchmarkDepends", "dependencies")] ''Derivation
106+
makeLensesFor (fmap (,"dependencies") ["_setupDepends", "_libraryDepends", "_executableDepends", "_testDepends", "_benchmarkDepends"]) ''Derivation
106107

107108
instance Package Derivation where
108109
packageId = view pkgid
@@ -123,11 +124,11 @@ instance Pretty Derivation where
123124
, boolattr "isLibrary" (not _isLibrary || _isExecutable) _isLibrary
124125
, boolattr "isExecutable" (not _isLibrary || _isExecutable) _isExecutable
125126
, boolattr "enableSeparateDataOutput" _enableSeparateDataOutput _enableSeparateDataOutput
126-
, onlyIf (_setupDepends /= mempty) $ pPrintBuildInfo "setup" _setupDepends
127-
, onlyIf (_libraryDepends /= mempty) $ pPrintBuildInfo "library" _libraryDepends
128-
, onlyIf (_executableDepends /= mempty) $ pPrintBuildInfo "executable" _executableDepends
129-
, onlyIf (_testDepends /= mempty) $ pPrintBuildInfo "test" _testDepends
130-
, onlyIf (_benchmarkDepends /= mempty) $ pPrintBuildInfo "benchmark" _benchmarkDepends
127+
, pPrintBuildInfo "setup" _setupDepends
128+
, pPrintBuildInfo "library" _libraryDepends
129+
, pPrintBuildInfo "executable" _executableDepends
130+
, pPrintBuildInfo "test" _testDepends
131+
, pPrintBuildInfo "benchmark" _benchmarkDepends
131132
, boolattr "enableLibraryProfiling" _enableLibraryProfiling _enableLibraryProfiling
132133
, boolattr "enableExecutableProfiling" _enableExecutableProfiling _enableExecutableProfiling
133134
, boolattr "doHaddock" (not _runHaddock) _runHaddock

cabal2nix/src/Distribution/Nixpkgs/Haskell/FromCabal.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ fromPackageDescription haskellResolver nixpkgsResolver missingDeps flags Package
124124
& isExecutable .~ not (null executables)
125125
& extraFunctionArgs .~ mempty
126126
& extraAttributes .~ mempty
127-
& libraryDepends .~ foldMap (convertBuildInfo . libBuildInfo) (maybeToList library ++ subLibraries)
128-
& executableDepends .~ mconcat (map (convertBuildInfo . buildInfo) executables)
129-
& testDepends .~ mconcat (map (convertBuildInfo . testBuildInfo) testSuites)
130-
& benchmarkDepends .~ mconcat (map (convertBuildInfo . benchmarkBuildInfo) benchmarks)
127+
& libraryDepends .~ deps libBuildInfo (maybeToList library ++ subLibraries)
128+
& executableDepends .~ deps buildInfo executables
129+
& testDepends .~ deps testBuildInfo testSuites
130+
& benchmarkDepends .~ deps benchmarkBuildInfo benchmarks
131131
& Nix.setupDepends .~ maybe mempty convertSetupBuildInfo setupBuildInfo
132132
& configureFlags .~ mempty
133133
& cabalFlags .~ flags
@@ -163,6 +163,9 @@ fromPackageDescription haskellResolver nixpkgsResolver missingDeps flags Package
163163
& Nix.broken .~ not (null missingDeps)
164164
)
165165
where
166+
deps :: (a -> Cabal.BuildInfo) -> [a] -> Nix.BuildInfo
167+
deps getBuildInfo = foldMap (convertBuildInfo . getBuildInfo)
168+
166169
xrev = maybe 0 read (lookup "x-revision" customFieldsPD)
167170

168171
nixLicense :: Nix.License

cabal2nix/src/Distribution/Nixpkgs/Haskell/FromCabal/Normalize.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module Distribution.Nixpkgs.Haskell.FromCabal.Normalize ( normalize ) where
44

55
import Control.Lens
66
import qualified Data.Set as Set
7-
import Data.String
87
import Distribution.Nixpkgs.Haskell
98
import Distribution.Nixpkgs.Haskell.FromCabal.Name (toNixName)
109
import Distribution.Nixpkgs.Meta
@@ -13,12 +12,14 @@ import Language.Nix hiding ( quote )
1312

1413
normalize :: Derivation -> Derivation
1514
normalize drv = drv
16-
& over libraryDepends (normalizeBuildInfo (packageName drv))
17-
& over executableDepends (normalizeBuildInfo (packageName drv))
18-
& over testDepends (normalizeBuildInfo (packageName drv))
19-
& over benchmarkDepends (normalizeBuildInfo (packageName drv))
15+
& deps libraryDepends
16+
& deps executableDepends
17+
& deps testDepends
18+
& deps benchmarkDepends
2019
& over metaSection normalizeMeta
2120
& jailbreak %~ (&& (packageName drv /= "jailbreak-cabal"))
21+
where
22+
deps f = over f $ normalizeBuildInfo (packageName drv)
2223

2324
normalizeBuildInfo :: PackageName -> BuildInfo -> BuildInfo
2425
normalizeBuildInfo pname bi = bi

cabal2nix/src/Distribution/Nixpkgs/Haskell/FromCabal/PostProcess.hs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
module Distribution.Nixpkgs.Haskell.FromCabal.PostProcess ( postProcess, pkg ) where
55

66
import Control.Lens
7-
import Control.Monad.Trans.State
87
import Data.List.Split
98
import Data.Map ( Map )
109
import qualified Data.Map as Map
@@ -58,17 +57,20 @@ fixGtkBuilds drv = drv & dependencies . pkgconfig %~ Set.filter (not . collidesW
5857
-- also work for Stack). Until that changes, we provide do this to work around
5958
-- those package's brokenness.
6059
fixBuildDependsForTools :: Derivation -> Derivation
61-
fixBuildDependsForTools = foldr (.) id
62-
[ fmap snd $ runState $ do
63-
needs <- use $ cloneLens c . haskell . contains p
64-
cloneLens c . tool . contains p ||= needs
65-
| (c :: ALens' Derivation BuildInfo) <- [ testDepends, benchmarkDepends ]
66-
, p <- self <$> [ "hspec-discover"
67-
, "tasty-discover"
68-
, "hsx2hs"
69-
, "markdown-unlit"
70-
]
71-
]
60+
fixBuildDependsForTools = foldr (.) id $ fmap go [ testDepends, benchmarkDepends ]
61+
where
62+
go c drv =
63+
over (l . tool) (Set.union needed) drv
64+
where
65+
l :: Lens' Derivation BuildInfo
66+
l = cloneLens c
67+
needed = Set.intersection executables $ view (l . haskell) drv
68+
executables = Set.fromList $ self <$>
69+
[ "hspec-discover"
70+
, "tasty-discover"
71+
, "hsx2hs"
72+
, "markdown-unlit"
73+
]
7274

7375
hooks :: [(PackageVersionConstraint, Derivation -> Derivation)]
7476
hooks =

0 commit comments

Comments
 (0)