Install.hs 54.4 KB
Newer Older
1
2
-----------------------------------------------------------------------------
-- |
3
-- Module      :  Distribution.Client.Install
4
5
6
-- Copyright   :  (c) 2005 David Himmelstrup
--                    2007 Bjorn Bringert
--                    2007-2010 Duncan Coutts
7
8
-- License     :  BSD-like
--
9
-- Maintainer  :  cabal-devel@haskell.org
10
11
12
13
14
-- Stability   :  provisional
-- Portability :  portable
--
-- High level interface to package installation.
-----------------------------------------------------------------------------
15
module Distribution.Client.Install (
16
17
18
19
20
21
22
23
24
25
26
27
    -- * High-level interface
    install,

    -- * Lower-level interface that allows to manipulate the install plan
    makeInstallContext,
    makeInstallPlan,
    processInstallPlan,
    InstallArgs,
    InstallContext,

    -- * Prune certain packages from the install plan
    pruneInstallPlan
28
  ) where
29

30
import Data.List
31
         ( unfoldr, nub, sort, (\\) )
32
import qualified Data.Set as S
Duncan Coutts's avatar
Duncan Coutts committed
33
import Data.Maybe
34
         ( isJust, fromMaybe, maybeToList )
35
import Control.Exception as Exception
36
37
         ( Exception(toException), bracket, catches, Handler(Handler), handleJust
         , IOException, SomeException )
Duncan Coutts's avatar
Duncan Coutts committed
38
39
import System.Exit
         ( ExitCode )
40
import Distribution.Compat.Exception
41
         ( catchIO, catchExit )
42
import Control.Monad
43
         ( when, unless )
44
import System.Directory
Duncan Coutts's avatar
Duncan Coutts committed
45
         ( getTemporaryDirectory, doesFileExist, createDirectoryIfMissing )
Duncan Coutts's avatar
Duncan Coutts committed
46
import System.FilePath
Duncan Coutts's avatar
Duncan Coutts committed
47
         ( (</>), (<.>), takeDirectory )
Duncan Coutts's avatar
Duncan Coutts committed
48
import System.IO
49
         ( openFile, IOMode(WriteMode), hClose )
50
51
import System.IO.Error
         ( isDoesNotExistError, ioeGetFileName )
bjorn@bringert.net's avatar
bjorn@bringert.net committed
52

53
import Distribution.Client.Targets
54
import Distribution.Client.Dependency
55
56
import Distribution.Client.Dependency.Types
         ( Solver(..) )
Duncan Coutts's avatar
Duncan Coutts committed
57
import Distribution.Client.FetchUtils
58
import qualified Distribution.Client.Haddock as Haddock (regenerateHaddockIndex)
59
import Distribution.Client.IndexUtils as IndexUtils
60
         ( getSourcePackages, getInstalledPackages )
61
62
63
import qualified Distribution.Client.InstallPlan as InstallPlan
import Distribution.Client.InstallPlan (InstallPlan)
import Distribution.Client.Setup
64
65
         ( GlobalFlags(..)
         , ConfigFlags(..), configureCommand, filterConfigureFlags
66
         , ConfigExFlags(..), InstallFlags(..) )
Duncan Coutts's avatar
Duncan Coutts committed
67
import Distribution.Client.Config
68
         ( defaultCabalDir, defaultUserInstall )
69
70
71
import Distribution.Client.Sandbox.Timestamp
         ( withUpdateTimestamps )
import Distribution.Client.Sandbox.Types
72
73
         ( SandboxPackageInfo(..), UseSandbox(..), isUseSandbox
         , whenUsingSandbox )
74
import Distribution.Client.Tar (extractTarGzFile)
75
import Distribution.Client.Types as Source
76
77
import Distribution.Client.BuildReports.Types
         ( ReportLevel(..) )
78
import Distribution.Client.SetupWrapper
Duncan Coutts's avatar
Duncan Coutts committed
79
         ( setupWrapper, SetupScriptOptions(..), defaultSetupScriptOptions )
David Himmelstrup's avatar
David Himmelstrup committed
80
import qualified Distribution.Client.BuildReports.Anonymous as BuildReports
Duncan Coutts's avatar
Duncan Coutts committed
81
82
import qualified Distribution.Client.BuildReports.Storage as BuildReports
         ( storeAnonymous, storeLocal, fromInstallPlan )
83
import qualified Distribution.Client.InstallSymlink as InstallSymlink
84
         ( symlinkBinaries )
85
import qualified Distribution.Client.PackageIndex as SourcePackageIndex
86
import qualified Distribution.Client.Win32SelfUpgrade as Win32SelfUpgrade
87
import qualified Distribution.Client.World as World
88
import qualified Distribution.InstalledPackageInfo as Installed
89
import Paths_cabal_install (getBinDir)
90
import Distribution.Client.JobControl
91

92
import Distribution.Simple.Compiler
93
         ( CompilerId(..), Compiler(compilerId), compilerFlavor
94
         , PackageDB(..), PackageDBStack )
refold's avatar
refold committed
95
96
import Distribution.Simple.Program (ProgramConfiguration,
                                    defaultProgramConfiguration)
97
import qualified Distribution.Simple.InstallDirs as InstallDirs
98
99
import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.Simple.PackageIndex (PackageIndex)
100
import Distribution.Simple.Setup
101
         ( haddockCommand, HaddockFlags(..)
102
103
104
         , buildCommand, BuildFlags(..), emptyBuildFlags
         , toFlag, fromFlag, fromFlagOrDefault, flagToMaybe )
import qualified Distribution.Simple.Setup as Cabal
105
         ( installCommand, InstallFlags(..), TestFlags(..), emptyInstallFlags
106
         , emptyTestFlags, testCommand, Flag(..) )
107
import Distribution.Simple.Utils
108
         ( rawSystemExit, comparing, writeFileAtomic )
109
110
import Distribution.Simple.InstallDirs as InstallDirs
         ( PathTemplate, fromPathTemplate, toPathTemplate, substPathTemplate
111
         , initialPathTemplateEnv, installDirsTemplateEnv )
112
import Distribution.Package
113
         ( PackageIdentifier, PackageId, packageName, packageVersion
114
         , Package(..), PackageFixedDeps(..)
115
         , Dependency(..), thisPackageVersion, InstalledPackageId )
