{-# 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
  [[Char]]
args' <- [[Char]] -> IO [[Char]]
expandResponse [[Char]]
args
  CommandParse (GlobalFlags, CommandParse (GlobalFlags -> IO ()))
command <- CommandUI GlobalFlags
-> [Command (GlobalFlags -> IO ())]
-> [[Char]]
-> IO
     (CommandParse (GlobalFlags, CommandParse (GlobalFlags -> IO ())))
forall a action.
CommandUI a
-> [Command action]
-> [[Char]]
-> IO (CommandParse (a, CommandParse action))
commandsRun ([Command (GlobalFlags -> IO ())] -> CommandUI GlobalFlags
forall action. [Command action] -> CommandUI GlobalFlags
globalCommand [Command (GlobalFlags -> IO ())]
commands) [Command (GlobalFlags -> IO ())]
commands [[Char]]
args'
  case CommandParse (GlobalFlags, CommandParse (GlobalFlags -> IO ()))
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
  SymbolicPath Pkg ('Dir Dist)
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 :: CommonSetupFlags
commonFlags = ConfigFlags -> CommonSetupFlags
configCommonFlags ConfigFlags
flags
      commonFlags' :: CommonSetupFlags
commonFlags' =
        CommonSetupFlags
commonFlags
          { setupDistPref = toFlag distPref
          , setupWorkingDir = globalWorkingDir globalFlags <> setupWorkingDir commonFlags
          , setupTargets = args
          }
      flags' :: ConfigFlags
flags' =
        ConfigFlags
flags
          { configCommonFlags = commonFlags'
          }
      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
commonFlags'
      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
commonFlags'

  -- See docs for 'HookedBuildInfo'
  HookedBuildInfo
pbi <- UserHooks -> [[Char]] -> ConfigFlags -> IO HookedBuildInfo
preConf UserHooks
hooks [[Char]]
args ConfigFlags
flags'

  (Maybe (SymbolicPath Pkg 'File)
mb_pd_file, GenericPackageDescription
pkg_descr0) <-
    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))
mbWorkDir
      (Flag (SymbolicPath Pkg 'File) -> Maybe (SymbolicPath Pkg 'File)
forall a. Flag a -> Maybe a
flagToMaybe (CommonSetupFlags -> Flag (SymbolicPath Pkg 'File)
setupCabalFilePath CommonSetupFlags
commonFlags'))

  let epkg_descr :: (GenericPackageDescription, HookedBuildInfo)
epkg_descr = (GenericPackageDescription
pkg_descr0, HookedBuildInfo
pbi)

  LocalBuildInfo
lbi1 <- UserHooks
-> (GenericPackageDescription, HookedBuildInfo)
-> ConfigFlags
-> IO LocalBuildInfo
confHook UserHooks
hooks (GenericPackageDescription, HookedBuildInfo)
epkg_descr ConfigFlags
flags'

  -- remember the .cabal filename if we know it
  -- and all the extra command line args
  let localbuildinfo :: LocalBuildInfo
localbuildinfo =
        LocalBuildInfo
lbi1
          { pkgDescrFile = mb_pd_file
          , extraConfigArgs = args
          }
  Maybe (SymbolicPath CWD ('Dir Pkg))
-> SymbolicPath Pkg ('Dir Dist) -> LocalBuildInfo -> IO ()
writePersistBuildConfig Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir SymbolicPath Pkg ('Dir Dist)
distPref LocalBuildInfo
localbuildinfo

  let pkg_descr :: PackageDescription
pkg_descr = LocalBuildInfo -> PackageDescription
localPkgDescr LocalBuildInfo
localbuildinfo
  UserHooks
-> [[Char]]
-> ConfigFlags
-> PackageDescription
-> LocalBuildInfo
-> IO ()
postConf UserHooks
hooks [[Char]]
args ConfigFlags
flags' PackageDescription
pkg_descr LocalBuildInfo
localbuildinfo
  LocalBuildInfo -> IO LocalBuildInfo
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return LocalBuildInfo
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
  Maybe GenericPackageDescription
mdescr <- UserHooks -> IO (Maybe GenericPackageDescription)
readDesc UserHooks
hooks
  case Maybe GenericPackageDescription
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
      SymbolicPath Pkg 'File
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
      Verbosity -> [Char] -> IO ()
info Verbosity
verbosity [Char]
"Using Parsec parser"
      GenericPackageDescription
descr <- HasCallStack =>
Verbosity
-> Maybe (SymbolicPath CWD ('Dir Pkg))
-> SymbolicPath Pkg 'File
-> IO GenericPackageDescription
Verbosity
-> Maybe (SymbolicPath CWD ('Dir Pkg))
-> SymbolicPath Pkg 'File
-> IO GenericPackageDescription
readGenericPackageDescription Verbosity
verbosity Maybe (SymbolicPath CWD ('Dir Pkg))
cwd SymbolicPath Pkg 'File
pdfile
      (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 (SymbolicPath Pkg 'File -> Maybe (SymbolicPath Pkg 'File)
forall a. a -> Maybe a
Just SymbolicPath Pkg 'File
pdfile, GenericPackageDescription
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
  SymbolicPath Pkg ('Dir Dist)
distPref <- Flag (SymbolicPath Pkg ('Dir Dist))
-> IO (SymbolicPath Pkg ('Dir Dist))
findDistPrefOrDefault (CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
setupDistPref CommonSetupFlags
commonFlags)
  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
$ CommonSetupFlags -> Flag Verbosity
setupVerbosity CommonSetupFlags
commonFlags
  LocalBuildInfo
lbi <- GlobalFlags
-> UserHooks
-> Verbosity
-> SymbolicPath Pkg ('Dir Dist)
-> IO LocalBuildInfo
getBuildConfig GlobalFlags
globalFlags UserHooks
hooks Verbosity
verbosity SymbolicPath Pkg ('Dir Dist)
distPref
  let common' :: CommonSetupFlags
common' = ConfigFlags -> CommonSetupFlags
configCommonFlags (ConfigFlags -> CommonSetupFlags)
-> ConfigFlags -> CommonSetupFlags
forall a b. (a -> b) -> a -> b
$ LocalBuildInfo -> ConfigFlags
configFlags LocalBuildInfo
lbi
  (LocalBuildInfo, CommonSetupFlags)
-> IO (LocalBuildInfo, CommonSetupFlags)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ((LocalBuildInfo, CommonSetupFlags)
 -> IO (LocalBuildInfo, CommonSetupFlags))
-> (LocalBuildInfo, CommonSetupFlags)
-> IO (LocalBuildInfo, CommonSetupFlags)
forall a b. (a -> b) -> a -> b
$
    ( LocalBuildInfo
lbi
    , CommonSetupFlags
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
  (LocalBuildInfo
lbi, CommonSetupFlags
common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' :: BuildFlags
flags' = BuildFlags
flags{buildCommonFlags = common'}

  ProgramDb
progs <-
    Verbosity
-> [([Char], [Char])]
-> [([Char], [[Char]])]
-> ProgramDb
-> IO ProgramDb
reconfigurePrograms
      Verbosity
verbosity
      (BuildFlags -> [([Char], [Char])]
buildProgramPaths BuildFlags
flags')
      (BuildFlags -> [([Char], [[Char]])]
buildProgramArgs BuildFlags
flags')
      (LocalBuildInfo -> ProgramDb
withPrograms LocalBuildInfo
lbi)

  Verbosity
-> (UserHooks -> [[Char]] -> BuildFlags -> IO HookedBuildInfo)
-> (UserHooks
    -> PackageDescription
    -> LocalBuildInfo
    -> UserHooks
    -> BuildFlags
    -> IO ())
-> (UserHooks
    -> [[Char]]
    -> BuildFlags
    -> PackageDescription
    -> LocalBuildInfo
    -> IO ())
-> IO LocalBuildInfo
-> UserHooks
-> BuildFlags
-> [[Char]]
-> IO ()
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]] -> BuildFlags -> IO HookedBuildInfo
preBuild
    UserHooks
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> BuildFlags
-> IO ()
buildHook
    UserHooks
-> [[Char]]
-> BuildFlags
-> PackageDescription
-> LocalBuildInfo
-> IO ()
postBuild
    (LocalBuildInfo -> IO LocalBuildInfo
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return LocalBuildInfo
lbi{withPrograms = progs})
    UserHooks
hooks
    BuildFlags
flags'
    [[Char]]
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
  (LocalBuildInfo
lbi, CommonSetupFlags
common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' :: ReplFlags
flags' = ReplFlags
flags{replCommonFlags = common'}
  ProgramDb
progs <-
    Verbosity
-> [([Char], [Char])]
-> [([Char], [[Char]])]
-> ProgramDb
-> IO ProgramDb
reconfigurePrograms
      Verbosity
verbosity
      (ReplFlags -> [([Char], [Char])]
replProgramPaths ReplFlags
flags')
      (ReplFlags -> [([Char], [[Char]])]
replProgramArgs ReplFlags
flags')
      (LocalBuildInfo -> ProgramDb
withPrograms LocalBuildInfo
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
  HookedBuildInfo
pbi <- UserHooks -> [[Char]] -> ReplFlags -> IO HookedBuildInfo
preRepl UserHooks
hooks [[Char]]
args ReplFlags
flags'
  let pkg_descr0 :: PackageDescription
pkg_descr0 = LocalBuildInfo -> PackageDescription
localPkgDescr LocalBuildInfo
lbi
  Verbosity -> PackageDescription -> HookedBuildInfo -> IO ()
sanityCheckHookedBuildInfo Verbosity
verbosity PackageDescription
pkg_descr0 HookedBuildInfo
pbi
  let pkg_descr :: PackageDescription
pkg_descr = HookedBuildInfo -> PackageDescription -> PackageDescription
updatePackageDescription HookedBuildInfo
pbi PackageDescription
pkg_descr0
      lbi' :: LocalBuildInfo
lbi' =
        LocalBuildInfo
lbi
          { withPrograms = progs
          , localPkgDescr = pkg_descr
          }
  UserHooks
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> ReplFlags
-> [[Char]]
-> IO ()
replHook UserHooks
hooks PackageDescription
pkg_descr LocalBuildInfo
lbi' UserHooks
hooks ReplFlags
flags' [[Char]]
args
  UserHooks
-> [[Char]]
-> ReplFlags
-> PackageDescription
-> LocalBuildInfo
-> IO ()
postRepl UserHooks
hooks [[Char]]
args ReplFlags
flags' PackageDescription
pkg_descr LocalBuildInfo
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
  (LocalBuildInfo
_lbi, CommonSetupFlags
common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' :: HscolourFlags
flags' = HscolourFlags
flags{hscolourCommonFlags = common'}
      distPref :: SymbolicPath Pkg ('Dir Dist)
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'

  Verbosity
-> (UserHooks -> [[Char]] -> HscolourFlags -> IO HookedBuildInfo)
-> (UserHooks
    -> PackageDescription
    -> LocalBuildInfo
    -> UserHooks
    -> HscolourFlags
    -> IO ())
-> (UserHooks
    -> [[Char]]
    -> HscolourFlags
    -> PackageDescription
    -> LocalBuildInfo
    -> IO ())
-> IO LocalBuildInfo
-> UserHooks
-> HscolourFlags
-> [[Char]]
-> IO ()
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]] -> HscolourFlags -> IO HookedBuildInfo
preHscolour
    UserHooks
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> HscolourFlags
-> IO ()
hscolourHook
    UserHooks
-> [[Char]]
-> HscolourFlags
-> PackageDescription
-> LocalBuildInfo
-> IO ()
postHscolour
    (GlobalFlags
-> UserHooks
-> Verbosity
-> SymbolicPath Pkg ('Dir Dist)
-> IO LocalBuildInfo
getBuildConfig GlobalFlags
globalFlags UserHooks
hooks Verbosity
verbosity SymbolicPath Pkg ('Dir Dist)
distPref)
    UserHooks
hooks
    HscolourFlags
flags'
    [[Char]]
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
  (LocalBuildInfo
lbi, CommonSetupFlags
common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' :: HaddockFlags
flags' = HaddockFlags
flags{haddockCommonFlags = common'}

  ProgramDb
progs <-
    Verbosity
-> [([Char], [Char])]
-> [([Char], [[Char]])]
-> ProgramDb
-> IO ProgramDb
reconfigurePrograms
      Verbosity
verbosity
      (HaddockFlags -> [([Char], [Char])]
haddockProgramPaths HaddockFlags
flags')
      (HaddockFlags -> [([Char], [[Char]])]
haddockProgramArgs HaddockFlags
flags')
      (LocalBuildInfo -> ProgramDb
withPrograms LocalBuildInfo
lbi)

  Verbosity
-> (UserHooks -> [[Char]] -> HaddockFlags -> IO HookedBuildInfo)
-> (UserHooks
    -> PackageDescription
    -> LocalBuildInfo
    -> UserHooks
    -> HaddockFlags
    -> IO ())
-> (UserHooks
    -> [[Char]]
    -> HaddockFlags
    -> PackageDescription
    -> LocalBuildInfo
    -> IO ())
-> IO LocalBuildInfo
-> UserHooks
-> HaddockFlags
-> [[Char]]
-> IO ()
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]] -> HaddockFlags -> IO HookedBuildInfo
preHaddock
    UserHooks
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> HaddockFlags
-> IO ()
haddockHook
    UserHooks
-> [[Char]]
-> HaddockFlags
-> PackageDescription
-> LocalBuildInfo
-> IO ()
postHaddock
    (LocalBuildInfo -> IO LocalBuildInfo
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return LocalBuildInfo
lbi{withPrograms = progs})
    UserHooks
hooks
    HaddockFlags
flags'
    [[Char]]
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
  SymbolicPath Pkg ('Dir Dist)
distPref <- Flag (SymbolicPath Pkg ('Dir Dist))
-> IO (SymbolicPath Pkg ('Dir Dist))
findDistPrefOrDefault (CommonSetupFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
setupDistPref CommonSetupFlags
common)
  Either ConfigStateFileError LocalBuildInfo
elbi <- GlobalFlags
-> UserHooks
-> Verbosity
-> SymbolicPath Pkg ('Dir Dist)
-> IO (Either ConfigStateFileError LocalBuildInfo)
tryGetBuildConfig GlobalFlags
globalFlags UserHooks
hooks Verbosity
verbosity SymbolicPath Pkg ('Dir Dist)
distPref
  let common' :: CommonSetupFlags
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' =
        CleanFlags
flags{cleanCommonFlags = common'}

      mbWorkDirFlag :: Flag (SymbolicPath CWD ('Dir Pkg))
mbWorkDirFlag = CleanFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
cleanWorkingDir CleanFlags
flags'
      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))
mbWorkDirFlag

  HookedBuildInfo
pbi <- UserHooks -> [[Char]] -> CleanFlags -> IO HookedBuildInfo
preClean UserHooks
hooks [[Char]]
args CleanFlags
flags'

  (Maybe (SymbolicPath Pkg 'File)
_, GenericPackageDescription
ppd) <- 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))
mbWorkDir Maybe (SymbolicPath Pkg 'File)
forall a. Maybe a
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 :: PackageDescription
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 :: PackageDescription
pkg_descr = HookedBuildInfo -> PackageDescription -> PackageDescription
updatePackageDescription HookedBuildInfo
pbi PackageDescription
pkg_descr0

  UserHooks
-> PackageDescription -> () -> UserHooks -> CleanFlags -> IO ()
cleanHook UserHooks
hooks PackageDescription
pkg_descr () UserHooks
hooks CleanFlags
flags'
  UserHooks
-> [[Char]] -> CleanFlags -> PackageDescription -> () -> IO ()
postClean UserHooks
hooks [[Char]]
args CleanFlags
flags' PackageDescription
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
  (LocalBuildInfo
_lbi, CommonSetupFlags
common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' :: CopyFlags
flags' = CopyFlags
flags{copyCommonFlags = common'}
      distPref :: SymbolicPath Pkg ('Dir Dist)
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'
  Verbosity
-> (UserHooks -> [[Char]] -> CopyFlags -> IO HookedBuildInfo)
-> (UserHooks
    -> PackageDescription
    -> LocalBuildInfo
    -> UserHooks
    -> CopyFlags
    -> IO ())
-> (UserHooks
    -> [[Char]]
    -> CopyFlags
    -> PackageDescription
    -> LocalBuildInfo
    -> IO ())
-> IO LocalBuildInfo
-> UserHooks
-> CopyFlags
-> [[Char]]
-> IO ()
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]] -> CopyFlags -> IO HookedBuildInfo
preCopy
    UserHooks
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> CopyFlags
-> IO ()
copyHook
    UserHooks
-> [[Char]]
-> CopyFlags
-> PackageDescription
-> LocalBuildInfo
-> IO ()
postCopy
    (GlobalFlags
-> UserHooks
-> Verbosity
-> SymbolicPath Pkg ('Dir Dist)
-> IO LocalBuildInfo
getBuildConfig GlobalFlags
globalFlags UserHooks
hooks Verbosity
verbosity SymbolicPath Pkg ('Dir Dist)
distPref)
    UserHooks
hooks
    CopyFlags
flags'
    [[Char]]
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
  (LocalBuildInfo
_lbi, CommonSetupFlags
common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' :: InstallFlags
flags' = InstallFlags
flags{installCommonFlags = common'}
      distPref :: SymbolicPath Pkg ('Dir Dist)
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'
  Verbosity
-> (UserHooks -> [[Char]] -> InstallFlags -> IO HookedBuildInfo)
-> (UserHooks
    -> PackageDescription
    -> LocalBuildInfo
    -> UserHooks
    -> InstallFlags
    -> IO ())
-> (UserHooks
    -> [[Char]]
    -> InstallFlags
    -> PackageDescription
    -> LocalBuildInfo
    -> IO ())
-> IO LocalBuildInfo
-> UserHooks
-> InstallFlags
-> [[Char]]
-> IO ()
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]] -> InstallFlags -> IO HookedBuildInfo
preInst
    UserHooks
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> InstallFlags
-> IO ()
instHook
    UserHooks
-> [[Char]]
-> InstallFlags
-> PackageDescription
-> LocalBuildInfo
-> IO ()
postInst
    (GlobalFlags
-> UserHooks
-> Verbosity
-> SymbolicPath Pkg ('Dir Dist)
-> IO LocalBuildInfo
getBuildConfig GlobalFlags
globalFlags UserHooks
hooks Verbosity
verbosity SymbolicPath Pkg ('Dir Dist)
distPref)
    UserHooks
hooks
    InstallFlags
flags'
    [[Char]]
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
  (Maybe (SymbolicPath Pkg 'File)
_, GenericPackageDescription
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 :: PackageDescription
pkg_descr = GenericPackageDescription -> PackageDescription
flattenPackageDescription GenericPackageDescription
ppd
  PackageDescription
-> SDistFlags -> ([Char] -> [Char]) -> [PPSuffixHandler] -> IO ()
sdist PackageDescription
pkg_descr SDistFlags
flags [Char] -> [Char]
srcPref [PPSuffixHandler]
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
  (LocalBuildInfo
_lbi, CommonSetupFlags
common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' :: TestFlags
flags' = TestFlags
flags{testCommonFlags = common'}
      distPref :: SymbolicPath Pkg ('Dir Dist)
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'
  Verbosity
-> (UserHooks -> [[Char]] -> TestFlags -> IO HookedBuildInfo)
-> (UserHooks
    -> [[Char]]
    -> PackageDescription
    -> LocalBuildInfo
    -> UserHooks
    -> TestFlags
    -> IO ())
-> (UserHooks
    -> [[Char]]
    -> TestFlags
    -> PackageDescription
    -> LocalBuildInfo
    -> IO ())
-> IO LocalBuildInfo
-> UserHooks
-> TestFlags
-> [[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]] -> TestFlags -> IO HookedBuildInfo
preTest
    UserHooks
-> [[Char]]
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> TestFlags
-> IO ()
testHook
    UserHooks
-> [[Char]]
-> TestFlags
-> PackageDescription
-> LocalBuildInfo
-> IO ()
postTest
    (GlobalFlags
-> UserHooks
-> Verbosity
-> SymbolicPath Pkg ('Dir Dist)
-> IO LocalBuildInfo
getBuildConfig GlobalFlags
globalFlags UserHooks
hooks Verbosity
verbosity SymbolicPath Pkg ('Dir Dist)
distPref)
    UserHooks
hooks
    TestFlags
flags'
    [[Char]]
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
  (LocalBuildInfo
_lbi, CommonSetupFlags
common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' :: BenchmarkFlags
flags' = BenchmarkFlags
flags{benchmarkCommonFlags = common'}
      distPref :: SymbolicPath Pkg ('Dir Dist)
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'
  Verbosity
-> (UserHooks -> [[Char]] -> BenchmarkFlags -> IO HookedBuildInfo)
-> (UserHooks
    -> [[Char]]
    -> PackageDescription
    -> LocalBuildInfo
    -> UserHooks
    -> BenchmarkFlags
    -> IO ())
-> (UserHooks
    -> [[Char]]
    -> BenchmarkFlags
    -> PackageDescription
    -> LocalBuildInfo
    -> IO ())
-> IO LocalBuildInfo
-> UserHooks
-> BenchmarkFlags
-> [[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]] -> BenchmarkFlags -> IO HookedBuildInfo
preBench
    UserHooks
-> [[Char]]
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> BenchmarkFlags
-> IO ()
benchHook
    UserHooks
-> [[Char]]
-> BenchmarkFlags
-> PackageDescription
-> LocalBuildInfo
-> IO ()
postBench
    (GlobalFlags
-> UserHooks
-> Verbosity
-> SymbolicPath Pkg ('Dir Dist)
-> IO LocalBuildInfo
getBuildConfig GlobalFlags
globalFlags UserHooks
hooks Verbosity
verbosity SymbolicPath Pkg ('Dir Dist)
distPref)
    UserHooks
hooks
    BenchmarkFlags
flags'
    [[Char]]
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
  (LocalBuildInfo
_lbi, CommonSetupFlags
common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' :: RegisterFlags
flags' = RegisterFlags
flags{registerCommonFlags = common'}
      distPref :: SymbolicPath Pkg ('Dir Dist)
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'
  Verbosity
-> (UserHooks -> [[Char]] -> RegisterFlags -> IO HookedBuildInfo)
-> (UserHooks
    -> PackageDescription
    -> LocalBuildInfo
    -> UserHooks
    -> RegisterFlags
    -> IO ())
-> (UserHooks
    -> [[Char]]
    -> RegisterFlags
    -> PackageDescription
    -> LocalBuildInfo
    -> IO ())
-> IO LocalBuildInfo
-> UserHooks
-> RegisterFlags
-> [[Char]]
-> IO ()
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]] -> RegisterFlags -> IO HookedBuildInfo
preReg
    UserHooks
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> RegisterFlags
-> IO ()
regHook
    UserHooks
-> [[Char]]
-> RegisterFlags
-> PackageDescription
-> LocalBuildInfo
-> IO ()
postReg
    (GlobalFlags
-> UserHooks
-> Verbosity
-> SymbolicPath Pkg ('Dir Dist)
-> IO LocalBuildInfo
getBuildConfig GlobalFlags
globalFlags UserHooks
hooks Verbosity
verbosity SymbolicPath Pkg ('Dir Dist)
distPref)
    UserHooks
hooks
    RegisterFlags
flags'
    [[Char]]
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
  (LocalBuildInfo
_lbi, CommonSetupFlags
common') <- GlobalFlags
-> UserHooks
-> CommonSetupFlags
-> [[Char]]
-> IO (LocalBuildInfo, CommonSetupFlags)
getCommonFlags GlobalFlags
globalFlags UserHooks
hooks CommonSetupFlags
common [[Char]]
args
  let flags' :: RegisterFlags
flags' = RegisterFlags
flags{registerCommonFlags = common'}
      distPref :: SymbolicPath Pkg ('Dir Dist)
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'
  Verbosity
-> (UserHooks -> [[Char]] -> RegisterFlags -> IO HookedBuildInfo)
-> (UserHooks
    -> PackageDescription
    -> LocalBuildInfo
    -> UserHooks
    -> RegisterFlags
    -> IO ())
-> (UserHooks
    -> [[Char]]
    -> RegisterFlags
    -> PackageDescription
    -> LocalBuildInfo
    -> IO ())
-> IO LocalBuildInfo
-> UserHooks
-> RegisterFlags
-> [[Char]]
-> IO ()
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]] -> RegisterFlags -> IO HookedBuildInfo
preUnreg
    UserHooks
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> RegisterFlags
-> IO ()
unregHook
    UserHooks
-> [[Char]]
-> RegisterFlags
-> PackageDescription
-> LocalBuildInfo
-> IO ()
postUnreg
    (GlobalFlags
-> UserHooks
-> Verbosity
-> SymbolicPath Pkg ('Dir Dist)
-> IO LocalBuildInfo
getBuildConfig GlobalFlags
globalFlags UserHooks
hooks Verbosity
verbosity SymbolicPath Pkg ('Dir Dist)
distPref)
    UserHooks
hooks
    RegisterFlags
flags'
    [[Char]]
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
    HookedBuildInfo
pbi <- UserHooks -> [[Char]] -> flags -> IO HookedBuildInfo
pre_hook UserHooks
hooks [[Char]]
args flags
flags
    LocalBuildInfo
lbi0 <- IO LocalBuildInfo
get_build_config
    let pkg_descr0 :: PackageDescription
pkg_descr0 = LocalBuildInfo -> PackageDescription
localPkgDescr LocalBuildInfo
lbi0
    Verbosity -> PackageDescription -> HookedBuildInfo -> IO ()
sanityCheckHookedBuildInfo Verbosity
verbosity PackageDescription
pkg_descr0 HookedBuildInfo
pbi
    let pkg_descr :: PackageDescription
pkg_descr = HookedBuildInfo -> PackageDescription -> PackageDescription
updatePackageDescription HookedBuildInfo
pbi PackageDescription
pkg_descr0
        lbi :: LocalBuildInfo
lbi = LocalBuildInfo
lbi0{localPkgDescr = pkg_descr}
    UserHooks
-> [[Char]]
-> PackageDescription
-> LocalBuildInfo
-> UserHooks
-> flags
-> IO ()
cmd_hook UserHooks
hooks [[Char]]
args PackageDescription
pkg_descr LocalBuildInfo
lbi UserHooks
hooks flags
flags
    UserHooks
-> [[Char]]
-> flags
-> PackageDescription
-> LocalBuildInfo
-> IO ()
post_hook UserHooks
hooks [[Char]]
args flags
flags PackageDescription
pkg_descr LocalBuildInfo
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
  LocalBuildInfo
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 =
        LocalBuildInfo
lbi_wo_programs
          { withPrograms =
              restoreProgramDb
                (builtinPrograms ++ hookedPrograms hooks)
                (withPrograms lbi_wo_programs)
          }

  case LocalBuildInfo -> Maybe (SymbolicPath Pkg 'File)
pkgDescrFile LocalBuildInfo
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
      Bool
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 Bool
outdated
        then SymbolicPath Pkg 'File -> LocalBuildInfo -> IO LocalBuildInfo
reconfigure SymbolicPath Pkg 'File
pkg_descr_file LocalBuildInfo
lbi
        else LocalBuildInfo -> IO LocalBuildInfo
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return LocalBuildInfo
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..."

  Maybe LocalBuildInfo
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.
  [Char] -> IO () -> IO ()
chattyTry [Char]
"removing dist/" (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
    Bool
exists <- [Char] -> IO Bool
doesDirectoryExist [Char]
distPath
    Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
exists ([Char] -> IO ()
removeDirectoryRecursive [Char]
distPath)

  -- Any extra files the user wants to remove
  (RelativePath Pkg 'File -> IO ())
-> [RelativePath Pkg 'File] -> IO ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ ([Char] -> IO ()
removeFileOrDirectory ([Char] -> IO ())
-> (RelativePath Pkg 'File -> [Char])
-> RelativePath Pkg 'File
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RelativePath Pkg 'File -> [Char]
forall {allowAbsolute :: AllowAbsolute} {to :: FileOrDir}.
SymbolicPathX allowAbsolute Pkg to -> [Char]
i) (PackageDescription -> [RelativePath Pkg 'File]
extraTmpFiles PackageDescription
pkg_descr)

  -- If the user wanted to save the config, write it back
  (LocalBuildInfo -> IO ()) -> Maybe LocalBuildInfo -> IO ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (Maybe (SymbolicPath CWD ('Dir Pkg))
-> SymbolicPath Pkg ('Dir Dist) -> LocalBuildInfo -> IO ()
writePersistBuildConfig Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir SymbolicPath Pkg ('Dir Dist)
distPref) Maybe LocalBuildInfo
maybeConfig
  where
    removeFileOrDirectory :: FilePath -> IO ()
    removeFileOrDirectory :: [Char] -> IO ()
removeFileOrDirectory [Char]
fname = do
      Bool
isDir <- [Char] -> IO Bool
doesDirectoryExist [Char]
fname
      Bool
isFile <- [Char] -> IO Bool
doesFileExist [Char]
fname
      if Bool
isDir
        then [Char] -> IO ()
removeDirectoryRecursive [Char]
fname
        else Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
isFile (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ [Char] -> IO ()
removeFile [Char]
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)
        HookedBuildInfo
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)
        Verbosity -> PackageDescription -> HookedBuildInfo -> IO ()
sanityCheckHookedBuildInfo Verbosity
verbosity PackageDescription
pkg_descr HookedBuildInfo
pbi
        let pkg_descr' :: PackageDescription
pkg_descr' = HookedBuildInfo -> PackageDescription -> PackageDescription
updatePackageDescription HookedBuildInfo
pbi PackageDescription
pkg_descr
            lbi' :: LocalBuildInfo
lbi' = LocalBuildInfo
lbi{localPkgDescr = pkg_descr'}
        UserHooks
-> [[Char]]
-> ConfigFlags
-> PackageDescription
-> LocalBuildInfo
-> IO ()
postConf UserHooks
simpleUserHooks [[Char]]
args ConfigFlags
flags PackageDescription
pkg_descr' LocalBuildInfo
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
      SymbolicPath Pkg ('Dir Dist)
dist_dir <- Flag (SymbolicPath Pkg ('Dir Dist))
-> IO (SymbolicPath Pkg ('Dir Dist))
findDistPrefOrDefault Flag (SymbolicPath Pkg ('Dir Dist))
distPref
      Verbosity
-> Maybe (SymbolicPath CWD ('Dir Pkg))
-> SymbolicPath Pkg ('Dir Build)
-> IO HookedBuildInfo
getHookedBuildInfo Verbosity
verbosity Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir (SymbolicPath Pkg ('Dir Dist)
dist_dir SymbolicPath Pkg ('Dir Dist)
-> RelativePath Dist ('Dir Build) -> SymbolicPath Pkg ('Dir Build)
forall p q r. PathLike p q r => p -> q -> r
</> [Char] -> RelativePath Dist ('Dir Build)
forall from (to :: FileOrDir).
HasCallStack =>
[Char] -> RelativePath from to
makeRelativePathEx [Char]
"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
      SymbolicPath Pkg ('Dir Dist)
dist_dir <- Flag (SymbolicPath Pkg ('Dir Dist))
-> IO (SymbolicPath Pkg ('Dir Dist))
findDistPrefOrDefault Flag (SymbolicPath Pkg ('Dir Dist))
distPref
      Verbosity
-> Maybe (SymbolicPath CWD ('Dir Pkg))
-> SymbolicPath Pkg ('Dir Build)
-> IO HookedBuildInfo
getHookedBuildInfo Verbosity
verbosity Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir (SymbolicPath Pkg ('Dir Dist)
dist_dir SymbolicPath Pkg ('Dir Dist)
-> RelativePath Dist ('Dir Build) -> SymbolicPath Pkg ('Dir Build)
forall p q r. PathLike p q r => p -> q -> r
</> [Char] -> RelativePath Dist ('Dir Build)
forall from (to :: FileOrDir).
HasCallStack =>
[Char] -> RelativePath from to
makeRelativePathEx [Char]
"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 (SymbolicPath Pkg 'File)
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 (SymbolicPath Pkg 'File)
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
          { $sel:localBuildConfig:PostConfPackageInputs :: PostConfPackageInputs -> LocalBuildConfig
SetupHooks.localBuildConfig =
            LBC.LocalBuildConfig{$sel:withPrograms:LocalBuildConfig :: LocalBuildConfig -> ProgramDb
LBC.withPrograms = ProgramDb
progs}
          , $sel:packageBuildDescr:PostConfPackageInputs :: PostConfPackageInputs -> PackageBuildDescr
SetupHooks.packageBuildDescr =
            LBC.PackageBuildDescr
              { $sel:configFlags:PackageBuildDescr :: PackageBuildDescr -> ConfigFlags
LBC.configFlags = ConfigFlags
cfg
              , $sel:flagAssignment:PackageBuildDescr :: PackageBuildDescr -> FlagAssignment
LBC.flagAssignment = FlagAssignment
flags
              , $sel:hostPlatform:PackageBuildDescr :: 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
          { $sel:packageBuildDescr:PreConfComponentInputs :: PreConfComponentInputs -> PackageBuildDescr
SetupHooks.packageBuildDescr =
            LBC.PackageBuildDescr
              { $sel:configFlags:PackageBuildDescr :: PackageBuildDescr -> ConfigFlags
LBC.configFlags = ConfigFlags
cfg
              , $sel:localPkgDescr:PackageBuildDescr :: PackageBuildDescr -> PackageDescription
localPkgDescr = PackageDescription
pkg_descr
              }
          , $sel:component:PreConfComponentInputs :: 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
        SymbolicPath Pkg ('Dir Dist)
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).
        HookedBuildInfo
hbi <- Verbosity
-> Maybe (SymbolicPath CWD ('Dir Pkg))
-> SymbolicPath Pkg ('Dir Build)
-> IO HookedBuildInfo
getHookedBuildInfo Verbosity
verbosity Maybe (SymbolicPath CWD ('Dir Pkg))
mbWorkDir (SymbolicPath Pkg ('Dir Dist)
dist_dir SymbolicPath Pkg ('Dir Dist)
-> RelativePath Dist ('Dir Build) -> SymbolicPath Pkg ('Dir Build)
forall p q r. PathLike p q r => p -> q -> r
</> [Char] -> RelativePath Dist ('Dir Build)
forall from (to :: FileOrDir).
HasCallStack =>
[Char] -> RelativePath from to
makeRelativePathEx [Char]
"build")
        Verbosity -> PackageDescription -> HookedBuildInfo -> IO ()
sanityCheckHookedBuildInfo Verbosity
verbosity PackageDescription
pkg_descr HookedBuildInfo
hbi
        -- SetupHooks TODO: we are reading getHookedBuildInfo once
        -- for each component. I think this is inherent to the SetupHooks
        -- approach.
        let comp_name :: ComponentName
comp_name = Component -> ComponentName
componentName Component
component
        ComponentDiff
diff <- case HookedBuildInfo -> ComponentName -> Maybe (IO ComponentDiff)
SetupHooks.hookedBuildInfoComponentDiff_maybe HookedBuildInfo
hbi ComponentName
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
        PreConfComponentOutputs -> IO PreConfComponentOutputs
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (PreConfComponentOutputs -> IO PreConfComponentOutputs)
-> PreConfComponentOutputs -> IO PreConfComponentOutputs
forall a b. (a -> b) -> a -> b
$
          SetupHooks.PreConfComponentOutputs
            { $sel:componentDiff:PreConfComponentOutputs :: ComponentDiff
SetupHooks.componentDiff = 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
          }
  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)