{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
-----------------------------------------------------------------------------
{-
Work around this warning:
libraries/Cabal/Distribution/Simple.hs:78:0:
    Warning: In the use of `runTests'
             (imported from Distribution.Simple.UserHooks):
             Deprecated: "Please use the new testing interface instead!"
-}
{-# OPTIONS_GHC -fno-warn-deprecations #-}

-- |
-- Module      :  Distribution.Simple
-- Copyright   :  Isaac Jones 2003-2005
-- License     :  BSD3
--
-- Maintainer  :  cabal-devel@haskell.org
-- Portability :  portable
--
-- This is the command line front end to the Simple build system. When given
-- the parsed command-line args and package information, is able to perform
-- basic commands like configure, build, install, register, etc.
--
-- This module exports the main functions that Setup.hs scripts use. It
-- re-exports the 'UserHooks' type, the standard entry points like
-- 'defaultMain' and 'defaultMainWithHooks' and the predefined sets of
-- 'UserHooks' that custom @Setup.hs@ scripts can extend to add their own
-- behaviour.
--
-- This module isn't called \"Simple\" because it's simple.  Far from
-- it.  It's called \"Simple\" because it does complicated things to
-- simple software.
--
-- The original idea was that there could be different build systems that all
-- presented the same compatible command line interfaces. There is still a
-- "Distribution.Make" system but in practice no packages use it.
module Distribution.Simple
  ( module Distribution.Package
  , module Distribution.Version
  , module Distribution.License
  , module Distribution.Simple.Compiler
  , module Language.Haskell.Extension

    -- * Simple interface
  , defaultMain
  , defaultMainNoRead
  , defaultMainArgs

    -- * Customization
  , UserHooks (..)
  , Args
  , defaultMainWithHooks
  , defaultMainWithSetupHooks
  , defaultMainWithSetupHooksArgs
  , defaultMainWithHooksArgs
  , defaultMainWithHooksNoRead
  , defaultMainWithHooksNoReadArgs

    -- ** Standard sets of hooks
  , simpleUserHooks
  , autoconfUserHooks
  , autoconfSetupHooks
  , emptyUserHooks
  ) where

import Control.Exception (try)

import Distribution.Compat.Prelude
import Distribution.Compat.ResponseFile (expandResponse)
import Prelude ()

-- local

import Distribution.Package
import Distribution.PackageDescription
import Distribution.PackageDescription.Configuration
import Distribution.Simple.Command
import Distribution.Simple.Compiler
import Distribution.Simple.PackageDescription
import Distribution.Simple.PreProcess
import Distribution.Simple.Program
import Distribution.Simple.Setup
import qualified Distribution.Simple.SetupHooks.Internal as SetupHooks
import Distribution.Simple.UserHooks

import Distribution.Simple.Build
import Distribution.Simple.Register
import Distribution.Simple.SrcDist

import Distribution.Simple.Configure

import Distribution.License
import Distribution.Pretty
import Distribution.Simple.Bench
import Distribution.Simple.BuildPaths
import Distribution.Simple.ConfigureScript (runConfigureScript)
import Distribution.Simple.Errors
import Distribution.Simple.Haddock
import Distribution.Simple.Install
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.SetupHooks.Internal
  ( SetupHooks
  )
import Distribution.Simple.Test
import Distribution.Simple.Utils
import qualified Distribution.Types.LocalBuildConfig as LBC
import Distribution.Utils.Path
import Distribution.Verbosity
import Distribution.Version
import Language.Haskell.Extension

-- Base
import Data.List (unionBy, (\\))
import System.Directory
  ( doesDirectoryExist
  , doesFileExist
  , removeDirectoryRecursive
  , removeFile
  )
import System.Environment (getArgs, getProgName)

-- | A simple implementation of @main@ for a Cabal setup script.
-- It reads the package description file using IO, and performs the
-- action specified on the command line.
defaultMain :: IO ()
defaultMain :: IO ()
defaultMain = IO [[Char]]
getArgs IO [[Char]] -> ([[Char]] -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= UserHooks -> [[Char]] -> IO ()
defaultMainHelper UserHooks
simpleUserHooks

-- | A version of 'defaultMain' that is passed the command line
-- arguments, rather than getting them from the environment.
defaultMainArgs :: [String] -> IO ()
defaultMainArgs :: [[Char]] -> IO ()
defaultMainArgs = UserHooks -> [[Char]] -> IO ()
defaultMainHelper UserHooks
simpleUserHooks

defaultMainWithSetupHooks :: SetupHooks -> IO ()
defaultMainWithSetupHooks :: SetupHooks -> IO ()
defaultMainWithSetupHooks SetupHooks
setup_hooks =
  IO [[Char]]
getArgs IO [[Char]] -> ([[Char]] -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= SetupHooks -> [[Char]] -> IO ()
defaultMainWithSetupHooksArgs SetupHooks
setup_hooks

defaultMainWithSetupHooksArgs :: SetupHooks -> [String] -> IO ()
defaultMainWithSetupHooksArgs :: SetupHooks -> [[Char]] -> IO ()
defaultMainWithSetupHooksArgs SetupHooks
setupHooks =
  UserHooks -> [[Char]] -> IO ()
defaultMainHelper (UserHooks -> [[Char]] -> IO ()) -> UserHooks -> [[Char]] -> IO ()
forall a b. (a -> b) -> a -> b
$
    UserHooks
simpleUserHooks
      { confHook = setup_confHook
      , buildHook = setup_buildHook
      , copyHook = setup_copyHook
      , instHook = setup_installHook
      , replHook = setup_replHook
      , haddockHook = setup_haddockHook
      , hscolourHook = setup_hscolourHook
      }
  where
    setup_confHook
      :: (GenericPackageDescription, HookedBuildInfo)
      -> ConfigFlags
      -> IO LocalBuildInfo
    setup_confHook :: (GenericPackageDescription, HookedBuildInfo)
-> ConfigFlags -> IO LocalBuildInfo
setup_confHook =
      ConfigureHooks
-> (GenericPackageDescription, HookedBuildInfo)
-> ConfigFlags
-> IO LocalBuildInfo
configure_setupHooks
        (SetupHooks -> ConfigureHooks
SetupHooks.configureHooks SetupHooks
setupHooks)

    setup_buildHook
      :: PackageDescription
      -> LocalBuildInfo
      -> UserHooks
      -> BuildFlags
      -> IO ()
    setup_buildHook :: PackageDescription
-> LocalBuildInfo -> UserHooks -> BuildFlags -> IO ()
setup_buildHook PackageDescription
pkg_descr LocalBuildInfo
lbi UserHooks
hooks BuildFlags
flags =
      BuildHooks
-> PackageDescription
-> LocalBuildInfo
-> BuildFlags
-> [PPSuffixHandler]
-> IO ()
build_setupHooks
        (SetupHooks -> BuildHooks
SetupHooks.buildHooks SetupHooks
setupHooks)
        PackageDescription
pkg_descr
        LocalBuildInfo
lbi
        BuildFlags
flags
        (UserHooks -> [PPSuffixHandler]
allSuffixHandlers UserHooks
hooks)

    setup_copyHook
      :: PackageDescription
      -> LocalBuildInfo
      -> UserHooks
      -> CopyFlags
      -> IO ()
    setup_copyHook :: PackageDescription
-> LocalBuildInfo -> UserHooks -> CopyFlags -> IO ()
setup_copyHook PackageDescription
pkg_descr LocalBuildInfo
lbi UserHooks
_hooks CopyFlags
flags =
      InstallHooks
-> PackageDescription -> LocalBuildInfo -> CopyFlags -> IO ()
install_setupHooks
        (SetupHooks -> InstallHooks
SetupHooks.installHooks SetupHooks
setupHooks)
        PackageDescription
pkg_descr
        LocalBuildInfo
lbi
        CopyFlags
flags

    setup_installHook
      :: PackageDescription
      -> LocalBuildInfo
      -> UserHooks
      -> InstallFlags
      -> IO ()
    setup_installHook :: PackageDescription
-> LocalBuildInfo -> UserHooks -> InstallFlags -> IO ()
setup_installHook =
      InstallHooks
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> InstallFlags
-> IO ()
defaultInstallHook_setupHooks
        (SetupHooks -> InstallHooks
SetupHooks.installHooks SetupHooks
setupHooks)

    setup_replHook
      :: PackageDescription
      -> LocalBuildInfo
      -> UserHooks
      -> ReplFlags
      -> [String]
      -> IO ()
    setup_replHook :: PackageDescription
-> LocalBuildInfo -> UserHooks -> ReplFlags -> [[Char]] -> IO ()
setup_replHook PackageDescription
pkg_descr LocalBuildInfo
lbi UserHooks
hooks ReplFlags
flags [[Char]]
args =
      BuildHooks
-> PackageDescription
-> LocalBuildInfo
-> ReplFlags
-> [PPSuffixHandler]
-> [[Char]]
-> IO ()
repl_setupHooks
        (SetupHooks -> BuildHooks
SetupHooks.buildHooks SetupHooks
setupHooks)
        PackageDescription
pkg_descr
        LocalBuildInfo
lbi
        ReplFlags
flags
        (UserHooks -> [PPSuffixHandler]
allSuffixHandlers UserHooks
hooks)
        [[Char]]
args

    setup_haddockHook
      :: PackageDescription
      -> LocalBuildInfo
      -> UserHooks
      -> HaddockFlags
      -> IO ()
    setup_haddockHook :: PackageDescription
-> LocalBuildInfo -> UserHooks -> HaddockFlags -> IO ()
setup_haddockHook PackageDescription
pkg_descr LocalBuildInfo
lbi UserHooks
hooks HaddockFlags
flags =
      BuildHooks
-> PackageDescription
-> LocalBuildInfo
-> [PPSuffixHandler]
-> HaddockFlags
-> IO ()
haddock_setupHooks
        (SetupHooks -> BuildHooks
SetupHooks.buildHooks SetupHooks
setupHooks)
        PackageDescription
pkg_descr
        LocalBuildInfo
lbi
        (UserHooks -> [PPSuffixHandler]
allSuffixHandlers UserHooks
hooks)
        HaddockFlags
flags

    setup_hscolourHook
      :: PackageDescription
      -> LocalBuildInfo
      -> UserHooks
      -> HscolourFlags
      -> IO ()
    setup_hscolourHook :: PackageDescription
-> LocalBuildInfo -> UserHooks -> HscolourFlags -> IO ()
setup_hscolourHook PackageDescription
pkg_descr LocalBuildInfo
lbi UserHooks
hooks HscolourFlags
flags =
      BuildHooks
-> PackageDescription
-> LocalBuildInfo
-> [PPSuffixHandler]
-> HscolourFlags
-> IO ()
hscolour_setupHooks
        (SetupHooks -> BuildHooks
SetupHooks.buildHooks SetupHooks
setupHooks)
        PackageDescription
pkg_descr
        LocalBuildInfo
lbi
        (UserHooks -> [PPSuffixHandler]
allSuffixHandlers UserHooks
hooks)
        HscolourFlags
flags

-- | A customizable version of 'defaultMain'.
defaultMainWithHooks :: UserHooks -> IO ()
defaultMainWithHooks :: UserHooks -> IO ()
defaultMainWithHooks UserHooks
hooks = IO [[Char]]
getArgs IO [[Char]] -> ([[Char]] -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= UserHooks -> [[Char]] -> IO ()
defaultMainHelper UserHooks
hooks

-- | A customizable version of 'defaultMain' that also takes the command
-- line arguments.
defaultMainWithHooksArgs :: UserHooks -> [String] -> IO ()
defaultMainWithHooksArgs :: UserHooks -> [[Char]] -> IO ()
defaultMainWithHooksArgs = UserHooks -> [[Char]] -> IO ()
defaultMainHelper

-- | Like 'defaultMain', but accepts the package description as input
-- rather than using IO to read it.
defaultMainNoRead :: GenericPackageDescription -> IO ()
defaultMainNoRead :: GenericPackageDescription -> IO ()
defaultMainNoRead = UserHooks -> GenericPackageDescription -> IO ()
defaultMainWithHooksNoRead UserHooks
simpleUserHooks

-- | A customizable version of 'defaultMainNoRead'.
defaultMainWithHooksNoRead :: UserHooks -> GenericPackageDescription -> IO ()
defaultMainWithHooksNoRead :: UserHooks -> GenericPackageDescription -> IO ()
defaultMainWithHooksNoRead UserHooks
hooks GenericPackageDescription
pkg_descr =
  IO [[Char]]
getArgs
    IO [[Char]] -> ([[Char]] -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= UserHooks -> [[Char]] -> IO ()
defaultMainHelper UserHooks
hooks{readDesc = return (Just pkg_descr)}

-- | A customizable version of 'defaultMainNoRead' that also takes the
-- command line arguments.
--
-- @since 2.2.0.0
defaultMainWithHooksNoReadArgs :: UserHooks -> GenericPackageDescription -> [String] -> IO ()
defaultMainWithHooksNoReadArgs :: UserHooks -> GenericPackageDescription -> [[Char]] -> IO ()
defaultMainWithHooksNoReadArgs UserHooks
hooks GenericPackageDescription
pkg_descr =
  UserHooks -> [[Char]] -> IO ()
defaultMainHelper UserHooks
hooks{readDesc = return (Just pkg_descr)}

-- | The central command chooser of the Simple build system,
-- with other defaultMain functions acting as exposed callers,
-- and with 'topHandler' operating as an exceptions handler.
--
-- This uses 'expandResponse' to read response files, preprocessing
-- response files given by "@" prefixes.
--
-- Given hooks and args, this runs 'commandsRun' onto the args,
-- getting 'CommandParse' data back, which is then pattern-matched into
-- IO actions for execution, with arguments applied by the parser.
defaultMainHelper :: UserHooks -> Args -> IO ()
defaultMainHelper :: UserHooks -> [[Char]] -> IO ()
defaultMainHelper UserHooks
hooks [[Char]]
args = IO () -> IO ()
forall a. IO a -> IO a
topHandler (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
  args' <- [[Char]] -> IO [[Char]]
expandResponse [[Char]]
args
  command <- commandsRun (globalCommand commands) commands args'
  case command of
    CommandHelp [Char] -> [Char]
help -> ([Char] -> [Char]) -> IO ()
printHelp [Char] -> [Char]
help
    CommandList [[Char]]
opts -> [[Char]] -> IO ()
printOptionsList [[Char]]
opts
    CommandErrors [[Char]]
errs -> [[Char]] -> IO ()
forall {b}. [[Char]] -> IO b
printErrors [[Char]]
errs
    CommandReadyToGo (GlobalFlags
globalFlags, CommandParse (GlobalFlags -> IO ())
commandParse) ->
      case CommandParse (GlobalFlags -> IO ())
commandParse of
        CommandParse (GlobalFlags -> IO ())
_
          | Flag Bool -> Bool
forall a. WithCallStack (Flag a -> a)
fromFlag (GlobalFlags -> Flag Bool
globalVersion GlobalFlags
globalFlags) -> IO ()
printVersion
          | Flag Bool -> Bool
forall a. WithCallStack (Flag a -> a)
fromFlag (GlobalFlags -> Flag Bool
globalNumericVersion GlobalFlags
globalFlags) -> IO ()
printNumericVersion
        CommandHelp [Char] -> [Char]
help -> ([Char] -> [Char]) -> IO ()
printHelp [Char] -> [Char]
help
        CommandList [[Char]]
opts -> [[Char]] -> IO ()
printOptionsList [[Char]]
opts
        CommandErrors [[Char]]
errs -> [[Char]] -> IO ()
forall {b}. [[Char]] -> IO b
printErrors [[Char]]
errs
        CommandReadyToGo GlobalFlags -> IO ()
action -> GlobalFlags -> IO ()
action GlobalFlags
globalFlags
  where
    printHelp :: ([Char] -> [Char]) -> IO ()
printHelp [Char] -> [Char]
help = IO [Char]
getProgName IO [Char] -> ([Char] -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Char] -> IO ()
putStr ([Char] -> IO ()) -> ([Char] -> [Char]) -> [Char] -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char]
help
    printOptionsList :: [[Char]] -> IO ()
printOptionsList = [Char] -> IO ()
putStr ([Char] -> IO ()) -> ([[Char]] -> [Char]) -> [[Char]] -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Char]] -> [Char]
unlines
    printErrors :: [[Char]] -> IO b
printErrors [[Char]]
errs = do
      [Char] -> IO ()
putStr ([Char] -> [[Char]] -> [Char]
forall a. [a] -> [[a]] -> [a]
intercalate [Char]
"\n" [[Char]]
errs)
      ExitCode -> IO b
forall a. ExitCode -> IO a
exitWith (Int -> ExitCode
ExitFailure Int
1)
    printNumericVersion :: IO ()
printNumericVersion = [Char] -> IO ()
putStrLn ([Char] -> IO ()) -> [Char] -> IO ()
forall a b. (a -> b) -> a -> b
$ Version -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow Version
cabalVersion
    printVersion :: IO ()
printVersion =
      [Char] -> IO ()
putStrLn ([Char] -> IO ()) -> [Char] -> IO ()
forall a b. (a -> b) -> a -> b
$
        [Char]
"Cabal library version "
          [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Version -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow Version
cabalVersion

    progs :: ProgramDb
progs = [Program] -> ProgramDb -> ProgramDb
addKnownPrograms (UserHooks -> [Program]
hookedPrograms UserHooks
hooks) ProgramDb
defaultProgramDb
    addAction :: CommandUI flags -> (GlobalFlags -> UserHooks -> flags -> [String] -> IO res) -> Command (GlobalFlags -> IO ())
    addAction :: forall flags res.
CommandUI flags
-> (GlobalFlags -> UserHooks -> flags -> [[Char]] -> IO res)
-> Command (GlobalFlags -> IO ())
addAction CommandUI flags
cmd GlobalFlags -> UserHooks -> flags -> [[Char]] -> IO res
action =
      CommandUI flags
cmd CommandUI flags
-> (flags -> [[Char]] -> GlobalFlags -> IO ())
-> Command (GlobalFlags -> IO ())
forall flags action.
CommandUI flags -> (flags -> [[Char]] -> action) -> Command action
`commandAddAction` \flags
flags [[Char]]
as GlobalFlags
globalFlags -> IO res -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO res -> IO ()) -> IO res -> IO ()
forall a b. (a -> b) -> a -> b
$ GlobalFlags -> UserHooks -> flags -> [[Char]] -> IO res
action GlobalFlags
globalFlags UserHooks
hooks flags
flags [[Char]]
as
    commands :: [Command (GlobalFlags -> IO ())]
    commands :: [Command (GlobalFlags -> IO ())]
commands =
      [ ProgramDb -> CommandUI ConfigFlags
configureCommand ProgramDb
progs CommandUI ConfigFlags
-> (GlobalFlags
    -> UserHooks -> ConfigFlags -> [[Char]] -> IO LocalBuildInfo)
-> Command (GlobalFlags -> IO ())
forall flags res.
CommandUI flags
-> (GlobalFlags -> UserHooks -> flags -> [[Char]] -> IO res)
-> Command (GlobalFlags -> IO ())
`addAction` GlobalFlags
-> UserHooks -> ConfigFlags -> [[Char]] -> IO LocalBuildInfo
configureAction
      , ProgramDb -> CommandUI BuildFlags
buildCommand ProgramDb
progs CommandUI BuildFlags
-> (GlobalFlags -> UserHooks -> BuildFlags -> [[Char]] -> IO ())
-> Command (GlobalFlags -> IO ())
forall flags res.
CommandUI flags
-> (GlobalFlags -> UserHooks -> flags -> [[Char]] -> IO res)
-> Command (GlobalFlags -> IO ())
`addAction` GlobalFlags -> UserHooks -> BuildFlags -> [[Char]] -> IO ()
buildAction
      , ProgramDb -> CommandUI ReplFlags
replCommand ProgramDb
progs CommandUI ReplFlags
-> (GlobalFlags -> UserHooks -> ReplFlags -> [[Char]] -> IO ())
-> Command (GlobalFlags -> IO ())
forall flags res.
CommandUI flags
-> (GlobalFlags -> UserHooks -> flags -> [[Char]] -> IO res)
-> Command (GlobalFlags -> IO ())
`addAction` GlobalFlags -> UserHooks -> ReplFlags -> [[Char]] -> IO ()
replAction
      , CommandUI InstallFlags
installCommand CommandUI InstallFlags
-> (GlobalFlags -> UserHooks -> InstallFlags -> [[Char]] -> IO ())
-> Command (GlobalFlags -> IO ())
forall flags res.
CommandUI flags
-> (GlobalFlags -> UserHooks -> flags -> [[Char]] -> IO res)
-> Command (GlobalFlags -> IO ())
`addAction` GlobalFlags -> UserHooks -> InstallFlags -> [[Char]] -> IO ()
installAction
      , CommandUI CopyFlags
copyCommand CommandUI CopyFlags
-> (GlobalFlags -> UserHooks -> CopyFlags -> [[Char]] -> IO ())
-> Command (GlobalFlags -> IO ())
forall flags res.
CommandUI flags
-> (GlobalFlags -> UserHooks -> flags -> [[Char]] -> IO res)
-> Command (GlobalFlags -> IO ())
`addAction` GlobalFlags -> UserHooks -> CopyFlags -> [[Char]] -> IO ()
copyAction
      , CommandUI HaddockFlags
haddockCommand CommandUI HaddockFlags
-> (GlobalFlags -> UserHooks -> HaddockFlags -> [[Char]] -> IO ())
-> Command (GlobalFlags -> IO ())
forall flags res.
CommandUI flags
-> (GlobalFlags -> UserHooks -> flags -> [[Char]] -> IO res)
-> Command (GlobalFlags -> IO ())
`addAction` GlobalFlags -> UserHooks -> HaddockFlags -> [[Char]] -> IO ()
haddockAction
      , CommandUI CleanFlags
cleanCommand CommandUI CleanFlags
-> (GlobalFlags -> UserHooks -> CleanFlags -> [[Char]] -> IO ())
-> Command (GlobalFlags -> IO ())
forall flags res.
CommandUI flags
-> (GlobalFlags -> UserHooks -> flags -> [[Char]] -> IO res)
-> Command (GlobalFlags -> IO ())
`addAction` GlobalFlags -> UserHooks -> CleanFlags -> [[Char]] -> IO ()
cleanAction
      , CommandUI SDistFlags
sdistCommand CommandUI SDistFlags
-> (GlobalFlags -> UserHooks -> SDistFlags -> [[Char]] -> IO ())
-> Command (GlobalFlags -> IO ())
forall flags res.
CommandUI flags
-> (GlobalFlags -> UserHooks -> flags -> [[Char]] -> IO res)
-> Command (GlobalFlags -> IO ())
`addAction` GlobalFlags -> UserHooks -> SDistFlags -> [[Char]] -> IO ()
sdistAction
      , CommandUI HscolourFlags
hscolourCommand CommandUI HscolourFlags
-> (GlobalFlags -> UserHooks -> HscolourFlags -> [[Char]] -> IO ())
-> Command (GlobalFlags -> IO ())
forall flags res.
CommandUI flags
-> (GlobalFlags -> UserHooks -> flags -> [[Char]] -> IO res)
-> Command (GlobalFlags -> IO ())
`addAction` GlobalFlags -> UserHooks -> HscolourFlags -> [[Char]] -> IO ()
hscolourAction
      , CommandUI RegisterFlags
registerCommand CommandUI RegisterFlags
-> (GlobalFlags -> UserHooks -> RegisterFlags -> [[Char]] -> IO ())
-> Command (GlobalFlags -> IO ())
forall flags res.
CommandUI flags
-> (GlobalFlags -> UserHooks -> flags -> [[Char]] -> IO res)
-> Command (GlobalFlags -> IO ())
`addAction` GlobalFlags -> UserHooks -> RegisterFlags -> [[Char]] -> IO ()
registerAction
      , CommandUI RegisterFlags
unregisterCommand CommandUI RegisterFlags
-> (GlobalFlags -> UserHooks -> RegisterFlags -> [[Char]] -> IO ())
-> Command (GlobalFlags -> IO ())
forall flags res.
CommandUI flags
-> (GlobalFlags -> UserHooks -> flags -> [[Char]] -> IO res)
-> Command (GlobalFlags -> IO ())
`addAction` GlobalFlags -> UserHooks -> RegisterFlags -> [[Char]] -> IO ()
unregisterAction
      , CommandUI TestFlags
testCommand CommandUI TestFlags
-> (GlobalFlags -> UserHooks -> TestFlags -> [[Char]] -> IO ())
-> Command (GlobalFlags -> IO ())
forall flags res.
CommandUI flags
-> (GlobalFlags -> UserHooks -> flags -> [[Char]] -> IO res)
-> Command (GlobalFlags -> IO ())
`addAction` GlobalFlags -> UserHooks -> TestFlags -> [[Char]] -> IO ()
testAction
      , CommandUI BenchmarkFlags
benchmarkCommand CommandUI BenchmarkFlags
-> (GlobalFlags
    -> UserHooks -> BenchmarkFlags -> [[Char]] -> IO ())
-> Command (GlobalFlags -> IO ())
forall flags res.
CommandUI flags
-> (GlobalFlags -> UserHooks -> flags -> [[Char]] -> IO res)
-> Command (GlobalFlags -> IO ())
`addAction` GlobalFlags -> UserHooks -> BenchmarkFlags -> [[Char]] -> IO ()
benchAction
      ]

-- | Combine the preprocessors in the given hooks with the
-- preprocessors built into cabal.
allSuffixHandlers
  :: UserHooks
  -> [PPSuffixHandler]
allSuffixHandlers :: UserHooks -> [PPSuffixHandler]
allSuffixHandlers UserHooks
hooks =
  [PPSuffixHandler] -> [PPSuffixHandler] -> [PPSuffixHandler]
overridesPP (UserHooks -> [PPSuffixHandler]
hookedPreProcessors UserHooks
hooks) [PPSuffixHandler]
knownSuffixHandlers
  where
    overridesPP :: [PPSuffixHandler] -> [PPSuffixHandler] -> [PPSuffixHandler]
    overridesPP :: [PPSuffixHandler] -> [PPSuffixHandler] -> [PPSuffixHandler]
overridesPP = (PPSuffixHandler -> PPSuffixHandler -> Bool)
-> [PPSuffixHandler] -> [PPSuffixHandler] -> [PPSuffixHandler]
forall a. (a -> a -> Bool) -> [a] -> [a] -> [a]
unionBy (\PPSuffixHandler
x PPSuffixHandler
y -> PPSuffixHandler -> Suffix
forall a b. (a, b) -> a
fst PPSuffixHandler
x Suffix -> Suffix -> Bool
forall a. Eq a => a -> a -> Bool
== PPSuffixHandler -> Suffix
forall a b. (a, b) -> a
fst PPSuffixHandler
y)

configureAction :: GlobalFlags -> UserHooks -> ConfigFlags -> Args -> IO LocalBuildInfo
configureAction :: GlobalFlags
-> UserHooks -> ConfigFlags -> [[Char]] -> IO LocalBuildInfo
configureAction GlobalFlags
globalFlags UserHooks
hooks ConfigFlags
flags [[Char]]
args = do
  distPref <- Flag (SymbolicPath Pkg ('Dir Dist))
-> IO (SymbolicPath Pkg ('Dir Dist))
findDistPrefOrDefault (CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
setupDistPref (CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist)))
-> CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
forall a b. (a -> b) -> a -> b
$ ConfigFlags -> CommonSetupFlags
configCommonFlags ConfigFlags
flags)
  let commonFlags = ConfigFlags -> CommonSetupFlags
configCommonFlags ConfigFlags
flags
      commonFlags' =
        CommonSetupFlags
commonFlags
          { setupDistPref = toFlag distPref
          , setupWorkingDir = globalWorkingDir globalFlags <> setupWorkingDir commonFlags
          , setupTargets = args
          }
      flags' =
        ConfigFlags
flags
          { configCommonFlags = commonFlags'
          }
      mbWorkDir = Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a. Flag a -> Maybe a
flagToMaybe (Flag (SymbolicPath CWD ('Dir Pkg))
 -> Maybe (SymbolicPath CWD ('Dir Pkg)))
-> Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
setupWorkingDir CommonSetupFlags
commonFlags'
      verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag Verbosity -> Verbosity) -> Flag Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
commonFlags'

  -- See docs for 'HookedBuildInfo'
  pbi <- preConf hooks args flags'

  (mb_pd_file, pkg_descr0) <-
    confPkgDescr
      hooks
      verbosity
      mbWorkDir
      (flagToMaybe (setupCabalFilePath commonFlags'))

  let epkg_descr = (GenericPackageDescription
pkg_descr0, HookedBuildInfo
pbi)

  lbi1 <- confHook hooks epkg_descr flags'

  -- remember the .cabal filename if we know it
  -- and all the extra command line args
  let localbuildinfo =
        LocalBuildInfo
lbi1
          { pkgDescrFile = mb_pd_file
          , extraConfigArgs = args
          }
  writePersistBuildConfig mbWorkDir distPref localbuildinfo

  let pkg_descr = LocalBuildInfo -> PackageDescription
localPkgDescr LocalBuildInfo
localbuildinfo
  postConf hooks args flags' pkg_descr localbuildinfo
  return localbuildinfo

confPkgDescr
  :: UserHooks
  -> Verbosity
  -> Maybe (SymbolicPath CWD (Dir Pkg))
  -> Maybe (SymbolicPath Pkg File)
  -> IO (Maybe (SymbolicPath Pkg File), GenericPackageDescription)
confPkgDescr :: UserHooks
-> Verbosity
-> Maybe (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath Pkg 'File)
-> IO (Maybe (SymbolicPath Pkg 'File), GenericPackageDescription)
confPkgDescr UserHooks
hooks Verbosity
verbosity Maybe (SymbolicPath CWD ('Dir Pkg))
cwd Maybe (SymbolicPath Pkg 'File)
mb_path = do
  mdescr <- UserHooks -> IO (Maybe GenericPackageDescription)
readDesc UserHooks
hooks
  case mdescr of
    Just GenericPackageDescription
descr -> (Maybe (SymbolicPath Pkg 'File), GenericPackageDescription)
-> IO (Maybe (SymbolicPath Pkg 'File), GenericPackageDescription)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (SymbolicPath Pkg 'File)
forall a. Maybe a
Nothing, GenericPackageDescription
descr)
    Maybe GenericPackageDescription
Nothing -> do
      pdfile <- case Maybe (SymbolicPath Pkg 'File)
mb_path of
        Maybe (SymbolicPath Pkg 'File)
Nothing -> RelativePath Pkg 'File -> SymbolicPath Pkg 'File
forall from (to :: FileOrDir).
RelativePath from to -> SymbolicPath from to
relativeSymbolicPath (RelativePath Pkg 'File -> SymbolicPath Pkg 'File)
-> IO (RelativePath Pkg 'File) -> IO (SymbolicPath Pkg 'File)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Verbosity
-> Maybe (SymbolicPath CWD ('Dir Pkg))
-> IO (RelativePath Pkg 'File)
tryFindPackageDesc Verbosity
verbosity Maybe (SymbolicPath CWD ('Dir Pkg))
cwd
        Just SymbolicPath Pkg 'File
path -> SymbolicPath Pkg 'File -> IO (SymbolicPath Pkg 'File)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return SymbolicPath Pkg 'File
path
      info verbosity "Using Parsec parser"
      descr <- readGenericPackageDescription verbosity cwd pdfile
      return (Just pdfile, descr)

getCommonFlags
  :: GlobalFlags
  -> UserHooks
  -> CommonSetupFlags
  -> Args
  -> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags :: GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
commonFlags [[Char]]
args = do
  distPref <- Flag (SymbolicPath Pkg ('Dir Dist))
-> IO (SymbolicPath Pkg ('Dir Dist))
findDistPrefOrDefault (CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
setupDistPref CommonSetupFlags
commonFlags)
  let verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag Verbosity -> Verbosity) -> Flag Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
commonFlags
  lbi <- getBuildConfig globalFlags hooks verbosity distPref
  let common' = ConfigFlags -> CommonSetupFlags
configCommonFlags (ConfigFlags -> CommonSetupFlags)
-> ConfigFlags -> CommonSetupFlags
forall a b. (a -> b) -> a -> b
$ LocalBuildInfo -> ConfigFlags
configFlags LocalBuildInfo
lbi
  return $
    ( lbi
    , commonFlags
        { setupDistPref = toFlag distPref
        , setupCabalFilePath = setupCabalFilePath common' <> setupCabalFilePath commonFlags
        , setupWorkingDir =
            globalWorkingDir globalFlags
              <> setupWorkingDir common'
              <> setupWorkingDir commonFlags
        , setupTargets = args
        }
    )

buildAction :: GlobalFlags -> UserHooks -> BuildFlags -> Args -> IO ()
buildAction :: GlobalFlags -> UserHooks -> BuildFlags -> [[Char]] -> IO ()
buildAction GlobalFlags
globalFlags UserHooks
hooks BuildFlags
flags [[Char]]
args = do
  let common :: CommonSetupFlags
common = BuildFlags -> CommonSetupFlags
buildCommonFlags BuildFlags
flags
      verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag Verbosity -> Verbosity) -> Flag Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
common
  (lbi, common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' = BuildFlags
flags{buildCommonFlags = common'}

  progs <-
    reconfigurePrograms
      verbosity
      (buildProgramPaths flags')
      (buildProgramArgs flags')
      (withPrograms lbi)

  hookedAction
    verbosity
    preBuild
    buildHook
    postBuild
    (return lbi{withPrograms = progs})
    hooks
    flags'
    args

replAction :: GlobalFlags -> UserHooks -> ReplFlags -> Args -> IO ()
replAction :: GlobalFlags -> UserHooks -> ReplFlags -> [[Char]] -> IO ()
replAction GlobalFlags
globalFlags UserHooks
hooks ReplFlags
flags [[Char]]
args = do
  let common :: CommonSetupFlags
common = ReplFlags -> CommonSetupFlags
replCommonFlags ReplFlags
flags
      verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag Verbosity -> Verbosity) -> Flag Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
common
  (lbi, common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' = ReplFlags
flags{replCommonFlags = common'}
  progs <-
    reconfigurePrograms
      verbosity
      (replProgramPaths flags')
      (replProgramArgs flags')
      (withPrograms lbi)

  -- As far as I can tell, the only reason this doesn't use
  -- 'hookedActionWithArgs' is because the arguments of 'replHook'
  -- takes the args explicitly.  UGH.   -- ezyang
  pbi <- preRepl hooks args flags'
  let pkg_descr0 = LocalBuildInfo -> PackageDescription
localPkgDescr LocalBuildInfo
lbi
  sanityCheckHookedBuildInfo verbosity pkg_descr0 pbi
  let pkg_descr = HookedBuildInfo -> PackageDescription -> PackageDescription
updatePackageDescription HookedBuildInfo
pbi PackageDescription
pkg_descr0
      lbi' =
        LocalBuildInfo
lbi
          { withPrograms = progs
          , localPkgDescr = pkg_descr
          }
  replHook hooks pkg_descr lbi' hooks flags' args
  postRepl hooks args flags' pkg_descr lbi'

hscolourAction :: GlobalFlags -> UserHooks -> HscolourFlags -> Args -> IO ()
hscolourAction :: GlobalFlags -> UserHooks -> HscolourFlags -> [[Char]] -> IO ()
hscolourAction GlobalFlags
globalFlags UserHooks
hooks HscolourFlags
flags [[Char]]
args = do
  let common :: CommonSetupFlags
common = HscolourFlags -> CommonSetupFlags
hscolourCommonFlags HscolourFlags
flags
      verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag Verbosity -> Verbosity) -> Flag Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
common
  (_lbi, common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' = HscolourFlags
flags{hscolourCommonFlags = common'}
      distPref = Flag (SymbolicPath Pkg ('Dir Dist)) -> SymbolicPath Pkg ('Dir Dist)
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag (SymbolicPath Pkg ('Dir Dist))
 -> SymbolicPath Pkg ('Dir Dist))
-> Flag (SymbolicPath Pkg ('Dir Dist))
-> SymbolicPath Pkg ('Dir Dist)
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
setupDistPref CommonSetupFlags
common'

  hookedAction
    verbosity
    preHscolour
    hscolourHook
    postHscolour
    (getBuildConfig globalFlags hooks verbosity distPref)
    hooks
    flags'
    args

haddockAction :: GlobalFlags -> UserHooks -> HaddockFlags -> Args -> IO ()
haddockAction :: GlobalFlags -> UserHooks -> HaddockFlags -> [[Char]] -> IO ()
haddockAction GlobalFlags
globalFlags UserHooks
hooks HaddockFlags
flags [[Char]]
args = do
  let common :: CommonSetupFlags
common = HaddockFlags -> CommonSetupFlags
haddockCommonFlags HaddockFlags
flags
      verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag Verbosity -> Verbosity) -> Flag Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
common
  (lbi, common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' = HaddockFlags
flags{haddockCommonFlags = common'}

  progs <-
    reconfigurePrograms
      verbosity
      (haddockProgramPaths flags')
      (haddockProgramArgs flags')
      (withPrograms lbi)

  hookedAction
    verbosity
    preHaddock
    haddockHook
    postHaddock
    (return lbi{withPrograms = progs})
    hooks
    flags'
    args

cleanAction :: GlobalFlags -> UserHooks -> CleanFlags -> Args -> IO ()
cleanAction :: GlobalFlags -> UserHooks -> CleanFlags -> [[Char]] -> IO ()
cleanAction GlobalFlags
globalFlags UserHooks
hooks CleanFlags
flags [[Char]]
args = do
  let common :: CommonSetupFlags
common = CleanFlags -> CommonSetupFlags
cleanCommonFlags CleanFlags
flags
      verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag Verbosity -> Verbosity) -> Flag Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
common
  distPref <- Flag (SymbolicPath Pkg ('Dir Dist))
-> IO (SymbolicPath Pkg ('Dir Dist))
findDistPrefOrDefault (CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
setupDistPref CommonSetupFlags
common)
  elbi <- tryGetBuildConfig globalFlags hooks verbosity distPref
  let common' =
        CommonSetupFlags
common
          { setupDistPref = toFlag distPref
          , setupWorkingDir = case elbi of
              Left ConfigStateFileError
_ ->
                GlobalFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
globalWorkingDir GlobalFlags
globalFlags
                  Flag (SymbolicPath CWD ('Dir Pkg))
-> Flag (SymbolicPath CWD ('Dir Pkg))
-> Flag (SymbolicPath CWD ('Dir Pkg))
forall a. Semigroup a => a -> a -> a
<> CommonSetupFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
setupWorkingDir CommonSetupFlags
common
              Right LocalBuildInfo
lbi ->
                GlobalFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
globalWorkingDir GlobalFlags
globalFlags
                  Flag (SymbolicPath CWD ('Dir Pkg))
-> Flag (SymbolicPath CWD ('Dir Pkg))
-> Flag (SymbolicPath CWD ('Dir Pkg))
forall a. Semigroup a => a -> a -> a
<> CommonSetupFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
setupWorkingDir (ConfigFlags -> CommonSetupFlags
configCommonFlags (ConfigFlags -> CommonSetupFlags)
-> ConfigFlags -> CommonSetupFlags
forall a b. (a -> b) -> a -> b
$ LocalBuildInfo -> ConfigFlags
configFlags LocalBuildInfo
lbi)
                  Flag (SymbolicPath CWD ('Dir Pkg))
-> Flag (SymbolicPath CWD ('Dir Pkg))
-> Flag (SymbolicPath CWD ('Dir Pkg))
forall a. Semigroup a => a -> a -> a
<> CommonSetupFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
setupWorkingDir CommonSetupFlags
common
          , setupCabalFilePath = case elbi of
              Left ConfigStateFileError
_ -> CommonSetupFlags -> Flag (SymbolicPath Pkg 'File)
setupCabalFilePath CommonSetupFlags
common
              Right LocalBuildInfo
lbi ->
                CommonSetupFlags -> Flag (SymbolicPath Pkg 'File)
setupCabalFilePath CommonSetupFlags
common
                  Flag (SymbolicPath Pkg 'File)
-> Flag (SymbolicPath Pkg 'File) -> Flag (SymbolicPath Pkg 'File)
forall a. Semigroup a => a -> a -> a
<> CommonSetupFlags -> Flag (SymbolicPath Pkg 'File)
setupCabalFilePath (ConfigFlags -> CommonSetupFlags
configCommonFlags (ConfigFlags -> CommonSetupFlags)
-> ConfigFlags -> CommonSetupFlags
forall a b. (a -> b) -> a -> b
$ LocalBuildInfo -> ConfigFlags
configFlags LocalBuildInfo
lbi)
          , setupTargets = args
          }
      flags' =
        CleanFlags
flags{cleanCommonFlags = common'}

      mbWorkDirFlag = CleanFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
cleanWorkingDir CleanFlags
flags'
      mbWorkDir = Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a. Flag a -> Maybe a
flagToMaybe Flag (SymbolicPath CWD ('Dir Pkg))
mbWorkDirFlag

  pbi <- preClean hooks args flags'

  (_, ppd) <- confPkgDescr hooks verbosity mbWorkDir Nothing
  -- It might seem like we are doing something clever here
  -- but we're really not: if you look at the implementation
  -- of 'clean' in the end all the package description is
  -- used for is to clear out @extra-tmp-files@.  IMO,
  -- the configure script goo should go into @dist@ too!
  --          -- ezyang
  let pkg_descr0 = GenericPackageDescription -> PackageDescription
flattenPackageDescription GenericPackageDescription
ppd
  -- We don't sanity check for clean as an error
  -- here would prevent cleaning:
  -- sanityCheckHookedBuildInfo verbosity pkg_descr0 pbi
  let pkg_descr = HookedBuildInfo -> PackageDescription -> PackageDescription
updatePackageDescription HookedBuildInfo
pbi PackageDescription
pkg_descr0

  cleanHook hooks pkg_descr () hooks flags'
  postClean hooks args flags' pkg_descr ()

copyAction :: GlobalFlags -> UserHooks -> CopyFlags -> Args -> IO ()
copyAction :: GlobalFlags -> UserHooks -> CopyFlags -> [[Char]] -> IO ()
copyAction GlobalFlags
globalFlags UserHooks
hooks CopyFlags
flags [[Char]]
args = do
  let common :: CommonSetupFlags
common = CopyFlags -> CommonSetupFlags
copyCommonFlags CopyFlags
flags
      verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag Verbosity -> Verbosity) -> Flag Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
common
  (_lbi, common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' = CopyFlags
flags{copyCommonFlags = common'}
      distPref = Flag (SymbolicPath Pkg ('Dir Dist)) -> SymbolicPath Pkg ('Dir Dist)
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag (SymbolicPath Pkg ('Dir Dist))
 -> SymbolicPath Pkg ('Dir Dist))
-> Flag (SymbolicPath Pkg ('Dir Dist))
-> SymbolicPath Pkg ('Dir Dist)
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
setupDistPref CommonSetupFlags
common'
  hookedAction
    verbosity
    preCopy
    copyHook
    postCopy
    (getBuildConfig globalFlags hooks verbosity distPref)
    hooks
    flags'
    args

installAction :: GlobalFlags -> UserHooks -> InstallFlags -> Args -> IO ()
installAction :: GlobalFlags -> UserHooks -> InstallFlags -> [[Char]] -> IO ()
installAction GlobalFlags
globalFlags UserHooks
hooks InstallFlags
flags [[Char]]
args = do
  let common :: CommonSetupFlags
common = InstallFlags -> CommonSetupFlags
installCommonFlags InstallFlags
flags
      verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag Verbosity -> Verbosity) -> Flag Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
common
  (_lbi, common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' = InstallFlags
flags{installCommonFlags = common'}
      distPref = Flag (SymbolicPath Pkg ('Dir Dist)) -> SymbolicPath Pkg ('Dir Dist)
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag (SymbolicPath Pkg ('Dir Dist))
 -> SymbolicPath Pkg ('Dir Dist))
-> Flag (SymbolicPath Pkg ('Dir Dist))
-> SymbolicPath Pkg ('Dir Dist)
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
setupDistPref CommonSetupFlags
common'
  hookedAction
    verbosity
    preInst
    instHook
    postInst
    (getBuildConfig globalFlags hooks verbosity distPref)
    hooks
    flags'
    args

-- Since Cabal-3.4 UserHooks are completely ignored
sdistAction :: GlobalFlags -> UserHooks -> SDistFlags -> Args -> IO ()
sdistAction :: GlobalFlags -> UserHooks -> SDistFlags -> [[Char]] -> IO ()
sdistAction GlobalFlags
_globalFlags UserHooks
_hooks SDistFlags
flags [[Char]]
_args = do
  let mbWorkDir :: Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir = Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a. Flag a -> Maybe a
flagToMaybe (Flag (SymbolicPath CWD ('Dir Pkg))
 -> Maybe (SymbolicPath CWD ('Dir Pkg)))
-> Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a b. (a -> b) -> a -> b
$ SDistFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
sDistWorkingDir SDistFlags
flags
  (_, ppd) <- UserHooks
-> Verbosity
-> Maybe (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath Pkg 'File)
-> IO (Maybe (SymbolicPath Pkg 'File), GenericPackageDescription)
confPkgDescr UserHooks
emptyUserHooks Verbosity
verbosity Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir Maybe (SymbolicPath Pkg 'File)
forall a. Maybe a
Nothing
  let pkg_descr = GenericPackageDescription -> PackageDescription
flattenPackageDescription GenericPackageDescription
ppd
  sdist pkg_descr flags srcPref knownSuffixHandlers
  where
    verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (CommonSetupFlags -> Flag Verbosity
setupVerbosity (CommonSetupFlags -> Flag Verbosity)
-> CommonSetupFlags -> Flag Verbosity
forall a b. (a -> b) -> a -> b
$ SDistFlags -> CommonSetupFlags
sDistCommonFlags SDistFlags
flags)

testAction :: GlobalFlags -> UserHooks -> TestFlags -> Args -> IO ()
testAction :: GlobalFlags -> UserHooks -> TestFlags -> [[Char]] -> IO ()
testAction GlobalFlags
globalFlags UserHooks
hooks TestFlags
flags [[Char]]
args = do
  let common :: CommonSetupFlags
common = TestFlags -> CommonSetupFlags
testCommonFlags TestFlags
flags
      verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag Verbosity -> Verbosity) -> Flag Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
common
  (_lbi, common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' = TestFlags
flags{testCommonFlags = common'}
      distPref = Flag (SymbolicPath Pkg ('Dir Dist)) -> SymbolicPath Pkg ('Dir Dist)
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag (SymbolicPath Pkg ('Dir Dist))
 -> SymbolicPath Pkg ('Dir Dist))
-> Flag (SymbolicPath Pkg ('Dir Dist))
-> SymbolicPath Pkg ('Dir Dist)
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
setupDistPref CommonSetupFlags
common'
  hookedActionWithArgs
    verbosity
    preTest
    testHook
    postTest
    (getBuildConfig globalFlags hooks verbosity distPref)
    hooks
    flags'
    args

benchAction :: GlobalFlags -> UserHooks -> BenchmarkFlags -> Args -> IO ()
benchAction :: GlobalFlags -> UserHooks -> BenchmarkFlags -> [[Char]] -> IO ()
benchAction GlobalFlags
globalFlags UserHooks
hooks BenchmarkFlags
flags [[Char]]
args = do
  let common :: CommonSetupFlags
common = BenchmarkFlags -> CommonSetupFlags
benchmarkCommonFlags BenchmarkFlags
flags
      verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag Verbosity -> Verbosity) -> Flag Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
common
  (_lbi, common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' = BenchmarkFlags
flags{benchmarkCommonFlags = common'}
      distPref = Flag (SymbolicPath Pkg ('Dir Dist)) -> SymbolicPath Pkg ('Dir Dist)
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag (SymbolicPath Pkg ('Dir Dist))
 -> SymbolicPath Pkg ('Dir Dist))
-> Flag (SymbolicPath Pkg ('Dir Dist))
-> SymbolicPath Pkg ('Dir Dist)
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
setupDistPref CommonSetupFlags
common'
  hookedActionWithArgs
    verbosity
    preBench
    benchHook
    postBench
    (getBuildConfig globalFlags hooks verbosity distPref)
    hooks
    flags'
    args

registerAction :: GlobalFlags -> UserHooks -> RegisterFlags -> Args -> IO ()
registerAction :: GlobalFlags -> UserHooks -> RegisterFlags -> [[Char]] -> IO ()
registerAction GlobalFlags
globalFlags UserHooks
hooks RegisterFlags
flags [[Char]]
args = do
  let common :: CommonSetupFlags
common = RegisterFlags -> CommonSetupFlags
registerCommonFlags RegisterFlags
flags
      verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag Verbosity -> Verbosity) -> Flag Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
common
  (_lbi, common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' = RegisterFlags
flags{registerCommonFlags = common'}
      distPref = Flag (SymbolicPath Pkg ('Dir Dist)) -> SymbolicPath Pkg ('Dir Dist)
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag (SymbolicPath Pkg ('Dir Dist))
 -> SymbolicPath Pkg ('Dir Dist))
-> Flag (SymbolicPath Pkg ('Dir Dist))
-> SymbolicPath Pkg ('Dir Dist)
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
setupDistPref CommonSetupFlags
common'
  hookedAction
    verbosity
    preReg
    regHook
    postReg
    (getBuildConfig globalFlags hooks verbosity distPref)
    hooks
    flags'
    args

unregisterAction :: GlobalFlags -> UserHooks -> RegisterFlags -> Args -> IO ()
unregisterAction :: GlobalFlags -> UserHooks -> RegisterFlags -> [[Char]] -> IO ()
unregisterAction GlobalFlags
globalFlags UserHooks
hooks RegisterFlags
flags [[Char]]
args = do
  let common :: CommonSetupFlags
common = RegisterFlags -> CommonSetupFlags
registerCommonFlags RegisterFlags
flags
      verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag Verbosity -> Verbosity) -> Flag Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
common
  (_lbi, common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' = RegisterFlags
flags{registerCommonFlags = common'}
      distPref = Flag (SymbolicPath Pkg ('Dir Dist)) -> SymbolicPath Pkg ('Dir Dist)
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag (SymbolicPath Pkg ('Dir Dist))
 -> SymbolicPath Pkg ('Dir Dist))
-> Flag (SymbolicPath Pkg ('Dir Dist))
-> SymbolicPath Pkg ('Dir Dist)
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
setupDistPref CommonSetupFlags
common'
  hookedAction
    verbosity
    preUnreg
    unregHook
    postUnreg
    (getBuildConfig globalFlags hooks verbosity distPref)
    hooks
    flags'
    args

hookedAction
  :: Verbosity
  -> (UserHooks -> Args -> flags -> IO HookedBuildInfo)
  -> ( UserHooks
       -> PackageDescription
       -> LocalBuildInfo
       -> UserHooks
       -> flags
       -> IO ()
     )
  -> ( UserHooks
       -> Args
       -> flags
       -> PackageDescription
       -> LocalBuildInfo
       -> IO ()
     )
  -> IO LocalBuildInfo
  -> UserHooks
  -> flags
  -> Args
  -> IO ()
hookedAction :: forall flags.
Verbosity
-> (UserHooks -> [[Char]] -> flags -> IO HookedBuildInfo)
-> (UserHooks
    -> PackageDescription
    -> LocalBuildInfo
    -> UserHooks
    -> flags
    -> IO ())
-> (UserHooks
    -> [[Char]]
    -> flags
    -> PackageDescription
    -> LocalBuildInfo
    -> IO ())
-> IO LocalBuildInfo
-> UserHooks
-> flags
-> [[Char]]
-> IO ()
hookedAction Verbosity
verbosity UserHooks -> [[Char]] -> flags -> IO HookedBuildInfo
pre_hook UserHooks
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> flags
-> IO ()
cmd_hook =
  Verbosity
-> (UserHooks -> [[Char]] -> flags -> IO HookedBuildInfo)
-> (UserHooks
    -> [[Char]]
    -> PackageDescription
    -> LocalBuildInfo
    -> UserHooks
    -> flags
    -> IO ())
-> (UserHooks
    -> [[Char]]
    -> flags
    -> PackageDescription
    -> LocalBuildInfo
    -> IO ())
-> IO LocalBuildInfo
-> UserHooks
-> flags
-> [[Char]]
-> IO ()
forall flags.
Verbosity
-> (UserHooks -> [[Char]] -> flags -> IO HookedBuildInfo)
-> (UserHooks
    -> [[Char]]
    -> PackageDescription
    -> LocalBuildInfo
    -> UserHooks
    -> flags
    -> IO ())
-> (UserHooks
    -> [[Char]]
    -> flags
    -> PackageDescription
    -> LocalBuildInfo
    -> IO ())
-> IO LocalBuildInfo
-> UserHooks
-> flags
-> [[Char]]
-> IO ()
hookedActionWithArgs
    Verbosity
verbosity
    UserHooks -> [[Char]] -> flags -> IO HookedBuildInfo
pre_hook
    ( \UserHooks
h [[Char]]
_ PackageDescription
pd LocalBuildInfo
lbi UserHooks
uh flags
flags ->
        UserHooks
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> flags
-> IO ()
cmd_hook UserHooks
h PackageDescription
pd LocalBuildInfo
lbi UserHooks
uh flags
flags
    )

hookedActionWithArgs
  :: Verbosity
  -> (UserHooks -> Args -> flags -> IO HookedBuildInfo)
  -> ( UserHooks
       -> Args
       -> PackageDescription
       -> LocalBuildInfo
       -> UserHooks
       -> flags
       -> IO ()
     )
  -> ( UserHooks
       -> Args
       -> flags
       -> PackageDescription
       -> LocalBuildInfo
       -> IO ()
     )
  -> IO LocalBuildInfo
  -> UserHooks
  -> flags
  -> Args
  -> IO ()
hookedActionWithArgs :: forall flags.
Verbosity
-> (UserHooks -> [[Char]] -> flags -> IO HookedBuildInfo)
-> (UserHooks
    -> [[Char]]
    -> PackageDescription
    -> LocalBuildInfo
    -> UserHooks
    -> flags
    -> IO ())
-> (UserHooks
    -> [[Char]]
    -> flags
    -> PackageDescription
    -> LocalBuildInfo
    -> IO ())
-> IO LocalBuildInfo
-> UserHooks
-> flags
-> [[Char]]
-> IO ()
hookedActionWithArgs
  Verbosity
verbosity
  UserHooks -> [[Char]] -> flags -> IO HookedBuildInfo
pre_hook
  UserHooks
-> [[Char]]
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> flags
-> IO ()
cmd_hook
  UserHooks
-> [[Char]]
-> flags
-> PackageDescription
-> LocalBuildInfo
-> IO ()
post_hook
  IO LocalBuildInfo
get_build_config
  UserHooks
hooks
  flags
flags
  [[Char]]
args = do
    pbi <- UserHooks -> [[Char]] -> flags -> IO HookedBuildInfo
pre_hook UserHooks
hooks [[Char]]
args flags
flags
    lbi0 <- get_build_config
    let pkg_descr0 = LocalBuildInfo -> PackageDescription
localPkgDescr LocalBuildInfo
lbi0
    sanityCheckHookedBuildInfo verbosity pkg_descr0 pbi
    let pkg_descr = HookedBuildInfo -> PackageDescription -> PackageDescription
updatePackageDescription HookedBuildInfo
pbi PackageDescription
pkg_descr0
        lbi = LocalBuildInfo
lbi0{localPkgDescr = pkg_descr}
    cmd_hook hooks args pkg_descr lbi hooks flags
    post_hook hooks args flags pkg_descr lbi

sanityCheckHookedBuildInfo
  :: Verbosity -> PackageDescription -> HookedBuildInfo -> IO ()
sanityCheckHookedBuildInfo :: Verbosity -> PackageDescription -> HookedBuildInfo -> IO ()
sanityCheckHookedBuildInfo
  Verbosity
verbosity
  (PackageDescription{library :: PackageDescription -> Maybe Library
library = Maybe Library
Nothing})
  (Just BuildInfo
_, [(UnqualComponentName, BuildInfo)]
_) =
    Verbosity -> CabalException -> IO ()
forall a1 a.
(HasCallStack, Show a1, Typeable a1,
 Exception (VerboseException a1)) =>
Verbosity -> a1 -> IO a
dieWithException Verbosity
verbosity (CabalException -> IO ()) -> CabalException -> IO ()
forall a b. (a -> b) -> a -> b
$ CabalException
NoLibraryForPackage
sanityCheckHookedBuildInfo Verbosity
verbosity PackageDescription
pkg_descr (Maybe BuildInfo
_, [(UnqualComponentName, BuildInfo)]
hookExes)
  | UnqualComponentName
exe1 : [UnqualComponentName]
_ <- [UnqualComponentName]
nonExistant =
      Verbosity -> CabalException -> IO ()
forall a1 a.
(HasCallStack, Show a1, Typeable a1,
 Exception (VerboseException a1)) =>
Verbosity -> a1 -> IO a
dieWithException Verbosity
verbosity (CabalException -> IO ()) -> CabalException -> IO ()
forall a b. (a -> b) -> a -> b
$ UnqualComponentName -> CabalException
SanityCheckHookedBuildInfo UnqualComponentName
exe1
  where
    pkgExeNames :: [UnqualComponentName]
pkgExeNames = [UnqualComponentName] -> [UnqualComponentName]
forall a. Eq a => [a] -> [a]
nub ((Executable -> UnqualComponentName)
-> [Executable] -> [UnqualComponentName]
forall a b. (a -> b) -> [a] -> [b]
map Executable -> UnqualComponentName
exeName (PackageDescription -> [Executable]
executables PackageDescription
pkg_descr))
    hookExeNames :: [UnqualComponentName]
hookExeNames = [UnqualComponentName] -> [UnqualComponentName]
forall a. Eq a => [a] -> [a]
nub (((UnqualComponentName, BuildInfo) -> UnqualComponentName)
-> [(UnqualComponentName, BuildInfo)] -> [UnqualComponentName]
forall a b. (a -> b) -> [a] -> [b]
map (UnqualComponentName, BuildInfo) -> UnqualComponentName
forall a b. (a, b) -> a
fst [(UnqualComponentName, BuildInfo)]
hookExes)
    nonExistant :: [UnqualComponentName]
nonExistant = [UnqualComponentName]
hookExeNames [UnqualComponentName]
-> [UnqualComponentName] -> [UnqualComponentName]
forall a. Eq a => [a] -> [a] -> [a]
\\ [UnqualComponentName]
pkgExeNames
sanityCheckHookedBuildInfo Verbosity
_ PackageDescription
_ HookedBuildInfo
_ = () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | Try to read the 'localBuildInfoFile'
tryGetBuildConfig
  :: GlobalFlags
  -> UserHooks
  -> Verbosity
  -> SymbolicPath Pkg (Dir Dist)
  -> IO (Either ConfigStateFileError LocalBuildInfo)
tryGetBuildConfig :: GlobalFlags
-> UserHooks
-> Verbosity
-> SymbolicPath Pkg ('Dir Dist)
-> IO (Either ConfigStateFileError LocalBuildInfo)
tryGetBuildConfig GlobalFlags
g UserHooks
u Verbosity
v = IO LocalBuildInfo
-> IO (Either ConfigStateFileError LocalBuildInfo)
forall e a. Exception e => IO a -> IO (Either e a)
try (IO LocalBuildInfo
 -> IO (Either ConfigStateFileError LocalBuildInfo))
-> (SymbolicPath Pkg ('Dir Dist) -> IO LocalBuildInfo)
-> SymbolicPath Pkg ('Dir Dist)
-> IO (Either ConfigStateFileError LocalBuildInfo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GlobalFlags
-> UserHooks
-> Verbosity
-> SymbolicPath Pkg ('Dir Dist)
-> IO LocalBuildInfo
getBuildConfig GlobalFlags
g UserHooks
u Verbosity
v

-- | Read the 'localBuildInfoFile' or throw an exception.
getBuildConfig
  :: GlobalFlags
  -> UserHooks
  -> Verbosity
  -> SymbolicPath Pkg (Dir Dist)
  -> IO LocalBuildInfo
getBuildConfig :: GlobalFlags
-> UserHooks
-> Verbosity
-> SymbolicPath Pkg ('Dir Dist)
-> IO LocalBuildInfo
getBuildConfig GlobalFlags
globalFlags UserHooks
hooks Verbosity
verbosity SymbolicPath Pkg ('Dir Dist)
distPref = do
  lbi_wo_programs <- Maybe (SymbolicPath CWD ('Dir Pkg))
-> SymbolicPath Pkg ('Dir Dist) -> IO LocalBuildInfo
getPersistBuildConfig Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir SymbolicPath Pkg ('Dir Dist)
distPref
  -- Restore info about unconfigured programs, since it is not serialized
  let lbi =
        LocalBuildInfo
lbi_wo_programs
          { withPrograms =
              restoreProgramDb
                (builtinPrograms ++ hookedPrograms hooks)
                (withPrograms lbi_wo_programs)
          }

  case pkgDescrFile lbi of
    Maybe (SymbolicPath Pkg 'File)
Nothing -> LocalBuildInfo -> IO LocalBuildInfo
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return LocalBuildInfo
lbi
    Just SymbolicPath Pkg 'File
pkg_descr_file -> do
      outdated <- Maybe (SymbolicPath CWD ('Dir Pkg))
-> SymbolicPath Pkg ('Dir Dist)
-> SymbolicPath Pkg 'File
-> IO Bool
checkPersistBuildConfigOutdated Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir SymbolicPath Pkg ('Dir Dist)
distPref SymbolicPath Pkg 'File
pkg_descr_file
      if outdated
        then reconfigure pkg_descr_file lbi
        else return lbi
  where
    mbWorkDir :: Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir = Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a. Flag a -> Maybe a
flagToMaybe (Flag (SymbolicPath CWD ('Dir Pkg))
 -> Maybe (SymbolicPath CWD ('Dir Pkg)))
-> Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a b. (a -> b) -> a -> b
$ GlobalFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
globalWorkingDir GlobalFlags
globalFlags
    reconfigure :: SymbolicPath Pkg File -> LocalBuildInfo -> IO LocalBuildInfo
    reconfigure :: SymbolicPath Pkg 'File -> LocalBuildInfo -> IO LocalBuildInfo
reconfigure SymbolicPath Pkg 'File
pkg_descr_file LocalBuildInfo
lbi = do
      Verbosity -> [Char] -> IO ()
notice Verbosity
verbosity ([Char] -> IO ()) -> [Char] -> IO ()
forall a b. (a -> b) -> a -> b
$
        SymbolicPath Pkg 'File -> [Char]
forall (allowAbsolute :: AllowAbsolute) from (to :: FileOrDir).
SymbolicPathX allowAbsolute from to -> [Char]
getSymbolicPath SymbolicPath Pkg 'File
pkg_descr_file
          [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" has been changed. "
          [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"Re-configuring with most recently used options. "
          [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"If this fails, please run configure manually.\n"
      let cFlags :: ConfigFlags
cFlags = LocalBuildInfo -> ConfigFlags
configFlags LocalBuildInfo
lbi
      let cFlags' :: ConfigFlags
cFlags' =
            ConfigFlags
cFlags
              { -- Since the list of unconfigured programs is not serialized,
                -- restore it to the same value as normally used at the beginning
                -- of a configure run:
                configPrograms_ =
                  fmap
                    ( restoreProgramDb
                        (builtinPrograms ++ hookedPrograms hooks)
                    )
                    `fmap` configPrograms_ cFlags
              , configCommonFlags =
                  (configCommonFlags cFlags)
                    { -- Use the current, not saved verbosity level:
                      setupVerbosity = Flag verbosity
                    }
              }
      GlobalFlags
-> UserHooks -> ConfigFlags -> [[Char]] -> IO LocalBuildInfo
configureAction GlobalFlags
globalFlags UserHooks
hooks ConfigFlags
cFlags' (LocalBuildInfo -> [[Char]]
extraConfigArgs LocalBuildInfo
lbi)

-- --------------------------------------------------------------------------
-- Cleaning

clean :: PackageDescription -> CleanFlags -> IO ()
clean :: PackageDescription -> CleanFlags -> IO ()
clean PackageDescription
pkg_descr CleanFlags
flags = do
  let common :: CommonSetupFlags
common = CleanFlags -> CommonSetupFlags
cleanCommonFlags CleanFlags
flags
      verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
common)
      distPref :: SymbolicPath Pkg ('Dir Dist)
distPref = SymbolicPath Pkg ('Dir Dist)
-> Flag (SymbolicPath Pkg ('Dir Dist))
-> SymbolicPath Pkg ('Dir Dist)
forall a. a -> Flag a -> a
fromFlagOrDefault SymbolicPath Pkg ('Dir Dist)
defaultDistPref (Flag (SymbolicPath Pkg ('Dir Dist))
 -> SymbolicPath Pkg ('Dir Dist))
-> Flag (SymbolicPath Pkg ('Dir Dist))
-> SymbolicPath Pkg ('Dir Dist)
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
setupDistPref CommonSetupFlags
common
      mbWorkDir :: Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir = Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a. Flag a -> Maybe a
flagToMaybe (Flag (SymbolicPath CWD ('Dir Pkg))
 -> Maybe (SymbolicPath CWD ('Dir Pkg)))
-> Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
setupWorkingDir CommonSetupFlags
common
      i :: SymbolicPathX allowAbsolute Pkg to -> [Char]
i = Maybe (SymbolicPath CWD ('Dir Pkg))
-> SymbolicPathX allowAbsolute Pkg to -> [Char]
forall from (allowAbsolute :: AllowAbsolute) (to :: FileOrDir).
Maybe (SymbolicPath CWD ('Dir from))
-> SymbolicPathX allowAbsolute from to -> [Char]
interpretSymbolicPath Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir -- See Note [Symbolic paths] in Distribution.Utils.Path
      distPath :: [Char]
distPath = SymbolicPath Pkg ('Dir Dist) -> [Char]
forall {allowAbsolute :: AllowAbsolute} {to :: FileOrDir}.
SymbolicPathX allowAbsolute Pkg to -> [Char]
i SymbolicPath Pkg ('Dir Dist)
distPref
  Verbosity -> [Char] -> IO ()
notice Verbosity
verbosity [Char]
"cleaning..."

  maybeConfig <-
    if Flag Bool -> Bool
forall a. WithCallStack (Flag a -> a)
fromFlag (CleanFlags -> Flag Bool
cleanSaveConf CleanFlags
flags)
      then Maybe (SymbolicPath CWD ('Dir Pkg))
-> SymbolicPath Pkg ('Dir Dist) -> IO (Maybe LocalBuildInfo)
maybeGetPersistBuildConfig Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir SymbolicPath Pkg ('Dir Dist)
distPref
      else Maybe LocalBuildInfo -> IO (Maybe LocalBuildInfo)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe LocalBuildInfo
forall a. Maybe a
Nothing

  -- remove the whole dist/ directory rather than tracking exactly what files
  -- we created in there.
  chattyTry "removing dist/" $ do
    exists <- doesDirectoryExist distPath
    when exists (removeDirectoryRecursive distPath)

  -- Any extra files the user wants to remove
  traverse_ (removeFileOrDirectory . i) (extraTmpFiles pkg_descr)

  -- If the user wanted to save the config, write it back
  traverse_ (writePersistBuildConfig mbWorkDir distPref) maybeConfig
  where
    removeFileOrDirectory :: FilePath -> IO ()
    removeFileOrDirectory :: [Char] -> IO ()
removeFileOrDirectory [Char]
fname = do
      isDir <- [Char] -> IO Bool
doesDirectoryExist [Char]
fname
      isFile <- doesFileExist fname
      if isDir
        then removeDirectoryRecursive fname
        else when isFile $ removeFile fname

-- --------------------------------------------------------------------------
-- Default hooks

-- | Hooks that correspond to a plain instantiation of the
-- \"simple\" build system
simpleUserHooks :: UserHooks
simpleUserHooks :: UserHooks
simpleUserHooks =
  UserHooks
emptyUserHooks
    { confHook = configure
    , postConf = finalChecks
    , buildHook = defaultBuildHook
    , replHook = defaultReplHook
    , copyHook = \PackageDescription
desc LocalBuildInfo
lbi UserHooks
_ CopyFlags
f -> PackageDescription -> LocalBuildInfo -> CopyFlags -> IO ()
install PackageDescription
desc LocalBuildInfo
lbi CopyFlags
f
    , -- 'install' has correct 'copy' behavior with params
      instHook = defaultInstallHook
    , testHook = defaultTestHook
    , benchHook = defaultBenchHook
    , cleanHook = \PackageDescription
p ()
_ UserHooks
_ CleanFlags
f -> PackageDescription -> CleanFlags -> IO ()
clean PackageDescription
p CleanFlags
f
    , hscolourHook = \PackageDescription
p LocalBuildInfo
l UserHooks
h HscolourFlags
f -> PackageDescription
-> LocalBuildInfo -> [PPSuffixHandler] -> HscolourFlags -> IO ()
hscolour PackageDescription
p LocalBuildInfo
l (UserHooks -> [PPSuffixHandler]
allSuffixHandlers UserHooks
h) HscolourFlags
f
    , haddockHook = \PackageDescription
p LocalBuildInfo
l UserHooks
h HaddockFlags
f -> PackageDescription
-> LocalBuildInfo -> [PPSuffixHandler] -> HaddockFlags -> IO ()
haddock PackageDescription
p LocalBuildInfo
l (UserHooks -> [PPSuffixHandler]
allSuffixHandlers UserHooks
h) HaddockFlags
f
    , regHook = defaultRegHook
    , unregHook = \PackageDescription
p LocalBuildInfo
l UserHooks
_ RegisterFlags
f -> PackageDescription -> LocalBuildInfo -> RegisterFlags -> IO ()
unregister PackageDescription
p LocalBuildInfo
l RegisterFlags
f
    }
  where
    finalChecks :: p -> ConfigFlags -> PackageDescription -> LocalBuildInfo -> IO ()
finalChecks p
_args ConfigFlags
flags PackageDescription
pkg_descr LocalBuildInfo
lbi =
      PackageDescription -> LocalBuildInfo -> Verbosity -> IO ()
checkForeignDeps PackageDescription
pkg_descr LocalBuildInfo
lbi (Verbosity -> Verbosity
lessVerbose Verbosity
verbosity)
      where
        verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (CommonSetupFlags -> Flag Verbosity
setupVerbosity (CommonSetupFlags -> Flag Verbosity)
-> CommonSetupFlags -> Flag Verbosity
forall a b. (a -> b) -> a -> b
$ ConfigFlags -> CommonSetupFlags
configCommonFlags ConfigFlags
flags)

-- | Basic autoconf 'UserHooks':
--
-- * 'postConf' runs @.\/configure@, if present.
--
-- * the pre-hooks, except for pre-conf, read additional build information from
--   /package/@.buildinfo@, if present.
--
-- Thus @configure@ can use local system information to generate
-- /package/@.buildinfo@ and possibly other files.
autoconfUserHooks :: UserHooks
autoconfUserHooks :: UserHooks
autoconfUserHooks =
  UserHooks
simpleUserHooks
    { postConf = defaultPostConf
    , preBuild = readHookWithArgs buildCommonFlags
    , preRepl = readHookWithArgs replCommonFlags
    , preCopy = readHookWithArgs copyCommonFlags
    , preClean = readHook cleanCommonFlags
    , preInst = readHook installCommonFlags
    , preHscolour = readHook hscolourCommonFlags
    , preHaddock = readHookWithArgs haddockCommonFlags
    , preReg = readHook registerCommonFlags
    , preUnreg = readHook registerCommonFlags
    , preTest = readHookWithArgs testCommonFlags
    , preBench = readHookWithArgs benchmarkCommonFlags
    }
  where
    defaultPostConf
      :: Args
      -> ConfigFlags
      -> PackageDescription
      -> LocalBuildInfo
      -> IO ()
    defaultPostConf :: [[Char]]
-> ConfigFlags -> PackageDescription -> LocalBuildInfo -> IO ()
defaultPostConf [[Char]]
args ConfigFlags
flags PackageDescription
pkg_descr LocalBuildInfo
lbi =
      do
        let common :: CommonSetupFlags
common = ConfigFlags -> CommonSetupFlags
configCommonFlags ConfigFlags
flags
            verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag Verbosity -> Verbosity) -> Flag Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
common
            mbWorkDir :: Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir = Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a. Flag a -> Maybe a
flagToMaybe (Flag (SymbolicPath CWD ('Dir Pkg))
 -> Maybe (SymbolicPath CWD ('Dir Pkg)))
-> Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
setupWorkingDir CommonSetupFlags
common
        ConfigFlags -> FlagAssignment -> ProgramDb -> Platform -> IO ()
runConfigureScript
          ConfigFlags
flags
          (LocalBuildInfo -> FlagAssignment
flagAssignment LocalBuildInfo
lbi)
          (LocalBuildInfo -> ProgramDb
withPrograms LocalBuildInfo
lbi)
          (LocalBuildInfo -> Platform
hostPlatform LocalBuildInfo
lbi)
        pbi <- Verbosity
-> Maybe (SymbolicPath CWD ('Dir Pkg))
-> SymbolicPath Pkg ('Dir Build)
-> IO HookedBuildInfo
getHookedBuildInfo Verbosity
verbosity Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir (LocalBuildInfo -> SymbolicPath Pkg ('Dir Build)
buildDir LocalBuildInfo
lbi)
        sanityCheckHookedBuildInfo verbosity pkg_descr pbi
        let pkg_descr' = HookedBuildInfo -> PackageDescription -> PackageDescription
updatePackageDescription HookedBuildInfo
pbi PackageDescription
pkg_descr
            lbi' = LocalBuildInfo
lbi{localPkgDescr = pkg_descr'}
        postConf simpleUserHooks args flags pkg_descr' lbi'

    readHookWithArgs
      :: (flags -> CommonSetupFlags)
      -> Args
      -> flags
      -> IO HookedBuildInfo
    readHookWithArgs :: forall flags.
(flags -> CommonSetupFlags)
-> [[Char]] -> flags -> IO HookedBuildInfo
readHookWithArgs flags -> CommonSetupFlags
get_common_flags [[Char]]
_args flags
flags = do
      let common :: CommonSetupFlags
common = flags -> CommonSetupFlags
get_common_flags flags
flags
          verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
common)
          mbWorkDir :: Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir = Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a. Flag a -> Maybe a
flagToMaybe (Flag (SymbolicPath CWD ('Dir Pkg))
 -> Maybe (SymbolicPath CWD ('Dir Pkg)))
-> Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
setupWorkingDir CommonSetupFlags
common
          distPref :: Flag (SymbolicPath Pkg ('Dir Dist))
distPref = CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
setupDistPref CommonSetupFlags
common
      dist_dir <- Flag (SymbolicPath Pkg ('Dir Dist))
-> IO (SymbolicPath Pkg ('Dir Dist))
findDistPrefOrDefault Flag (SymbolicPath Pkg ('Dir Dist))
distPref
      getHookedBuildInfo verbosity mbWorkDir (dist_dir </> makeRelativePathEx "build")

    readHook
      :: (flags -> CommonSetupFlags)
      -> Args
      -> flags
      -> IO HookedBuildInfo
    readHook :: forall flags.
(flags -> CommonSetupFlags)
-> [[Char]] -> flags -> IO HookedBuildInfo
readHook flags -> CommonSetupFlags
get_common_flags [[Char]]
args flags
flags = do
      let common :: CommonSetupFlags
common = flags -> CommonSetupFlags
get_common_flags flags
flags
          verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
common)
          mbWorkDir :: Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir = Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a. Flag a -> Maybe a
flagToMaybe (Flag (SymbolicPath CWD ('Dir Pkg))
 -> Maybe (SymbolicPath CWD ('Dir Pkg)))
-> Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a b. (a -> b) -> a -> b
$ CommonSetupFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
setupWorkingDir CommonSetupFlags
common
          distPref :: Flag (SymbolicPath Pkg ('Dir Dist))
distPref = CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
setupDistPref CommonSetupFlags
common
      [[Char]] -> IO ()
noExtraFlags [[Char]]
args
      dist_dir <- Flag (SymbolicPath Pkg ('Dir Dist))
-> IO (SymbolicPath Pkg ('Dir Dist))
findDistPrefOrDefault Flag (SymbolicPath Pkg ('Dir Dist))
distPref
      getHookedBuildInfo verbosity mbWorkDir (dist_dir </> makeRelativePathEx "build")

getHookedBuildInfo
  :: Verbosity
  -> Maybe (SymbolicPath CWD (Dir Pkg))
  -> SymbolicPath Pkg (Dir Build)
  -> IO HookedBuildInfo
getHookedBuildInfo :: Verbosity
-> Maybe (SymbolicPath CWD ('Dir Pkg))
-> SymbolicPath Pkg ('Dir Build)
-> IO HookedBuildInfo
getHookedBuildInfo Verbosity
verbosity Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir SymbolicPath Pkg ('Dir Build)
build_dir = do
  maybe_infoFile <- Verbosity
-> Maybe (SymbolicPath CWD ('Dir Pkg))
-> SymbolicPath Pkg ('Dir Build)
-> IO (Maybe (SymbolicPath Pkg 'File))
findHookedPackageDesc Verbosity
verbosity Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir SymbolicPath Pkg ('Dir Build)
build_dir
  case maybe_infoFile of
    Maybe (SymbolicPath Pkg 'File)
Nothing -> HookedBuildInfo -> IO HookedBuildInfo
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return HookedBuildInfo
emptyHookedBuildInfo
    Just SymbolicPath Pkg 'File
infoFile -> do
      Verbosity -> [Char] -> IO ()
info Verbosity
verbosity ([Char] -> IO ()) -> [Char] -> IO ()
forall a b. (a -> b) -> a -> b
$ [Char]
"Reading parameters from " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ SymbolicPath Pkg 'File -> [Char]
forall (allowAbsolute :: AllowAbsolute) from (to :: FileOrDir).
SymbolicPathX allowAbsolute from to -> [Char]
getSymbolicPath SymbolicPath Pkg 'File
infoFile
      Verbosity
-> Maybe (SymbolicPath CWD ('Dir Pkg))
-> SymbolicPath Pkg 'File
-> IO HookedBuildInfo
readHookedBuildInfo Verbosity
verbosity Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir SymbolicPath Pkg 'File
infoFile

autoconfSetupHooks :: SetupHooks
autoconfSetupHooks :: SetupHooks
autoconfSetupHooks =
  SetupHooks
SetupHooks.noSetupHooks
    { SetupHooks.configureHooks =
        SetupHooks.noConfigureHooks
          { SetupHooks.postConfPackageHook = Just post_conf_pkg
          , SetupHooks.preConfComponentHook = Just pre_conf_comp
          }
    }
  where
    post_conf_pkg
      :: SetupHooks.PostConfPackageInputs
      -> IO ()
    post_conf_pkg :: PostConfPackageHook
post_conf_pkg
      ( SetupHooks.PostConfPackageInputs
          { localBuildConfig :: PostConfPackageInputs -> LocalBuildConfig
SetupHooks.localBuildConfig =
            LBC.LocalBuildConfig{withPrograms :: LocalBuildConfig -> ProgramDb
LBC.withPrograms = ProgramDb
progs}
          , packageBuildDescr :: PostConfPackageInputs -> PackageBuildDescr
SetupHooks.packageBuildDescr =
            LBC.PackageBuildDescr
              { configFlags :: PackageBuildDescr -> ConfigFlags
LBC.configFlags = ConfigFlags
cfg
              , flagAssignment :: PackageBuildDescr -> FlagAssignment
LBC.flagAssignment = FlagAssignment
flags
              , hostPlatform :: PackageBuildDescr -> Platform
LBC.hostPlatform = Platform
plat
              }
          }
        ) = ConfigFlags -> FlagAssignment -> ProgramDb -> Platform -> IO ()
runConfigureScript ConfigFlags
cfg FlagAssignment
flags ProgramDb
progs Platform
plat

    pre_conf_comp
      :: SetupHooks.PreConfComponentInputs
      -> IO SetupHooks.PreConfComponentOutputs
    pre_conf_comp :: PreConfComponentHook
pre_conf_comp
      ( SetupHooks.PreConfComponentInputs
          { packageBuildDescr :: PreConfComponentInputs -> PackageBuildDescr
SetupHooks.packageBuildDescr =
            LBC.PackageBuildDescr
              { configFlags :: PackageBuildDescr -> ConfigFlags
LBC.configFlags = ConfigFlags
cfg
              , localPkgDescr :: PackageBuildDescr -> PackageDescription
localPkgDescr = PackageDescription
pkg_descr
              }
          , component :: PreConfComponentInputs -> Component
SetupHooks.component = Component
component
          }
        ) = do
        let verbosity :: Verbosity
verbosity = Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (Flag Verbosity -> Verbosity) -> Flag Verbosity -> Verbosity
forall a b. (a -> b) -> a -> b
$ ConfigFlags -> Flag Verbosity
configVerbosity ConfigFlags
cfg
            mbWorkDir :: Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir = Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a. Flag a -> Maybe a
flagToMaybe (Flag (SymbolicPath CWD ('Dir Pkg))
 -> Maybe (SymbolicPath CWD ('Dir Pkg)))
-> Flag (SymbolicPath CWD ('Dir Pkg))
-> Maybe (SymbolicPath CWD ('Dir Pkg))
forall a b. (a -> b) -> a -> b
$ ConfigFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
configWorkingDir ConfigFlags
cfg
            distPref :: Flag (SymbolicPath Pkg ('Dir Dist))
distPref = ConfigFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
configDistPref ConfigFlags
cfg
        dist_dir <- Flag (SymbolicPath Pkg ('Dir Dist))
-> IO (SymbolicPath Pkg ('Dir Dist))
findDistPrefOrDefault Flag (SymbolicPath Pkg ('Dir Dist))
distPref
        -- Read the ".buildinfo" file and use that to update
        -- the components (main library + executables only).
        hbi <- getHookedBuildInfo verbosity mbWorkDir (dist_dir </> makeRelativePathEx "build")
        sanityCheckHookedBuildInfo verbosity pkg_descr hbi
        -- SetupHooks TODO: we are reading getHookedBuildInfo once
        -- for each component. I think this is inherent to the SetupHooks
        -- approach.
        let comp_name = Component -> ComponentName
componentName Component
component
        diff <- case SetupHooks.hookedBuildInfoComponentDiff_maybe hbi comp_name of
          Maybe (IO ComponentDiff)
Nothing -> ComponentDiff -> IO ComponentDiff
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ComponentDiff -> IO ComponentDiff)
-> ComponentDiff -> IO ComponentDiff
forall a b. (a -> b) -> a -> b
$ ComponentName -> ComponentDiff
SetupHooks.emptyComponentDiff ComponentName
comp_name
          Just IO ComponentDiff
do_diff -> IO ComponentDiff
do_diff
        return $
          SetupHooks.PreConfComponentOutputs
            { SetupHooks.componentDiff = diff
            }

defaultTestHook
  :: Args
  -> PackageDescription
  -> LocalBuildInfo
  -> UserHooks
  -> TestFlags
  -> IO ()
defaultTestHook :: [[Char]]
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> TestFlags
-> IO ()
defaultTestHook [[Char]]
args PackageDescription
pkg_descr LocalBuildInfo
localbuildinfo UserHooks
_ TestFlags
flags =
  [[Char]]
-> PackageDescription -> LocalBuildInfo -> TestFlags -> IO ()
test [[Char]]
args PackageDescription
pkg_descr LocalBuildInfo
localbuildinfo TestFlags
flags

defaultBenchHook
  :: Args
  -> PackageDescription
  -> LocalBuildInfo
  -> UserHooks
  -> BenchmarkFlags
  -> IO ()
defaultBenchHook :: [[Char]]
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> BenchmarkFlags
-> IO ()
defaultBenchHook [[Char]]
args PackageDescription
pkg_descr LocalBuildInfo
localbuildinfo UserHooks
_ BenchmarkFlags
flags =
  [[Char]]
-> PackageDescription -> LocalBuildInfo -> BenchmarkFlags -> IO ()
bench [[Char]]
args PackageDescription
pkg_descr LocalBuildInfo
localbuildinfo BenchmarkFlags
flags

defaultInstallHook
  :: PackageDescription
  -> LocalBuildInfo
  -> UserHooks
  -> InstallFlags
  -> IO ()
defaultInstallHook :: PackageDescription
-> LocalBuildInfo -> UserHooks -> InstallFlags -> IO ()
defaultInstallHook =
  InstallHooks
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> InstallFlags
-> IO ()
defaultInstallHook_setupHooks InstallHooks
SetupHooks.noInstallHooks

defaultInstallHook_setupHooks
  :: SetupHooks.InstallHooks
  -> PackageDescription
  -> LocalBuildInfo
  -> UserHooks
  -> InstallFlags
  -> IO ()
defaultInstallHook_setupHooks :: InstallHooks
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> InstallFlags
-> IO ()
defaultInstallHook_setupHooks InstallHooks
inst_hooks PackageDescription
pkg_descr LocalBuildInfo
localbuildinfo UserHooks
_ InstallFlags
flags = do
  let copyFlags :: CopyFlags
copyFlags =
        CopyFlags
defaultCopyFlags
          { copyDest = installDest flags
          , copyCommonFlags = installCommonFlags flags
          }
  InstallHooks
-> PackageDescription -> LocalBuildInfo -> CopyFlags -> IO ()
install_setupHooks InstallHooks
inst_hooks PackageDescription
pkg_descr LocalBuildInfo
localbuildinfo CopyFlags
copyFlags
  let registerFlags :: RegisterFlags
registerFlags =
        RegisterFlags
defaultRegisterFlags
          { regInPlace = installInPlace flags
          , regPackageDB = installPackageDB flags
          , registerCommonFlags = installCommonFlags flags
          }
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (PackageDescription -> Bool
hasLibs PackageDescription
pkg_descr) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
    PackageDescription -> LocalBuildInfo -> RegisterFlags -> IO ()
register PackageDescription
pkg_descr LocalBuildInfo
localbuildinfo RegisterFlags
registerFlags

defaultBuildHook
  :: PackageDescription
  -> LocalBuildInfo
  -> UserHooks
  -> BuildFlags
  -> IO ()
defaultBuildHook :: PackageDescription
-> LocalBuildInfo -> UserHooks -> BuildFlags -> IO ()
defaultBuildHook PackageDescription
pkg_descr LocalBuildInfo
localbuildinfo UserHooks
hooks BuildFlags
flags =
  PackageDescription
-> LocalBuildInfo -> BuildFlags -> [PPSuffixHandler] -> IO ()
build PackageDescription
pkg_descr LocalBuildInfo
localbuildinfo BuildFlags
flags (UserHooks -> [PPSuffixHandler]
allSuffixHandlers UserHooks
hooks)

defaultReplHook
  :: PackageDescription
  -> LocalBuildInfo
  -> UserHooks
  -> ReplFlags
  -> [String]
  -> IO ()
defaultReplHook :: PackageDescription
-> LocalBuildInfo -> UserHooks -> ReplFlags -> [[Char]] -> IO ()
defaultReplHook PackageDescription
pkg_descr LocalBuildInfo
localbuildinfo UserHooks
hooks ReplFlags
flags [[Char]]
args =
  PackageDescription
-> LocalBuildInfo
-> ReplFlags
-> [PPSuffixHandler]
-> [[Char]]
-> IO ()
repl PackageDescription
pkg_descr LocalBuildInfo
localbuildinfo ReplFlags
flags (UserHooks -> [PPSuffixHandler]
allSuffixHandlers UserHooks
hooks) [[Char]]
args

defaultRegHook
  :: PackageDescription
  -> LocalBuildInfo
  -> UserHooks
  -> RegisterFlags
  -> IO ()
defaultRegHook :: PackageDescription
-> LocalBuildInfo -> UserHooks -> RegisterFlags -> IO ()
defaultRegHook PackageDescription
pkg_descr LocalBuildInfo
localbuildinfo UserHooks
_ RegisterFlags
flags =
  if PackageDescription -> Bool
hasLibs PackageDescription
pkg_descr
    then PackageDescription -> LocalBuildInfo -> RegisterFlags -> IO ()
register PackageDescription
pkg_descr LocalBuildInfo
localbuildinfo RegisterFlags
flags
    else
      Verbosity -> [Char] -> PackageIdentifier -> IO ()
setupMessage
        (Flag Verbosity -> Verbosity
forall a. WithCallStack (Flag a -> a)
fromFlag (CommonSetupFlags -> Flag Verbosity
setupVerbosity (CommonSetupFlags -> Flag Verbosity)
-> CommonSetupFlags -> Flag Verbosity
forall a b. (a -> b) -> a -> b
$ RegisterFlags -> CommonSetupFlags
registerCommonFlags RegisterFlags
flags))
        [Char]
"Package contains no library to register:"
        (PackageDescription -> PackageIdentifier
forall pkg. Package pkg => pkg -> PackageIdentifier
packageId PackageDescription
pkg_descr)