{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE OverloadedStrings #-}
-- |
--
-- @since 2.2.0.0
module Distribution.PackageDescription.Quirks (patchQuirks) where

import           Prelude ()
import           Distribution.Compat.Prelude
import           GHC.Fingerprint (Fingerprint (..), fingerprintData)
import           Foreign.Ptr (castPtr)
import           System.IO.Unsafe (unsafeDupablePerformIO)

import qualified Data.ByteString as BS
import qualified Data.ByteString.Unsafe as BS
import qualified Data.Map as Map

-- | Patch legacy @.cabal@ file contents to allow parsec parser to accept
-- all of Hackage.
--
-- Bool part of the result tells whether the output is modified.
--
-- @since 2.2.0.0
patchQuirks :: BS.ByteString -> (Bool, BS.ByteString)
patchQuirks :: ByteString -> (Bool, ByteString)
patchQuirks bs :: ByteString
bs = case (ByteString, Fingerprint)
-> Map
     (ByteString, Fingerprint) (Fingerprint, ByteString -> ByteString)
-> Maybe (Fingerprint, ByteString -> ByteString)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (Int -> ByteString -> ByteString
BS.take 256 ByteString
bs, ByteString -> Fingerprint
md5 ByteString
bs) Map
  (ByteString, Fingerprint) (Fingerprint, ByteString -> ByteString)
patches of
    Nothing -> (Bool
False, ByteString
bs)
    Just (post :: Fingerprint
post, f :: ByteString -> ByteString
f)
        | Fingerprint
post Fingerprint -> Fingerprint -> Bool
forall a. Eq a => a -> a -> Bool
/= ByteString -> Fingerprint
md5 ByteString
output -> (Bool
False, ByteString
bs)
        | Bool
otherwise          -> (Bool
True, ByteString
output)
      where
        output :: ByteString
output = ByteString -> ByteString
f ByteString
bs

md5 :: BS.ByteString -> Fingerprint
md5 :: ByteString -> Fingerprint
md5 bs :: ByteString
bs = IO Fingerprint -> Fingerprint
forall a. IO a -> a
unsafeDupablePerformIO (IO Fingerprint -> Fingerprint) -> IO Fingerprint -> Fingerprint
forall a b. (a -> b) -> a -> b
$ ByteString -> (CStringLen -> IO Fingerprint) -> IO Fingerprint
forall a. ByteString -> (CStringLen -> IO a) -> IO a
BS.unsafeUseAsCStringLen ByteString
bs ((CStringLen -> IO Fingerprint) -> IO Fingerprint)
-> (CStringLen -> IO Fingerprint) -> IO Fingerprint
forall a b. (a -> b) -> a -> b
$ \(ptr :: Ptr CChar
ptr, len :: Int
len) ->
    Ptr Word8 -> Int -> IO Fingerprint
fingerprintData (Ptr CChar -> Ptr Word8
forall a b. Ptr a -> Ptr b
castPtr Ptr CChar
ptr) Int
len

-- | 'patches' contains first 256 bytes, pre- and post-fingerprints and a patch function.
--
--
patches :: Map.Map (BS.ByteString, Fingerprint) (Fingerprint, BS.ByteString -> BS.ByteString)
patches :: Map
  (ByteString, Fingerprint) (Fingerprint, ByteString -> ByteString)
patches = [((ByteString, Fingerprint),
  (Fingerprint, ByteString -> ByteString))]
-> Map
     (ByteString, Fingerprint) (Fingerprint, ByteString -> ByteString)
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
    -- http://hackage.haskell.org/package/unicode-transforms-0.3.3
    -- other-modules: .
    -- ReadP assumed dot is empty line
    [ ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "-- This file has been generated from package.yaml by hpack version 0.17.0.\n--\n-- see: https://github.com/sol/hpack\n\nname:                unicode-transforms\nversion:             0.3.3\nsynopsis:            Unicode normalization\ndescription:         Fast Unic"
         (Word64 -> Word64 -> Fingerprint
Fingerprint 15958160436627155571 10318709190730872881)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 11008465475756725834 13815629925116264363)
         (ByteString -> ByteString -> ByteString
bsRemove "  other-modules:\n      .\n") -- TODO: remove traling \n to test structural-diff
    -- http://hackage.haskell.org/package/DSTM-0.1.2
    -- http://hackage.haskell.org/package/DSTM-0.1.1
    -- http://hackage.haskell.org/package/DSTM-0.1
    -- Other Modules: no dash
    -- ReadP parsed as section
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "Name: DSTM\nVersion: 0.1.2\nCopyright: (c) 2010, Frank Kupke\nLicense: LGPL\nLicense-File: LICENSE\nAuthor: Frank Kupke\nMaintainer: frk@informatik.uni-kiel.de\nCabal-Version: >= 1.2.3\nStability: provisional\nSynopsis: A framework for using STM within distributed "
         (Word64 -> Word64 -> Fingerprint
Fingerprint 6919263071548559054 9050746360708965827)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 17015177514298962556 11943164891661867280)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "Other modules:" "-- ")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "Name: DSTM\nVersion: 0.1.1\nCopyright: (c) 2010, Frank Kupke\nLicense: LGPL\nLicense-File: LICENSE\nAuthor: Frank Kupke\nMaintainer: frk@informatik.uni-kiel.de\nCabal-Version: >= 1.2.3\nStability: provisional\nSynopsis: A framework for using STM within distributed "
         (Word64 -> Word64 -> Fingerprint
Fingerprint 17313105789069667153 9610429408495338584)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 17250946493484671738 17629939328766863497)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "Other modules:" "-- ")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "Name: DSTM\nVersion: 0.1\nCopyright: (c) 2010, Frank Kupke\nLicense: LGPL\nLicense-File: LICENSE\nAuthor: Frank Kupke\nMaintainer: frk@informatik.uni-kiel.de\nCabal-Version: >= 1.2.3\nStability: provisional\nSynopsis: A framework for using STM within distributed sy"
         (Word64 -> Word64 -> Fingerprint
Fingerprint 10502599650530614586 16424112934471063115)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 13562014713536696107 17899511905611879358)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "Other modules:" "-- ")
    -- http://hackage.haskell.org/package/control-monad-exception-mtl-0.10.3
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "name: control-monad-exception-mtl\nversion: 0.10.3\nCabal-Version:  >= 1.10\nbuild-type: Simple\nlicense: PublicDomain\nauthor: Pepe Iborra\nmaintainer: pepeiborra@gmail.com\nhomepage: http://pepeiborra.github.com/control-monad-exception\nsynopsis: MTL instances f"
         (Word64 -> Word64 -> Fingerprint
Fingerprint 18274748422558568404 4043538769550834851)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 11395257416101232635 4303318131190196308)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace " default- extensions:" "unknown-section")
    -- http://hackage.haskell.org/package/vacuum-opengl-0.0
    -- \DEL character
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "Name:                vacuum-opengl\nVersion:             0.0\nSynopsis:            Visualize live Haskell data structures using vacuum, graphviz and OpenGL.\nDescription:         \DELVisualize live Haskell data structures using vacuum, graphviz and OpenGL.\n     "
         (Word64 -> Word64 -> Fingerprint
Fingerprint 5946760521961682577 16933361639326309422)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 14034745101467101555 14024175957788447824)
         (ByteString -> ByteString -> ByteString
bsRemove "\DEL")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "Name:                vacuum-opengl\nVersion:             0.0.1\nSynopsis:            Visualize live Haskell data structures using vacuum, graphviz and OpenGL.\nDescription:         \DELVisualize live Haskell data structures using vacuum, graphviz and OpenGL.\n   "
         (Word64 -> Word64 -> Fingerprint
Fingerprint 10790950110330119503 1309560249972452700)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 1565743557025952928 13645502325715033593)
         (ByteString -> ByteString -> ByteString
bsRemove "\DEL")
    -- http://hackage.haskell.org/package/ixset-1.0.4
    -- {- comments -}
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "Name:                ixset\nVersion:             1.0.4\nSynopsis:            Efficient relational queries on Haskell sets.\nDescription:\n    Create and query sets that are indexed by multiple indices.\nLicense:             BSD3\nLicense-file:        COPYING\nAut"
         (Word64 -> Word64 -> Fingerprint
Fingerprint 11886092342440414185 4150518943472101551)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 5731367240051983879 17473925006273577821)
         (ByteString -> ByteString -> ByteString
bsRemoveStarting "{-")
    -- : after section
    -- http://hackage.haskell.org/package/ds-kanren
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "name:                ds-kanren\nversion:             0.2.0.0\nsynopsis:            A subset of the miniKanren language\ndescription:\n  ds-kanren is an implementation of the <http://minikanren.org miniKanren> language.\n  .\n  == What's in ds-kanren?\n  .\n  ['dis"
         (Word64 -> Word64 -> Fingerprint
Fingerprint 2804006762382336875 9677726932108735838)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 9830506174094917897 12812107316777006473)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "Test-Suite test-unify:" "Test-Suite \"test-unify:\"" (ByteString -> ByteString)
-> (ByteString -> ByteString) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString -> ByteString -> ByteString
bsReplace "Test-Suite test-list-ops:" "Test-Suite \"test-list-ops:\"")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "name:                ds-kanren\nversion:             0.2.0.1\nsynopsis:            A subset of the miniKanren language\ndescription:\n  ds-kanren is an implementation of the <http://minikanren.org miniKanren> language.\n\nlicense:             MIT\nlicense-file:  "
         (Word64 -> Word64 -> Fingerprint
Fingerprint 9130259649220396193 2155671144384738932)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 1847988234352024240 4597789823227580457)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "Test-Suite test-unify:" "Test-Suite \"test-unify:\"" (ByteString -> ByteString)
-> (ByteString -> ByteString) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString -> ByteString -> ByteString
bsReplace "Test-Suite test-list-ops:" "Test-Suite \"test-list-ops:\"")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "name:                metric\nversion:             0.1.4\nsynopsis:            Metric spaces.\nlicense:             MIT\nlicense-file:        LICENSE\nauthor:              Vikram Verma\nmaintainer:          me@vikramverma.com\ncategory:            Data\nbuild-type:"
         (Word64 -> Word64 -> Fingerprint
Fingerprint 6150019278861565482 3066802658031228162)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 9124826020564520548 15629704249829132420)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "test-suite metric-tests:" "test-suite \"metric-tests:\"")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "name:                metric\nversion:             0.2.0\nsynopsis:            Metric spaces.\nlicense:             MIT\nlicense-file:        LICENSE\nauthor:              Vikram Verma\nmaintainer:          me@vikramverma.com\ncategory:            Data\nbuild-type:"
         (Word64 -> Word64 -> Fingerprint
Fingerprint 4639805967994715694 7859317050376284551)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 5566222290622325231 873197212916959151)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "test-suite metric-tests:" "test-suite \"metric-tests:\"")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "name:          phasechange\ncategory:      Data\nversion:       0.1\nauthor:        G\195\161bor Lehel\nmaintainer:    G\195\161bor Lehel <illissius@gmail.com>\nhomepage:      http://github.com/glehel/phasechange\ncopyright:     Copyright (C) 2012 G\195\161bor Lehel\nlicense:     "
         (Word64 -> Word64 -> Fingerprint
Fingerprint 10546509771395401582 245508422312751943)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 5169853482576003304 7247091607933993833)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "impl(ghc >= 7.4):" "erroneous-section" (ByteString -> ByteString)
-> (ByteString -> ByteString) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString -> ByteString -> ByteString
bsReplace "impl(ghc >= 7.6):" "erroneous-section")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "Name:                smartword\nSynopsis:            Web based flash card for Word Smart I and II vocabularies\nVersion:             0.0.0.5\nHomepage:            http://kyagrd.dyndns.org/~kyagrd/project/smartword/\nCategory:            Web,Education\nLicense: "
         (Word64 -> Word64 -> Fingerprint
Fingerprint 7803544783533485151 10807347873998191750)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 1665635316718752601 16212378357991151549)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "build depends:" "--")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "name:           shelltestrunner\n-- sync with README.md, ANNOUNCE:\nversion:        1.3\ncategory:       Testing\nsynopsis:       A tool for testing command-line programs.\ndescription:\n shelltestrunner is a cross-platform tool for testing command-line\n program"
         (Word64 -> Word64 -> Fingerprint
Fingerprint 4403237110790078829 15392625961066653722)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 10218887328390239431 4644205837817510221)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "other modules:" "--")
    -- &&!
    -- http://hackage.haskell.org/package/hblas-0.3.0.0
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "-- Initial hblas.cabal generated by cabal init.  For further \n-- documentation, see http://haskell.org/cabal/users-guide/\n\n-- The name of the package.\nname:                hblas\n\n-- The package version.  See the Haskell package versioning policy (PVP) \n-- "
         (Word64 -> Word64 -> Fingerprint
Fingerprint 8570120150072467041 18315524331351505945)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 10838007242302656005 16026440017674974175)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "&&!" "&& !")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "-- Initial hblas.cabal generated by cabal init.  For further \n-- documentation, see http://haskell.org/cabal/users-guide/\n\n-- The name of the package.\nname:                hblas\n\n-- The package version.  See the Haskell package versioning policy (PVP) \n-- "
         (Word64 -> Word64 -> Fingerprint
Fingerprint 5262875856214215155 10846626274067555320)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 3022954285783401045 13395975869915955260)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "&&!" "&& !")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "-- Initial hblas.cabal generated by cabal init.  For further \n-- documentation, see http://haskell.org/cabal/users-guide/\n\n-- The name of the package.\nname:                hblas\n\n-- The package version.  See the Haskell package versioning policy (PVP) \n-- "
         (Word64 -> Word64 -> Fingerprint
Fingerprint 54222628930951453 5526514916844166577)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 1749630806887010665 8607076506606977549)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "&&!" "&& !")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "-- Initial hblas.cabal generated by cabal init.  For further\n-- documentation, see http://haskell.org/cabal/users-guide/\n\n-- The name of the package.\nname:                hblas\n\n-- The package version.  See the Haskell package versioning policy (PVP)\n-- fo"
         (Word64 -> Word64 -> Fingerprint
Fingerprint 6817250511240350300 15278852712000783849)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 15757717081429529536 15542551865099640223)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "&&!" "&& !")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "-- Initial hblas.cabal generated by cabal init.  For further\n-- documentation, see http://haskell.org/cabal/users-guide/\n\n-- The name of the package.\nname:                hblas\n\n-- The package version.  See the Haskell package versioning policy (PVP)\n-- fo"
         (Word64 -> Word64 -> Fingerprint
Fingerprint 8310050400349211976 201317952074418615)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 10283381191257209624 4231947623042413334)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "&&!" "&& !")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "-- Initial hblas.cabal generated by cabal init.  For further\n-- documentation, see http://haskell.org/cabal/users-guide/\n\n-- The name of the package.\nname:                hblas\n\n-- The package version.  See the Haskell package versioning policy (PVP)\n-- fo"
         (Word64 -> Word64 -> Fingerprint
Fingerprint 7010988292906098371 11591884496857936132)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 6158672440010710301 6419743768695725095)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "&&!" "&& !")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "-- Initial hblas.cabal generated by cabal init.  For further\r\n-- documentation, see http://haskell.org/cabal/users-guide/\r\n\r\n-- The name of the package.\r\nname:                hblas\r\n\r\n-- The package version.  See the Haskell package versioning policy (PVP)"
         (Word64 -> Word64 -> Fingerprint
Fingerprint 2076850805659055833 16615160726215879467)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 10634706281258477722 5285812379517916984)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "&&!" "&& !")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "-- Initial hblas.cabal generated by cabal init.  For further\r\n-- documentation, see http://haskell.org/cabal/users-guide/\r\n\r\n-- The name of the package.\r\nname:                hblas\r\n\r\n-- The package version.  See the Haskell package versioning policy (PVP)"
         (Word64 -> Word64 -> Fingerprint
Fingerprint 11850020631622781099 11956481969231030830)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 13702868780337762025 13383526367149067158)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "&&!" "&& !")
    , ByteString