116
117
import qualified Distribution.PackageDescription as PackageDescription
import Distribution.PackageDescription
118
119
         ( PackageDescription, GenericPackageDescription(..), Flag(..)
         , FlagName(..), FlagAssignment )
120
import Distribution.PackageDescription.Configuration
121
         ( finalizePackageDescription )
122
import Distribution.Version
123
         ( Version, anyVersion, thisVersion )
124
import Distribution.Simple.Utils as Utils
125
         ( notice, info, warn, debugNoWrap, die, intercalate, withTempDirectory )
126
import Distribution.Client.Utils
127
128
         ( numberOfProcessors, inDir, mergeBy, MergeResult(..)
         , tryCanonicalizePath )
129
import Distribution.System
130
         ( Platform, OS(Windows), buildOS )
131
132
import Distribution.Text
         ( display )
Duncan Coutts's avatar
Duncan Coutts committed
133
import Distribution.Verbosity as Verbosity
134
         ( Verbosity, showForCabal, normal, verbose )
135
import Distribution.Simple.BuildPaths ( exeExtension )
bjorn@bringert.net's avatar
bjorn@bringert.net committed
136

137
138
139
140
141
142
143
144
145
146
147
--TODO:
-- * assign flags to packages individually
--   * complain about flags that do not apply to any package given as target
--     so flags do not apply to dependencies, only listed, can use flag
--     constraints for dependencies
--   * only record applicable flags in world file
-- * allow flag constraints
-- * allow installed constraints
-- * allow flag and installed preferences
-- * change world file to use cabal section syntax
--   * allow persistent configure flags for each package individually
148

149
150
151
152
153
154
-- ------------------------------------------------------------
-- * Top level user actions
-- ------------------------------------------------------------

-- | Installs the packages needed to satisfy a list of dependencies.
--
155
install
156
  :: Verbosity
157
  -> PackageDBStack
158
159
  -> [Repo]
  -> Compiler
160
  -> Platform
161
  -> ProgramConfiguration
162
  -> UseSandbox
163
  -> Maybe SandboxPackageInfo
164
  -> GlobalFlags
165
  -> ConfigFlags
166
  -> ConfigExFlags
167
  -> InstallFlags
168
  -> HaddockFlags
169
  -> [UserTarget]
170
  -> IO ()
171
install verbosity packageDBs repos comp platform conf useSandbox mSandboxPkgInfo
refold's avatar
refold committed
172
173
  globalFlags configFlags configExFlags installFlags haddockFlags
  userTargets0 = do
174

175
    installContext <- makeInstallContext verbosity args (Just userTargets0)
Mikhail Glushenkov's avatar
Mikhail Glushenkov committed
176
    installPlan    <- foldProgress logMsg die' return =<<
177
178
179
180
181
                      makeInstallPlan verbosity args installContext

    processInstallPlan verbosity args installContext installPlan
  where
    args :: InstallArgs
182
    args = (packageDBs, repos, comp, platform, conf, useSandbox, mSandboxPkgInfo,
183
184
185
            globalFlags, configFlags, configExFlags, installFlags,
            haddockFlags)

Mikhail Glushenkov's avatar
Mikhail Glushenkov committed
186
187
188
189
190
191
192
193
    die' message = die (message ++ if isUseSandbox useSandbox
                                   then installFailedInSandbox else [])
    -- TODO: use a better error message, remove duplication.
    installFailedInSandbox =
      "Note: when using a sandbox, all packages are required to have \
      \consistent dependencies. \
      \Try reinstalling/unregistering the offending packages or \
      \recreating the sandbox."
194
195
    logMsg message rest = debugNoWrap verbosity message >> rest

refold's avatar
refold committed
196
-- TODO: Make InstallContext a proper datatype with documented fields.
197
198
199
200
-- | Common context for makeInstallPlan and processInstallPlan.
type InstallContext = ( PackageIndex, SourcePackageDb
                      , [UserTarget], [PackageSpecifier SourcePackage] )

refold's avatar
refold committed
201
202
-- TODO: Make InstallArgs a proper datatype with documented fields or just get
-- rid of it completely.
203
204
205
206
-- | Initial arguments given to 'install' or 'makeInstallContext'.
type InstallArgs = ( PackageDBStack
                   , [Repo]
                   , Compiler
207
                   , Platform
208
                   , ProgramConfiguration
209
                   , UseSandbox
210
                   , Maybe SandboxPackageInfo
211
212
213
214
215
216
217
                   , GlobalFlags
                   , ConfigFlags
                   , ConfigExFlags
                   , InstallFlags
                   , HaddockFlags )

-- | Make an install context given install arguments.
218
makeInstallContext :: Verbosity -> InstallArgs -> Maybe [UserTarget]
219
220
                      -> IO InstallContext
makeInstallContext verbosity
221
  (packageDBs, repos, comp, _, conf,_,_,
222
   globalFlags, _, _, _, _) mUserTargets = do
223

224
225
    installedPkgIndex <- getInstalledPackages verbosity comp packageDBs conf
    sourcePkgDb       <- getSourcePackages    verbosity repos
226

227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
    (userTargets, pkgSpecifiers) <- case mUserTargets of
      Nothing           ->
        -- We want to distinguish between the case where the user has given an
        -- empty list of targets on the command-line and the case where we
        -- specifically want to have an empty list of targets.
        return ([], [])
      Just userTargets0 -> do
        -- For install, if no target is given it means we use the current
        -- directory as the single target.
        let userTargets | null userTargets0 = [UserTargetLocalDir "."]
                        | otherwise         = userTargets0

        pkgSpecifiers <- resolveUserTargets verbosity
                         (fromFlag $ globalWorldFile globalFlags)
                         (packageIndex sourcePkgDb)
                         userTargets
        return (userTargets, pkgSpecifiers)
244
245

    return (installedPkgIndex, sourcePkgDb, userTargets, pkgSpecifiers)
246

247
248
249
250
-- | Make an install plan given install context and install arguments.
makeInstallPlan :: Verbosity -> InstallArgs -> InstallContext
                -> IO (Progress String String InstallPlan)
makeInstallPlan verbosity
251
  (_, _, comp, platform, _, _, mSandboxPkgInfo,
252
253
254
255
256
257
258
   _, configFlags, configExFlags, installFlags,
   _)
  (installedPkgIndex, sourcePkgDb,
   _, pkgSpecifiers) = do

    solver <- chooseSolver verbosity (fromFlag (configSolver configExFlags))
              (compilerId comp)
