git.iko.soy/typeable/cabal2nix
on master help sign in
re-factoring: switch [String] to Set String in Meta type
1d3d51bPeter Simons
src/Cabal2Nix/Generate.hs+3−3
@@ -53,9 +53,9 @@ cabal2nix' tpkg = normalize $ postProcess $ normalize $ MkDerivation
53 { homepage = Cabal.homepage tpkg
53 { homepage = Cabal.homepage tpkg
54 , description = Cabal.synopsis tpkg
54 , description = Cabal.synopsis tpkg
55 , license = fromCabalLicense (Cabal.license tpkg)
55 , license = fromCabalLicense (Cabal.license tpkg)
56− , platforms = []
56+ , platforms = Set.empty
57− , hydraPlatforms = []
57+ , hydraPlatforms = Set.empty
58− , maintainers = []
58+ , maintainers = Set.empty
59 , broken = False
59 , broken = False
60 }
60 }
61 }
61 }
src/Cabal2Nix/Normalize.hs+10−11
@@ -63,20 +63,19 @@ normalizeNixBuildTools = normalizeSet . Set.fromList . concatMap buildToolNixNam
63-- |Strip any kind of path prefix from maintainer names, filter duplicates, and
63-- |Strip any kind of path prefix from maintainer names, filter duplicates, and
64-- sort the resulting list alphabetically.
64-- sort the resulting list alphabetically.
65--
65--
66−-- >>> normalizeMaintainers ["self.stdenv.lib.maintainers.foobar", "foobar"]
66+-- >>> normalizeMaintainers $ Set.fromList ["self.stdenv.lib.maintainers.foobar", "foobar"]
67−-- ["foobar"]
67+-- fromList ["foobar"]
68--
68--
69−-- >>> normalizeMaintainers ["any.prefix.is.recognized.yo", "abc.def"]
69+-- >>> normalizeMaintainers $ Set.fromList ["any.prefix.is.recognized.yo", "abc.def"]
70−-- ["def","yo"]
70+-- fromList ["def","yo"]
71
71
72−normalizeMaintainers :: [String] -> [String]
72+normalizeMaintainers :: Set String -> Set String
73−normalizeMaintainers maints = normalizeList
73+normalizeMaintainers = normalizeSet . Set.map
74− [ (m `regsubmatch` "^([^.].*\\.)?([^.]+)$") !! 1 | m <- maints ]
74+ (\m -> (m `regsubmatch` "^([^.].*\\.)?([^.]+)$") !! 1)
75
75
76−normalizePlatforms :: [String] -> [String]
76+normalizePlatforms :: Set String -> Set String
77−normalizePlatforms [] = ["ghc.meta.platforms"]
77+normalizePlatforms = normalizeSet . Set.map
78−normalizePlatforms plats = normalizeList
79− [ if '.' `elem` p then p else "stdenv.lib.platforms." ++ p | p <- plats ]
78+ (\p -> if '.' `elem` p then p else "stdenv.lib.platforms." ++ p)
80
79
81
80
82-- |When a flag is specified multiple times, the first occurrence
81-- |When a flag is specified multiple times, the first occurrence
src/Distribution/NixOS/Derivation/Meta.hs+24−22
@@ -1,4 +1,4 @@
1−{-# LANGUAGE DeriveGeneric #-}
1+{-# LANGUAGE DeriveGeneric, RecordWildCards #-}
2{- |
2{- |
3 Module : Distribution.NixOS.Derivation.Meta
3 Module : Distribution.NixOS.Derivation.Meta
4 License : BSD3
4 License : BSD3
@@ -22,14 +22,16 @@ import Control.DeepSeq.Generics
22import Distribution.NixOS.Derivation.License
22import Distribution.NixOS.Derivation.License
23import Distribution.NixOS.Util.PrettyPrinting
23import Distribution.NixOS.Util.PrettyPrinting
24import GHC.Generics ( Generic )
24import GHC.Generics ( Generic )
25+import Data.Set ( Set )
26+import qualified Data.Set as Set
25
27
26-- | A representation of the @meta@ section used in Nix expressions.
28-- | A representation of the @meta@ section used in Nix expressions.
27--
29--
28-- >>> :{
30-- >>> :{
29-- print (pPrint (Meta "http://example.org" "an example package" (Unknown Nothing)
31-- print (pPrint (Meta "http://example.org" "an example package" (Unknown Nothing)
30−-- ["stdenv.lib.platforms.unix"]
32+-- (Set.singleton "stdenv.lib.platforms.unix")
31−-- ["stdenv.lib.platforms.none"]
33+-- (Set.singleton "stdenv.lib.platforms.none")
32−-- ["joe","jane"]
34+-- (Set.fromList ["joe","jane"])
33-- True))
35-- True))
34-- :}
36-- :}
35-- homepage = "http://example.org";
37-- homepage = "http://example.org";
@@ -37,20 +39,20 @@ import GHC.Generics ( Generic )
37-- license = "unknown";
39-- license = "unknown";
38-- platforms = stdenv.lib.platforms.unix;
40-- platforms = stdenv.lib.platforms.unix;
39-- hydraPlatforms = stdenv.lib.platforms.none;
41-- hydraPlatforms = stdenv.lib.platforms.none;
40−-- maintainers = with stdenv.lib.maintainers; [ joe jane ];
42+-- maintainers = with stdenv.lib.maintainers; [ jane joe ];
41-- broken = true;
43-- broken = true;
42--
44--
43-- Note that the "Text" instance definition provides pretty-printing,
45-- Note that the "Text" instance definition provides pretty-printing,
44-- but no parsing as of now!
46-- but no parsing as of now!
45
47
46data Meta = Meta
48data Meta = Meta
47− { homepage :: String -- ^ URL of the package homepage
49+ { homepage :: String -- ^ URL of the package homepage
48− , description :: String -- ^ short description of the package
50+ , description :: String -- ^ short description of the package
49− , license :: License -- ^ licensing terms
51+ , license :: License -- ^ licensing terms
50− , platforms :: [String] -- ^ list of supported platforms (from @pkgs\/lib\/platforms.nix@)
52+ , platforms :: Set String -- ^ list of supported platforms (from @pkgs\/lib\/platforms.nix@)
51− , hydraPlatforms :: [String] -- ^ list of platforms built by Hydra (from @pkgs\/lib\/platforms.nix@)
53+ , hydraPlatforms :: Set String -- ^ list of platforms built by Hydra (from @pkgs\/lib\/platforms.nix@)
52− , maintainers :: [String] -- ^ list of maintainers from @pkgs\/lib\/maintainers.nix@
54+ , maintainers :: Set String -- ^ list of maintainers from @pkgs\/lib\/maintainers.nix@
53− , broken :: Bool -- ^ set to @true@ if the build is known to fail
55+ , broken :: Bool -- ^ set to @true@ if the build is known to fail
54 }
56 }
55 deriving (Show, Eq, Ord, Generic)
57 deriving (Show, Eq, Ord, Generic)
56
58
@@ -60,16 +62,16 @@ instance Pretty Meta where
60instance NFData Meta where rnf = genericRnf
62instance NFData Meta where rnf = genericRnf
61
63
62renderMeta :: Meta -> Doc
64renderMeta :: Meta -> Doc
63−renderMeta meta = vcat
65+renderMeta (Meta {..}) = vcat
64− [ onlyIf (not (null (homepage meta))) $ attr "homepage" $ string (homepage meta)
66+ [ onlyIf (not (null homepage)) $ attr "homepage" $ string homepage
65− , onlyIf (not (null (description meta))) $ attr "description" $ string (description meta)
67+ , onlyIf (not (null description)) $ attr "description" $ string description
66− , attr "license" $ pPrint (license meta)
68+ , attr "license" $ pPrint license
67− , onlyIf (not (null (platforms meta)) && platforms meta /= ["ghc.meta.platforms"]) $ sep
69+ , onlyIf (not (Set.null platforms) && platforms /= Set.singleton "ghc.meta.platforms") $ sep
68− [ text "platforms" <+> equals, renderPlatformList (platforms meta) ]
70+ [ text "platforms" <+> equals, renderPlatformList (Set.toAscList platforms) ]
69− , onlyIf (not (null (hydraPlatforms meta))) $ sep
71+ , onlyIf (not (Set.null hydraPlatforms)) $ sep
70− [ text "hydraPlatforms" <+> equals, renderPlatformList (hydraPlatforms meta) ]
72+ [ text "hydraPlatforms" <+> equals, renderPlatformList (Set.toAscList hydraPlatforms) ]
71− , listattr "maintainers" (text "with stdenv.lib.maintainers;") (maintainers meta)
73+ , listattr "maintainers" (text "with stdenv.lib.maintainers;") (Set.toAscList maintainers)
72− , boolattr "broken" (broken meta) (broken meta)
74+ , boolattr "broken" broken broken
73 ]
75 ]
74
76
75renderPlatformList :: [String] -> Doc
77renderPlatformList :: [String] -> Doc
src/cabal2nix.hs+2−2
@@ -110,8 +110,8 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
110 , hyperlinkSource = optHyperlinkSource cfg
110 , hyperlinkSource = optHyperlinkSource cfg
111 }
111 }
112 deriv' = deriv { metaSection = (metaSection deriv)
112 deriv' = deriv { metaSection = (metaSection deriv)
113− { maintainers = optMaintainer cfg
113+ { maintainers = Set.fromList (optMaintainer cfg)
114− , platforms = optPlatform cfg
114+ , platforms = Set.fromList (optPlatform cfg)
115 }
115 }
116 , doCheck = doCheck deriv && optDoCheck cfg
116 , doCheck = doCheck deriv && optDoCheck cfg
117 , extraFunctionArgs = Set.insert "stdenv" (extraFunctionArgs deriv)
117 , extraFunctionArgs = Set.insert "stdenv" (extraFunctionArgs deriv)
src/hackage2nix.hs+1−1
@@ -139,7 +139,7 @@ generatePackageSet config hackage nixpkgs = do
139 drv = drv' { src = srcSpec, editedCabalFile = if revision drv == 0 then "" else cabalFileHash
139 drv = drv' { src = srcSpec, editedCabalFile = if revision drv == 0 then "" else cabalFileHash
140 , metaSection = (metaSection drv') { broken = not (Set.null missing) -- Missing Haskell dependencies!
140 , metaSection = (metaSection drv') { broken = not (Set.null missing) -- Missing Haskell dependencies!
141 , hydraPlatforms = if PackageName name `Set.member` brokenPackages config
141 , hydraPlatforms = if PackageName name `Set.member` brokenPackages config
142− then ["stdenv.lib.platforms.none"]
142+ then Set.singleton "stdenv.lib.platforms.none"
143 else hydraPlatforms (metaSection drv')
143 else hydraPlatforms (metaSection drv')
144 }
144 }
145 , jailbreak = not (null missingDeps) -- Dependency constraints aren't fulfilled
145 , jailbreak = not (null missingDeps) -- Dependency constraints aren't fulfilled
test/spec.hs+2−1
@@ -7,13 +7,14 @@ import Control.DeepSeq
7import Control.Exception
7import Control.Exception
8import Distribution.NixOS.Derivation.License
8import Distribution.NixOS.Derivation.License
9import Distribution.NixOS.Derivation.Meta
9import Distribution.NixOS.Derivation.Meta
10+import Data.Set ( empty )
10
11
11main :: IO ()
12main :: IO ()
12main = do
13main = do
13 hspec $ do
14 hspec $ do
14 describe "DeepSeq instances work properly for" $ do
15 describe "DeepSeq instances work properly for" $ do
15 it "License" $ mapM_ hitsBottom [Known undefined, Unknown (Just undefined)]
16 it "License" $ mapM_ hitsBottom [Known undefined, Unknown (Just undefined)]
16− it "Meta" $ do let meta = Meta "" "" (Unknown Nothing) [] [] [] False
17+ it "Meta" $ do let meta = Meta "" "" (Unknown Nothing) empty empty empty False
17 mapM_ hitsBottom
18 mapM_ hitsBottom
18 [ meta { homepage = undefined }
19 [ meta { homepage = undefined }
19 , meta { description = undefined }
20 , meta { description = undefined }