Commit a8769407 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Add some more common utils we'll need in a sec and make use of intercalate

Have to define it locally since it only appeared in Data.List recently.
parent f996c255
......@@ -53,7 +53,7 @@ import System.Directory (doesFileExist)
import Distribution.PackageDescription
import Distribution.Compiler(CompilerFlavor(..))
import Distribution.License (License(..))
import Distribution.Simple.Utils (cabalVersion)
import Distribution.Simple.Utils (cabalVersion, intercalate)
import Distribution.Version (Version(..), withinRange, showVersionRange)
import Distribution.Package (PackageIdentifier(..))
......@@ -447,4 +447,4 @@ quote :: String -> String
quote s = "'" ++ s ++ "'"
commaSep :: [String] -> String
commaSep = concat . intersperse ","
commaSep = intercalate ","
......@@ -60,7 +60,7 @@ module Distribution.PackageDescription.Parse (
import Data.Char (isSpace, toLower)
import Data.Maybe (listToMaybe)
import Data.List (nub, unfoldr, partition, (\\), intersperse)
import Data.List (nub, unfoldr, partition, (\\))
import Control.Monad (liftM, foldM, when)
import System.Directory (doesFileExist)
......@@ -75,7 +75,7 @@ import Distribution.Version (Dependency, showVersion, parseVersion,
import Distribution.Verbosity (Verbosity)
import Distribution.Compiler (CompilerFlavor(..))
import Distribution.PackageDescription.Configuration (parseCondition, freeVars)
import Distribution.Simple.Utils (die, dieWithLocation, warn)
import Distribution.Simple.Utils (die, dieWithLocation, warn, intercalate)
-- -----------------------------------------------------------------------------
......@@ -615,7 +615,7 @@ parsePackageDescription file = do
let fv = nub $ freeVars ct
when (not . all (`elem` definedFlags) $ fv) $
fail $ "These flags are used without having been defined: " ++
(concat . intersperse " " $ (fv \\ definedFlags))
(intercalate " " (fv \\ definedFlags))
-- | Parse a list of fields, given a list of field descriptions,
......
......@@ -69,6 +69,7 @@ import Distribution.License
import Distribution.Version
import Distribution.Package ( parsePackageName )
import Distribution.Compat.ReadP as ReadP hiding (get)
import Distribution.Simple.Utils (intercalate)
import Language.Haskell.Extension (Extension)
import Text.PrettyPrint.HughesPJ hiding (braces)
......@@ -450,7 +451,7 @@ mkField d (Node (n,_,l) ts) = case span (\c -> isAlphaNum c || c == '-') l of
followingLines' = map (\(_,_,s) -> stripDot s) followingLines
allLines | null firstLine' = followingLines'
| otherwise = firstLine' : followingLines'
in (concat . intersperse "\n") allLines
in intercalate "\n" allLines
stripDot "." = ""
stripDot s = s
......
......@@ -91,7 +91,8 @@ import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.BuildPaths
( distPref )
import Distribution.Simple.Utils
( die, warn, info, setupMessage, createDirectoryIfMissingVerbose )
( die, warn, info, setupMessage, createDirectoryIfMissingVerbose
, intercalate )
import Distribution.Simple.Register
( removeInstalledConfig )
import Distribution.System
......@@ -238,7 +239,7 @@ configure (pkg_descr0, pbi) cfg
when (not (null flags)) $
info verbosity $ "Flags chosen: " ++ (concat . intersperse ", " .
info verbosity $ "Flags chosen: " ++ (intercalate ", " .
map (\(n,b) -> n ++ "=" ++ show b) $ flags)
checkPackageProblems verbosity (updatePackageDescription pbi pkg_descr)
......
......@@ -69,13 +69,13 @@ import Distribution.Version ( VersionRange(AnyVersion) )
import Distribution.Package ( PackageIdentifier(..), showPackageId,
parsePackageId )
import Distribution.Simple.Utils( createDirectoryIfMissingVerbose,
copyFileVerbose, die, info )
copyFileVerbose, die, info, intercalate )
import System.FilePath ( (</>) )
import Distribution.Verbosity
import Distribution.Compat.ReadP
( readP_to_S, many, skipSpaces )
import Data.List ( nub, intersperse )
import Data.List ( nub )
import Data.Char ( isSpace )
......@@ -161,10 +161,10 @@ jhcPkgConf :: PackageDescription -> String
jhcPkgConf pd =
let sline name sel = name ++ ": "++sel pd
Just lib = library pd
comma f l = concat $ intersperse "," $ map f l
comma = intercalate ","
in unlines [sline "name" (showPackageId . package)
,"exposed-modules: " ++ (comma id (exposedModules lib))
,"hidden-modules: " ++ (comma id (otherModules $ libBuildInfo lib))
,"exposed-modules: " ++ (comma (exposedModules lib))
,"hidden-modules: " ++ (comma (otherModules $ libBuildInfo lib))
]
installLib :: Verbosity -> FilePath -> FilePath -> PackageDescription -> Library -> IO ()
......
......@@ -46,38 +46,59 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.Simple.Utils (
cabalVersion,
-- * logging and errors
die,
dieWithLocation,
warn, notice, setupMessage, info, debug,
chattyTry,
breaks,
wrapText,
-- * running programs
rawSystemExit,
rawSystemStdout,
rawSystemStdout',
maybeExit,
xargs,
-- * copying files
smartCopySources,
createDirectoryIfMissingVerbose,
copyFileVerbose,
copyDirectoryRecursiveVerbose,
copyFiles,
-- * file names
currentDir,
dotToSep,
-- * finding files
findFile,
findFileWithExtension,
findFileWithExtension',
withTempFile,
-- * .cabal and .buildinfo files
defaultPackageDesc,
findPackageDesc,
defaultHookedPackageDesc,
findHookedPackageDesc,
-- * generic utils
equating,
comparing,
isInfixOf,
intercalate,
lowercase,
wrapText,
) where
import Control.Monad
( when, unless )
import Data.List
( nub, unfoldr )
( nub, unfoldr, isPrefixOf, tails, intersperse )
import Data.Char as Char
( toLower )
import System.Directory
( getDirectoryContents, getCurrentDirectory, doesDirectoryExist
......@@ -507,3 +528,22 @@ findHookedPackageDesc dir = do
[] -> return Nothing
[f] -> return (Just f)
_ -> die ("Multiple files with extension " ++ buildInfoExt)
-- ------------------------------------------------------------
-- * Common utils
-- ------------------------------------------------------------
equating :: Eq a => (b -> a) -> b -> b -> Bool
equating p x y = p x == p y
comparing :: Ord a => (b -> a) -> b -> b -> Ordering
comparing p x y = p x `compare` p y
isInfixOf :: String -> String -> Bool
isInfixOf needle haystack = any (isPrefixOf needle) (tails haystack)
intercalate :: [a] -> [[a]] -> [a]
intercalate sep = concat . intersperse sep
lowercase :: String -> String
lowercase = map Char.toLower
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