git.iko.soy/typeable/cabal2nix
on master help sign in
re-factoring: switch [String] to Set String in Meta type
commit1d3d51bc6eb97c89e072b6c1b5986e5b168ccb3e authorPeter Simons <simons@cryp.to> dateFri 23 Jan 2015, 21:56 (12 years ago) parent2ebe4dc
6 files changed+42−40
src/Cabal2Nix/Generate.hs+3−3 src/Cabal2Nix/Normalize.hs+10−11 src/Distribution/NixOS/Derivation/Meta.hs+24−22 src/cabal2nix.hs+2−2 src/hackage2nix.hs+1−1 test/spec.hs+2−1
src/Cabal2Nix/Generate.hs+3−3
@@ -53,9 +53,9 @@ cabal2nix' tpkg = normalize $ postProcess $ normalize $ MkDerivation
5353 { homepage = Cabal.homepage tpkg
5454 , description = Cabal.synopsis tpkg
5555 , license = fromCabalLicense (Cabal.license tpkg)
56− , platforms = []
57− , hydraPlatforms = []
58− , maintainers = []
56+ , platforms = Set.empty
57+ , hydraPlatforms = Set.empty
58+ , maintainers = Set.empty
5959 , broken = False
6060 }
6161 }
src/Cabal2Nix/Normalize.hs+10−11
@@ -63,20 +63,19 @@ normalizeNixBuildTools = normalizeSet . Set.fromList . concatMap buildToolNixNam
6363-- |Strip any kind of path prefix from maintainer names, filter duplicates, and
6464-- sort the resulting list alphabetically.
6565--
66−-- >>> normalizeMaintainers ["self.stdenv.lib.maintainers.foobar", "foobar"]
67−-- ["foobar"]
66+-- >>> normalizeMaintainers $ Set.fromList ["self.stdenv.lib.maintainers.foobar", "foobar"]
67+-- fromList ["foobar"]
6868--
69−-- >>> normalizeMaintainers ["any.prefix.is.recognized.yo", "abc.def"]
70−-- ["def","yo"]
69+-- >>> normalizeMaintainers $ Set.fromList ["any.prefix.is.recognized.yo", "abc.def"]
70+-- fromList ["def","yo"]
7171
72−normalizeMaintainers :: [String] -> [String]
73−normalizeMaintainers maints = normalizeList
74− [ (m `regsubmatch` "^([^.].*\\.)?([^.]+)$") !! 1 | m <- maints ]
72+normalizeMaintainers :: Set String -> Set String
73+normalizeMaintainers = normalizeSet . Set.map
74+ (\m -> (m `regsubmatch` "^([^.].*\\.)?([^.]+)$") !! 1)
7575
76−normalizePlatforms :: [String] -> [String]
77−normalizePlatforms [] = ["ghc.meta.platforms"]
78−normalizePlatforms plats = normalizeList
79− [ if '.' `elem` p then p else "stdenv.lib.platforms." ++ p | p <- plats ]
76+normalizePlatforms :: Set String -> Set String
77+normalizePlatforms = normalizeSet . Set.map
78+ (\p -> if '.' `elem` p then p else "stdenv.lib.platforms." ++ p)
8079
8180
8281-- |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 #-}
22{- |
33 Module : Distribution.NixOS.Derivation.Meta
44 License : BSD3
@@ -22,14 +22,16 @@ import Control.DeepSeq.Generics
2222import Distribution.NixOS.Derivation.License
2323import Distribution.NixOS.Util.PrettyPrinting
2424import GHC.Generics ( Generic )
25+import Data.Set ( Set )
26+import qualified Data.Set as Set
2527
2628-- | A representation of the @meta@ section used in Nix expressions.
2729--
2830-- >>> :{
2931-- print (pPrint (Meta "http://example.org" "an example package" (Unknown Nothing)
30−-- ["stdenv.lib.platforms.unix"]
31−-- ["stdenv.lib.platforms.none"]
32−-- ["joe","jane"]
32+-- (Set.singleton "stdenv.lib.platforms.unix")
33+-- (Set.singleton "stdenv.lib.platforms.none")
34+-- (Set.fromList ["joe","jane"])
3335-- True))
3436-- :}
3537-- homepage = "http://example.org";
@@ -37,20 +39,20 @@ import GHC.Generics ( Generic )
3739-- license = "unknown";
3840-- platforms = stdenv.lib.platforms.unix;
3941-- hydraPlatforms = stdenv.lib.platforms.none;
40−-- maintainers = with stdenv.lib.maintainers; [ joe jane ];
42+-- maintainers = with stdenv.lib.maintainers; [ jane joe ];
4143-- broken = true;
4244--
4345-- Note that the "Text" instance definition provides pretty-printing,
4446-- but no parsing as of now!
4547
4648data Meta = Meta
47− { homepage :: String -- ^ URL of the package homepage
48− , description :: String -- ^ short description of the package
49− , license :: License -- ^ licensing terms
50− , platforms :: [String] -- ^ list of supported platforms (from @pkgs\/lib\/platforms.nix@)
51− , hydraPlatforms :: [String] -- ^ list of platforms built by Hydra (from @pkgs\/lib\/platforms.nix@)
52− , maintainers :: [String] -- ^ list of maintainers from @pkgs\/lib\/maintainers.nix@
53− , broken :: Bool -- ^ set to @true@ if the build is known to fail
49+ { homepage :: String -- ^ URL of the package homepage
50+ , description :: String -- ^ short description of the package
51+ , license :: License -- ^ licensing terms
52+ , platforms :: Set String -- ^ list of supported platforms (from @pkgs\/lib\/platforms.nix@)
53+ , hydraPlatforms :: Set String -- ^ list of platforms built by Hydra (from @pkgs\/lib\/platforms.nix@)
54+ , maintainers :: Set String -- ^ list of maintainers from @pkgs\/lib\/maintainers.nix@
55+ , broken :: Bool -- ^ set to @true@ if the build is known to fail
5456 }
5557 deriving (Show, Eq, Ord, Generic)
5658
@@ -60,16 +62,16 @@ instance Pretty Meta where
6062instance NFData Meta where rnf = genericRnf
6163
6264renderMeta :: Meta -> Doc
63−renderMeta meta = vcat
64− [ onlyIf (not (null (homepage meta))) $ attr "homepage" $ string (homepage meta)
65− , onlyIf (not (null (description meta))) $ attr "description" $ string (description meta)
66− , attr "license" $ pPrint (license meta)
67− , onlyIf (not (null (platforms meta)) && platforms meta /= ["ghc.meta.platforms"]) $ sep
68− [ text "platforms" <+> equals, renderPlatformList (platforms meta) ]
69− , onlyIf (not (null (hydraPlatforms meta))) $ sep
70− [ text "hydraPlatforms" <+> equals, renderPlatformList (hydraPlatforms meta) ]
71− , listattr "maintainers" (text "with stdenv.lib.maintainers;") (maintainers meta)
72− , boolattr "broken" (broken meta) (broken meta)
65+renderMeta (Meta {..}) = vcat
66+ [ onlyIf (not (null homepage)) $ attr "homepage" $ string homepage
67+ , onlyIf (not (null description)) $ attr "description" $ string description
68+ , attr "license" $ pPrint license
69+ , onlyIf (not (Set.null platforms) && platforms /= Set.singleton "ghc.meta.platforms") $ sep
70+ [ text "platforms" <+> equals, renderPlatformList (Set.toAscList platforms) ]
71+ , onlyIf (not (Set.null hydraPlatforms)) $ sep
72+ [ text "hydraPlatforms" <+> equals, renderPlatformList (Set.toAscList hydraPlatforms) ]
73+ , listattr "maintainers" (text "with stdenv.lib.maintainers;") (Set.toAscList maintainers)
74+ , boolattr "broken" broken broken
7375 ]
7476
7577renderPlatformList :: [String] -> Doc
src/cabal2nix.hs+2−2
@@ -110,8 +110,8 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
110110 , hyperlinkSource = optHyperlinkSource cfg
111111 }
112112 deriv' = deriv { metaSection = (metaSection deriv)
113− { maintainers = optMaintainer cfg
114− , platforms = optPlatform cfg
113+ { maintainers = Set.fromList (optMaintainer cfg)
114+ , platforms = Set.fromList (optPlatform cfg)
115115 }
116116 , doCheck = doCheck deriv && optDoCheck cfg
117117 , extraFunctionArgs = Set.insert "stdenv" (extraFunctionArgs deriv)
src/hackage2nix.hs+1−1
@@ -139,7 +139,7 @@ generatePackageSet config hackage nixpkgs = do
139139 drv = drv' { src = srcSpec, editedCabalFile = if revision drv == 0 then "" else cabalFileHash
140140 , metaSection = (metaSection drv') { broken = not (Set.null missing) -- Missing Haskell dependencies!
141141 , hydraPlatforms = if PackageName name `Set.member` brokenPackages config
142− then ["stdenv.lib.platforms.none"]
142+ then Set.singleton "stdenv.lib.platforms.none"
143143 else hydraPlatforms (metaSection drv')
144144 }
145145 , jailbreak = not (null missingDeps) -- Dependency constraints aren't fulfilled
test/spec.hs+2−1
@@ -7,13 +7,14 @@ import Control.DeepSeq
77import Control.Exception
88import Distribution.NixOS.Derivation.License
99import Distribution.NixOS.Derivation.Meta
10+import Data.Set ( empty )
1011
1112main :: IO ()
1213main = do
1314 hspec $ do
1415 describe "DeepSeq instances work properly for" $ do
1516 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
1718 mapM_ hitsBottom
1819 [ meta { homepage = undefined }
1920 , meta { description = undefined }