git.iko.soy/typeable/cabal2nix
on master help sign in
normalizeCabalFlags: fix broken precedence logic

The function assumed that given a sequence of multiple instances of the same flag, Cabal chooses the value given first, but in fact it chooses the value given last. Not sure whether this behavior ever changed at some point in time, but it's certainly more in line with what one would expect.

commitadd05d06310137ad9241ec1b0905d6401eed5743 authorPeter Simons <simons@cryp.to> dateThu 18 Jan 2018, 12:19 (9 years ago) parent0876866
1 file changed+9−7
src/Distribution/Nixpkgs/Haskell/FromCabal/Normalize.hs+9−7
src/Distribution/Nixpkgs/Haskell/FromCabal/Normalize.hs+9−7
@@ -47,14 +47,16 @@ quote ('"':cs) = '\\' : '"' : quote cs
4747quote (c:cs) = c : quote cs
4848quote [] = []
4949
50−-- | When a flag is specified multiple times, the first occurrence counts. This
51−-- is counter-intuitive, IMHO, but it's how cabal does it. Flag names are
52−-- spelled in all lowercase.
50+-- | When a flag is specified multiple times, the last occurrence counts. Flag
51+-- names are spelled all lowercase.
5352--
5453-- >>> normalizeCabalFlags [(mkFlagName "foo", True), (mkFlagName "FOO", True), (mkFlagName "Foo", False)]
55−-- [(FlagName "foo",True)]
54+-- [(FlagName "foo",False)]
5655
5756normalizeCabalFlags :: FlagAssignment -> FlagAssignment
58−normalizeCabalFlags flags' = nubBy ((==) `on` fst) (sortBy (compare `on` fst) flags)
59− where
60− flags = [ (mkFlagName (lowercase (unFlagName n)), b) | (n, b) <- flags' ]
57+normalizeCabalFlags flags =
58+ sortBy (compare `on` fst) $
59+ reverse $
60+ nubBy ((==) `on` fst) $
61+ reverse $
62+ [ (mkFlagName (lowercase (unFlagName n)), b) | (n, b) <- flags ]