-> Fingerprint
-> Fingerprint
-> (ByteString -> ByteString)
-> ((ByteString, Fingerprint),
    (Fingerprint, ByteString -> ByteString))
forall a b a b. a -> b -> a -> b -> ((a, b), (a, b))
mk "-- Initial hblas.cabal generated by cabal init.  For further\n-- documentation, see http://haskell.org/cabal/users-guide/\n\n-- The name of the package.\nname:                hblas\n\n-- The package version.  See the Haskell package versioning policy (PVP)\n-- fo"
         (Word64 -> Word64 -> Fingerprint
Fingerprint 13690322768477779172 19704059263540994)
         (Word64 -> Word64 -> Fingerprint
Fingerprint 11189374824645442376 8363528115442591078)
         (ByteString -> ByteString -> ByteString -> ByteString
bsReplace "&&!" "&& !")
    ]
  where
    mk :: a -> b -> a -> b -> ((a, b), (a, b))
mk a :: a
a b :: b
b c :: a
c d :: b
d = ((a
a, b
b), (a
c, b
d))

-- | Helper to create entries in patches
_makePatchKey :: FilePath -> (BS.ByteString -> BS.ByteString) -> NoCallStackIO ()
_makePatchKey :: FilePath -> (ByteString -> ByteString) -> NoCallStackIO ()
_makePatchKey fp :: FilePath
fp transform :: ByteString -> ByteString
transform = do
    ByteString
