Fix warnings as of GHC 8.2.2 / Cabal 2.0.1.0.

parent c05c43ff
......@@ -28,7 +28,7 @@ import Distribution.PackageDescription (
PackageDescription,
package,
#if MIN_VERSION_Cabal(2,0,0)
FlagName, mkFlagName,
mkFlagName,
#else
FlagName (FlagName),
#endif
......@@ -45,13 +45,15 @@ import Distribution.Simple.LocalBuildInfo (
)
import Distribution.Simple.Program (
Program,
ProgramConfiguration,
getProgramOutput,
lookupProgram,
programPath,
runDbProgram,
simpleProgram,
)
-- I don't think Distribution.Simple.Program exported ProgramDb back in
-- Cabal-1.22.5.0, so we import it from the Db submodule:
import Distribution.Simple.Program.Db (ProgramDb)
import Distribution.Simple.Setup (
BuildFlags,
CleanFlags,
......@@ -79,8 +81,12 @@ import Distribution.Simple.UserHooks (
postConf
),
)
#if MIN_VERSION_Cabal(2,0,0)
import Distribution.Simple.Utils (die')
#else
import Distribution.Simple.Utils (die)
#endif
import Distribution.Simple.Utils (
die,
info,
installOrdinaryFile,
notice,
......@@ -141,10 +147,15 @@ listenerGenProgram = simpleProgram "qtah-listener-gen"
makeProgram :: Program
makeProgram = simpleProgram "make"
findQmake :: ProgramConfiguration -> Verbosity -> IO (FilePath, [String])
findQmake :: ProgramDb -> Verbosity -> IO (FilePath, [String])
findQmake programDb verbosity = do
#if MIN_VERSION_Cabal(2,0,0)
let dieFn = die' verbosity
#else
let dieFn = die
#endif
generatorConfiguredProgram <-
maybe (die $ packageName ++ ": Couldn't find qtah-generator. Is it installed?") return $
maybe (dieFn $ packageName ++ ": Couldn't find qtah-generator. Is it installed?") return $
lookupProgram generatorProgram programDb
output <- fmap lines $
getProgramOutput verbosity generatorConfiguredProgram ["--qmake-executable"]
......@@ -159,6 +170,11 @@ generateSources configFlags localBuildInfo = do
let cppSourceDir = startDir </> "cpp"
programDb = withPrograms localBuildInfo
verbosity = fromFlagOrDefault normal $ configVerbosity configFlags
#if MIN_VERSION_Cabal(2,0,0)
dieFn = die' verbosity
#else
dieFn = die
#endif
-- Parse the Qt version to use from flags and the environment, and export it
-- to the generator.
......@@ -166,7 +182,7 @@ generateSources configFlags localBuildInfo = do
listenerGenPath <- case lookupProgram listenerGenProgram programDb of
Nothing ->
die $ packageName ++
dieFn $ packageName ++
": Couldn't find qtah-listener-gen. Is qtah-generator installed and on the path?"
Just configuredProgram -> return $ programPath configuredProgram
......@@ -273,6 +289,11 @@ exportQtVersion :: ConfigFlags -> LocalBuildInfo -> IO String
exportQtVersion configFlags localBuildInfo = do
let verbosity = fromFlagOrDefault normal $ configVerbosity configFlags
programDb = withPrograms localBuildInfo
#if MIN_VERSION_Cabal(2,0,0)
dieFn = die' verbosity
#else
dieFn = die
#endif
-- Determine what version of Qt to use. If we have a Qt version preference
-- specified, either through package flags or through QTAH_QT, then
......@@ -294,7 +315,7 @@ exportQtVersion configFlags localBuildInfo = do
qt5Flag = fromMaybe False $ lookup (mkFlagName "qt5") flags
qtFlag = if qt4Flag then Just 4 else if qt5Flag then Just 5 else Nothing
when (qt4Flag && qt5Flag) $
die $ concat
dieFn $ concat
[packageName, ": The qt4 and qt5 flags are mutually exclusive. Please select at most one."]
-- Inspect the QTAH_QT environment variable.
......@@ -303,8 +324,8 @@ exportQtVersion configFlags localBuildInfo = do
Just s | not $ null s -> do
let majorStr = takeWhile (/= '.') s
unless (all isDigit majorStr) $
die $ concat [packageName, ": Invalid QTAH_QT value ", show s,
". Expected a numeric version string."]
dieFn $ concat [packageName, ": Invalid QTAH_QT value ", show s,
". Expected a numeric version string."]
return $ Just (read majorStr :: Int)
_ -> return Nothing
......@@ -314,7 +335,7 @@ exportQtVersion configFlags localBuildInfo = do
-- If both QTAH_QT and one of the qtX flags above is set, then they must agree.
(Just m, Just n) -> do
when (m /= n) $
die $ concat
dieFn $ concat
[packageName, ": QTAH_QT=", show $ fromMaybe "" qtahQtStr, " and the qt",
show n, " flag conflict."]
-- Otherwise, if QTAH_QT is not already set but we have a flag preference,
......@@ -344,12 +365,12 @@ exportQtVersion configFlags localBuildInfo = do
-- Log a message showing which Qt qtah-generator is actually using.
generatorConfiguredProgram <-
maybe (die $ packageName ++ ": Couldn't find qtah-generator. Is it installed?") return $
maybe (dieFn $ packageName ++ ": Couldn't find qtah-generator. Is it installed?") return $
lookupProgram generatorProgram programDb
qtVersionOutput <- getProgramOutput verbosity generatorConfiguredProgram ["--qt-version"]
qtVersion <- case lines qtVersionOutput of
[line] -> return line
_ -> die $ concat
_ -> dieFn $ concat
[packageName, ": Couldn't understand qtah-generator --qt-version output: ",
show qtVersionOutput]
notice verbosity $
......
......@@ -16,6 +16,7 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
{-# OPTIONS_GHC -W -fwarn-incomplete-patterns -fwarn-unused-do-bind #-}
{-# LANGUAGE CPP, RankNTypes #-}
import Control.Monad (unless, when)
import Distribution.PackageDescription (PackageDescription)
......@@ -35,9 +36,15 @@ import Distribution.Simple.Setup (
cleanVerbosity,
configVerbosity,
copyDest,
#if MIN_VERSION_Cabal(2,0,0)
copyVerbosity,
#endif
flagToMaybe,
fromFlagOrDefault,
installDistPref,
#if MIN_VERSION_Cabal(2,0,0)
installVerbosity,
#endif
)
import Distribution.Simple.UserHooks (
UserHooks (
......@@ -48,7 +55,12 @@ import Distribution.Simple.UserHooks (
postConf
),
)
import Distribution.Simple.Utils (die, info, installExecutableFile)
#if MIN_VERSION_Cabal(2,0,0)
import Distribution.Simple.Utils (die')
#else
import Distribution.Simple.Utils (die)
#endif
import Distribution.Simple.Utils (info, installExecutableFile)
import Distribution.Verbosity (normal, verbose)
import System.Directory (
createDirectoryIfMissing,
......@@ -62,6 +74,8 @@ import System.Directory (
)
import System.FilePath ((</>), joinPath, takeDirectory)
type DieFn = forall a. String -> IO a
main :: IO ()
main = defaultMainWithHooks qtahHooks
......@@ -71,10 +85,21 @@ qtahHooks = simpleUserHooks
, postConf = \_ cf _ lbi -> generateSources cf lbi
, copyHook = \pd lbi uh cf -> do let dest = fromFlagOrDefault NoCopyDest $ copyDest cf
doInstall pd lbi dest
#if MIN_VERSION_Cabal(2,0,0)
(die' $ fromFlagOrDefault normal $ copyVerbosity cf)
#else
die
#endif
copyHook simpleUserHooks pd lbi uh cf
, instHook = \pd lbi uh if' -> do let dest = maybe NoCopyDest CopyTo $
flagToMaybe $ installDistPref if'
doInstall pd lbi dest
#if MIN_VERSION_Cabal(2,0,0)
(die' $ fromFlagOrDefault normal $ installVerbosity if')
#else
die
#endif
instHook simpleUserHooks pd lbi uh if'
, cleanHook = \pd z uh cf -> do doClean cf
cleanHook simpleUserHooks pd z uh cf
......@@ -83,18 +108,27 @@ qtahHooks = simpleUserHooks
bashProgram :: Program
bashProgram = simpleProgram "bash"
findProjectRootDir :: LocalBuildInfo -> IO FilePath
findProjectRootDir localBuildInfo = case pkgDescrFile localBuildInfo of
findProjectRootDir :: LocalBuildInfo -> DieFn -> IO FilePath
findProjectRootDir localBuildInfo dieFn = case pkgDescrFile localBuildInfo of
Just path -> return $ takeDirectory path
Nothing -> die "Couldn't find the project root path."
Nothing -> dieFn "Couldn't find the project root path."
generateSources :: ConfigFlags -> LocalBuildInfo -> IO ()
generateSources configFlags localBuildInfo = do
-- Generate binding sources for the generated C++ listener classes.
projectRootDir <- findProjectRootDir localBuildInfo
let verbosity = fromFlagOrDefault normal $ configVerbosity configFlags
projectRootDir <-
findProjectRootDir
localBuildInfo
#if MIN_VERSION_Cabal(2,0,0)
(die' verbosity)
#else
die
#endif
let genPath = projectRootDir </> "qtah-listener-gen"
programDb = withPrograms localBuildInfo
verbosity = fromFlagOrDefault normal $ configVerbosity configFlags
-- Cabal 1.24 (GHC 8?) seems to remove the executable bit from
-- qtah-listener-gen before configuring, so we have to re-add it.
......@@ -106,9 +140,9 @@ generateSources configFlags localBuildInfo = do
runDbProgram verbosity bashProgram programDb [genPath, "--gen-hs-dir", "."]
doInstall :: PackageDescription -> LocalBuildInfo -> CopyDest -> IO ()
doInstall packageDesc localBuildInfo copyDest = do
projectRootDir <- findProjectRootDir localBuildInfo
doInstall :: PackageDescription -> LocalBuildInfo -> CopyDest -> DieFn -> IO ()
doInstall packageDesc localBuildInfo copyDest dieFn = do
projectRootDir <- findProjectRootDir localBuildInfo dieFn
let binDir = bindir $ absoluteInstallDirs packageDesc localBuildInfo copyDest
createDirectoryIfMissing True binDir
installExecutableFile verbose
......
......@@ -16,7 +16,7 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
{-# OPTIONS_GHC -W -fwarn-incomplete-patterns -fwarn-unused-do-bind #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE CPP, RankNTypes #-}
import Control.Applicative ((<|>))
import Control.Monad (unless, when)
......@@ -27,7 +27,7 @@ import Distribution.InstalledPackageInfo (libraryDirs)
import Distribution.Package (
pkgName, unPackageName,
#if MIN_VERSION_Cabal(2,0,0)
PackageName, mkPackageName,
mkPackageName,
#else
PackageName (PackageName),
#endif
......@@ -40,7 +40,7 @@ import Distribution.PackageDescription (
extraLibs,
package,
#if MIN_VERSION_Cabal(2,0,0)
FlagName, mkFlagName,
mkFlagName,
#else
FlagName (FlagName),
#endif
......@@ -91,7 +91,12 @@ import Distribution.Simple.UserHooks (
preTest
),
)
import Distribution.Simple.Utils (die, info, installOrdinaryFile, notice)
#if MIN_VERSION_Cabal(2,0,0)
import Distribution.Simple.Utils (die')
#else
import Distribution.Simple.Utils (die)
#endif
import Distribution.Simple.Utils (info, installOrdinaryFile, notice)
import Distribution.Verbosity (Verbosity, normal)
import System.Directory (
createDirectoryIfMissing,
......@@ -105,6 +110,8 @@ import System.Directory (
import System.Environment (lookupEnv, setEnv)
import System.FilePath ((</>), joinPath, takeDirectory)
type DieFn = forall a. String -> IO a
#if !MIN_VERSION_Cabal(2,0,0)
mkPackageName = PackageName
mkFlagName = FlagName
......@@ -124,7 +131,13 @@ main = defaultMainWithHooks qtahHooks
qtahHooks :: UserHooks
qtahHooks = simpleUserHooks
{ hookedPrograms = [generatorProgram]
, postConf = \args cf pd lbi -> do libDir <- lookupQtahCppLibDir lbi
, postConf = \args cf pd lbi -> do libDir <-
lookupQtahCppLibDir lbi
#if MIN_VERSION_Cabal(2,0,0)
(die' $ fromFlagOrDefault normal $ configVerbosity cf)
#else
die
#endif
storeQtahCppLibDir libDir
generateSources cf lbi libDir
postConf simpleUserHooks args cf pd lbi
......@@ -149,14 +162,14 @@ qtahHooks = simpleUserHooks
qtahCppLibDirFile :: FilePath
qtahCppLibDirFile = "dist/build/qtah-cpp-libdir"
lookupQtahCppLibDir :: LocalBuildInfo -> IO String
lookupQtahCppLibDir localBuildInfo = do
lookupQtahCppLibDir :: LocalBuildInfo -> DieFn -> IO String
lookupQtahCppLibDir localBuildInfo dieFn = do
-- Look for an installed qtah-cpp package.
qtahCppPkg <- case lookupPackageName (installedPkgs localBuildInfo) $
mkPackageName cppPackageName of
[(_, [qtahCppPkg])] -> return qtahCppPkg
results ->
die $ concat
dieFn $ concat
[packageName, ": Failed to find a unique ", cppPackageName, " installation. Found ",
show results, "."]
......@@ -164,7 +177,7 @@ lookupQtahCppLibDir localBuildInfo = do
-- where libraryDirs includes the library directories of dependencies as well.
case filter (\x -> cppPackageName `isInfixOf` x) $ libraryDirs qtahCppPkg of
[libDir] -> return libDir
libDirs -> die $ concat
libDirs -> dieFn $ concat
[packageName, ": Expected a single library directory for ",
cppPackageName, ", got ", show libDirs, "."]
......@@ -191,6 +204,11 @@ generateSources :: ConfigFlags -> LocalBuildInfo -> FilePath -> IO ()
generateSources configFlags localBuildInfo qtahCppLibDir = do
let verbosity = fromFlagOrDefault normal $ configVerbosity configFlags
programDb = withPrograms localBuildInfo
#if MIN_VERSION_Cabal(2,0,0)
dieFn = die' verbosity
#else
dieFn = die
#endif
-- Parse the Qt version to use from flags and the environment, and export it
-- to the generator.
......@@ -201,12 +219,12 @@ generateSources configFlags localBuildInfo qtahCppLibDir = do
qtahCppQtVersion <-
(\contents -> case lines contents of
[line] -> return line
_ -> die $ concat
_ -> dieFn $ concat
[packageName, ": Expected a single line in ", qtahCppQtVersionFile, ", got ",
show contents, "."]) =<<
readFile qtahCppQtVersionFile
when (qtVersion /= qtahCppQtVersion) $
die $ concat
dieFn $ concat
[packageName, ": Qt version mismatch between ", packageName, " (", qtVersion, ") and ",
cppPackageName, " (", qtahCppQtVersion, "). Please reconfigure one or the other."]
......@@ -292,6 +310,11 @@ exportQtVersion :: ConfigFlags -> LocalBuildInfo -> IO String
exportQtVersion configFlags localBuildInfo = do
let verbosity = fromFlagOrDefault normal $ configVerbosity configFlags
programDb = withPrograms localBuildInfo
#if MIN_VERSION_Cabal(2,0,0)
dieFn = die' verbosity
#else
dieFn = die
#endif
-- Determine what version of Qt to use. If we have a Qt version preference
-- specified, either through package flags or through QTAH_QT, then
......@@ -313,7 +336,7 @@ exportQtVersion configFlags localBuildInfo = do
qt5Flag = fromMaybe False $ lookup (mkFlagName "qt5") flags
qtFlag = if qt4Flag then Just 4 else if qt5Flag then Just 5 else Nothing
when (qt4Flag && qt5Flag) $
die $ concat
dieFn $ concat
[packageName, ": The qt4 and qt5 flags are mutually exclusive. Please select at most one."]
-- Inspect the QTAH_QT environment variable.
......@@ -322,7 +345,7 @@ exportQtVersion configFlags localBuildInfo = do
Just s | not $ null s -> do
let majorStr = takeWhile (/= '.') s
unless (all isDigit majorStr) $
die $ concat [packageName, ": Invalid QTAH_QT value ", show s,
dieFn $ concat [packageName, ": Invalid QTAH_QT value ", show s,
". Expected a numeric version string."]
return $ Just (read majorStr :: Int)
_ -> return Nothing
......@@ -333,7 +356,7 @@ exportQtVersion configFlags localBuildInfo = do
-- If both QTAH_QT and one of the qtX flags above is set, then they must agree.
(Just m, Just n) -> do
when (m /= n) $
die $ concat
dieFn $ concat
[packageName, ": QTAH_QT=", show $ fromMaybe "" qtahQtStr, " and the qt",
show n, " flag conflict."]
-- Otherwise, if QTAH_QT is not already set but we have a flag preference,
......@@ -363,12 +386,12 @@ exportQtVersion configFlags localBuildInfo = do
-- Log a message showing which Qt qtah-generator is actually using.
generatorConfiguredProgram <-
maybe (die $ packageName ++ ": Couldn't find qtah-generator. Is it installed?") return $
maybe (dieFn $ packageName ++ ": Couldn't find qtah-generator. Is it installed?") return $
lookupProgram generatorProgram programDb
qtVersionOutput <- getProgramOutput verbosity generatorConfiguredProgram ["--qt-version"]
qtVersion <- case lines qtVersionOutput of
[line] -> return line
_ -> die $ concat
_ -> dieFn $ concat
[packageName, ": Couldn't understand qtah-generator --qt-version output: ",
show qtVersionOutput]
notice verbosity $
......
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