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

Add setup register --gen-pkg-config flag for distros that want that.

It generates the actual file to be passed to the compiler's package program.
This is obviously compiler-specific.
parent a8c1ea26
......@@ -221,6 +221,8 @@ data SDistFlags = SDistFlags {sDistSnapshot :: Bool
-- in-place, verbosity)
data RegisterFlags = RegisterFlags { regUser :: MaybeUserFlag
, regGenScript :: Bool
, regGenPkgConf :: Bool
, regPkgConfFile :: Maybe FilePath
, regInPlace :: Bool
, regWithHcPkg :: Maybe FilePath
, regVerbose :: Verbosity }
......@@ -230,6 +232,8 @@ data RegisterFlags = RegisterFlags { regUser :: MaybeUserFlag
emptyRegisterFlags :: RegisterFlags
emptyRegisterFlags = RegisterFlags { regUser = MaybeUserNone,
regGenScript = False,
regGenPkgConf = False,
regPkgConfFile = Nothing,
regInPlace = False,
regWithHcPkg = Nothing,
regVerbose = normal }
......@@ -317,6 +321,7 @@ data Flag a = GhcFlag | NhcFlag | HugsFlag | JhcFlag
| UserFlag | GlobalFlag
-- for register & unregister
| GenScriptFlag
| GetPkgConfFlag (Maybe FilePath)
| InPlaceFlag
-- For copy:
| InstPrefix FilePath
......@@ -850,7 +855,9 @@ registerCmd = Cmd {
Option "" ["inplace"] (NoArg InPlaceFlag)
"register the package in the build location, so it can be used without being installed",
Option "" ["gen-script"] (NoArg GenScriptFlag)
"Instead of performing the register command, generate a script to register later",
"instead of registering, generate a script to register later",
Option "" ["gen-pkg-config"] (OptArg GetPkgConfFlag "PKG")
"instead of registering, generate a package registration file",
cmd_with_hc_pkg
],
cmdAction = RegisterCmd
......@@ -866,6 +873,11 @@ registerUpdateCfg reg fl = case fl of
GlobalFlag -> reg { regUser=MaybeUserGlobal }
Verbose n -> reg { regVerbose=n }
GenScriptFlag -> reg { regGenScript=True }
GetPkgConfFlag
Nothing -> reg { regGenPkgConf=True }
GetPkgConfFlag
(Just f) -> reg { regGenPkgConf=True,
regPkgConfFile=Just f }
InPlaceFlag -> reg { regInPlace=True }
WithHcPkg f -> reg { regWithHcPkg=Just f }
_ -> error $ "Unexpected flag!"
......
......@@ -652,14 +652,14 @@ defaultBuildHook :: PackageDescription -> LocalBuildInfo
defaultBuildHook pkg_descr localbuildinfo hooks flags = do
build pkg_descr localbuildinfo flags (allSuffixHandlers hooks)
when (hasLibs pkg_descr) $
writeInstalledConfig pkg_descr localbuildinfo False
writeInstalledConfig pkg_descr localbuildinfo False Nothing
defaultMakefileHook :: PackageDescription -> LocalBuildInfo
-> UserHooks -> MakefileFlags -> IO ()
defaultMakefileHook pkg_descr localbuildinfo hooks flags = do
makefile pkg_descr localbuildinfo flags (allSuffixHandlers hooks)
when (hasLibs pkg_descr) $
writeInstalledConfig pkg_descr localbuildinfo False
writeInstalledConfig pkg_descr localbuildinfo False Nothing
defaultRegHook :: PackageDescription -> LocalBuildInfo
-> UserHooks -> RegisterFlags -> IO ()
......
......@@ -86,13 +86,13 @@ import Distribution.Compat.Directory
setPermissions, getPermissions, Permissions(executable)
)
import System.FilePath ((</>), isAbsolute)
import System.FilePath ((</>), (<.>), isAbsolute)
import System.Directory(doesFileExist, removeFile, getCurrentDirectory)
import System.IO.Error (try)
import Control.Monad (when, unless)
import Data.Maybe (isNothing, fromJust)
import Data.Maybe (isNothing, fromJust, fromMaybe)
import Data.List (partition)
#ifdef DEBUG
......@@ -126,15 +126,21 @@ register pkg_descr lbi regFlags
| otherwise = do
let ghc_63_plus = compilerVersion (compiler lbi) >= Version [6,3] []
genScript = regGenScript regFlags
genPkgConf = regGenPkgConf regFlags
genPkgConfigDefault = showPackageId (package pkg_descr) <.> "conf"
genPkgConfigFile = fromMaybe genPkgConfigDefault
(regPkgConfFile regFlags)
verbosity = regVerbose regFlags
user = regUser regFlags `userOverride` userConf lbi
inplace = regInPlace regFlags
hc = updateCompilerPkgTool (regWithHcPkg regFlags) (compiler lbi)
setupMessage (regVerbose regFlags)
(if genScript
then ("Writing registration script: " ++ regScriptLocation ++ " for")
else "Registering")
pkg_descr
message | genPkgConf = "Writing package registration file: "
++ genPkgConfigFile ++ " for"
| genScript = "Writing registration script: "
++ regScriptLocation ++ " for"
| otherwise = "Registering"
setupMessage (regVerbose regFlags) message pkg_descr
case compilerFlavor hc of
GHC -> do
config_flags <-
......@@ -150,13 +156,14 @@ register pkg_descr lbi regFlags
return ["--config-file=" ++ localConf]
else return []
let instConf = if inplace then inplacePkgConfigFile
else installedPkgConfigFile
let instConf | genPkgConf = genPkgConfigFile
| inplace = inplacePkgConfigFile
| otherwise = installedPkgConfigFile
unless genScript $ do
when (genPkgConf || not genScript) $ do
when (verbosity >= verbose) $
putStrLn ("create " ++ instConf)
writeInstalledConfig pkg_descr lbi inplace
writeInstalledConfig pkg_descr lbi inplace (Just instConf)
let register_flags
| ghc_63_plus = "update":
......@@ -179,11 +186,13 @@ register pkg_descr lbi regFlags
++ if ghc_63_plus && genScript then ["-"] else []
let pkgTool = compilerPkgToolPath hc
if genScript
then do cfg <- showInstalledConfig pkg_descr lbi inplace
case () of
_ | genPkgConf -> return ()
| genScript ->
do cfg <- showInstalledConfig pkg_descr lbi inplace
rawSystemPipe regScriptLocation verbosity cfg
pkgTool allFlags
else rawSystemExit verbosity pkgTool allFlags
_ -> rawSystemExit verbosity pkgTool allFlags
Hugs -> do
when inplace $ die "--inplace is not supported with Hugs"
......@@ -205,11 +214,14 @@ userPkgConfErr local_conf =
-- |Register doesn't drop the register info file, it must be done in a
-- separate step.
writeInstalledConfig :: PackageDescription -> LocalBuildInfo -> Bool -> IO ()
writeInstalledConfig pkg_descr lbi inplace = do
writeInstalledConfig :: PackageDescription -> LocalBuildInfo -> Bool
-> Maybe FilePath -> IO ()
writeInstalledConfig pkg_descr lbi inplace instConfOverride = do
pkg_config <- showInstalledConfig pkg_descr lbi inplace
writeFile (if inplace then inplacePkgConfigFile else installedPkgConfigFile)
(pkg_config ++ "\n")
let instConfDefault | inplace = inplacePkgConfigFile
| otherwise = installedPkgConfigFile
instConf = fromMaybe instConfDefault instConfOverride
writeFile instConf (pkg_config ++ "\n")
-- |Create a string suitable for writing out to the package config file
showInstalledConfig :: PackageDescription -> LocalBuildInfo -> Bool
......
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