259
    notice verbosity "Resolving dependencies..."
260
261
262
    return $ planPackages comp platform mSandboxPkgInfo solver
      configFlags configExFlags installFlags
      installedPkgIndex sourcePkgDb pkgSpecifiers
263

264
265
266
267
268
-- | Given an install plan, perform the actual installations.
processInstallPlan :: Verbosity -> InstallArgs -> InstallContext
                   -> InstallPlan
                   -> IO ()
processInstallPlan verbosity
269
  args@(_,_, _, _, _, _, _, _, _, _, installFlags, _)
270
271
  (installedPkgIndex, sourcePkgDb,
   userTargets, pkgSpecifiers) installPlan = do
272
273
    checkPrintPlan verbosity installedPkgIndex installPlan sourcePkgDb
      installFlags pkgSpecifiers
274

275
276
    unless dryRun $ do
      installPlan' <- performInstallations verbosity
277
278
                      args installedPkgIndex installPlan
      postInstallActions verbosity args userTargets installPlan'
279
  where
280
    dryRun = fromFlag (installDryRun installFlags)
281

282
283
284
-- ------------------------------------------------------------
-- * Installation planning
-- ------------------------------------------------------------
285

286
planPackages :: Compiler
287
             -> Platform
288
             -> Maybe SandboxPackageInfo
289
             -> Solver
290
291
292
             -> ConfigFlags
             -> ConfigExFlags
             -> InstallFlags
293
             -> PackageIndex
294
295
             -> SourcePackageDb
             -> [PackageSpecifier SourcePackage]
296
             -> Progress String String InstallPlan
297
298
planPackages comp platform mSandboxPkgInfo solver
             configFlags configExFlags installFlags
299
             installedPkgIndex sourcePkgDb pkgSpecifiers =
300

301
        resolveDependencies
302
          platform (compilerId comp)
303
          solver
304
          resolverParams
305

306
    >>= if onlyDeps then pruneInstallPlan pkgSpecifiers else return
307

308
309
310
  where
    resolverParams =

Andres Löh's avatar
Andres Löh committed
311
312
313
        setMaxBackjumps (if maxBackjumps < 0 then Nothing
                                             else Just maxBackjumps)

314
315
      . setIndependentGoals independentGoals

Andres Löh's avatar
Andres Löh committed
316
      . setReorderGoals reorderGoals
Andres Löh's avatar
Andres Löh committed
317
318

      . setAvoidReinstalls avoidReinstalls
319

320
321
      . setShadowPkgs shadowPkgs

322
      . setPreferenceDefault (if upgradeDeps then PreferAllLatest
323
324
325
326
327
328
329
330
331
                                             else PreferLatestForSelected)

      . addPreferences
          -- preferences from the config file or command line
          [ PackageVersionPreference name ver
          | Dependency name ver <- configPreferences configExFlags ]

      . addConstraints
          -- version constraints from the config file or command line
332
            (map userToPackageConstraint (configExConstraints configExFlags))
333
334
335
336

      . addConstraints
          --FIXME: this just applies all flags to all targets which
          -- is silly. We should check if the flags are appropriate
337
          [ PackageConstraintFlags (pkgSpecifierTarget pkgSpecifier) flags
338
339
          | let flags = configConfigurationsFlags configFlags
          , not (null flags)
340
341
342
343
344
          , pkgSpecifier <- pkgSpecifiers ]

      . addConstraints
          [ PackageConstraintStanzas (pkgSpecifierTarget pkgSpecifier) stanzas
          | pkgSpecifier <- pkgSpecifiers ]
345

346
347
      . maybe id applySandboxInstallPolicy mSandboxPkgInfo

348
349
      . (if reinstall then reinstallTargets else id)

350
      $ standardInstallPolicy
351
        installedPkgIndex sourcePkgDb pkgSpecifiers
352

353
354
355
356
    stanzas = concat
        [ if testsEnabled then [TestStanzas] else []
        , if benchmarksEnabled then [BenchStanzas] else []
        ]
357
    testsEnabled = fromFlagOrDefault False $ configTests configFlags
358
    benchmarksEnabled = fromFlagOrDefault False $ configBenchmarks configFlags
359

360
361
362
363
    reinstall        = fromFlag (installReinstall        installFlags)
    reorderGoals     = fromFlag (installReorderGoals     installFlags)
    independentGoals = fromFlag (installIndependentGoals installFlags)
    avoidReinstalls  = fromFlag (installAvoidReinstalls  installFlags)
364
    shadowPkgs       = fromFlag (installShadowPkgs       installFlags)
365
366
367
    maxBackjumps     = fromFlag (installMaxBackjumps     installFlags)
    upgradeDeps      = fromFlag (installUpgradeDeps      installFlags)
    onlyDeps         = fromFlag (installOnlyDeps         installFlags)
368

369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
-- | Remove the provided targets from the install plan.
pruneInstallPlan :: Package pkg => [PackageSpecifier pkg] -> InstallPlan
                    -> Progress String String InstallPlan
pruneInstallPlan pkgSpecifiers =
  -- TODO: this is a general feature and should be moved to D.C.Dependency
  -- Also, the InstallPlan.remove should return info more precise to the
  -- problem, rather than the very general PlanProblem type.
  either (Fail . explain) Done
  . InstallPlan.remove (\pkg -> packageName pkg `elem` targetnames)
  where
    explain :: [InstallPlan.PlanProblem] -> String
    explain problems =
      "Cannot select only the dependencies (as requested by the "
      ++ "'--only-dependencies' flag), "
      ++ (case pkgids of
             [pkgid] -> "the package " ++ display pkgid ++ " is "
             _       -> "the packages "
                        ++ intercalate ", " (map display pkgids) ++ " are ")
      ++ "required by a dependency of one of the other targets."
      where
        pkgids =
          nub [ depid
              | InstallPlan.PackageMissingDeps _ depids <- problems
              , depid <- depids
              , packageName depid `elem` targetnames ]

    targetnames  = map pkgSpecifierTarget pkgSpecifiers

397
398
399
400
-- ------------------------------------------------------------
-- * Informational messages
-- ------------------------------------------------------------

