planLocalPackage :: Verbosity -> Compiler
                 -> ConfigFlags -> ConfigExFlags
                 -> PackageIndex InstalledPackage
                 -> AvailablePackageDb
                 -> IO (Progress String String InstallPlan)
planLocalPackage verbosity comp configFlags configExFlags installed
  (AvailablePackageDb _ availablePrefs) = do
  pkg <- readPackageDescription verbosity =<< defaultPackageDesc verbosity

  let -- We create a local package and ask to resolve a dependency on it
      localPkg = AvailablePackage {
        packageInfoId                = packageId pkg,
        Available.packageDescription = pkg,
        packageSource                = LocalUnpackedPackage "."
      }

      resolverParams =

          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
            [ PackageVersionConstraint name ver
            | Dependency name ver <- configConstraints configFlags ]

        . addConstraints
            -- package flags from the config file or command line
            [ PackageFlagsConstraint (packageName pkg)
                                     (configConfigurationsFlags configFlags) ]

        $ standardInstallPolicy
            installed
            (AvailablePackageDb mempty availablePrefs)
            [SpecificSourcePackage localPkg]

  return (resolveDependencies buildPlatform (compilerId comp) resolverParams)


-- | Call an installer for an 'AvailablePackage' but override the configure
-- flags with the ones given by the 'ConfiguredPackage'. In particular the
-- '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.
--
planLocalPackage :: Verbosity -> Compiler
                 -> ConfigFlags -> ConfigExFlags
                 -> PackageIndex InstalledPackage
                 -> AvailablePackageDb
                 -> IO (Progress String String InstallPlan)
planLocalPackage verbosity comp configFlags configExFlags installed
  (AvailablePackageDb _ availablePrefs) = do
  pkg <- readPackageDescription verbosity =<< defaultPackageDesc verbosity

  let -- We create a local package and ask to resolve a dependency on it
      localPkg = AvailablePackage {
        packageInfoId                = packageId pkg,
        Available.packageDescription = pkg,
        packageSource                = LocalUnpackedPackage "."
      }

      resolverParams =

          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
            [ PackageVersionConstraint name ver
            | Dependency name ver <- configConstraints configFlags ]

        . addConstraints
            -- package flags from the config file or command line
            [ PackageFlagsConstraint (packageName pkg)
                                     (configConfigurationsFlags configFlags) ]

        $ standardInstallPolicy
            installed
            (AvailablePackageDb mempty availablePrefs)
            [SpecificSourcePackage localPkg]

  return (resolveDependencies buildPlatform (compilerId comp) resolverParams)


-- | Call an installer for an 'AvailablePackage' but override the configure
-- flags with the ones given by the 'ConfiguredPackage'. In particular the
-- '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.
--
planLocalPackage verbosity comp configFlags configExFlags installed
  (AvailablePackageDb _ availablePrefs) = do
  pkg <- readPackageDescription verbosity =<< defaultPackageDesc verbosity

  let -- We create a local package and ask to resolve a dependency on it
      localPkg = AvailablePackage {
        packageInfoId                = packageId pkg,
        Available.packageDescription = pkg,
        packageSource                = LocalUnpackedPackage "."
      }

      resolverParams =

          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
            [ PackageVersionConstraint name ver
            | Dependency name ver <- configConstraints configFlags ]

        . addConstraints
            -- package flags from the config file or command line
            [ PackageFlagsConstraint (packageName pkg)
                                     (configConfigurationsFlags configFlags) ]

        $ standardInstallPolicy
            installed
            (AvailablePackageDb mempty availablePrefs)
            [SpecificSourcePackage localPkg]

  return (resolveDependencies buildPlatform (compilerId comp) resolverParams)


-- | Call an installer for an 'AvailablePackage' but override the configure
-- flags with the ones given by the 'ConfiguredPackage'. In particular the
-- '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.
--