contents <- FilePath -> IO ByteString
BS.readFile FilePath
fp
    let output :: ByteString
output = ByteString -> ByteString
transform ByteString
contents
    let Fingerprint hi :: Word64
hi lo :: Word64
lo = ByteString -> Fingerprint
md5 ByteString
contents
    let Fingerprint hi' :: Word64
hi' lo' :: Word64
lo' = ByteString -> Fingerprint
md5 ByteString
output
    FilePath -> NoCallStackIO ()
putStrLn
        (FilePath -> NoCallStackIO ()) -> FilePath -> NoCallStackIO ()
forall a b. (a -> b) -> a -> b
$ FilePath -> ShowS
showString "    , mk "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ShowS
forall a. Show a => a -> ShowS
shows (Int -> ByteString -> ByteString
BS.take 256 ByteString
contents)
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> ShowS
showString "\n         (Fingerprint "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> ShowS
forall a. Show a => a -> ShowS
shows Word64
hi
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> ShowS
showString " "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> ShowS
forall a. Show a => a -> ShowS
shows Word64
lo
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> ShowS
showString ")\n         (Fingerprint "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> ShowS
forall a. Show a => a -> ShowS
shows Word64
hi'
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> ShowS
showString " "
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> ShowS
forall a. Show a => a -> ShowS
shows Word64
lo'
        ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> ShowS