401
402
-- | Perform post-solver checks of the install plan and print it if
-- either requested or needed.
403
404
405
checkPrintPlan :: Verbosity
               -> PackageIndex
               -> InstallPlan
406
               -> SourcePackageDb
407
               -> InstallFlags
408
               -> [PackageSpecifier SourcePackage]
409
               -> IO ()
410
411
checkPrintPlan verbosity installed installPlan sourcePkgDb
  installFlags pkgSpecifiers = do
412

413
414
415
416
417
418
419
420
  -- User targets that are already installed.
  let preExistingTargets =
        [ p | let tgts = map pkgSpecifierTarget pkgSpecifiers,
              InstallPlan.PreExisting p <- InstallPlan.toList installPlan,
              packageName p `elem` tgts ]

  -- If there's nothing to install, we print the already existing
  -- target packages as an explanation.
421
  when nothingToInstall $
422
423
424
425
    notice verbosity $ unlines $
         "All the requested packages are already installed:"
       : map (display . packageId) preExistingTargets
      ++ ["Use --reinstall if you want to reinstall anyway."]
426

427
  let lPlan = linearizeInstallPlan installed installPlan
428
429
  -- Are any packages classified as reinstalls?
  let reinstalledPkgs = concatMap (extractReinstalls . snd) lPlan
430
431
432
433
434
435
436
437
  -- Packages that are already broken.
  let oldBrokenPkgs =
          map Installed.installedPackageId
        . PackageIndex.reverseDependencyClosure installed
        . map (Installed.installedPackageId . fst)
        . PackageIndex.brokenPackages
        $ installed
  let excluded = reinstalledPkgs ++ oldBrokenPkgs
438
  -- Packages that are reverse dependencies of replaced packages are very
439
440
441
  -- likely to be broken. We exclude packages that are already broken.
  let newBrokenPkgs =
        filter (\ p -> not (Installed.installedPackageId p `elem` excluded))
442
443
               (PackageIndex.reverseDependencyClosure installed reinstalledPkgs)
  let containsReinstalls = not (null reinstalledPkgs)
444
  let breaksPkgs         = not (null newBrokenPkgs)
445
446
447
448
449
450
451
452

  let adaptedVerbosity
        | containsReinstalls && not overrideReinstall = verbosity `max` verbose
        | otherwise                                   = verbosity

  -- We print the install plan if we are in a dry-run or if we are confronted
  -- with a dangerous install plan.
  when (dryRun || containsReinstalls && not overrideReinstall) $
453
454
    printPlan (dryRun || breaksPkgs && not overrideReinstall)
      adaptedVerbosity lPlan sourcePkgDb
455

456
457
458
459
460
461
462
463
  -- If the install plan is dangerous, we print various warning messages. In
  -- particular, if we can see that packages are likely to be broken, we even
  -- bail out (unless installation has been forced with --force-reinstalls).
  when containsReinstalls $ do
    if breaksPkgs
      then do
        (if dryRun || overrideReinstall then warn verbosity else die) $ unlines $
            "The following packages are likely to be broken by the reinstalls:"
464
          : map (display . Installed.sourcePackageId) newBrokenPkgs
465
466
467
468
469
470
471
          ++ if overrideReinstall
               then if dryRun then [] else
                 ["Continuing even though the plan contains dangerous reinstalls."]
               else
                 ["Use --force-reinstalls if you want to install anyway."]
      else unless dryRun $ warn verbosity
             "Note that reinstalls are always dangerous. Continuing anyway..."
472
473
474

  where
    nothingToInstall = null (InstallPlan.ready installPlan)
475
476

    dryRun            = fromFlag (installDryRun            installFlags)
477
    overrideReinstall = fromFlag (installOverrideReinstall installFlags)
478

479
480
481
linearizeInstallPlan :: PackageIndex
                     -> InstallPlan
                     -> [(ConfiguredPackage, PackageStatus)]
482
483
linearizeInstallPlan installedPkgIndex plan =
    unfoldr next plan
484
485
486
  where
    next plan' = case InstallPlan.ready plan' of
      []      -> Nothing
