1{-# LANGUAGE RecordWildCards #-}
3module Cabal2Nix.Normalize ( normalize, normalizeList ) where
5import Distribution.NixOS.Derivation.Cabal
7import Cabal2Nix.CorePackages
11import Distribution.NixOS.Regex ( regsubmatch )
13normalize :: Derivation -> Derivation
14normalize deriv@(MkDerivation {..}) = deriv
15 { buildDepends = normalizeNixNames (filter (`notElem` (pname : corePackages)) buildDepends)
16 , testDepends = normalizeNixNames (filter (`notElem` (pname : corePackages)) testDepends)
17 , buildTools = normalizeNixBuildTools (filter (`notElem` coreBuildTools) buildTools)
18 , extraLibs = normalizeNixLibs extraLibs
19 , pkgConfDeps = normalizeNixLibs pkgConfDeps
20 , metaSection = normalizeMeta metaSection
23normalizeMeta :: Meta -> Meta
24normalizeMeta meta@(Meta {..}) = meta
25 { description = normalizeDescription description
26 , maintainers = normalizeMaintainers maintainers
27 , platforms = normalizePlatforms platforms
30normalizeDescription :: String -> String
31normalizeDescription desc
33 | last desc == '.' && length (filter ('.'==) desc) == 1 = normalizeDescription (init desc)
34 | otherwise = quote (unwords (words desc))
36quote :: String -> String
37quote ('\\':c:cs) = '\\' : c : quote cs
38quote ('"':cs) = '\\' : '"' : quote cs
39quote (c:cs) = c : quote cs
42normalizeList :: [String] -> [String]
43normalizeList = nub . sortBy (compare `on` map toLower)
45normalizeNixNames :: [String] -> [String]
46normalizeNixNames = normalizeList . map toNixName
48normalizeNixLibs :: [String] -> [String]
49normalizeNixLibs = normalizeList . concatMap libNixName
51normalizeNixBuildTools :: [String] -> [String]
52normalizeNixBuildTools = normalizeList . concatMap buildToolNixName
54-- |Strip the "self.ghc.meta.platforms" prefix from platform names, filter
55-- duplicates, and sort the resulting list alphabetically.
57-- >>> normalizeMaintainers ["self.stdenv.lib.maintainers.foobar", "foobar"]
60-- >>> normalizeMaintainers ["any.prefix.is.recognized.yo", "abc.def"]
63normalizeMaintainers :: [String] -> [String]
64normalizeMaintainers maints = normalizeList
65 [ (m `regsubmatch` "^([^.].*\\.)?([^.]+)$") !! 1 | m <- maints ]
67normalizePlatforms :: [String] -> [String]
68normalizePlatforms [] = ["ghc.meta.platforms"]
69normalizePlatforms plats = normalizeList
70 [ if '.' `elem` p then p else "stdenv.lib.platforms." ++ p | p <- plats ]
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list