Commit 0d8ee7b8 authored by ijones's avatar ijones
Browse files

moved currentDir into utils

Utils used to depend on Distribution.Package, so Package couldn't
easily use Utils.  I removed this dependency by moving a couple of
functions into D.Package, then moved currentDir into Utils where it
belongs.
parent c99385d6
......@@ -53,16 +53,18 @@ module Distribution.Package (
Executable(..),
emptyExecutable,
allModules,
setupMessage,
withLib,
#ifdef DEBUG
hunitTests,
test
#endif
) where
import Control.Monad(foldM, liftM)
import Control.Monad(foldM, liftM, when)
import Data.Char
import Data.List(concatMap)
import Data.Maybe(fromMaybe)
import Data.Maybe(fromMaybe, fromJust)
import Text.PrettyPrint.HughesPJ
import Distribution.Version(Version(..), VersionRange(..),
......@@ -70,6 +72,7 @@ import Distribution.Version(Version(..), VersionRange(..),
showVersionRange, parseVersionRange)
import Distribution.Misc(License(..), Dependency(..), Extension(..))
import Distribution.Setup(CompilerFlavor(..))
import Distribution.Simple.Utils(currentDir)
import Compat.H98
import Compat.ReadP hiding (get)
......@@ -156,9 +159,6 @@ data BuildInfo = BuildInfo {
}
deriving (Show,Read,Eq)
currentDir :: FilePath
currentDir = "."-- FIX: FileUtils.currentDir
emptyBuildInfo :: BuildInfo
emptyBuildInfo = BuildInfo {
buildDepends = [],
......@@ -193,6 +193,20 @@ emptyExecutable = Executable {
buildInfo = emptyBuildInfo
}
-- ------------------------------------------------------------
-- * Utils
-- ------------------------------------------------------------
-- |If the package description has a library section, call the given
-- function with the library build info as argument.
withLib :: PackageDescription -> (BuildInfo -> IO ()) -> IO ()
withLib pkg_descr f = when (hasLibs pkg_descr) $ f (fromJust (library pkg_descr))
setupMessage :: String -> PackageDescription -> IO ()
setupMessage msg pkg_descr =
putStrLn (msg ++ ' ':showPackageId (package pkg_descr) ++ "...")
-- ------------------------------------------------------------
-- * Parsing & Pretty printing
-- ------------------------------------------------------------
......
......@@ -43,9 +43,10 @@ module Distribution.PreProcess (preprocessSources, knownSuffixHandlers,
where
import Distribution.PreProcess.Unlit(plain, unlit)
import Distribution.Package (PackageDescription(..), BuildInfo(..), Executable(..))
import Distribution.Package (setupMessage, PackageDescription(..),
BuildInfo(..), Executable(..))
import Distribution.Simple.Configure (LocalBuildInfo(..))
import Distribution.Simple.Utils (setupMessage, rawSystemPath, splitFilePath,
import Distribution.Simple.Utils (rawSystemPath, splitFilePath,
joinFilenameDir, joinExt, moduleToFilePath,
sequenceMap, removeFiles, hasExt, pathJoin)
import Control.Monad(when)
......
......@@ -67,7 +67,7 @@ import Distribution.Simple.Register ( register, unregister,
import Distribution.Simple.Configure(LocalBuildInfo(..), getPersistBuildConfig,
configure, writePersistBuildConfig, localBuildInfoFile)
import Distribution.Simple.Install(install)
import Distribution.Simple.Utils (die, pathJoin, removeFileRecursive)
import Distribution.Simple.Utils (die, pathJoin, removeFileRecursive, currentDir)
import Distribution.Misc (License(..), Extension(..), Dependency(..))
import Distribution.Version (Version(..), VersionRange(..),
orLaterVersion, orEarlierVersion,
......@@ -97,9 +97,6 @@ doBuildInstall f pkgConf
= do lbi <- getPersistBuildConfig
f pkgConf lbi
currentDir :: FilePath
currentDir = "."-- FIX: FileUtils.currentDir
defaultMain :: IO ()
defaultMain = readPackageDescription defaultPackageDesc >>= defaultMainNoRead
......
......@@ -50,15 +50,14 @@ module Distribution.Simple.Build (
import Distribution.Misc (extensionsToGHCFlag, extensionsToNHCFlag)
import Distribution.Setup (Compiler(..), CompilerFlavor(..))
import Distribution.Package (PackageIdentifier(..), PackageDescription(..),
BuildInfo(..), showPackageId, Executable(..))
BuildInfo(..), showPackageId, setupMessage,
withLib, Executable(..))
import Distribution.PreProcess (preprocessSources, PPSuffixHandler)
import Distribution.Simple.Configure (LocalBuildInfo(..), compiler, exeDeps)
import Distribution.Simple.Utils (rawSystemExit, setupMessage,
die, rawSystemPathExit,
import Distribution.Simple.Utils (rawSystemExit, die, rawSystemPathExit,
split, createIfNotExists,
mkLibName, pathJoin,
splitFilePath, joinFilenameDir, joinExt,
withLib
splitFilePath, joinFilenameDir, joinExt
)
......
......@@ -61,10 +61,11 @@ import Distribution.Misc(Dependency(..), extensionsToGHCFlag,
extensionsToNHCFlag, extensionsToHugsFlag)
import Distribution.Setup(ConfigFlags,CompilerFlavor(..), Compiler(..))
import Distribution.Package(PackageDescription(..), PackageIdentifier(..),
BuildInfo(..), Executable(..), emptyPackageDescription
BuildInfo(..), Executable(..), setupMessage,
emptyPackageDescription
)
import Distribution.Simple.Utils (die, setupMessage, findBinary,
splitFilePath, joinFilenameDir, joinExt)
import Distribution.Simple.Utils (die, findBinary, splitFilePath,
joinFilenameDir, joinExt)
import Distribution.Package ( PackageIdentifier )
import Distribution.Version (Version(..), VersionRange(..))
......
......@@ -55,9 +55,9 @@ module Distribution.Simple.Install (
#endif
import Distribution.Package (PackageDescription(..), BuildInfo(..), Executable(..),
showPackageId, hasLibs)
showPackageId, setupMessage, hasLibs)
import Distribution.Simple.Configure(LocalBuildInfo(..))
import Distribution.Simple.Utils(setupMessage, moveSources,
import Distribution.Simple.Utils(moveSources,
mkLibName, pathJoin,
copyFile, die, createIfNotExists
)
......
......@@ -55,8 +55,8 @@ module Distribution.Simple.Register (
import Distribution.Simple.Configure (LocalBuildInfo, compiler)
import Distribution.Setup (CompilerFlavor(..), Compiler(..))
import Distribution.Package (PackageDescription(..), PackageIdentifier(..))
import Distribution.Simple.Utils (setupMessage, rawSystemExit, die)
import Distribution.Package (setupMessage, PackageDescription(..), PackageIdentifier(..))
import Distribution.Simple.Utils (rawSystemExit, die)
import Distribution.Simple.GHCPackageConfig (mkGHCPackageConfig, showGHCPackageConfig)
import qualified Distribution.Simple.GHCPackageConfig as GHC (localPackageConfig)
......
......@@ -50,9 +50,10 @@ module Distribution.Simple.SrcDist (
#endif
) where
import Distribution.Package(PackageDescription(..), BuildInfo(..), buildInfo, showPackageId)
import Distribution.Package(PackageDescription(..), BuildInfo(..), buildInfo,
setupMessage, showPackageId)
import Distribution.Simple.Configure(LocalBuildInfo)
import Distribution.Simple.Utils(setupMessage, moveSources, die, pathJoin, sequenceMap)
import Distribution.Simple.Utils(moveSources, die, pathJoin, sequenceMap)
import Distribution.PreProcess (PPSuffixHandler, ppSuffixes, removePreprocessed)
import Control.Monad(when)
......
......@@ -49,7 +49,6 @@ module Distribution.Simple.Utils (
isPathSeparator,
pathSeparatorStr,
split,
setupMessage,
die,
findBinary,
rawSystemPath,
......@@ -63,10 +62,10 @@ module Distribution.Simple.Utils (
copyFile,
pathJoin,
removeFileRecursive,
withLib,
sequenceMap,
removeFiles,
hasExt,
currentDir,
#ifdef DEBUG
hunitTests
#endif
......@@ -76,9 +75,6 @@ module Distribution.Simple.Utils (
#include "config.h"
#endif
import Distribution.Package (PackageDescription(..), showPackageId,
BuildInfo(..), hasLibs)
import Control.Monad(when, unless, liftM, mapM)
import Data.List(nub, intersperse, findIndices)
import Data.Maybe(Maybe, listToMaybe, isNothing, fromJust, catMaybes)
......@@ -242,10 +238,6 @@ parsePath path = split pathSep path
-- -----------------------------------------------------------------------------
-- Utils for setup
setupMessage :: String -> PackageDescription -> IO ()
setupMessage msg pkg_descr =
putStrLn (msg ++ ' ':showPackageId (package pkg_descr) ++ "...")
die :: String -> IO a
die msg = do hFlush stdout; hPutStr stderr (msg++"\n"); exitWith (ExitFailure 1)
......@@ -390,6 +382,10 @@ moveSources pref _targetDir sources searchSuffixes
>> exitWith (ExitFailure 1))
return p
-- |The path name that represents the current directory. May be
-- system-specific. In Unix, it's "." FIX: What about other arches?
currentDir :: FilePath
currentDir = "."
mkLibName :: FilePath -- ^file Prefix
-> String -- ^library name.
......@@ -493,12 +489,6 @@ filesWithExtensions dir extension
= do allFiles <- getDirectoryContents dir
return $ filter ((flip hasExt) extension) allFiles
-- |If the package description has a library section, call the given
-- function with the library build info as argument.
withLib :: PackageDescription -> (BuildInfo -> IO ()) -> IO ()
withLib pkg_descr f = when (hasLibs pkg_descr) $ f (fromJust (library pkg_descr))
sequenceMap :: (Monad m) => (a -> m b) -> [a] -> m [b]
sequenceMap f l = sequence $ map f l
......
** where are we using allModules, is this the right place?
** move some of the junk in Utils up one level, then use currentDir =
"." there.
** integrate w/ GHC distro
** what other preprocessors can't unlit?
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment