git.iko.soy/typeable/cabal2nix
on master help sign in
Restrict export list of BuildInfo, Meta, and Derivation types to enforce access through lenses.
commitd63faad1794dc251fd576c0dec9f6619b4daae51 authorPeter Simons <simons@cryp.to> dateSat 8 Aug 2015, 18:28 (11 years ago) parent65a1bd0
4 files changed+61−57
src/Cabal2Nix/Generate.hs+2−45 src/Distribution/Nixpkgs/Haskell.hs+35−2 src/Distribution/Nixpkgs/Meta.hs+16−1 test/spec.hs+8−9
src/Cabal2Nix/Generate.hs+2−45
@@ -37,30 +37,6 @@ cabal2nix flags' cabal = normalize $ drv & cabalFlags .~ flags
3737 []
3838 cabal
3939
40−nullDerivation :: Derivation
41−nullDerivation = MkDerivation
42− { _pkgid = error "undefined _pkgid"
43− , _revision = error "undefined _revision"
44− , _src = error "undefined _src"
45− , _isLibrary = error "undefined _isLibrary"
46− , _isExecutable = error "undefined _isExecutable"
47− , _extraFunctionArgs = error "undefined _extraFunctionArgs"
48− , _libraryDepends = error "undefined _libraryDepends"
49− , _executableDepends = error "undefined _executableDepends"
50− , _testDepends = error "undefined _testDepends"
51− , _configureFlags = error "undefined _configureFlags"
52− , _cabalFlags = error "undefined _cabalFlags"
53− , _runHaddock = error "undefined _runHaddock"
54− , _jailbreak = error "undefined _jailbreak"
55− , _doCheck = error "undefined _doCheck"
56− , _testTarget = error "undefined _testTarget"
57− , _hyperlinkSource = error "undefined _hyperlinkSource"
58− , _enableSplitObjs = error "undefined _enableSplitObjs"
59− , _phaseOverrides = error "undefined _phaseOverrides"
60− , _editedCabalFile = error "undefined _editedCabalFile"
61− , _metaSection = error "undefined _metaSection"
62− }
63−
6440cabal2nix' :: PackageDescription -> Derivation
6541cabal2nix' PackageDescription {..} = normalize $ postProcess $
6642 let
@@ -91,7 +67,7 @@ cabal2nix' PackageDescription {..} = normalize $ postProcess $
9167 & enableSplitObjs .~ True
9268 & phaseOverrides .~ mempty
9369 & editedCabalFile .~ (if xrev > 0 then fromJust (lookup "x-cabal-file-hash" customFieldsPD) else "")
94− & metaSection .~ ( nullMeta
70+ & metaSection .~ ( Nix.nullMeta
9571 & Nix.homepage .~ homepage
9672 & Nix.description .~ synopsis
9773 & Nix.license .~ fromCabalLicense license
@@ -101,27 +77,8 @@ cabal2nix' PackageDescription {..} = normalize $ postProcess $
10177 & Nix.broken .~ False
10278 )
10379
104−nullBuildInfo :: Nix.BuildInfo
105−nullBuildInfo = Nix.BuildInfo
106− { _haskell = error "undefined _haskell"
107− , _pkgconfig = error "undefined _pkgconfig"
108− , _system = error "undefined _system"
109− , _tool = error "undefined _tool"
110− }
111−
112−nullMeta :: Nix.Meta
113−nullMeta = Nix.Meta
114− { Nix._homepage = error "undefined Nix._homepage"
115− , Nix._description = error "undefined Nix._description"
116− , Nix._license = error "undefined Nix._license"
117− , Nix._platforms = error "undefined Nix._platforms"
118− , Nix._hydraPlatforms = error "undefined Nix._hydraPlatforms"
119− , Nix._maintainers = error "undefined Nix._maintainers"
120− , Nix._broken = error "undefined Nix._broken"
121− }
122−
12380convertBuildInfo :: Cabal.BuildInfo -> Nix.BuildInfo
124−convertBuildInfo Cabal.BuildInfo {..} = nullBuildInfo
81+convertBuildInfo Cabal.BuildInfo {..} = mempty
12582 & haskell .~ Set.fromList targetBuildDepends
12683 & system .~ Set.fromList [ Dependency (PackageName y) anyVersion | x <- extraLibs, y <- libNixName x, not (null y) ]
12784 & pkgconfig .~ Set.fromList [ Dependency (PackageName y) anyVersion | Dependency (PackageName x) _ <- pkgconfigDepends, y <- libNixName x, not (null y) ]
src/Distribution/Nixpkgs/Haskell.hs+35−2
@@ -2,7 +2,16 @@
22{-# LANGUAGE RecordWildCards, DeriveGeneric #-}
33{-# OPTIONS_GHC -fno-warn-orphans #-} -- for FlagName below
44
5−module Distribution.Nixpkgs.Haskell where
5+module Distribution.Nixpkgs.Haskell
6+ ( Derivation, nullDerivation, pkgid, revision, src, isLibrary, isExecutable
7+ , extraFunctionArgs, libraryDepends, executableDepends, testDepends, configureFlags
8+ , cabalFlags, runHaddock, jailbreak, doCheck, testTarget, hyperlinkSource, enableSplitObjs
9+ , phaseOverrides, editedCabalFile, metaSection
10+ , BuildInfo, haskell, pkgconfig, system, tool
11+ , dependencies
12+ , unDep
13+ )
14+ where
615
716import Control.DeepSeq.Generics
817import Control.Lens
@@ -62,12 +71,36 @@ data Derivation = MkDerivation
6271 }
6372 deriving (Show, Eq, Generic)
6473
74+nullDerivation :: Derivation
75+nullDerivation = MkDerivation
76+ { _pkgid = error "undefined _pkgid"
77+ , _revision = error "undefined _revision"
78+ , _src = error "undefined _src"
79+ , _isLibrary = error "undefined _isLibrary"
80+ , _isExecutable = error "undefined _isExecutable"
81+ , _extraFunctionArgs = error "undefined _extraFunctionArgs"
82+ , _libraryDepends = error "undefined _libraryDepends"
83+ , _executableDepends = error "undefined _executableDepends"
84+ , _testDepends = error "undefined _testDepends"
85+ , _configureFlags = error "undefined _configureFlags"
86+ , _cabalFlags = error "undefined _cabalFlags"
87+ , _runHaddock = error "undefined _runHaddock"
88+ , _jailbreak = error "undefined _jailbreak"
89+ , _doCheck = error "undefined _doCheck"
90+ , _testTarget = error "undefined _testTarget"
91+ , _hyperlinkSource = error "undefined _hyperlinkSource"
92+ , _enableSplitObjs = error "undefined _enableSplitObjs"
93+ , _phaseOverrides = error "undefined _phaseOverrides"
94+ , _editedCabalFile = error "undefined _editedCabalFile"
95+ , _metaSection = error "undefined _metaSection"
96+ }
97+
6598makeLenses ''Derivation
6699
67100makeLensesFor [("_libraryDepends", "dependencies"), ("_executableDepends", "dependencies"), ("_testDepends", "dependencies")] ''Derivation
68101
69102instance Package Derivation where
70− packageId = _pkgid
103+ packageId = view pkgid
71104
72105instance NFData BuildInfo where rnf = genericRnf
73106
src/Distribution/Nixpkgs/Meta.hs+16−1
@@ -6,7 +6,11 @@
66 of the Nixpkgs manual at <http://nixos.org/nixpkgs/docs.html>.
77 -}
88
9−module Distribution.Nixpkgs.Meta where
9+module Distribution.Nixpkgs.Meta
10+ ( Meta, nullMeta
11+ , homepage, description, license, platforms, hydraPlatforms, maintainers, broken
12+ ) where
13+
1014
1115import Control.DeepSeq.Generics
1216import Control.Lens
@@ -67,3 +71,14 @@ instance Pretty Meta where
6771renderPlatformList :: [String] -> Doc
6872renderPlatformList plats =
6973 nest 2 (fsep $ punctuate (text " ++") $ map text plats) <> semi
74+
75+nullMeta :: Meta
76+nullMeta = Meta
77+ { _homepage = error "undefined Nix._homepage"
78+ , _description = error "undefined Nix._description"
79+ , _license = error "undefined Nix._license"
80+ , _platforms = error "undefined Nix._platforms"
81+ , _hydraPlatforms = error "undefined Nix._hydraPlatforms"
82+ , _maintainers = error "undefined Nix._maintainers"
83+ , _broken = error "undefined Nix._broken"
84+ }
test/spec.hs+8−9
@@ -1,8 +1,8 @@
11module Main ( main ) where
22
3+import Control.Lens
34import Control.DeepSeq
45import Control.Exception
5−import Data.Set ( empty )
66import Distribution.Nixpkgs.License
77import Distribution.Nixpkgs.Meta
88import Test.Hspec
@@ -12,14 +12,13 @@ main = do
1212 hspec $ do
1313 describe "DeepSeq instances work properly for" $ do
1414 it "License" $ mapM_ hitsBottom [Known undefined, Unknown (Just undefined)]
15− it "Meta" $ do let meta = Meta "" "" (Unknown Nothing) empty empty empty False
16− mapM_ hitsBottom
17− [ meta { _homepage = undefined }
18− , meta { _description = undefined }
19− , meta { _license = undefined }
20− , meta { _platforms = undefined }
21− , meta { _maintainers = undefined }
22− , meta { _broken = undefined }
15+ it "Meta" $ do mapM_ hitsBottom
16+ [ nullMeta & homepage .~ undefined
17+ , nullMeta & description .~ undefined
18+ , nullMeta & license .~ undefined
19+ , nullMeta & platforms .~ undefined
20+ , nullMeta & maintainers .~ undefined
21+ , nullMeta & broken .~ undefined
2322 ]
2423
2524hitsBottom :: NFData a => a -> Expectation