git.iko.soy/typeable/cabal2nix
on master help sign in
cabal2nix: add support for library and executable profiling

The following new command-line flags control profiling support in the generated expression: --enable-library-profiling enable library profiling in the generated build --enable-executable-profiling enable executable profiling in the generated build --enable-profiling enable both library and executable profiling in the generated build This patch resolves https://github.com/NixOS/cabal2nix/issues/189.

commitb3891fc41896ab7e08ebed3ff957f7229b589b7c authorPeter Simons <simons@cryp.to> dateWed 26 Aug 2015, 22:53 (11 years ago) parentbfa4994
3 files changed+41−27
src/Distribution/Nixpkgs/Haskell/Derivation.hs+27−21 src/Distribution/Nixpkgs/Haskell/FromCabal.hs+2 src/cabal2nix.hs+12−6
src/Distribution/Nixpkgs/Haskell/Derivation.hs+27−21
@@ -7,7 +7,7 @@ module Distribution.Nixpkgs.Haskell.Derivation
77 ( Derivation, pkgid, revision, src, isLibrary, isExecutable
88 , extraFunctionArgs, libraryDepends, executableDepends, testDepends, configureFlags
99 , cabalFlags, runHaddock, jailbreak, doCheck, testTarget, hyperlinkSource, enableSplitObjs
10− , phaseOverrides, editedCabalFile, metaSection
10+ , enableLibraryProfiling, enableExecutableProfiling, phaseOverrides, editedCabalFile, metaSection
1111 , dependencies
1212 )
1313 where
@@ -33,26 +33,28 @@ import Language.Nix
3333-- 'PackageDescription' from Cabal.
3434
3535data Derivation = MkDerivation
36− { _pkgid :: PackageIdentifier
37− , _revision :: Int
38− , _src :: DerivationSource
39− , _isLibrary :: Bool
40− , _isExecutable :: Bool
41− , _extraFunctionArgs :: Set Identifier
42− , _libraryDepends :: BuildInfo
43− , _executableDepends :: BuildInfo
44− , _testDepends :: BuildInfo
45− , _configureFlags :: Set String
46− , _cabalFlags :: FlagAssignment
47− , _runHaddock :: Bool
48− , _jailbreak :: Bool
49− , _doCheck :: Bool
50− , _testTarget :: String
51− , _hyperlinkSource :: Bool
52− , _enableSplitObjs :: Bool
53− , _phaseOverrides :: String
54− , _editedCabalFile :: String
55− , _metaSection :: Meta
36+ { _pkgid :: PackageIdentifier
37+ , _revision :: Int
38+ , _src :: DerivationSource
39+ , _isLibrary :: Bool
40+ , _isExecutable :: Bool
41+ , _extraFunctionArgs :: Set Identifier
42+ , _libraryDepends :: BuildInfo
43+ , _executableDepends :: BuildInfo
44+ , _testDepends :: BuildInfo
45+ , _configureFlags :: Set String
46+ , _cabalFlags :: FlagAssignment
47+ , _runHaddock :: Bool
48+ , _jailbreak :: Bool
49+ , _doCheck :: Bool
50+ , _testTarget :: String
51+ , _hyperlinkSource :: Bool
52+ , _enableLibraryProfiling :: Bool
53+ , _enableExecutableProfiling :: Bool
54+ , _enableSplitObjs :: Bool
55+ , _phaseOverrides :: String
56+ , _editedCabalFile :: String
57+ , _metaSection :: Meta
5658 }
5759 deriving (Show, Eq, Generic)
5860
@@ -74,6 +76,8 @@ instance Default Derivation where
7476 , _doCheck = error "undefined Derivation.doCheck"
7577 , _testTarget = error "undefined Derivation.testTarget"
7678 , _hyperlinkSource = error "undefined Derivation.hyperlinkSource"
79+ , _enableLibraryProfiling = error "undefined Derivation.enableLibraryProfiling"
80+ , _enableExecutableProfiling = error "undefined Derivation.enableExecutableProfiling"
7781 , _enableSplitObjs = error "undefined Derivation.enableSplitObjs"
7882 , _phaseOverrides = error "undefined Derivation.phaseOverrides"
7983 , _editedCabalFile = error "undefined Derivation.editedCabalFile"
@@ -104,6 +108,8 @@ instance Pretty Derivation where
104108 , onlyIf (_libraryDepends /= mempty) $ pPrintBuildInfo "library" _libraryDepends
105109 , onlyIf (_executableDepends /= mempty) $ pPrintBuildInfo "executable" _executableDepends
106110 , onlyIf (_testDepends /= mempty) $ pPrintBuildInfo "test" _testDepends
111+ , boolattr "enableLibraryProfiling" _enableLibraryProfiling _enableLibraryProfiling
112+ , boolattr "enableExecutableProfiling" _enableExecutableProfiling _enableExecutableProfiling
107113 , boolattr "enableSplitObjs" (not _enableSplitObjs) _enableSplitObjs
108114 , boolattr "doHaddock" (not _runHaddock) _runHaddock
109115 , boolattr "jailbreak" _jailbreak _jailbreak
src/Distribution/Nixpkgs/Haskell/FromCabal.hs+2
@@ -83,6 +83,8 @@ fromPackageDescription haskellResolver nixpkgsResolver mismatchedDeps missingDep
8383 & testTarget .~ mempty
8484 & hyperlinkSource .~ True
8585 & enableSplitObjs .~ True
86+ & enableLibraryProfiling .~ False
87+ & enableExecutableProfiling .~ False
8688 & phaseOverrides .~ mempty
8789 & editedCabalFile .~ (if xrev > 0
8890 then fromMaybe (error (display package ++ ": X-Cabal-File-Hash field is missing")) (lookup "X-Cabal-File-Hash" customFieldsPD)
src/cabal2nix.hs+12−6
@@ -32,6 +32,9 @@ data Options = Options
3232 , optJailbreak :: Bool
3333 , optRevision :: Maybe String
3434 , optHyperlinkSource :: Bool
35+ , optEnableLibraryProfiling :: Bool
36+ , optEnableExecutableProfiling :: Bool
37+ , optEnableProfiling :: Maybe Bool
3538 , optHackageDb :: Maybe FilePath
3639 , optNixShellOutput :: Bool
3740 , optFlags :: [String]
@@ -49,6 +52,9 @@ options = Options
4952 <*> switch (long "jailbreak" <> help "disregard version restrictions on build inputs")
5053 <*> optional (strOption $ long "revision" <> help "revision to use when fetching from VCS")
5154 <*> flag True False (long "no-hyperlink-source" <> help "don't generate pretty-printed source code for the documentation")
55+ <*> switch (long "enable-library-profiling" <> help "enable library profiling in the generated build")
56+ <*> switch (long "enable-executable-profiling" <> help "enable executable profiling in the generated build")
57+ <*> optional (switch (long "enable-profiling" <> help "enable both library and executable profiling in the generated build"))
5258 <*> optional (strOption $ long "hackage-db" <> metavar "PATH" <> help "path to the local hackage db in tar format")
5359 <*> switch (long "shell" <> help "generate output suitable for nix-shell")
5460 <*> many (strOption $ short 'f' <> long "flag" <> help "Cabal flag (may be specified multiple times)")
@@ -87,20 +93,20 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
8793
8894 pkg <- getPackage optHackageDb $ Source optUrl (fromMaybe "" optRevision) (maybe UnknownHash Guess optSha256)
8995
90− let flags = readFlagList optFlags
91−
92− deriv :: Derivation
96+ let deriv :: Derivation
9397 deriv = fromGenericPackageDescription (const True)
9498 (\i -> Just (create binding (i, create path [i])))
9599 (platform ghc7102)
96100 (compilerInfo ghc7102)
97− flags
101+ (readFlagList optFlags)
98102 []
99103 (pkgCabal pkg)
100104 & src .~ pkgSource pkg
101105 & runHaddock .~ optHaddock
102106 & jailbreak .~ optJailbreak
103107 & hyperlinkSource .~ optHyperlinkSource
108+ & enableLibraryProfiling .~ (fromMaybe False optEnableProfiling || optEnableLibraryProfiling)
109+ & enableExecutableProfiling .~ (fromMaybe False optEnableProfiling || optEnableExecutableProfiling)
104110 & metaSection.maintainers .~ Set.fromList optMaintainer
105111 & metaSection.platforms .~ Set.fromList optPlatform
106112 & doCheck &&~ optDoCheck
@@ -117,8 +123,8 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
117123 , hcat [ text " f = ", pPrint deriv, semi ]
118124 , text ""
119125 , text " haskellPackages = if compiler == \"default\""
120− , text " then pkgs.haskellPackages"
121− , text " else pkgs.haskell.packages.${compiler};"
126+ , text " then pkgs.haskellPackages"
127+ , text " else pkgs.haskell.packages.${compiler};"
122128 , text ""
123129 , text " drv = haskellPackages.callPackage f {};"
124130 , text ""