SrcDist.hs 19.8 KB
Newer Older
1 2 3 4
-----------------------------------------------------------------------------
-- |
-- Module      :  Distribution.Simple.SrcDist
-- Copyright   :  Simon Marlow 2004
5
-- License     :  BSD3
6
--
Duncan Coutts's avatar
Duncan Coutts committed
7
-- Maintainer  :  cabal-devel@haskell.org
ijones's avatar
ijones committed
8
-- Portability :  portable
9
--
Duncan Coutts's avatar
Duncan Coutts committed
10 11 12 13 14 15 16 17 18
-- This handles the @sdist@ command. The module exports an 'sdist' action but
-- also some of the phases that make it up so that other tools can use just the
-- bits they need. In particular the preparation of the tree of files to go
-- into the source tarball is separated from actually building the source
-- tarball.
--
-- The 'createArchive' action uses the external @tar@ program and assumes that
-- it accepts the @-z@ flag. Neither of these assumptions are valid on Windows.
-- The 'sdist' action now also does some distribution QA checks.
19

20 21 22
-- NOTE: FIX: we don't have a great way of testing this module, since
-- we can't easily look inside a tarball once its created.

23
module Distribution.Simple.SrcDist (
Duncan Coutts's avatar
Duncan Coutts committed
24 25 26 27 28 29 30 31
  -- * The top level action
  sdist,

  -- ** Parts of 'sdist'
  printPackageProblems,
  prepareTree,
  createArchive,

Ian D. Bollinger's avatar
Ian D. Bollinger committed
32
  -- ** Snapshots
Duncan Coutts's avatar
Duncan Coutts committed
33
  prepareSnapshotTree,
34
  snapshotPackage,
Duncan Coutts's avatar
Duncan Coutts committed
35 36
  snapshotVersion,
  dateToSnapshotNumber,
37

refold's avatar
refold committed
38
  -- * Extracting the source files
refold's avatar
refold committed
39 40
  listPackageSources

41 42
  )  where

simonmar's avatar
simonmar committed
43
import Distribution.PackageDescription
44
         ( PackageDescription(..), BuildInfo(..), Executable(..), Library(..)
45 46
         , TestSuite(..), TestSuiteInterface(..), Benchmark(..)
         , BenchmarkInterface(..) )
47
import Distribution.PackageDescription.Check
48
         ( PackageCheck(..), checkConfiguredPackage, checkPackageFiles )
49
import Distribution.Package
50
         ( PackageIdentifier(pkgVersion), Package(..), packageVersion )
51 52
import Distribution.ModuleName (ModuleName)
import qualified Distribution.ModuleName as ModuleName
Duncan Coutts's avatar
Duncan Coutts committed
53
import Distribution.Version
54
         ( Version(versionBranch) )
55
import Distribution.Simple.Utils
56
         ( createDirectoryIfMissingVerbose, withUTF8FileContents, writeUTF8File
refold's avatar
refold committed
57
         , installOrdinaryFiles, installMaybeExecutableFiles
58
         , findFile, findFileWithExtension, matchFileGlob
59
         , withTempDirectory, defaultPackageDesc
60
         , die, warn, notice, info, setupMessage )
61 62
import Distribution.Simple.Setup ( Flag(..), SDistFlags(..)
                                 , fromFlag, flagToMaybe)
refold's avatar
refold committed
63 64
import Distribution.Simple.PreProcess ( PPSuffixHandler, ppSuffixes
                                      , preprocessComponent )
65 66
import Distribution.Simple.LocalBuildInfo
         ( LocalBuildInfo(..), withAllComponentsInBuildOrder )
67
import Distribution.Simple.BuildPaths ( autogenModuleName )
68
import Distribution.Simple.Program ( defaultProgramConfiguration, requireProgram,
69
                                     runProgram, programProperties, tarProgram )
70 71
import Distribution.Text
         ( display )
72