487
488
489
490
491
492
493
494
495
      (pkg:_) -> Just ((pkg, status), plan'')
        where
          pkgid  = packageId pkg
          status = packageStatus installedPkgIndex pkg
          plan'' = InstallPlan.completed pkgid
                     (BuildOk DocsNotTried TestsNotTried)
                     (InstallPlan.processing [pkg] plan')
          --FIXME: This is a bit of a hack,
          -- pretending that each package is installed
496

497
498
data PackageStatus = NewPackage
                   | NewVersion [Version]
499
                   | Reinstall  [InstalledPackageId] [PackageChange]
500
501
502

type PackageChange = MergeResult PackageIdentifier PackageIdentifier

503
504
505
extractReinstalls :: PackageStatus -> [InstalledPackageId]
extractReinstalls (Reinstall ipids _) = ipids
extractReinstalls _                   = []
506
507
508
509
510
511

packageStatus :: PackageIndex -> ConfiguredPackage -> PackageStatus
packageStatus installedPkgIndex cpkg =
  case PackageIndex.lookupPackageName installedPkgIndex
                                      (packageName cpkg) of
    [] -> NewPackage
refold's avatar
refold committed
512
513
    ps ->  case filter ((==packageId cpkg)
                        . Installed.sourcePackageId) (concatMap snd ps) of
514
515
516
      []           -> NewVersion (map fst ps)
      pkgs@(pkg:_) -> Reinstall (map Installed.installedPackageId pkgs)
                                (changes pkg cpkg)
517
518
519
520
521
522

  where

    changes :: Installed.InstalledPackageInfo
            -> ConfiguredPackage
            -> [MergeResult PackageIdentifier PackageIdentifier]
refold's avatar
refold committed
523
524
525
526
527
528
529
530
531
532
533
    changes pkg pkg' =
      filter changed
      $ mergeBy (comparing packageName)
        -- get dependencies of installed package (convert to source pkg ids via
        -- index)
        (nub . sort . concatMap
         (maybeToList . fmap Installed.sourcePackageId .
          PackageIndex.lookupInstalledPackageId installedPkgIndex) .
         Installed.depends $ pkg)
        -- get dependencies of configured package
        (nub . sort . depends $ pkg')
534
535
536
537

    changed (InBoth    pkgid pkgid') = pkgid /= pkgid'
    changed _                        = True

538
539
540
printPlan :: Bool -- is dry run
          -> Verbosity
          -> [(ConfiguredPackage, PackageStatus)]
541
          -> SourcePackageDb
542
          -> IO ()
543
printPlan dryRun verbosity plan sourcePkgDb = case plan of
544
545
546
  []   -> return ()
  pkgs
    | verbosity >= Verbosity.verbose -> notice verbosity $ unlines $
547
        ("In order, the following " ++ wouldWill ++ " be installed:")
548
549
      : map showPkgAndReason pkgs
    | otherwise -> notice verbosity $ unlines $
refold's avatar
refold committed
550
551
        ("In order, the following " ++ wouldWill
         ++ " be installed (use -v for more details):")
552
      : map showPkg pkgs
553
  where
554
555
556
    wouldWill | dryRun    = "would"
              | otherwise = "will"

557
558
559
    showPkg (pkg, _) = display (packageId pkg) ++
                       showLatest (pkg)

560
    showPkgAndReason (pkg', pr) = display (packageId pkg') ++
561
          showLatest pkg' ++
562
563
          showFlagAssignment (nonDefaultFlags pkg') ++
          showStanzas (stanzas pkg') ++ " " ++
564
          case pr of
565
566
567
            NewPackage     -> "(new package)"
            NewVersion _   -> "(new version)"
            Reinstall _ cs -> "(reinstall)" ++ case cs of
568
569
570
                []   -> ""
                diff -> " changes: "  ++ intercalate ", " (map change diff)

571
    showLatest :: ConfiguredPackage -> String
572
573
574
575
576
577
    showLatest pkg = case mLatestVersion of
        Just latestVersion ->
            if pkgVersion /= latestVersion
            then (" (latest: " ++ display latestVersion ++ ")")
            else ""
        Nothing -> ""
578
579
      where
        pkgVersion    = packageVersion pkg
580
581
582
583
584
585
        mLatestVersion :: Maybe Version
        mLatestVersion = case SourcePackageIndex.lookupPackageName
                                (packageIndex sourcePkgDb)
                                (packageName pkg) of
            [] -> Nothing
            x -> Just $ packageVersion $ last x
586

587
588
589
590
    toFlagAssignment :: [Flag] -> FlagAssignment
    toFlagAssignment = map (\ f -> (flagName f, flagDefault f))

    nonDefaultFlags :: ConfiguredPackage -> FlagAssignment
591
    nonDefaultFlags (ConfiguredPackage spkg fa _ _) =
592
593
594
595
596
      let defaultAssignment =
            toFlagAssignment
             (genPackageFlags (Source.packageDescription spkg))
      in  fa \\ defaultAssignment

597
598
599
600
601
602
603
604
    stanzas :: ConfiguredPackage -> [OptionalStanza]
    stanzas (ConfiguredPackage _ _ sts _) = sts

    showStanzas :: [OptionalStanza] -> String
    showStanzas = concatMap ((' ' :) . showStanza)
    showStanza TestStanzas  = "*test"
    showStanza BenchStanzas = "*bench"

605
    -- FIXME: this should be a proper function in a proper place
606
    showFlagAssignment :: FlagAssignment -> String
607
608
609
610
611
    showFlagAssignment = concatMap ((' ' :) . showFlagValue)
    showFlagValue (f, True)   = '+' : showFlagName f
    showFlagValue (f, False)  = '-' : showFlagName f
    showFlagName (FlagName f) = f

612
613
614
615
616
    change (OnlyInLeft pkgid)        = display pkgid ++ " removed"
    change (InBoth     pkgid pkgid') = display pkgid ++ " -> "
                                    ++ display (packageVersion pkgid')
    change (OnlyInRight      pkgid') = display pkgid' ++ " added"

617
618
619
620
621
622
623
624
625
626
-- ------------------------------------------------------------
-- * Post installation stuff
-- ------------------------------------------------------------

-- | Various stuff we do after successful or unsuccessfully installing a bunch
-- of packages. This includes:
--
--  * build reporting, local and remote
--  * symlinking binaries
--  * updating indexes
627
--  * updating world file
628
629
630
--  * error reporting
--
postInstallActions :: Verbosity
631
                   -> InstallArgs
632
                   -> [UserTarget]
633
634
635
                   -> InstallPlan
                   -> IO ()
postInstallActions verbosity
636
637
  (packageDBs, _, comp, platform, conf, useSandbox, mSandboxPkgInfo
  ,globalFlags, configFlags, _, installFlags, _)
638
  targets installPlan = do
639

640
  unless oneShot $
641
    World.insert verbosity worldFile
642
643
644
      --FIXME: does not handle flags
      [ World.WorldPkgInfo dep []
      | UserTargetNamed dep <- targets ]
645

646
  let buildReports = BuildReports.fromInstallPlan installPlan
refold's avatar
refold committed
647
648
  BuildReports.storeLocal (installSummaryFile installFlags) buildReports
    (InstallPlan.planPlatform installPlan)
649
650
651
652
653
  when (reportingLevel >= AnonymousReports) $
    BuildReports.storeAnonymous buildReports
  when (reportingLevel == DetailedReports) $
    storeDetailedBuildReports verbosity logsDir buildReports

654
  regenerateHaddockIndex verbosity packageDBs comp platform conf
655
656
657
658
659
660
                         configFlags installFlags installPlan

  symlinkBinaries verbosity configFlags installFlags installPlan

  printBuildFailures installPlan

661
662
663
  updateSandboxTimestampsFile useSandbox mSandboxPkgInfo
                              comp platform installPlan

664
665
  where
    reportingLevel = fromFlag (installBuildReports installFlags)
666
    logsDir        = fromFlag (globalLogsDir globalFlags)
667
668
    oneShot        = fromFlag (installOneShot installFlags)
    worldFile      = fromFlag $ globalWorldFile globalFlags
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705

storeDetailedBuildReports :: Verbosity -> FilePath
                          -> [(BuildReports.BuildReport, Repo)] -> IO ()
storeDetailedBuildReports verbosity logsDir reports = sequence_
  [ do dotCabal <- defaultCabalDir
       let logFileName = display (BuildReports.package report) <.> "log"
           logFile     = logsDir </> logFileName
           reportsDir  = dotCabal </> "reports" </> remoteRepoName remoteRepo
           reportFile  = reportsDir </> logFileName

       handleMissingLogFile $ do
         buildLog <- readFile logFile
         createDirectoryIfMissing True reportsDir -- FIXME
         writeFile reportFile (show (BuildReports.show report, buildLog))

  | (report, Repo { repoKind = Left remoteRepo }) <- reports
  , isLikelyToHaveLogFile (BuildReports.installOutcome report) ]

  where
    isLikelyToHaveLogFile BuildReports.ConfigureFailed {} = True
    isLikelyToHaveLogFile BuildReports.BuildFailed     {} = True
    isLikelyToHaveLogFile BuildReports.InstallFailed   {} = True
    isLikelyToHaveLogFile BuildReports.InstallOk       {} = True
    isLikelyToHaveLogFile _                               = False

    handleMissingLogFile = Exception.handleJust missingFile $ \ioe ->
      warn verbosity $ "Missing log file for build report: "
                    ++ fromMaybe ""  (ioeGetFileName ioe)

    missingFile ioe
      | isDoesNotExistError ioe  = Just ioe
    missingFile _                = Nothing


regenerateHaddockIndex :: Verbosity
                       -> [PackageDB]
                       -> Compiler
706
                       -> Platform
707
708
709
710
711
                       -> ProgramConfiguration
                       -> ConfigFlags
                       -> InstallFlags
                       -> InstallPlan
                       -> IO ()
712
regenerateHaddockIndex verbosity packageDBs comp platform conf
713
714
715
716
717
718
719
720
721
722
723
724
725
726
                       configFlags installFlags installPlan
  | haddockIndexFileIsRequested && shouldRegenerateHaddockIndex = do

  defaultDirs <- InstallDirs.defaultInstallDirs
                   (compilerFlavor comp)
                   (fromFlag (configUserInstall configFlags))
                   True
  let indexFileTemplate = fromFlag (installHaddockIndex installFlags)
      indexFile = substHaddockIndexFileName defaultDirs indexFileTemplate

  notice verbosity $
     "Updating documentation index " ++ indexFile

  --TODO: might be nice if the install plan gave us the new InstalledPackageInfo
727
728
  installedPkgIndex <- getInstalledPackages verbosity comp packageDBs conf
  Haddock.regenerateHaddockIndex verbosity installedPkgIndex conf indexFile
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755

  | otherwise = return ()
  where
    haddockIndexFileIsRequested =
         fromFlag (installDocumentation installFlags)
      && isJust (flagToMaybe (installHaddockIndex installFlags))

    -- We want to regenerate the index if some new documentation was actually
    -- installed. Since the index is per-user, we don't do it for global
    -- installs or special cases where we're installing into a specific db.
    shouldRegenerateHaddockIndex = normalUserInstall
                                && someDocsWereInstalled installPlan
      where
        someDocsWereInstalled = any installedDocs . InstallPlan.toList
        normalUserInstall     = (UserPackageDB `elem` packageDBs)
                             && all (not . isSpecificPackageDB) packageDBs

        installedDocs (InstallPlan.Installed _ (BuildOk DocsOk _)) = True
        installedDocs _                                            = False
        isSpecificPackageDB (SpecificPackageDB _) = True
        isSpecificPackageDB _                     = False

    substHaddockIndexFileName defaultDirs = fromPathTemplate
                                          . substPathTemplate env
      where
        env  = env0 ++ installDirsTemplateEnv absoluteDirs
        env0 = InstallDirs.compilerTemplateEnv (compilerId comp)
756
            ++ InstallDirs.platformTemplateEnv platform
757
758
759
760
761
762
        absoluteDirs = InstallDirs.substituteInstallDirTemplates
                         env0 templateDirs
        templateDirs = InstallDirs.combineInstallDirs fromFlagOrDefault
                         defaultDirs (configInstallDirs configFlags)


763
symlinkBinaries :: Verbosity
764
                -> ConfigFlags
765
                -> InstallFlags
766
                -> InstallPlan -> IO ()
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
symlinkBinaries verbosity configFlags installFlags plan = do
  failed <- InstallSymlink.symlinkBinaries configFlags installFlags plan
  case failed of
    [] -> return ()
    [(_, exe, path)] ->
      warn verbosity $
           "could not create a symlink in " ++ bindir ++ " for "
        ++ exe ++ " because the file exists there already but is not "
        ++ "managed by cabal. You can create a symlink for this executable "
        ++ "manually if you wish. The executable file has been installed at "
        ++ path
    exes ->
      warn verbosity $
           "could not create symlinks in " ++ bindir ++ " for "
        ++ intercalate ", " [ exe | (_, exe, _) <- exes ]
        ++ " because the files exist there already and are not "
        ++ "managed by cabal. You can create symlinks for these executables "
        ++ "manually if you wish. The executable files have been installed at "
        ++ intercalate ", " [ path | (_, _, path) <- exes ]
  where
787
    bindir = fromFlag (installSymlinkBinDir installFlags)
788

789

790
printBuildFailures :: InstallPlan -> IO ()
791
792
793
794
795
796
797
798
799
800
801
802
printBuildFailures plan =
  case [ (pkg, reason)
       | InstallPlan.Failed pkg reason <- InstallPlan.toList plan ] of
    []     -> return ()
    failed -> die . unlines
            $ "Error: some packages failed to install:"
            : [ display (packageId pkg) ++ printFailureReason reason
              | (pkg, reason) <- failed ]
  where
    printFailureReason reason = case reason of
      DependentFailed pkgid -> " depends on " ++ display pkgid
                            ++ " which failed to install."
803
804
      DownloadFailed  e -> " failed while downloading the package."
                        ++ " The exception was:\n  " ++ show e
805
806
807
808
809
810
      UnpackFailed    e -> " failed while unpacking the package."
                        ++ " The exception was:\n  " ++ show e
      ConfigureFailed e -> " failed during the configure step."
                        ++ " The exception was:\n  " ++ show e
      BuildFailed     e -> " failed during the building phase."
                        ++ " The exception was:\n  " ++ show e
811
812
      TestsFailed     e -> " failed during the tests phase."
                        ++ " The exception was:\n  " ++ show e
813
814
815
      InstallFailed   e -> " failed during the final install step."
                        ++ " The exception was:\n  " ++ show e

816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
-- | If we're working inside a sandbox and some add-source deps were installed,
-- update the timestamps of those deps.
updateSandboxTimestampsFile :: UseSandbox -> Maybe SandboxPackageInfo
                        -> Compiler -> Platform -> InstallPlan
                        -> IO ()
updateSandboxTimestampsFile (UseSandbox sandboxDir)
                            (Just (SandboxPackageInfo _ _ _ allAddSourceDeps))
                            comp platform installPlan =
  withUpdateTimestamps sandboxDir (compilerId comp) platform $ \_ -> do
    let allInstalled = [ pkg | InstallPlan.Installed pkg _
                            <- InstallPlan.toList installPlan ]
        allSrcPkgs   = [ pkg | ConfiguredPackage pkg _ _ _ <- allInstalled ]
        allPaths     = [ pth | LocalUnpackedPackage pth
                            <- map packageSource allSrcPkgs]
    allPathsCanonical <- mapM tryCanonicalizePath allPaths
    return $! filter (`S.member` allAddSourceDeps) allPathsCanonical

updateSandboxTimestampsFile _ _ _ _ _ = return ()
834
835
836
837
838
839
840
841
842
843

-- ------------------------------------------------------------
-- * Actually do the installations
-- ------------------------------------------------------------

data InstallMisc = InstallMisc {
    rootCmd    :: Maybe FilePath,
    libVersion :: Maybe Version
  }

refold's avatar
refold committed
844
845
846
847
-- | If logging is enabled, contains location of the log file and the verbosity
-- level for logging.
type UseLogFile = Maybe (PackageIdentifier -> FilePath, Verbosity)

848
performInstallations :: Verbosity
849
                     -> InstallArgs
850
                     -> PackageIndex
851
852
853
                     -> InstallPlan
                     -> IO InstallPlan
performInstallations verbosity
854
  (packageDBs, _, comp, _, conf, useSandbox, _,
855
   globalFlags, configFlags, configExFlags, installFlags, haddockFlags)
856
  installedPkgIndex installPlan = do
857

858
859
860
861
862
863
  -- With 'install -j' it can be a bit hard to tell whether a sandbox is used.
  whenUsingSandbox useSandbox $ \sandboxDir ->
    when parallelBuild $
      notice verbosity $ "Notice: installing into a sandbox located at "
                         ++ sandboxDir

864
865
866
867
  jobControl   <- if parallelBuild then newParallelJobControl
                                   else newSerialJobControl
  buildLimit   <- newJobLimit numJobs
  fetchLimit   <- newJobLimit (min numJobs numFetchJobs)
refold's avatar
refold committed
868
869
  installLock  <- newLock -- serialise installation
  cacheLock    <- newLock -- serialise access to setup exe cache
870

refold's avatar
refold committed
871
  executeInstallPlan verbosity jobControl useLogFile installPlan $ \cpkg ->
872
    installConfiguredPackage platform compid configFlags
873
                             cpkg $ \configFlags' src pkg pkgoverride ->
874
875
      fetchSourcePackage verbosity fetchLimit src $ \src' ->
        installLocalPackage verbosity buildLimit (packageId pkg) src' $ \mpath ->
refold's avatar
refold committed
876
          installUnpackedPackage verbosity buildLimit installLock numJobs
refold's avatar
refold committed
877
                                 (setupScriptOptions installedPkgIndex cacheLock)
878
                                 miscOptions configFlags' installFlags haddockFlags
879
                                 compid platform pkg pkgoverride mpath useLogFile
880
881
882
883
884

  where
    platform = InstallPlan.planPlatform installPlan
    compid   = InstallPlan.planCompiler installPlan

885
886
887
888
    numJobs  = case installNumJobs installFlags of
      Cabal.NoFlag        -> 1
      Cabal.Flag Nothing  -> numberOfProcessors
      Cabal.Flag (Just n) -> n
refold's avatar
refold committed
889
    numFetchJobs  = 2
890
891
    parallelBuild = numJobs >= 2

refold's avatar
refold committed
892
    setupScriptOptions index lock = SetupScriptOptions {
893
894
      useCabalVersion  = maybe anyVersion thisVersion (libVersion miscOptions),
      useCompiler      = Just comp,
895
      usePlatform      = Just platform,
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
      -- Hack: we typically want to allow the UserPackageDB for finding the
      -- Cabal lib when compiling any Setup.hs even if we're doing a global
      -- install. However we also allow looking in a specific package db.
      usePackageDB     = if UserPackageDB `elem` packageDBs
                           then packageDBs
                           else let (db@GlobalPackageDB:dbs) = packageDBs
                                 in db : UserPackageDB : dbs,
                                --TODO: use Ord instance:
                                -- insert UserPackageDB packageDBs
      usePackageIndex  = if UserPackageDB `elem` packageDBs
                           then Just index
                           else Nothing,
      useProgramConfig = conf,
      useDistPref      = fromFlagOrDefault
                           (useDistPref defaultSetupScriptOptions)
                           (configDistPref configFlags),
      useLoggingHandle = Nothing,
913
      useWorkingDir    = Nothing,
refold's avatar
refold committed
914
      forceExternalSetupMethod = parallelBuild,
refold's avatar
refold committed
915
      setupCacheLock   = Just lock
916
917
    }
    reportingLevel = fromFlag (installBuildReports installFlags)
918
    logsDir        = fromFlag (globalLogsDir globalFlags)
refold's avatar
refold committed
919
920
921
922
923

    -- Should the build output be written to a log file instead of stdout?
    useLogFile :: UseLogFile
    useLogFile = fmap ((\f -> (f, loggingVerbosity)) . substLogFileName)
                 logFileTemplate
924
      where
refold's avatar
refold committed
925
926
927
928
929
930
931
        installLogFile' = flagToMaybe $ installLogFile installFlags
        defaultTemplate = toPathTemplate $ logsDir </> "$pkgid" <.> "log"

        -- If the user has specified --remote-build-reporting=detailed, use the
        -- default log file location. If the --build-log option is set, use the
        -- provided location. Otherwise don't use logging, unless building in
        -- parallel (in which case the default location is used).
932
        logFileTemplate :: Maybe PathTemplate
refold's avatar
refold committed
933
934
935
936
937
938
939
940
941
942
943
944
945
946
        logFileTemplate
          | useDefaultTemplate = Just defaultTemplate
          | otherwise          = installLogFile'

        -- If the user has specified --remote-build-reporting=detailed or
        -- --build-log, use more verbose logging.
        loggingVerbosity :: Verbosity
        loggingVerbosity | overrideVerbosity = max Verbosity.verbose verbosity
                         | otherwise         = verbosity

        useDefaultTemplate :: Bool
        useDefaultTemplate
          | reportingLevel == DetailedReports = True
          | isJust installLogFile'            = False
947
          | parallelBuild                     = True
refold's avatar
refold committed
948
949
950
951
952
953
          | otherwise                         = False

        overrideVerbosity :: Bool
        overrideVerbosity
          | reportingLevel == DetailedReports = True
          | isJust installLogFile'            = True
954
          | parallelBuild                     = False
refold's avatar
refold committed
955
          | otherwise                         = False
956
957

    substLogFileName :: PathTemplate -> PackageIdentifier -> FilePath
958
959
960
    substLogFileName template pkg = fromPathTemplate
                                  . substPathTemplate env
                                  $ template
refold's avatar
refold committed
961
962
      where env = initialPathTemplateEnv (packageId pkg)
                  (compilerId comp) platform
refold's avatar
refold committed
963

964
965
    miscOptions  = InstallMisc {
      rootCmd    = if fromFlag (configUserInstall configFlags)
966
                      || (isUseSandbox useSandbox)
967
968
                     then Nothing      -- ignore --root-cmd if --user
                                       -- or working inside a sandbox.
969
970
971
972
973
                     else flagToMaybe (installRootCmd installFlags),
      libVersion = flagToMaybe (configCabalVersion configExFlags)
    }


974
975
executeInstallPlan :: Verbosity
                   -> JobControl IO (PackageId, BuildResult)
refold's avatar
refold committed
976
                   -> UseLogFile
977
978
979
                   -> InstallPlan
                   -> (ConfiguredPackage -> IO BuildResult)
                   -> IO InstallPlan
refold's avatar
refold committed
980
executeInstallPlan verbosity jobCtl useLogFile plan0 installPkg =
981
    tryNewTasks 0 plan0
982
  where
983
984
985
986
987
988
    tryNewTasks taskCount plan = do
      case InstallPlan.ready plan of
        [] | taskCount == 0 -> return plan
           | otherwise      -> waitForTasks taskCount plan
        pkgs                -> do
          sequence_
refold's avatar
refold committed
989
            [ do info verbosity $ "Ready to install " ++ display pkgid
990
991
992
993
994
995
996
997
998
999
1000
                 spawnJob jobCtl $ do
                   buildResult <- installPkg pkg
                   return (packageId pkg, buildResult)
            | pkg <- pkgs
            , let pkgid = packageId pkg]

          let taskCount' = taskCount + length pkgs
              plan'      = InstallPlan.processing pkgs plan
          waitForTasks taskCount' plan'

    waitForTasks taskCount plan = do
refold's avatar
refold committed
1001
      info verbosity $ "Waiting for install task to finish..."
1002
      (pkgid, buildResult) <- collectJob jobCtl
refold's avatar
refold committed
1003
      printBuildResult pkgid buildResult
1004
1005
1006
1007
      let taskCount' = taskCount-1
          plan'      = updatePlan pkgid buildResult plan
      tryNewTasks taskCount' plan'

refold's avatar
refold committed
1008
    updatePlan :: PackageIdentifier -> BuildResult -> InstallPlan -> InstallPlan
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
    updatePlan pkgid (Right buildSuccess) =
      InstallPlan.completed pkgid buildSuccess

    updatePlan pkgid (Left buildFailure) =
      InstallPlan.failed    pkgid buildFailure depsFailure
      where
        depsFailure = DependentFailed pkgid
        -- So this first pkgid failed for whatever reason (buildFailure).
        -- All the other packages that depended on this pkgid, which we
        -- now cannot build, we mark as failing due to 'DependentFailed'
        -- which kind of means it was not their fault.
1020

refold's avatar
refold committed
1021
1022
1023
1024
1025
1026
1027
    -- Print last 10 lines of the build log if something went wrong, and
    -- 'Installed $PKGID' otherwise.
    printBuildResult :: PackageId -> BuildResult -> IO ()
    printBuildResult pkgid buildResult = case buildResult of
        (Right _) -> notice verbosity $ "Installed " ++ display pkgid
        (Left _)  -> do
          notice verbosity $ "Failed to install " ++ display pkgid
1028
1029
1030
1031
          when (verbosity >= normal) $
            case useLogFile of
              Nothing                 -> return ()
              Just (mkLogFileName, _) -> do
1032
1033
                let logName = mkLogFileName pkgid
                    n       = 10
1034
                putStr $ "Last " ++ (show n)
1035
                  ++ " lines of the build log ( " ++ logName ++ " ):\n"
1036
                printLastNLines logName n
refold's avatar
refold committed
1037
1038
1039
1040
1041

    printLastNLines :: FilePath -> Int -> IO ()
    printLastNLines path n = do
      lns <- fmap lines $ readFile path
      let len = length lns
1042
1043
      let toDrop = if (len > n && n > 0) then (len - n) else 0
      mapM_ putStrLn (drop toDrop lns)
1044

1045
-- | Call an installer for an 'SourcePackage' but override the configure
1046
-- flags with the ones given by the 'ConfiguredPackage'. In particular the
1047
1048
1049
1050
-- 'ConfiguredPackage' specifies an exact 'FlagAssignment' and exactly
-- versioned package dependencies. So we ignore any previous partial flag
-- assignment or dependency constraints and use the new ones.
--
1051
installConfiguredPackage :: Platform -> CompilerId
1052
                         ->  ConfigFlags -> ConfiguredPackage
1053
                         -> (ConfigFlags -> PackageLocation (Maybe FilePath)
1054
1055
                                         -> PackageDescription
                                         -> PackageDescriptionOverride -> a)
1056
                         -> a
1057
installConfiguredPackage platform comp configFlags
refold's avatar
refold committed
1058
1059
  (ConfiguredPackage (SourcePackage _ gpkg source pkgoverride)
   flags stanzas deps)
1060
  installPkg = installPkg configFlags {