Commit fa2eac9f authored by Merijn Verstraaten's avatar Merijn Verstraaten
Browse files

Pass the REPL options to the REPL executable.

parent 56cd88d9
......@@ -171,8 +171,9 @@ repl pkg_descr lbi flags suffixes args = do
let clbi = targetCLBI target
comp = targetComponent target
lbi' = lbiForComponent comp lbi
replFlags = replReplOptions flags
componentInitialBuildSteps distPref pkg_descr lbi clbi verbosity
replComponent verbosity pkg_descr lbi' suffixes comp clbi distPref
replComponent replFlags verbosity pkg_descr lbi' suffixes comp clbi distPref
-- | Start an interpreter without loading any package files.
......@@ -340,7 +341,8 @@ addExtraCxxSources bi extras = bi { cxxSources = new }
exs = Set.fromList extras
replComponent :: Verbosity
replComponent :: [String]
-> Verbosity
-> PackageDescription
-> LocalBuildInfo
-> [PPSuffixHandler]
......@@ -348,29 +350,29 @@ replComponent :: Verbosity
-> ComponentLocalBuildInfo
-> FilePath
-> IO ()
replComponent verbosity pkg_descr lbi suffixes
replComponent replFlags verbosity pkg_descr lbi suffixes
comp@(CLib lib) clbi _ = do
preprocessComponent pkg_descr comp lbi clbi False verbosity suffixes
extras <- preprocessExtras verbosity comp lbi
let libbi = libBuildInfo lib
lib' = lib { libBuildInfo = libbi { cSources = cSources libbi ++ extras } }
replLib verbosity pkg_descr lbi lib' clbi
replLib replFlags verbosity pkg_descr lbi lib' clbi
replComponent verbosity pkg_descr lbi suffixes
replComponent replFlags verbosity pkg_descr lbi suffixes
comp@(CFLib flib) clbi _ = do
preprocessComponent pkg_descr comp lbi clbi False verbosity suffixes
replFLib verbosity pkg_descr lbi flib clbi
replFLib replFlags verbosity pkg_descr lbi flib clbi
replComponent verbosity pkg_descr lbi suffixes
replComponent replFlags verbosity pkg_descr lbi suffixes
comp@(CExe exe) clbi _ = do
preprocessComponent pkg_descr comp lbi clbi False verbosity suffixes
extras <- preprocessExtras verbosity comp lbi
let ebi = buildInfo exe
exe' = exe { buildInfo = ebi { cSources = cSources ebi ++ extras } }
replExe verbosity pkg_descr lbi exe' clbi
replExe replFlags verbosity pkg_descr lbi exe' clbi
replComponent verbosity pkg_descr lbi suffixes
replComponent replFlags verbosity pkg_descr lbi suffixes
comp@(CTest test@TestSuite { testInterface = TestSuiteExeV10{} })
clbi _distPref = do
let exe = testSuiteExeV10AsExe test
......@@ -378,10 +380,10 @@ replComponent verbosity pkg_descr lbi suffixes
extras <- preprocessExtras verbosity comp lbi
let ebi = buildInfo exe
exe' = exe { buildInfo = ebi { cSources = cSources ebi ++ extras } }
replExe verbosity pkg_descr lbi exe' clbi
replExe replFlags verbosity pkg_descr lbi exe' clbi
replComponent verbosity pkg_descr lbi0 suffixes
replComponent replFlags verbosity pkg_descr lbi0 suffixes
comp@(CTest
test@TestSuite { testInterface = TestSuiteLibV09{} })
clbi distPref = do
......@@ -392,16 +394,16 @@ replComponent verbosity pkg_descr lbi0 suffixes
extras <- preprocessExtras verbosity comp lbi
let libbi = libBuildInfo lib
lib' = lib { libBuildInfo = libbi { cSources = cSources libbi ++ extras } }
replLib verbosity pkg lbi lib' libClbi
replLib replFlags verbosity pkg lbi lib' libClbi
replComponent verbosity _ _ _
replComponent _ verbosity _ _ _
(CTest TestSuite { testInterface = TestSuiteUnsupported tt })
_ _ =
die' verbosity $ "No support for building test suite type " ++ display tt
replComponent verbosity pkg_descr lbi suffixes
replComponent replFlags verbosity pkg_descr lbi suffixes
comp@(CBench bm@Benchmark { benchmarkInterface = BenchmarkExeV10 {} })
clbi _ = do
let (exe, exeClbi) = benchmarkExeV10asExe bm clbi
......@@ -409,10 +411,10 @@ replComponent verbosity pkg_descr lbi suffixes
extras <- preprocessExtras verbosity comp lbi
let ebi = buildInfo exe
exe' = exe { buildInfo = ebi { cSources = cSources ebi ++ extras } }
replExe verbosity pkg_descr lbi exe' exeClbi
replExe replFlags verbosity pkg_descr lbi exe' exeClbi
replComponent verbosity _ _ _
replComponent _ verbosity _ _ _
(CBench Benchmark { benchmarkInterface = BenchmarkUnsupported tt })
_ _ =
die' verbosity $ "No support for building benchmark type " ++ display tt
......@@ -605,29 +607,32 @@ buildExe verbosity numJobs pkg_descr lbi exe clbi =
UHC -> UHC.buildExe verbosity pkg_descr lbi exe clbi
_ -> die' verbosity "Building is not supported with this compiler."
replLib :: Verbosity -> PackageDescription -> LocalBuildInfo
-> Library -> ComponentLocalBuildInfo -> IO ()
replLib verbosity pkg_descr lbi lib clbi =
replLib :: [String] -> Verbosity -> PackageDescription
-> LocalBuildInfo -> Library -> ComponentLocalBuildInfo
-> IO ()
replLib replFlags verbosity pkg_descr lbi lib clbi =
case compilerFlavor (compiler lbi) of
-- 'cabal repl' doesn't need to support 'ghc --make -j', so we just pass
-- NoFlag as the numJobs parameter.
GHC -> GHC.replLib verbosity NoFlag pkg_descr lbi lib clbi
GHCJS -> GHCJS.replLib verbosity NoFlag pkg_descr lbi lib clbi
GHC -> GHC.replLib replFlags verbosity NoFlag pkg_descr lbi lib clbi
GHCJS -> GHCJS.replLib replFlags verbosity NoFlag pkg_descr lbi lib clbi
_ -> die' verbosity "A REPL is not supported for this compiler."
replExe :: Verbosity -> PackageDescription -> LocalBuildInfo
-> Executable -> ComponentLocalBuildInfo -> IO ()
replExe verbosity pkg_descr lbi exe clbi =
replExe :: [String] -> Verbosity -> PackageDescription
-> LocalBuildInfo -> Executable -> ComponentLocalBuildInfo
-> IO ()
replExe replFlags verbosity pkg_descr lbi exe clbi =
case compilerFlavor (compiler lbi) of
GHC -> GHC.replExe verbosity NoFlag pkg_descr lbi exe clbi
GHCJS -> GHCJS.replExe verbosity NoFlag pkg_descr lbi exe clbi
GHC -> GHC.replExe replFlags verbosity NoFlag pkg_descr lbi exe clbi
GHCJS -> GHCJS.replExe replFlags verbosity NoFlag pkg_descr lbi exe clbi
_ -> die' verbosity "A REPL is not supported for this compiler."
replFLib :: Verbosity -> PackageDescription -> LocalBuildInfo
-> ForeignLib -> ComponentLocalBuildInfo -> IO ()
replFLib verbosity pkg_descr lbi exe clbi =
replFLib :: [String] -> Verbosity -> PackageDescription
-> LocalBuildInfo -> ForeignLib -> ComponentLocalBuildInfo
-> IO ()
replFLib replFlags verbosity pkg_descr lbi exe clbi =
case compilerFlavor (compiler lbi) of
GHC -> GHC.replFLib verbosity NoFlag pkg_descr lbi exe clbi
GHC -> GHC.replFLib replFlags verbosity NoFlag pkg_descr lbi exe clbi
_ -> die' verbosity "A REPL is not supported for this compiler."
-- | Runs 'componentInitialBuildSteps' on every configured component.
......
......@@ -509,16 +509,22 @@ getInstalledPackagesMonitorFiles verbosity platform progdb =
-- -----------------------------------------------------------------------------
-- Building a library
buildLib, replLib :: Verbosity -> Cabal.Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Library -> ComponentLocalBuildInfo -> IO ()
buildLib = buildOrReplLib False
replLib = buildOrReplLib True
buildOrReplLib :: Bool -> Verbosity -> Cabal.Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Library -> ComponentLocalBuildInfo -> IO ()
buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
buildLib :: Verbosity -> Cabal.Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Library -> ComponentLocalBuildInfo -> IO ()
buildLib = buildOrReplLib Nothing
replLib :: [String] -> Verbosity
-> Cabal.Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> Library
-> ComponentLocalBuildInfo -> IO ()
replLib = buildOrReplLib . Just
buildOrReplLib :: Maybe [String] -> Verbosity
-> Cabal.Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> Library
-> ComponentLocalBuildInfo -> IO ()
buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
let uid = componentUnitId clbi
libTargetDir = componentBuildDir lbi clbi
whenVanillaLib forceVanilla =
......@@ -529,7 +535,9 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
whenStaticLib forceStatic =
when (forceStatic || withStaticLib lbi)
whenGHCiLib = when (withGHCiLib lbi && withVanillaLib lbi)
forRepl = maybe False (const True) mReplFlags
ifReplLib = when forRepl
replFlags = fromMaybe mempty mReplFlags
comp = compiler lbi
ghcVersion = compilerVersion comp
implInfo = getImplInfo comp
......@@ -604,8 +612,9 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
[libTargetDir </> x | x <- cObjs]
}
replOpts = vanillaOpts {
ghcOptExtra = Internal.filterGhciFlags $
ghcOptExtra vanillaOpts,
ghcOptExtra = Internal.filterGhciFlags
(ghcOptExtra vanillaOpts)
<> replFlags,
ghcOptNumJobs = mempty
}
`mappend` linkerOpts
......@@ -889,48 +898,62 @@ startInterpreter verbosity progdb comp platform packageDBs = do
-- Building an executable or foreign library
-- | Build a foreign library
buildFLib, replFLib
buildFLib
:: Verbosity -> Cabal.Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> ForeignLib -> ComponentLocalBuildInfo -> IO ()
buildFLib v njobs pkg lbi = gbuild v njobs pkg lbi . GBuildFLib
replFLib v njobs pkg lbi = gbuild v njobs pkg lbi . GReplFLib
replFLib
:: [String] -> Verbosity
-> Cabal.Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> ForeignLib
-> ComponentLocalBuildInfo -> IO ()
replFLib replFlags v njobs pkg lbi =
gbuild v njobs pkg lbi . GReplFLib replFlags
-- | Build an executable with GHC.
--
buildExe, replExe
buildExe
:: Verbosity -> Cabal.Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Executable -> ComponentLocalBuildInfo -> IO ()
buildExe v njobs pkg lbi = gbuild v njobs pkg lbi . GBuildExe
replExe v njobs pkg lbi = gbuild v njobs pkg lbi . GReplExe
replExe
:: [String] -> Verbosity
-> Cabal.Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> Executable
-> ComponentLocalBuildInfo -> IO ()
replExe replFlags v njobs pkg lbi =
gbuild v njobs pkg lbi . GReplExe replFlags
-- | Building an executable, starting the REPL, and building foreign
-- libraries are all very similar and implemented in 'gbuild'. The
-- 'GBuildMode' distinguishes between the various kinds of operation.
data GBuildMode =
GBuildExe Executable
| GReplExe Executable
| GReplExe [String] Executable
| GBuildFLib ForeignLib
| GReplFLib ForeignLib
| GReplFLib [String] ForeignLib
gbuildInfo :: GBuildMode -> BuildInfo
gbuildInfo (GBuildExe exe) = buildInfo exe
gbuildInfo (GReplExe exe) = buildInfo exe
gbuildInfo (GReplExe _ exe) = buildInfo exe
gbuildInfo (GBuildFLib flib) = foreignLibBuildInfo flib
gbuildInfo (GReplFLib flib) = foreignLibBuildInfo flib
gbuildInfo (GReplFLib _ flib) = foreignLibBuildInfo flib
gbuildName :: GBuildMode -> String
gbuildName (GBuildExe exe) = unUnqualComponentName $ exeName exe
gbuildName (GReplExe exe) = unUnqualComponentName $ exeName exe
gbuildName (GReplExe _ exe) = unUnqualComponentName $ exeName exe
gbuildName (GBuildFLib flib) = unUnqualComponentName $ foreignLibName flib
gbuildName (GReplFLib flib) = unUnqualComponentName $ foreignLibName flib
gbuildName (GReplFLib _ flib) = unUnqualComponentName $ foreignLibName flib
gbuildTargetName :: LocalBuildInfo -> GBuildMode -> String
gbuildTargetName lbi (GBuildExe exe) = exeTargetName (hostPlatform lbi) exe
gbuildTargetName lbi (GReplExe exe) = exeTargetName (hostPlatform lbi) exe
gbuildTargetName lbi (GReplExe _ exe) = exeTargetName (hostPlatform lbi) exe
gbuildTargetName lbi (GBuildFLib flib) = flibTargetName lbi flib
gbuildTargetName lbi (GReplFLib flib) = flibTargetName lbi flib
gbuildTargetName lbi (GReplFLib _ flib) = flibTargetName lbi flib
exeTargetName :: Platform -> Executable -> String
exeTargetName platform exe = unUnqualComponentName (exeName exe) `withExt` exeExtension platform
......@@ -1005,17 +1028,17 @@ flibBuildName lbi flib
gbuildIsRepl :: GBuildMode -> Bool
gbuildIsRepl (GBuildExe _) = False
gbuildIsRepl (GReplExe _) = True
gbuildIsRepl (GReplExe _ _) = True
gbuildIsRepl (GBuildFLib _) = False
gbuildIsRepl (GReplFLib _) = True
gbuildIsRepl (GReplFLib _ _) = True
gbuildNeedDynamic :: LocalBuildInfo -> GBuildMode -> Bool
gbuildNeedDynamic lbi bm =
case bm of
GBuildExe _ -> withDynExe lbi
GReplExe _ -> withDynExe lbi
GReplExe _ _ -> withDynExe lbi
GBuildFLib flib -> withDynFLib flib
GReplFLib flib -> withDynFLib flib
GReplFLib _ flib -> withDynFLib flib
where
withDynFLib flib =
case foreignLibType flib of
......@@ -1028,9 +1051,9 @@ gbuildNeedDynamic lbi bm =
gbuildModDefFiles :: GBuildMode -> [FilePath]
gbuildModDefFiles (GBuildExe _) = []
gbuildModDefFiles (GReplExe _) = []
gbuildModDefFiles (GReplExe _ _) = []
gbuildModDefFiles (GBuildFLib flib) = foreignLibModDefFile flib
gbuildModDefFiles (GReplFLib flib) = foreignLibModDefFile flib
gbuildModDefFiles (GReplFLib _ flib) = foreignLibModDefFile flib
-- | "Main" module name when overridden by @ghc-options: -main-is ...@
-- or 'Nothing' if no @-main-is@ flag could be found.
......@@ -1102,9 +1125,9 @@ gbuildSources :: Verbosity
gbuildSources verbosity specVer tmpDir bm =
case bm of
GBuildExe exe -> exeSources exe
GReplExe exe -> exeSources exe
GReplExe _ exe -> exeSources exe
GBuildFLib flib -> return $ flibSources flib
GReplFLib flib -> return $ flibSources flib
GReplFLib _ flib -> return $ flibSources flib
where
exeSources :: Executable -> IO BuildSources
exeSources exe@Executable{buildInfo = bnfo, modulePath = modPath} = do
......@@ -1179,7 +1202,12 @@ gbuild :: Verbosity -> Cabal.Flag (Maybe Int)
-> GBuildMode -> ComponentLocalBuildInfo -> IO ()
gbuild verbosity numJobs pkg_descr lbi bm clbi = do
(ghcProg, _) <- requireProgram verbosity ghcProgram (withPrograms lbi)
let comp = compiler lbi
let replFlags = case bm of
GReplExe flags _ -> flags
GReplFLib flags _ -> flags
GBuildExe{} -> mempty
GBuildFLib{} -> mempty
comp = compiler lbi
platform = hostPlatform lbi
implInfo = getImplInfo comp
runGhcProg = runGHC verbosity ghcProg comp platform
......@@ -1237,7 +1265,7 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do
(withProfExeDetail lbi),
ghcOptHiSuffix = toFlag "p_hi",
ghcOptObjSuffix = toFlag "p_o",
ghcOptExtra = (hcProfOptions GHC bnfo),
ghcOptExtra = hcProfOptions GHC bnfo,
ghcOptHPCDir = hpcdir Hpc.Prof
}
dynOpts = baseOpts `mappend` mempty {
......@@ -1272,6 +1300,7 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do
replOpts = baseOpts {
ghcOptExtra = Internal.filterGhciFlags
(ghcOptExtra baseOpts)
<> replFlags
}
-- For a normal compile we do separate invocations of ghc for
-- compiling as for linking. But for repl we have to do just
......@@ -1387,8 +1416,8 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do
-- with ghci, but .c files can depend on .h files generated by ghc by ffi
-- exports.
case bm of
GReplExe _ -> runGhcProg replOpts
GReplFLib _ -> runGhcProg replOpts
GReplExe _ _ -> runGhcProg replOpts
GReplFLib _ _ -> runGhcProg replOpts
GBuildExe _ -> do
let linkOpts = commonOpts
`mappend` linkerOpts
......
......@@ -259,16 +259,22 @@ toJSLibName lib
| takeExtension lib == ".a" = replaceExtension lib "js_a"
| otherwise = lib <.> "js_a"
buildLib, replLib :: Verbosity -> Cabal.Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> Library -> ComponentLocalBuildInfo
-> IO ()
buildLib = buildOrReplLib False
replLib = buildOrReplLib True
buildOrReplLib :: Bool -> Verbosity -> Cabal.Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Library -> ComponentLocalBuildInfo -> IO ()
buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
buildLib :: Verbosity -> Cabal.Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> Library -> ComponentLocalBuildInfo
-> IO ()
buildLib = buildOrReplLib Nothing
replLib :: [String] -> Verbosity
-> Cabal.Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> Library
-> ComponentLocalBuildInfo -> IO ()
replLib = buildOrReplLib . Just
buildOrReplLib :: Maybe [String] -> Verbosity
-> Cabal.Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> Library
-> ComponentLocalBuildInfo -> IO ()
buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
let uid = componentUnitId clbi
libTargetDir = buildDir lbi
whenVanillaLib forceVanilla =
......@@ -277,7 +283,9 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
whenSharedLib forceShared =
when (not forRepl && (forceShared || withSharedLib lbi))
whenGHCiLib = when (not forRepl && withGHCiLib lbi && withVanillaLib lbi)
forRepl = maybe False (const True) mReplFlags
ifReplLib = when forRepl
replFlags = fromMaybe mempty mReplFlags
comp = compiler lbi
platform = hostPlatform lbi
implInfo = getImplInfo comp
......@@ -343,7 +351,8 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
}
replOpts = vanillaOptsNoJsLib {
ghcOptExtra = Internal.filterGhciFlags
(ghcOptExtra vanillaOpts),
(ghcOptExtra vanillaOpts)
<> replFlags,
ghcOptNumJobs = mempty
}
`mappend` linkerOpts
......@@ -498,20 +507,28 @@ startInterpreter verbosity progdb comp platform packageDBs = do
(ghcjsProg, _) <- requireProgram verbosity ghcjsProgram progdb
runGHC verbosity ghcjsProg comp platform replOpts
buildExe, replExe :: Verbosity -> Cabal.Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Executable -> ComponentLocalBuildInfo -> IO ()
buildExe = buildOrReplExe False
replExe = buildOrReplExe True
buildOrReplExe :: Bool -> Verbosity -> Cabal.Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Executable -> ComponentLocalBuildInfo -> IO ()
buildOrReplExe forRepl verbosity numJobs _pkg_descr lbi
buildExe :: Verbosity -> Cabal.Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Executable -> ComponentLocalBuildInfo -> IO ()
buildExe = buildOrReplExe Nothing
replExe :: [String] -> Verbosity
-> Cabal.Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> Executable
-> ComponentLocalBuildInfo -> IO ()
replExe = buildOrReplExe . Just
buildOrReplExe :: Maybe [String] -> Verbosity
-> Cabal.Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> Executable
-> ComponentLocalBuildInfo -> IO ()
buildOrReplExe mReplFlags verbosity numJobs _pkg_descr lbi
exe@Executable { exeName = exeName', modulePath = modPath } clbi = do
(ghcjsProg, _) <- requireProgram verbosity ghcjsProgram (withPrograms lbi)
let comp = compiler lbi
let forRepl = maybe False (const True) mReplFlags
replFlags = fromMaybe mempty mReplFlags
comp = compiler lbi
platform = hostPlatform lbi
implInfo = getImplInfo comp
runGhcjsProg = runGHC verbosity ghcjsProg comp platform
......@@ -592,6 +609,7 @@ buildOrReplExe forRepl verbosity numJobs _pkg_descr lbi
replOpts = baseOpts {
ghcOptExtra = Internal.filterGhciFlags
(ghcOptExtra baseOpts)
<> replFlags
}
-- For a normal compile we do separate invocations of ghc for
-- compiling as for linking. But for repl we have to do just
......@@ -813,7 +831,7 @@ componentGhcOptions verbosity lbi bi clbi odir =
let opts = Internal.componentGhcOptions verbosity implInfo lbi bi clbi odir
comp = compiler lbi
implInfo = getImplInfo comp
in opts { ghcOptExtra = ghcOptExtra opts `mappend` (hcOptions GHCJS bi)
in opts { ghcOptExtra = ghcOptExtra opts `mappend` hcOptions GHCJS bi
}
ghcjsProfOptions :: BuildInfo -> [String]
......
Supports Markdown
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