refold's avatar
refold committed
73
import Control.Monad(when, unless, forM)
Duncan Coutts's avatar
Duncan Coutts committed
74
import Data.Char (toLower)
75
import Data.List (partition, isPrefixOf)
76
import qualified Data.Map as Map
Duncan Coutts's avatar
Duncan Coutts committed
77
import Data.Maybe (isNothing, catMaybes)
78
import Data.Time (UTCTime, getCurrentTime, toGregorian, utctDay)
refold's avatar
refold committed
79
import System.Directory ( doesFileExist )
80
import System.IO (IOMode(WriteMode), hPutStrLn, withFile)
81
import Distribution.Verbosity (Verbosity)
Duncan Coutts's avatar
Duncan Coutts committed
82
import System.FilePath
refold's avatar
refold committed
83
         ( (</>), (<.>), dropExtension, isAbsolute )
84

85
-- |Create a source distribution.
86 87 88
sdist :: PackageDescription     -- ^information from the tarball
      -> Maybe LocalBuildInfo   -- ^Information from configure
      -> SDistFlags             -- ^verbosity & snapshot
89
      -> (FilePath -> FilePath) -- ^build prefix (temp dir)
90
      -> [PPSuffixHandler]      -- ^ extra preprocessors (includes suffixes)
91
      -> IO ()
92
sdist pkg mb_lbi flags mkTmpDir pps =
Duncan Coutts's avatar
Duncan Coutts committed
93

94 95 96 97 98 99
  -- When given --list-sources, just output the list of sources to a file.
  case (sDistListSources flags) of
    Flag path -> withFile path WriteMode $ \outHandle -> do
      (ordinary, maybeExecutable) <- listPackageSources verbosity pkg pps
      mapM_ (hPutStrLn outHandle) ordinary
      mapM_ (hPutStrLn outHandle) maybeExecutable
100 101
      notice verbosity $ "List of package sources written to file '"
                         ++ path ++ "'"
102 103 104 105 106 107 108 109 110 111 112 113 114 115
    NoFlag    -> do
      -- do some QA
      printPackageProblems verbosity pkg

      when (isNothing mb_lbi) $
        warn verbosity "Cannot run preprocessors. Run 'configure' command first."

      date <- getCurrentTime
      let pkg' | snapshot  = snapshotPackage date pkg
               | otherwise = pkg

      case flagToMaybe (sDistDirectory flags) of
        Just targetDir -> do
          generateSourceDir targetDir pkg'
116
          info verbosity $ "Source directory created: " ++ targetDir
117 118 119

        Nothing -> do
          createDirectoryIfMissingVerbose verbosity True tmpTargetDir
120
          withTempDirectory verbosity tmpTargetDir "sdist." $ \tmpDir -> do
121 122
            let targetDir = tmpDir </> tarBallName pkg'
            generateSourceDir targetDir pkg'
123
            targzFile <- createArchive verbosity pkg' mb_lbi tmpDir targetPref
124
            notice verbosity $ "Source tarball created: " ++ targzFile
Duncan Coutts's avatar
Duncan Coutts committed
125

126
  where
