{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ViewPatterns #-}
module Distribution.Simple.Setup.Install
( InstallFlags
( InstallCommonFlags
, installVerbosity
, installDistPref
, installCabalFilePath
, installWorkingDir
, installTargets
, ..
)
, emptyInstallFlags
, defaultInstallFlags
, installCommand
) where
import Distribution.Compat.Prelude hiding (get)
import Prelude ()
import Distribution.ReadE
import Distribution.Simple.Command hiding (boolOpt, boolOpt')
import Distribution.Simple.Compiler
import Distribution.Simple.Flag
import Distribution.Simple.InstallDirs
import Distribution.Simple.Setup.Common
import Distribution.Simple.Utils
import Distribution.Utils.Path
import Distribution.Verbosity
data InstallFlags = InstallFlags
{ InstallFlags -> CommonSetupFlags
installCommonFlags :: !CommonSetupFlags
, InstallFlags -> Flag PackageDB
installPackageDB :: Flag PackageDB
, InstallFlags -> Flag CopyDest
installDest :: Flag CopyDest
, InstallFlags -> Flag Bool
installUseWrapper :: Flag Bool
, InstallFlags -> Flag Bool
installInPlace :: Flag Bool
}
deriving (Int -> InstallFlags -> ShowS
[InstallFlags] -> ShowS
InstallFlags -> String
(Int -> InstallFlags -> ShowS)
-> (InstallFlags -> String)
-> ([InstallFlags] -> ShowS)
-> Show InstallFlags
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InstallFlags -> ShowS
showsPrec :: Int -> InstallFlags -> ShowS
$cshow :: InstallFlags -> String
show :: InstallFlags -> String
$cshowList :: [InstallFlags] -> ShowS
showList :: [InstallFlags] -> ShowS
Show, (forall x. InstallFlags -> Rep InstallFlags x)
-> (forall x. Rep InstallFlags x -> InstallFlags)
-> Generic InstallFlags
forall x. Rep InstallFlags x -> InstallFlags
forall x. InstallFlags -> Rep InstallFlags x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. InstallFlags -> Rep InstallFlags x
from :: forall x. InstallFlags -> Rep InstallFlags x
$cto :: forall x. Rep InstallFlags x -> InstallFlags
to :: forall x. Rep InstallFlags x -> InstallFlags
Generic)
pattern InstallCommonFlags
:: Flag Verbosity
-> Flag (SymbolicPath Pkg (Dir Dist))
-> Flag (SymbolicPath CWD (Dir Pkg))
-> Flag (SymbolicPath Pkg File)
-> [String]
-> InstallFlags
pattern $mInstallCommonFlags :: forall {r}.
InstallFlags
-> (Flag Verbosity
-> Flag (SymbolicPath Pkg ('Dir Dist))
-> Flag (SymbolicPath CWD ('Dir Pkg))
-> Flag (SymbolicPath Pkg 'File)
-> [String]
-> r)
-> ((# #) -> r)
-> r
InstallCommonFlags
{ InstallFlags -> Flag Verbosity
installVerbosity
, InstallFlags -> Flag (SymbolicPath Pkg ('Dir Dist))
installDistPref
, InstallFlags -> Flag (SymbolicPath CWD ('Dir Pkg))
installWorkingDir
, InstallFlags -> Flag (SymbolicPath Pkg 'File)
installCabalFilePath
, InstallFlags -> [String]
installTargets
} <-
( installCommonFlags ->
CommonSetupFlags
{ setupVerbosity = installVerbosity
, setupDistPref = installDistPref
, setupWorkingDir = installWorkingDir
, setupCabalFilePath = installCabalFilePath
, setupTargets = installTargets
}
)
defaultInstallFlags :: InstallFlags
defaultInstallFlags :: InstallFlags
defaultInstallFlags =
InstallFlags
{ installCommonFlags :: CommonSetupFlags
installCommonFlags = CommonSetupFlags
defaultCommonSetupFlags
, installPackageDB :: Flag PackageDB
installPackageDB = Flag PackageDB
forall a. Flag a
NoFlag
, installDest :: Flag CopyDest
installDest = CopyDest -> Flag CopyDest
forall a. a -> Flag a
Flag CopyDest
NoCopyDest
, installUseWrapper :: Flag Bool
installUseWrapper = Bool -> Flag Bool
forall a. a -> Flag a
Flag Bool
False
, installInPlace :: Flag Bool
installInPlace = Bool -> Flag Bool
forall a. a -> Flag a
Flag Bool
False
}
installCommand :: CommandUI InstallFlags
installCommand :: CommandUI InstallFlags
installCommand =
CommandUI
{ commandName :: String
commandName = String
"install"
, commandSynopsis :: String
commandSynopsis =
String
"Copy the files into the install locations. Run register."
, commandDescription :: Maybe ShowS
commandDescription = ShowS -> Maybe ShowS
forall a. a -> Maybe a
Just (ShowS -> Maybe ShowS) -> ShowS -> Maybe ShowS
forall a b. (a -> b) -> a -> b
$ \String
_ ->
ShowS
wrapText ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
String
"Unlike the copy command, install calls the register command. "
String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"If you want to install into a location that is not what was "
String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"specified in the configure step, use the copy command.\n"
, commandNotes :: Maybe ShowS
commandNotes = Maybe ShowS
forall a. Maybe a
Nothing
, commandUsage :: ShowS
commandUsage = \String
pname ->
String
"Usage: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
pname String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" install [FLAGS]\n"
, commandDefaultFlags :: InstallFlags
commandDefaultFlags = InstallFlags
defaultInstallFlags
, commandOptions :: ShowOrParseArgs -> [OptionField InstallFlags]
commandOptions = \ShowOrParseArgs
showOrParseArgs ->
(InstallFlags -> CommonSetupFlags)
-> (CommonSetupFlags -> InstallFlags -> InstallFlags)
-> ShowOrParseArgs
-> [OptionField InstallFlags]
-> [OptionField InstallFlags]
forall flags.
(flags -> CommonSetupFlags)
-> (CommonSetupFlags -> flags -> flags)
-> ShowOrParseArgs
-> [OptionField flags]
-> [OptionField flags]
withCommonSetupOptions
InstallFlags -> CommonSetupFlags
installCommonFlags
(\CommonSetupFlags
c InstallFlags
f -> InstallFlags
f{installCommonFlags = c})
ShowOrParseArgs
showOrParseArgs
([OptionField InstallFlags] -> [OptionField InstallFlags])
-> [OptionField InstallFlags] -> [OptionField InstallFlags]
forall a b. (a -> b) -> a -> b
$ case ShowOrParseArgs
showOrParseArgs of
ShowOrParseArgs
ShowArgs ->
(OptionField InstallFlags -> Bool)
-> [OptionField InstallFlags] -> [OptionField InstallFlags]
forall a. (a -> Bool) -> [a] -> [a]
filter
( (String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [String
"target-package-db"])
(String -> Bool)
-> (OptionField InstallFlags -> String)
-> OptionField InstallFlags
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OptionField InstallFlags -> String
forall a. OptionField a -> String
optionName
)
[OptionField InstallFlags]
installOptions
ShowOrParseArgs
ParseArgs -> [OptionField InstallFlags]
installOptions
}
installOptions :: [OptionField InstallFlags]
installOptions :: [OptionField InstallFlags]
installOptions =
[ String
-> [String]
-> String
-> (InstallFlags -> Flag Bool)
-> (Flag Bool -> InstallFlags -> InstallFlags)
-> MkOptDescr
(InstallFlags -> Flag Bool)
(Flag Bool -> InstallFlags -> InstallFlags)
InstallFlags
-> OptionField InstallFlags
forall get set a.
String
-> [String]
-> String
-> get
-> set
-> MkOptDescr get set a
-> OptionField a
option
String
""
[String
"inplace"]
String
"install the package in the install subdirectory of the dist prefix, so it can be used without being installed"
InstallFlags -> Flag Bool
installInPlace
(\Flag Bool
v InstallFlags
flags -> InstallFlags
flags{installInPlace = v})
MkOptDescr
(InstallFlags -> Flag Bool)
(Flag Bool -> InstallFlags -> InstallFlags)
InstallFlags
forall a. MkOptDescr (a -> Flag Bool) (Flag Bool -> a -> a) a
trueArg
, String
-> [String]
-> String
-> (InstallFlags -> Flag Bool)
-> (Flag Bool -> InstallFlags -> InstallFlags)
-> MkOptDescr
(InstallFlags -> Flag Bool)
(Flag Bool -> InstallFlags -> InstallFlags)
InstallFlags
-> OptionField InstallFlags
forall get set a.
String
-> [String]
-> String
-> get
-> set
-> MkOptDescr get set a
-> OptionField a
option
String
""
[String
"shell-wrappers"]
String
"using shell script wrappers around executables"
InstallFlags -> Flag Bool
installUseWrapper
(\Flag Bool
v InstallFlags
flags -> InstallFlags
flags{installUseWrapper = v})
(String
-> String
-> MkOptDescr
(InstallFlags -> Flag Bool)
(Flag Bool -> InstallFlags -> InstallFlags)
InstallFlags
forall a.
String
-> String -> MkOptDescr (a -> Flag Bool) (Flag Bool -> a -> a) a
boolOpt [] [])
, String
-> [String]
-> String
-> (InstallFlags -> Flag PackageDB)
-> (Flag PackageDB -> InstallFlags -> InstallFlags)
-> MkOptDescr
(InstallFlags -> Flag PackageDB)
(Flag PackageDB -> InstallFlags -> InstallFlags)
InstallFlags
-> OptionField InstallFlags
forall get set a.
String
-> [String]
-> String
-> get
-> set
-> MkOptDescr get set a
-> OptionField a
option
String
""
[String
"package-db"]
String
""
InstallFlags -> Flag PackageDB
installPackageDB
(\Flag PackageDB
v InstallFlags
flags -> InstallFlags
flags{installPackageDB = v})
( [(Flag PackageDB, OptFlags, String)]
-> MkOptDescr
(InstallFlags -> Flag PackageDB)
(Flag PackageDB -> InstallFlags -> InstallFlags)
InstallFlags
forall b a.
Eq b =>
[(b, OptFlags, String)] -> MkOptDescr (a -> b) (b -> a -> a) a
choiceOpt
[
( PackageDB -> Flag PackageDB
forall a. a -> Flag a
Flag PackageDB
forall fp. PackageDBX fp
UserPackageDB
, ([], [String
"user"])
, String
"upon configuration register this package in the user's local package database"
)
,
( PackageDB -> Flag PackageDB
forall a. a -> Flag a
Flag PackageDB
forall fp. PackageDBX fp
GlobalPackageDB
, ([], [String
"global"])
, String
"(default) upon configuration register this package in the system-wide package database"
)
]
)
, String
-> [String]
-> String
-> (InstallFlags -> Flag CopyDest)
-> (Flag CopyDest -> InstallFlags -> InstallFlags)
-> MkOptDescr
(InstallFlags -> Flag CopyDest)
(Flag CopyDest -> InstallFlags -> InstallFlags)
InstallFlags
-> OptionField InstallFlags
forall get set a.
String
-> [String]
-> String
-> get
-> set
-> MkOptDescr get set a
-> OptionField a
option
String
""
[String
"target-package-db"]
String
"package database to install into. Required when using ${pkgroot} prefix."
InstallFlags -> Flag CopyDest
installDest
(\Flag CopyDest
v InstallFlags
flags -> InstallFlags
flags{installDest = v})
( String
-> ReadE (Flag CopyDest)
-> (Flag CopyDest -> [String])
-> MkOptDescr
(InstallFlags -> Flag CopyDest)
(Flag CopyDest -> InstallFlags -> InstallFlags)
InstallFlags
forall b a.
Monoid b =>
String
-> ReadE b
-> (b -> [String])
-> MkOptDescr (a -> b) (b -> a -> a) a
reqArg
String
"DATABASE"
((String -> Flag CopyDest) -> ReadE (Flag CopyDest)
forall a. (String -> a) -> ReadE a
succeedReadE (CopyDest -> Flag CopyDest
forall a. a -> Flag a
Flag (CopyDest -> Flag CopyDest)
-> (String -> CopyDest) -> String -> Flag CopyDest
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> CopyDest
CopyToDb))
(\Flag CopyDest
f -> case Flag CopyDest
f of Flag (CopyToDb String
p) -> [String
p]; Flag CopyDest
_ -> [])
)
]
emptyInstallFlags :: InstallFlags
emptyInstallFlags :: InstallFlags
emptyInstallFlags = InstallFlags
forall a. Monoid a => a
mempty
instance Monoid InstallFlags where
mempty :: InstallFlags
mempty = InstallFlags
forall a. (Generic a, GMonoid (Rep a)) => a
gmempty
mappend :: InstallFlags -> InstallFlags -> InstallFlags
mappend = InstallFlags -> InstallFlags -> InstallFlags
forall a. Semigroup a => a -> a -> a
(<>)
instance Semigroup InstallFlags where
<> :: InstallFlags -> InstallFlags -> InstallFlags
(<>) = InstallFlags -> InstallFlags -> InstallFlags
forall a. (Generic a, GSemigroup (Rep a)) => a -> a -> a
gmappend