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 , configureFlags = normalizeList configureFlags
21 , metaSection = normalizeMeta metaSection
24normalizeMeta :: Meta -> Meta
25normalizeMeta meta@(Meta {..}) = meta
26 { description = normalizeDescription description
27 , maintainers = normalizeMaintainers maintainers
28 , platforms = normalizePlatforms platforms
31normalizeDescription :: String -> String
32normalizeDescription desc
34 | last desc == '.' && length (filter ('.'==) desc) == 1 = normalizeDescription (init desc)
35 | otherwise = quote (unwords (words desc))
37quote :: String -> String
38quote ('\\':c:cs) = '\\' : c : quote cs
39quote ('"':cs) = '\\' : '"' : quote cs
40quote (c:cs) = c : quote cs
43normalizeList :: [String] -> [String]
44normalizeList = nub . sortBy (compare `on` map toLower)
46normalizeNixNames :: [String] -> [String]
47normalizeNixNames = normalizeList . map toNixName
49normalizeNixLibs :: [String] -> [String]
50normalizeNixLibs = normalizeList . concatMap libNixName
52normalizeNixBuildTools :: [String] -> [String]
53normalizeNixBuildTools = normalizeList . concatMap buildToolNixName
55-- |Strip the "self.ghc.meta.platforms" prefix from platform names, filter
56-- duplicates, and sort the resulting list alphabetically.
58-- >>> normalizeMaintainers ["self.stdenv.lib.maintainers.foobar", "foobar"]
61-- >>> normalizeMaintainers ["any.prefix.is.recognized.yo", "abc.def"]
64normalizeMaintainers :: [String] -> [String]
65normalizeMaintainers maints = normalizeList
66 [ (m `regsubmatch` "^([^.].*\\.)?([^.]+)$") !! 1 | m <- maints ]
68normalizePlatforms :: [String] -> [String]
69normalizePlatforms [] = ["ghc.meta.platforms"]
70normalizePlatforms plats = normalizeList
71 [ 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