module Distribution.Simple.Install (
install,
) where
import Distribution.PackageDescription (
PackageDescription(..), BuildInfo(..), Library(..),
hasLibs, withLib, hasExes, withExe )
import Distribution.Package (Package(..))
import Distribution.Simple.LocalBuildInfo (
LocalBuildInfo(..), InstallDirs(..), absoluteInstallDirs,
substPathTemplate)
import Distribution.Simple.BuildPaths (haddockName, haddockPref)
import Distribution.Simple.Utils
( createDirectoryIfMissingVerbose, installDirectoryContents
, installOrdinaryFile, die, info, notice, matchDirFileGlob )
import Distribution.Simple.Compiler
( CompilerFlavor(..), compilerFlavor )
import Distribution.Simple.Setup (CopyFlags(..), CopyDest(..), fromFlag)
import qualified Distribution.Simple.GHC as GHC
import qualified Distribution.Simple.NHC as NHC
import qualified Distribution.Simple.JHC as JHC
import qualified Distribution.Simple.LHC as LHC
import qualified Distribution.Simple.Hugs as Hugs
import qualified Distribution.Simple.UHC as UHC
import Control.Monad (when, unless)
import System.Directory
( doesDirectoryExist, doesFileExist )
import System.FilePath
( takeFileName, takeDirectory, (</>), isAbsolute )
import Distribution.Verbosity
import Distribution.Text
( display )
install :: PackageDescription
-> LocalBuildInfo
-> CopyFlags
-> IO ()
install pkg_descr lbi flags = do
let distPref = fromFlag :: Flag a -> afromFlag (copyDistPref :: CopyFlags -> Flag FilePathcopyDistPref flags :: CopyFlagsflags)
verbosity = fromFlag :: Flag a -> afromFlag (copyVerbosity :: CopyFlags -> Flag VerbositycopyVerbosity flags :: CopyFlagsflags)
copydest = fromFlag :: Flag a -> afromFlag (copyDest :: CopyFlags -> Flag CopyDestcopyDest flags :: CopyFlagsflags)
installDirs@(InstallDirs {
bindir = binPref,
libdir = libPref,
datadir = dataPref,
progdir = progPref,
docdir = docPref,
htmldir = htmlPref,
haddockdir = interfacePref,
includedir = incPref})
= absoluteInstallDirs ::
PackageDescription
-> LocalBuildInfo
-> CopyDest
-> InstallDirs FilePathabsoluteInstallDirs pkg_descr :: PackageDescriptionpkg_descr lbi :: LocalBuildInfolbi copydest :: CopyDestcopydest
dynlibPref = libPref :: FilePathlibPref
progPrefixPref = substPathTemplate ::
PackageId -> LocalBuildInfo -> PathTemplate -> FilePathsubstPathTemplate (packageId :: Package pkg => pkg -> PackageIdentifierpackageId pkg_descr :: PackageDescriptionpkg_descr) lbi :: LocalBuildInfolbi (progPrefix :: LocalBuildInfo -> PathTemplateprogPrefix lbi :: LocalBuildInfolbi)
progSuffixPref = substPathTemplate ::
PackageId -> LocalBuildInfo -> PathTemplate -> FilePathsubstPathTemplate (packageId :: Package pkg => pkg -> PackageIdentifierpackageId pkg_descr :: PackageDescriptionpkg_descr) lbi :: LocalBuildInfolbi (progSuffix :: LocalBuildInfo -> PathTemplateprogSuffix lbi :: LocalBuildInfolbi)
docExists <- doesDirectoryExist :: FilePath -> IO BooldoesDirectoryExist ($) :: (a -> b) -> a -> b$ haddockPref :: FilePath -> PackageDescription -> FilePathhaddockPref distPref :: FilePathdistPref pkg_descr :: PackageDescriptionpkg_descr
info :: Verbosity -> String -> IO ()info verbosity :: Verbosityverbosity ("directory " (++) :: [a] -> [a] -> [a]++ haddockPref :: FilePath -> PackageDescription -> FilePathhaddockPref distPref :: FilePathdistPref pkg_descr :: PackageDescriptionpkg_descr (++) :: [a] -> [a] -> [a]++
" does exist: " (++) :: [a] -> [a] -> [a]++ show :: Show a => a -> Stringshow docExists :: BooldocExists)
installDataFiles ::
Verbosity -> PackageDescription -> FilePath -> IO ()installDataFiles verbosity :: Verbosityverbosity pkg_descr :: PackageDescriptionpkg_descr dataPref :: FilePathdataPref
when :: Monad m => Bool -> m () -> m ()when docExists :: BooldocExists ($) :: (a -> b) -> a -> b$ do
createDirectoryIfMissingVerbose ::
Verbosity -> Bool -> FilePath -> IO ()createDirectoryIfMissingVerbose verbosity :: Verbosityverbosity True :: BoolTrue htmlPref :: FilePathhtmlPref
installDirectoryContents ::
Verbosity -> FilePath -> FilePath -> IO ()installDirectoryContents verbosity :: Verbosityverbosity
(haddockPref :: FilePath -> PackageDescription -> FilePathhaddockPref distPref :: FilePathdistPref pkg_descr :: PackageDescriptionpkg_descr) htmlPref :: FilePathhtmlPref
let haddockInterfaceFileSrc = haddockPref :: FilePath -> PackageDescription -> FilePathhaddockPref distPref :: FilePathdistPref pkg_descr :: PackageDescriptionpkg_descr
(</>) :: FilePath -> FilePath -> FilePath</> haddockName :: PackageDescription -> FilePathhaddockName pkg_descr :: PackageDescriptionpkg_descr
haddockInterfaceFileDest = interfacePref :: FilePathinterfacePref (</>) :: FilePath -> FilePath -> FilePath</> haddockName :: PackageDescription -> FilePathhaddockName pkg_descr :: PackageDescriptionpkg_descr
exists <- doesFileExist :: FilePath -> IO BooldoesFileExist haddockInterfaceFileSrc :: FilePathhaddockInterfaceFileSrc
when :: Monad m => Bool -> m () -> m ()when exists :: Boolexists ($) :: (a -> b) -> a -> b$ do
createDirectoryIfMissingVerbose ::
Verbosity -> Bool -> FilePath -> IO ()createDirectoryIfMissingVerbose verbosity :: Verbosityverbosity True :: BoolTrue interfacePref :: FilePathinterfacePref
installOrdinaryFile :: Verbosity -> FilePath -> FilePath -> IO ()installOrdinaryFile verbosity :: Verbosityverbosity haddockInterfaceFileSrc :: FilePathhaddockInterfaceFileSrc
haddockInterfaceFileDest :: FilePathhaddockInterfaceFileDest
let lfile = licenseFile :: PackageDescription -> FilePathlicenseFile pkg_descr :: PackageDescriptionpkg_descr
unless :: Monad m => Bool -> m () -> m ()unless (null :: [a] -> Boolnull lfile :: FilePathlfile) ($) :: (a -> b) -> a -> b$ do
createDirectoryIfMissingVerbose ::
Verbosity -> Bool -> FilePath -> IO ()createDirectoryIfMissingVerbose verbosity :: Verbosityverbosity True :: BoolTrue docPref :: FilePathdocPref
installOrdinaryFile :: Verbosity -> FilePath -> FilePath -> IO ()installOrdinaryFile verbosity :: Verbosityverbosity lfile :: FilePathlfile (docPref :: FilePathdocPref (</>) :: FilePath -> FilePath -> FilePath</> takeFileName :: FilePath -> FilePathtakeFileName lfile :: FilePathlfile)
let buildPref = buildDir :: LocalBuildInfo -> FilePathbuildDir lbi :: LocalBuildInfolbi
when :: Monad m => Bool -> m () -> m ()when (hasLibs :: PackageDescription -> BoolhasLibs pkg_descr :: PackageDescriptionpkg_descr) ($) :: (a -> b) -> a -> b$
notice :: Verbosity -> String -> IO ()notice verbosity :: Verbosityverbosity ("Installing library in " (++) :: [a] -> [a] -> [a]++ libPref :: FilePathlibPref)
when :: Monad m => Bool -> m () -> m ()when (hasExes :: PackageDescription -> BoolhasExes pkg_descr :: PackageDescriptionpkg_descr) ($) :: (a -> b) -> a -> b$
notice :: Verbosity -> String -> IO ()notice verbosity :: Verbosityverbosity ("Installing executable(s) in " (++) :: [a] -> [a] -> [a]++ binPref :: FilePathbinPref)
when :: Monad m => Bool -> m () -> m ()when (hasLibs :: PackageDescription -> BoolhasLibs pkg_descr :: PackageDescriptionpkg_descr) ($) :: (a -> b) -> a -> b$ installIncludeFiles ::
Verbosity -> PackageDescription -> FilePath -> IO ()installIncludeFiles verbosity :: Verbosityverbosity pkg_descr :: PackageDescriptionpkg_descr incPref :: FilePathincPref
case compilerFlavor :: Compiler -> CompilerFlavorcompilerFlavor (compiler :: LocalBuildInfo -> Compilercompiler lbi :: LocalBuildInfolbi) of
GHC -> do withLib :: PackageDescription -> (Library -> IO ()) -> IO ()withLib pkg_descr :: PackageDescriptionpkg_descr ($) :: (a -> b) -> a -> b$
installLib ::
Verbosity
-> LocalBuildInfo
-> FilePath
-> FilePath
-> FilePath
-> PackageDescription
-> Library
-> IO ()GHC.installLib verbosity :: Verbosityverbosity lbi :: LocalBuildInfolbi libPref :: FilePathlibPref dynlibPref :: FilePathdynlibPref buildPref :: FilePathbuildPref pkg_descr :: PackageDescriptionpkg_descr
withExe :: PackageDescription -> (Executable -> IO ()) -> IO ()withExe pkg_descr :: PackageDescriptionpkg_descr ($) :: (a -> b) -> a -> b$
installExe ::
Verbosity
-> LocalBuildInfo
-> InstallDirs FilePath
-> FilePath
-> (FilePath, FilePath)
-> PackageDescription
-> Executable
-> IO ()GHC.installExe verbosity :: Verbosityverbosity lbi :: LocalBuildInfolbi installDirs :: InstallDirs FilePathinstallDirs buildPref :: FilePathbuildPref (progPrefixPref :: FilePathprogPrefixPref, progSuffixPref :: FilePathprogSuffixPref) pkg_descr :: PackageDescriptionpkg_descr
LHC -> do withLib :: PackageDescription -> (Library -> IO ()) -> IO ()withLib pkg_descr :: PackageDescriptionpkg_descr ($) :: (a -> b) -> a -> b$
installLib ::
Verbosity
-> LocalBuildInfo
-> FilePath
-> FilePath
-> FilePath
-> PackageDescription
-> Library
-> IO ()LHC.installLib verbosity :: Verbosityverbosity lbi :: LocalBuildInfolbi libPref :: FilePathlibPref dynlibPref :: FilePathdynlibPref buildPref :: FilePathbuildPref pkg_descr :: PackageDescriptionpkg_descr
withExe :: PackageDescription -> (Executable -> IO ()) -> IO ()withExe pkg_descr :: PackageDescriptionpkg_descr ($) :: (a -> b) -> a -> b$
installExe ::
Verbosity
-> LocalBuildInfo
-> InstallDirs FilePath
-> FilePath
-> (FilePath, FilePath)
-> PackageDescription
-> Executable
-> IO ()LHC.installExe verbosity :: Verbosityverbosity lbi :: LocalBuildInfolbi installDirs :: InstallDirs FilePathinstallDirs buildPref :: FilePathbuildPref (progPrefixPref :: FilePathprogPrefixPref, progSuffixPref :: FilePathprogSuffixPref) pkg_descr :: PackageDescriptionpkg_descr
JHC -> do withLib :: PackageDescription -> (Library -> IO ()) -> IO ()withLib pkg_descr :: PackageDescriptionpkg_descr ($) :: (a -> b) -> a -> b$
installLib ::
Verbosity
-> FilePath
-> FilePath
-> PackageDescription
-> Library
-> IO ()JHC.installLib verbosity :: Verbosityverbosity libPref :: FilePathlibPref buildPref :: FilePathbuildPref pkg_descr :: PackageDescriptionpkg_descr
withExe :: PackageDescription -> (Executable -> IO ()) -> IO ()withExe pkg_descr :: PackageDescriptionpkg_descr ($) :: (a -> b) -> a -> b$
installExe ::
Verbosity
-> FilePath
-> FilePath
-> (FilePath, FilePath)
-> PackageDescription
-> Executable
-> IO ()JHC.installExe verbosity :: Verbosityverbosity binPref :: FilePathbinPref buildPref :: FilePathbuildPref (progPrefixPref :: FilePathprogPrefixPref, progSuffixPref :: FilePathprogSuffixPref) pkg_descr :: PackageDescriptionpkg_descr
Hugs -> do
let targetProgPref = progdir :: InstallDirs dir -> dirprogdir (absoluteInstallDirs ::
PackageDescription
-> LocalBuildInfo
-> CopyDest
-> InstallDirs FilePathabsoluteInstallDirs pkg_descr :: PackageDescriptionpkg_descr lbi :: LocalBuildInfolbi NoCopyDest :: CopyDestNoCopyDest)
let scratchPref = scratchDir :: LocalBuildInfo -> FilePathscratchDir lbi :: LocalBuildInfolbi
install ::
Verbosity
-> LocalBuildInfo
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> (FilePath, FilePath)
-> PackageDescription
-> IO ()Hugs.install verbosity :: Verbosityverbosity lbi :: LocalBuildInfolbi libPref :: FilePathlibPref progPref :: FilePathprogPref binPref :: FilePathbinPref targetProgPref :: FilePathtargetProgPref scratchPref :: FilePathscratchPref (progPrefixPref :: FilePathprogPrefixPref, progSuffixPref :: FilePathprogSuffixPref) pkg_descr :: PackageDescriptionpkg_descr
NHC -> do withLib :: PackageDescription -> (Library -> IO ()) -> IO ()withLib pkg_descr :: PackageDescriptionpkg_descr ($) :: (a -> b) -> a -> b$ installLib ::
Verbosity
-> FilePath
-> FilePath
-> PackageIdentifier
-> Library
-> IO ()NHC.installLib verbosity :: Verbosityverbosity libPref :: FilePathlibPref buildPref :: FilePathbuildPref (packageId :: Package pkg => pkg -> PackageIdentifierpackageId pkg_descr :: PackageDescriptionpkg_descr)
withExe :: PackageDescription -> (Executable -> IO ()) -> IO ()withExe pkg_descr :: PackageDescriptionpkg_descr ($) :: (a -> b) -> a -> b$ installExe ::
Verbosity
-> FilePath
-> FilePath
-> (FilePath, FilePath)
-> Executable
-> IO ()NHC.installExe verbosity :: Verbosityverbosity binPref :: FilePathbinPref buildPref :: FilePathbuildPref (progPrefixPref :: FilePathprogPrefixPref, progSuffixPref :: FilePathprogSuffixPref)
UHC -> do withLib :: PackageDescription -> (Library -> IO ()) -> IO ()withLib pkg_descr :: PackageDescriptionpkg_descr ($) :: (a -> b) -> a -> b$ installLib ::
Verbosity
-> LocalBuildInfo
-> FilePath
-> FilePath
-> FilePath
-> PackageDescription
-> Library
-> IO ()UHC.installLib verbosity :: Verbosityverbosity lbi :: LocalBuildInfolbi libPref :: FilePathlibPref dynlibPref :: FilePathdynlibPref buildPref :: FilePathbuildPref pkg_descr :: PackageDescriptionpkg_descr
_ -> die :: String -> IO adie ($) :: (a -> b) -> a -> b$ "installing with "
(++) :: [a] -> [a] -> [a]++ display :: Text a => a -> Stringdisplay (compilerFlavor :: Compiler -> CompilerFlavorcompilerFlavor (compiler :: LocalBuildInfo -> Compilercompiler lbi :: LocalBuildInfolbi))
(++) :: [a] -> [a] -> [a]++ " is not implemented"
return :: Monad m => forall a. a -> m areturn ()
installDataFiles :: Verbosity -> PackageDescription -> FilePath -> IO ()
installDataFiles verbosity pkg_descr destDataDir =
flip :: (a -> b -> c) -> b -> a -> cflip mapM_ :: Monad m => (a -> m b) -> [a] -> m ()mapM_ (dataFiles :: PackageDescription -> [FilePath]dataFiles pkg_descr :: PackageDescriptionpkg_descr) ($) :: (a -> b) -> a -> b$ \ file -> do
let srcDataDir = dataDir :: PackageDescription -> FilePathdataDir pkg_descr :: PackageDescriptionpkg_descr
files <- matchDirFileGlob :: FilePath -> FilePath -> IO [FilePath]matchDirFileGlob srcDataDir :: FilePathsrcDataDir file :: FilePathfile
let dir = takeDirectory :: FilePath -> FilePathtakeDirectory file :: FilePathfile
createDirectoryIfMissingVerbose ::
Verbosity -> Bool -> FilePath -> IO ()createDirectoryIfMissingVerbose verbosity :: Verbosityverbosity True :: BoolTrue (destDataDir :: FilePathdestDataDir (</>) :: FilePath -> FilePath -> FilePath</> dir :: FilePathdir)
sequence_ :: Monad m => [m a] -> m ()sequence_ [ installOrdinaryFile :: Verbosity -> FilePath -> FilePath -> IO ()installOrdinaryFile verbosity :: Verbosityverbosity (srcDataDir :: FilePathsrcDataDir (</>) :: FilePath -> FilePath -> FilePath</> file' :: FilePathfile')
(destDataDir :: FilePathdestDataDir (</>) :: FilePath -> FilePath -> FilePath</> file' :: FilePathfile')
| file' <- files :: [FilePath]files ]
installIncludeFiles :: Verbosity -> PackageDescription -> FilePath -> IO ()
installIncludeFiles verbosity
PackageDescription { library = Just lib } destIncludeDir = do
incs <- mapM :: Monad m => (a -> m b) -> [a] -> m [b]mapM (findInc :: [FilePath] -> [Char] -> IO ([Char], FilePath)findInc relincdirs :: [[Char]]relincdirs) (installIncludes :: BuildInfo -> [FilePath]installIncludes lbi :: LocalBuildInfolbi)
sequence_ :: Monad m => [m a] -> m ()sequence_
[ do createDirectoryIfMissingVerbose ::
Verbosity -> Bool -> FilePath -> IO ()createDirectoryIfMissingVerbose verbosity :: Verbosityverbosity True :: BoolTrue destDir :: FilePathdestDir
installOrdinaryFile :: Verbosity -> FilePath -> FilePath -> IO ()installOrdinaryFile verbosity :: Verbosityverbosity srcFile :: FilePathsrcFile destFile :: FilePathdestFile
| (relFile, srcFile) <- incs :: [([Char], FilePath)]incs
, let destFile = destIncludeDir :: FilePathdestIncludeDir (</>) :: FilePath -> FilePath -> FilePath</> relFile :: [Char]relFile
destDir = takeDirectory :: FilePath -> FilePathtakeDirectory destFile :: FilePathdestFile ]
where
relincdirs = "." (:) :: a -> [a] -> [a]: filter :: (a -> Bool) -> [a] -> [a]filter (not :: Bool -> Boolnot(.) :: (b -> c) -> (a -> b) -> a -> c.isAbsolute :: FilePath -> BoolisAbsolute) (includeDirs :: BuildInfo -> [FilePath]includeDirs lbi :: LocalBuildInfolbi)
lbi = libBuildInfo :: Library -> BuildInfolibBuildInfo lib :: Librarylib
findInc [] file = die :: String -> IO adie ("can't find include file " (++) :: [a] -> [a] -> [a]++ file :: FilePathfile)
findInc (dir:dirs) file = do
let path = dir :: FilePathdir (</>) :: FilePath -> FilePath -> FilePath</> file :: FilePathfile
exists <- doesFileExist :: FilePath -> IO BooldoesFileExist path :: FilePathpath
if exists :: Boolexists then return :: Monad m => forall a. a -> m areturn (file :: FilePathfile, path :: FilePathpath) else findInc :: [FilePath] -> [Char] -> IO ([Char], FilePath)findInc dirs :: [FilePath]dirs file :: FilePathfile
installIncludeFiles _ _ _ = die :: String -> IO adie "installIncludeFiles: Can't happen?"