127 128 129
    generateSourceDir targetDir pkg' = do

      setupMessage verbosity "Building source dist for" (packageId pkg')
refold's avatar
refold committed
130
      prepareTree verbosity pkg' mb_lbi targetDir pps
131 132 133
      when snapshot $
        overwriteSnapshotPackageDesc verbosity pkg' targetDir

134
    verbosity = fromFlag (sDistVerbosity flags)
Duncan Coutts's avatar
Duncan Coutts committed
135
    snapshot  = fromFlag (sDistSnapshot flags)
136

137 138 139 140
    distPref     = fromFlag $ sDistDistPref flags
    targetPref   = distPref
    tmpTargetDir = mkTmpDir distPref

refold's avatar
refold committed
141 142 143 144 145 146 147 148
-- | List all source files of a package. Returns a tuple of lists: first
-- component is a list of ordinary files, second one is a list of those files
-- that may be executable.
listPackageSources :: Verbosity          -- ^ verbosity
                   -> PackageDescription -- ^ info from the cabal file
                   -> [PPSuffixHandler]  -- ^ extra preprocessors (include
                                         -- suffixes)
                   -> IO ([FilePath], [FilePath])
149
listPackageSources verbosity pkg_descr0 pps = do
refold's avatar
refold committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
  -- Call helpers that actually do all work.
  ordinary        <- listPackageSourcesOrdinary        verbosity pkg_descr pps
  maybeExecutable <- listPackageSourcesMaybeExecutable pkg_descr
  return (ordinary, maybeExecutable)
  where
    pkg_descr = filterAutogenModule pkg_descr0

-- | List those source files that may be executable (e.g. the configure script).
listPackageSourcesMaybeExecutable :: PackageDescription -> IO [FilePath]
listPackageSourcesMaybeExecutable pkg_descr =
  -- Extra source files.
  fmap concat . forM (extraSrcFiles pkg_descr) $ \fpath -> matchFileGlob fpath

-- | List those source files that should be copied with ordinary permissions.
listPackageSourcesOrdinary :: Verbosity
                           -> PackageDescription
                           -> [PPSuffixHandler]
                           -> IO [FilePath]
168
listPackageSourcesOrdinary verbosity pkg_descr pps =
refold's avatar
refold committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
  fmap concat . sequence $
  [
    -- Library sources.
    withLib $ \Library { exposedModules = modules, libBuildInfo = libBi } ->
     allSourcesBuildInfo libBi pps modules

    -- Executables sources.
  , fmap concat
    . withExe $ \Executable { modulePath = mainPath, buildInfo = exeBi } -> do
       biSrcs  <- allSourcesBuildInfo exeBi pps []
       mainSrc <- findMainExeFile exeBi pps mainPath
       return (mainSrc:biSrcs)

    -- Test suites sources.
  , fmap concat
    . withTest $ \t -> do
       let bi  = testBuildInfo t
       case testInterface t of
         TestSuiteExeV10 _ mainPath -> do
           biSrcs <- allSourcesBuildInfo bi pps []
           srcMainFile <- do
             ppFile <- findFileWithExtension (ppSuffixes pps)
                       (hsSourceDirs bi) (dropExtension mainPath)
             case ppFile of
               Nothing -> findFile (hsSourceDirs bi) mainPath
               Just pp -> return pp
           return (srcMainFile:biSrcs)
         TestSuiteLibV09 _ m ->
           allSourcesBuildInfo bi pps [m]
         TestSuiteUnsupported tp -> die $ "Unsupported test suite type: "
                                   ++ show tp

    -- Benchmarks sources.
  , fmap concat
    . withBenchmark $ \bm -> do
       let  bi = benchmarkBuildInfo bm
       case benchmarkInterface bm of
         BenchmarkExeV10 _ mainPath -> do
           biSrcs <- allSourcesBuildInfo bi pps []
           srcMainFile <- do
             ppFile <- findFileWithExtension (ppSuffixes pps)
                       (hsSourceDirs bi) (dropExtension mainPath)
             case ppFile of
               Nothing -> findFile (hsSourceDirs bi) mainPath
               Just pp -> return pp
           return (srcMainFile:biSrcs)
         BenchmarkUnsupported tp -> die $ "Unsupported benchmark type: "
                                    ++ show tp

    -- Data files.
  , fmap concat
    . forM (dataFiles pkg_descr) $ \filename ->
       matchFileGlob (dataDir pkg_descr </> filename)

223 224 225 226 227
    -- Extra doc files.
  , fmap concat
    . forM (extraDocFiles pkg_descr) $ \ filename ->
      matchFileGlob filename

Duncan Coutts's avatar
Duncan Coutts committed
228 229
    -- License file(s).
  , return (licenseFiles pkg_descr)
230

refold's avatar
refold committed
231 232 233 234 235 236
    -- Install-include files.
  , withLib $ \ l -> do
       let lbi = libBuildInfo l
           relincdirs = "." : filter (not.isAbsolute) (includeDirs lbi)
       mapM (fmap snd . findIncludeFile relincdirs) (installIncludes lbi)

237 238
    -- Setup script, if it exists.
  , fmap (maybe [] (\f -> [f])) $ findSetupFile ""
refold's avatar
refold committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252

    -- The .cabal file itself.
  , fmap (\d -> [d]) (defaultPackageDesc verbosity)

  ]
  where
    -- We have to deal with all libs and executables, so we have local
    -- versions of these functions that ignore the 'buildable' attribute:
    withLib       action = maybe (return []) action (library pkg_descr)
    withExe       action = mapM action (executables pkg_descr)
    withTest      action = mapM action (testSuites pkg_descr)
    withBenchmark action = mapM action (benchmarks pkg_descr)


253
-- |Prepare a directory tree of source files.
Duncan Coutts's avatar
Duncan Coutts committed
254 255
prepareTree :: Verbosity          -- ^verbosity
            -> PackageDescription -- ^info from the cabal file
256
            -> Maybe LocalBuildInfo
257
            -> FilePath           -- ^source tree to populate
258
            -> [PPSuffixHandler]  -- ^extra preprocessors (includes suffixes)
259
            -> IO ()
refold's avatar
refold committed
260
prepareTree verbosity pkg_descr0 mb_lbi targetDir pps = do
Mikhail Glushenkov's avatar
Mikhail Glushenkov committed
261
  -- If the package was configured then we can run platform-independent
refold's avatar
refold committed
262
  -- pre-processors and include those generated files.
Duncan Coutts's avatar
Duncan Coutts committed
263
  case mb_lbi of
264
    Just lbi | not (null pps) -> do
265
      let lbi' = lbi{ buildDir = targetDir </> buildDir lbi }
266
      withAllComponentsInBuildOrder pkg_descr lbi' $ \c _ ->
267
        preprocessComponent pkg_descr c lbi' True verbosity pps
Duncan Coutts's avatar
Duncan Coutts committed
268
    _ -> return ()
269

refold's avatar
refold committed
270 271 272
  (ordinary, mExecutable)  <- listPackageSources verbosity pkg_descr0 pps
  installOrdinaryFiles        verbosity targetDir (zip (repeat []) ordinary)
  installMaybeExecutableFiles verbosity targetDir (zip (repeat []) mExecutable)
273
  maybeCreateDefaultSetupScript targetDir
274

275
  where
refold's avatar
refold committed
276 277 278
    pkg_descr = filterAutogenModule pkg_descr0

-- | Find the setup script file, if it exists.
279 280 281
findSetupFile :: FilePath -> IO (Maybe FilePath)
findSetupFile targetDir = do
  hsExists  <- doesFileExist setupHs
refold's avatar
refold committed
282 283 284 285 286 287 288
  lhsExists <- doesFileExist setupLhs
  if hsExists
    then return (Just setupHs)
    else if lhsExists
         then return (Just setupLhs)
         else return Nothing
    where
289 290 291 292 293 294 295 296 297 298 299 300 301
      setupHs  = targetDir </> "Setup.hs"
      setupLhs = targetDir </> "Setup.lhs"

-- | Create a default setup script in the target directory, if it doesn't exist.
maybeCreateDefaultSetupScript :: FilePath -> IO ()
maybeCreateDefaultSetupScript targetDir = do
  mSetupFile <- findSetupFile targetDir
  case mSetupFile of
    Just _setupFile -> return ()
    Nothing         -> do
      writeUTF8File (targetDir </> "Setup.hs") $ unlines [
        "import Distribution.Simple",
        "main = defaultMain"]
refold's avatar
refold committed
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327

-- | Find the main executable file.
findMainExeFile :: BuildInfo -> [PPSuffixHandler] -> FilePath -> IO FilePath
findMainExeFile exeBi pps mainPath = do
  ppFile <- findFileWithExtension (ppSuffixes pps) (hsSourceDirs exeBi)
            (dropExtension mainPath)
  case ppFile of
    Nothing -> findFile (hsSourceDirs exeBi) mainPath
    Just pp -> return pp

-- | Given a list of include paths, try to find the include file named
-- @f@. Return the name of the file and the full path, or exit with error if
-- there's no such file.
findIncludeFile :: [FilePath] -> String -> IO (String, FilePath)
findIncludeFile [] f = die ("can't find include file " ++ f)
findIncludeFile (d:ds) f = do
  let path = (d </> f)
  b <- doesFileExist path
  if b then return (f,path) else findIncludeFile ds f

-- | Remove the auto-generated module ('Paths_*') from 'exposed-modules' and
-- 'other-modules'.
filterAutogenModule :: PackageDescription -> PackageDescription
filterAutogenModule pkg_descr0 = mapLib filterAutogenModuleLib $
                                 mapAllBuildInfo filterAutogenModuleBI pkg_descr0
  where
328 329 330 331 332 333
    mapLib f pkg = pkg { library = fmap f (library pkg) }
    filterAutogenModuleLib lib = lib {
      exposedModules = filter (/=autogenModule) (exposedModules lib)
    }
    filterAutogenModuleBI bi = bi {
      otherModules   = filter (/=autogenModule) (otherModules bi)
334 335 336
    }
    autogenModule = autogenModuleName pkg_descr0

337 338 339
-- | Prepare a directory tree of source files for a snapshot version.
-- It is expected that the appropriate snapshot version has already been set
-- in the package description, eg using 'snapshotPackage' or 'snapshotVersion'.
Duncan Coutts's avatar
Duncan Coutts committed
340 341 342 343 344
--
prepareSnapshotTree :: Verbosity          -- ^verbosity
                    -> PackageDescription -- ^info from the cabal file
                    -> Maybe LocalBuildInfo
                    -> FilePath           -- ^source tree to populate
refold's avatar
refold committed
345 346
                    -> [PPSuffixHandler]  -- ^extra preprocessors (includes
                                          -- suffixes)
347
                    -> IO ()
refold's avatar
refold committed
348 349
prepareSnapshotTree verbosity pkg mb_lbi targetDir pps = do
  prepareTree verbosity pkg mb_lbi targetDir pps
350
  overwriteSnapshotPackageDesc verbosity pkg targetDir
351

352 353 354 355 356 357 358 359 360 361 362
overwriteSnapshotPackageDesc :: Verbosity          -- ^verbosity
                             -> PackageDescription -- ^info from the cabal file
                             -> FilePath           -- ^source tree
                             -> IO ()
overwriteSnapshotPackageDesc verbosity pkg targetDir = do
    -- We could just writePackageDescription targetDescFile pkg_descr,
    -- but that would lose comments and formatting.
    descFile <- defaultPackageDesc verbosity
    withUTF8FileContents descFile $
      writeUTF8File (targetDir </> descFile)
        . unlines . map (replaceVersion (packageVersion pkg)) . lines
Duncan Coutts's avatar
Duncan Coutts committed
363

364
  where
Duncan Coutts's avatar
Duncan Coutts committed
365 366 367
    replaceVersion :: Version -> String -> String
    replaceVersion version line
      | "version:" `isPrefixOf` map toLower line
368
                  = "version: " ++ display version
Duncan Coutts's avatar
Duncan Coutts committed
369 370
      | otherwise = line

371 372 373
-- | Modifies a 'PackageDescription' by appending a snapshot number
-- corresponding to the given date.
--
374
snapshotPackage :: UTCTime -> PackageDescription -> PackageDescription
375 376 377 378 379 380
snapshotPackage date pkg =
  pkg {
    package = pkgid { pkgVersion = snapshotVersion date (pkgVersion pkgid) }
  }
  where pkgid = packageId pkg

Duncan Coutts's avatar
Duncan Coutts committed
381 382 383
-- | Modifies a 'Version' by appending a snapshot number corresponding
-- to the given date.
--
384
snapshotVersion :: UTCTime -> Version -> Version
Duncan Coutts's avatar
Duncan Coutts committed
385 386 387 388 389 390 391 392
snapshotVersion date version = version {
    versionBranch = versionBranch version
                 ++ [dateToSnapshotNumber date]
  }

-- | Given a date produce a corresponding integer representation.
-- For example given a date @18/03/2008@ produce the number @20080318@.
--
393 394 395 396 397 398
dateToSnapshotNumber :: UTCTime -> Int
dateToSnapshotNumber date = case toGregorian (utctDay date) of
                            (year, month, day) ->
                                fromIntegral year * 10000
                              + month             * 100
                              + day
Duncan Coutts's avatar
Duncan Coutts committed
399

400 401 402 403 404 405 406
-- | Callback type for use by sdistWith.
type CreateArchiveFun = Verbosity               -- ^verbosity
                        -> PackageDescription   -- ^info from cabal file
                        -> Maybe LocalBuildInfo -- ^info from configure
                        -> FilePath             -- ^source tree to archive
                        -> FilePath             -- ^name of archive to create
                        -> IO FilePath
407

408 409
-- | Create an archive from a tree of source files, and clean up the tree.
createArchive :: CreateArchiveFun
Duncan Coutts's avatar
Duncan Coutts committed
410 411
createArchive verbosity pkg_descr mb_lbi tmpDir targetPref = do
  let tarBallFilePath = targetPref </> tarBallName pkg_descr <.> "tar.gz"
412

413
  (tarProg, _) <- requireProgram verbosity tarProgram
414
                    (maybe defaultProgramConfiguration withPrograms mb_lbi)
415 416 417
  let formatOptSupported = maybe False (== "YES") $
                           Map.lookup "Supports --format"
                           (programProperties tarProg)
418
  runProgram verbosity tarProg $
419 420 421 422
    -- Hmm: I could well be skating on thinner ice here by using the -C option
    -- (=> seems to be supported at least by GNU and *BSD tar) [The
    -- prev. solution used pipes and sub-command sequences to set up the paths
    -- correctly, which is problematic in a Windows setting.]
423 424 425
    ["-czf", tarBallFilePath, "-C", tmpDir]
    ++ (if formatOptSupported then ["--format", "ustar"] else [])
    ++ [tarBallName pkg_descr]
426
  return tarBallFilePath
ijones's avatar
ijones committed
427

refold's avatar
refold committed
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
-- | Given a buildinfo, return the names of all source files.
allSourcesBuildInfo :: BuildInfo
                       -> [PPSuffixHandler] -- ^ Extra preprocessors
                       -> [ModuleName]      -- ^ Exposed modules
                       -> IO [FilePath]
allSourcesBuildInfo bi pps modules = do
  let searchDirs = hsSourceDirs bi
  sources <- sequence
    [ let file = ModuleName.toFilePath module_
      in findFileWithExtension suffixes searchDirs file
         >>= maybe (notFound module_) return
    | module_ <- modules ++ otherModules bi ]
  bootFiles <- sequence
    [ let file = ModuleName.toFilePath module_
          fileExts = ["hs-boot", "lhs-boot"]
      in findFileWithExtension fileExts (hsSourceDirs bi) file
    | module_ <- modules ++ otherModules bi ]

446
  return $ sources ++ catMaybes bootFiles ++ cSources bi ++ jsSources bi
refold's avatar
refold committed
447 448 449 450 451 452

  where
    suffixes = ppSuffixes pps ++ ["hs", "lhs"]
    notFound m = die $ "Error: Could not find module: " ++ display m
                 ++ " with any suffix: " ++ show suffixes

453

454 455 456
printPackageProblems :: Verbosity -> PackageDescription -> IO ()
printPackageProblems verbosity pkg_descr = do
  ioChecks      <- checkPackageFiles pkg_descr "."
457
  let pureChecks = checkConfiguredPackage pkg_descr
458 459 460
      isDistError (PackageDistSuspicious     _) = False
      isDistError (PackageDistSuspiciousWarn _) = False
      isDistError _                             = True
461 462 463 464 465 466
      (errors, warnings) = partition isDistError (pureChecks ++ ioChecks)
  unless (null errors) $
      notice verbosity $ "Distribution quality errors:\n"
                      ++ unlines (map explanation errors)
  unless (null warnings) $
      notice verbosity $ "Distribution quality warnings:\n"
467
                      ++ unlines (map explanation warnings)
468 469
  unless (null errors) $
      notice verbosity
470
        "Note: the public hackage server would reject this package."
471

ijones's avatar
ijones committed
472 473
------------------------------------------------------------

Duncan Coutts's avatar
Duncan Coutts committed
474 475 476
-- | The name of the tarball without extension
--
tarBallName :: PackageDescription -> String
477
tarBallName = display . packageId
478 479 480 481 482

mapAllBuildInfo :: (BuildInfo -> BuildInfo)
                -> (PackageDescription -> PackageDescription)
mapAllBuildInfo f pkg = pkg {
    library     = fmap mapLibBi (library pkg),
483
    executables = fmap mapExeBi (executables pkg),
484 485
    testSuites  = fmap mapTestBi (testSuites pkg),
    benchmarks  = fmap mapBenchBi (benchmarks pkg)
486 487
  }
  where
488 489 490 491
    mapLibBi lib  = lib { libBuildInfo       = f (libBuildInfo lib) }
    mapExeBi exe  = exe { buildInfo          = f (buildInfo exe) }
    mapTestBi t   = t   { testBuildInfo      = f (testBuildInfo t) }
    mapBenchBi bm = bm  { benchmarkBuildInfo = f (benchmarkBuildInfo bm) }