showString ")"
        ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ ""

-------------------------------------------------------------------------------
-- Patch helpers
-------------------------------------------------------------------------------

bsRemove
    :: BS.ByteString  -- ^ needle
    -> BS.ByteString -> BS.ByteString
bsRemove :: ByteString -> ByteString -> ByteString
bsRemove needle :: ByteString
needle haystack :: ByteString
haystack = case ByteString -> ByteString -> (ByteString, ByteString)
BS.breakSubstring ByteString
needle ByteString
haystack of
    (h :: ByteString
h, t :: ByteString
t) -> ByteString -> ByteString -> ByteString
BS.append ByteString
h (Int -> ByteString -> ByteString
BS.drop (ByteString -> Int
BS.length ByteString
needle) ByteString
t)

bsReplace
    :: BS.ByteString -- ^ needle
    -> BS.ByteString -- ^ replacement
    -> BS.ByteString -> BS.ByteString
bsReplace :: ByteString -> ByteString -> ByteString -> ByteString
bsReplace needle :: ByteString
needle repl :: ByteString
repl haystack :: ByteString
haystack = case ByteString -> ByteString -> (ByteString, ByteString)
BS.breakSubstring ByteString
needle ByteString
haystack of
    (h :: ByteString
h, t :: ByteString
t)
        | Bool -> Bool
not (ByteString -> Bool
BS.null ByteString
t) -> ByteString -> ByteString -> ByteString
BS.append ByteString
h (ByteString -> ByteString -> ByteString
BS.append ByteString
repl (Int -> ByteString -> ByteString
BS.drop (ByteString -> Int
BS.length ByteString
needle) ByteString
t))
        | Bool
otherwise -> ByteString
haystack

bsRemoveStarting
    :: BS.ByteString  -- ^ needle
    -> BS.ByteString -> BS.ByteString
bsRemoveStarting :: ByteString -> ByteString -> ByteString
bsRemoveStarting needle :: ByteString
needle haystack :: ByteString
haystack = case ByteString -> ByteString -> (ByteString, ByteString)
BS.breakSubstring ByteString
needle ByteString
haystack of
    (h :: ByteString
h, _) -> ByteString
h