Commit e378d71c authored by Mikhail Glushenkov's avatar Mikhail Glushenkov
Browse files

'setup build': pass the '-j' flag to GHC.

parent 70db82f4
......@@ -77,7 +77,7 @@ import qualified Distribution.ModuleName as ModuleName
import Distribution.ModuleName (ModuleName)
import Distribution.Simple.Setup
( BuildFlags(..), ReplFlags(..), fromFlag )
( Flag(..), BuildFlags(..), ReplFlags(..), fromFlag )
import Distribution.Simple.BuildTarget
( BuildTarget(..), readBuildTargets )
import Distribution.Simple.PreProcess
......@@ -151,7 +151,8 @@ build pkg_descr lbi flags suffixes = do
withPrograms = progs',
withPackageDB = withPackageDB lbi ++ [internalPackageDB]
}
in buildComponent verbosity pkg_descr lbi' suffixes comp clbi distPref
in buildComponent verbosity (buildNumJobs flags) pkg_descr
lbi' suffixes comp clbi distPref
repl :: PackageDescription -- ^ Mostly information from the .cabal file
......@@ -190,7 +191,8 @@ repl pkg_descr lbi flags suffixes args = do
sequence_
[ let comp = getComponent pkg_descr cname
lbi' = lbiForComponent comp lbi
in buildComponent verbosity pkg_descr lbi' suffixes comp clbi distPref
in buildComponent verbosity NoFlag
pkg_descr lbi' suffixes comp clbi distPref
| (cname, clbi) <- init componentsToBuild ]
-- repl for target components
......@@ -201,6 +203,7 @@ repl pkg_descr lbi flags suffixes args = do
buildComponent :: Verbosity
-> Flag (Maybe Int)
-> PackageDescription
-> LocalBuildInfo
-> [PPSuffixHandler]
......@@ -208,11 +211,11 @@ buildComponent :: Verbosity
-> ComponentLocalBuildInfo
-> FilePath
-> IO ()
buildComponent verbosity pkg_descr lbi suffixes
buildComponent verbosity numJobs pkg_descr lbi suffixes
comp@(CLib lib) clbi distPref = do
preprocessComponent pkg_descr comp lbi False verbosity suffixes
info verbosity "Building library..."
buildLib verbosity pkg_descr lbi lib clbi
buildLib verbosity numJobs pkg_descr lbi lib clbi
-- Register the library in-place, so exes can depend
-- on internally defined libraries.
......@@ -228,23 +231,23 @@ buildComponent verbosity pkg_descr lbi suffixes
(withPackageDB lbi)
buildComponent verbosity pkg_descr lbi suffixes
buildComponent verbosity numJobs pkg_descr lbi suffixes
comp@(CExe exe) clbi _ = do
preprocessComponent pkg_descr comp lbi False verbosity suffixes
info verbosity $ "Building executable " ++ exeName exe ++ "..."
buildExe verbosity pkg_descr lbi exe clbi
buildExe verbosity numJobs pkg_descr lbi exe clbi
buildComponent verbosity pkg_descr lbi suffixes
buildComponent verbosity numJobs pkg_descr lbi suffixes
comp@(CTest test@TestSuite { testInterface = TestSuiteExeV10{} })
clbi _distPref = do
let exe = testSuiteExeV10AsExe test
preprocessComponent pkg_descr comp lbi False verbosity suffixes
info verbosity $ "Building test suite " ++ testName test ++ "..."
buildExe verbosity pkg_descr lbi exe clbi
buildExe verbosity numJobs pkg_descr lbi exe clbi
buildComponent verbosity pkg_descr lbi suffixes
buildComponent verbosity numJobs pkg_descr lbi suffixes
comp@(CTest
test@TestSuite { testInterface = TestSuiteLibV09{} })
clbi -- This ComponentLocalBuildInfo corresponds to a detailed
......@@ -258,27 +261,27 @@ buildComponent verbosity pkg_descr lbi suffixes
testSuiteLibV09AsLibAndExe pkg_descr lbi test clbi distPref pwd
preprocessComponent pkg_descr comp lbi False verbosity suffixes
info verbosity $ "Building test suite " ++ testName test ++ "..."
buildLib verbosity pkg lbi lib libClbi
buildLib verbosity numJobs pkg lbi lib libClbi
registerPackage verbosity ipi pkg lbi True $ withPackageDB lbi
buildExe verbosity pkg_descr lbi exe exeClbi
buildExe verbosity numJobs pkg_descr lbi exe exeClbi
buildComponent _ _ _ _
buildComponent _ _ _ _ _
(CTest TestSuite { testInterface = TestSuiteUnsupported tt })
_ _ =
die $ "No support for building test suite type " ++ display tt
buildComponent verbosity pkg_descr lbi suffixes
buildComponent verbosity numJobs pkg_descr lbi suffixes
comp@(CBench bm@Benchmark { benchmarkInterface = BenchmarkExeV10 {} })
clbi _ = do
let (exe, exeClbi) = benchmarkExeV10asExe bm clbi
preprocessComponent pkg_descr comp lbi False verbosity suffixes
info verbosity $ "Building benchmark " ++ benchmarkName bm ++ "..."
buildExe verbosity pkg_descr lbi exe exeClbi
buildExe verbosity numJobs pkg_descr lbi exe exeClbi
buildComponent _ _ _ _
buildComponent _ _ _ _ _
(CBench Benchmark { benchmarkInterface = BenchmarkUnsupported tt })
_ _ =
die $ "No support for building benchmark type " ++ display tt
......@@ -461,29 +464,31 @@ addInternalBuildTools pkg lbi bi progs =
-- TODO: build separate libs in separate dirs so that we can build
-- multiple libs, e.g. for 'LibTest' library-style testsuites
buildLib :: Verbosity -> PackageDescription -> LocalBuildInfo
buildLib :: Verbosity -> Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Library -> ComponentLocalBuildInfo -> IO ()
buildLib verbosity pkg_descr lbi lib clbi =
buildLib verbosity numJobs pkg_descr lbi lib clbi =
case compilerFlavor (compiler lbi) of
GHC -> GHC.buildLib verbosity pkg_descr lbi lib clbi
JHC -> JHC.buildLib verbosity pkg_descr lbi lib clbi
LHC -> LHC.buildLib verbosity pkg_descr lbi lib clbi
Hugs -> Hugs.buildLib verbosity pkg_descr lbi lib clbi
NHC -> NHC.buildLib verbosity pkg_descr lbi lib clbi
UHC -> UHC.buildLib verbosity pkg_descr lbi lib clbi
GHC -> GHC.buildLib verbosity numJobs pkg_descr lbi lib clbi
JHC -> JHC.buildLib verbosity pkg_descr lbi lib clbi
LHC -> LHC.buildLib verbosity pkg_descr lbi lib clbi
Hugs -> Hugs.buildLib verbosity pkg_descr lbi lib clbi
NHC -> NHC.buildLib verbosity pkg_descr lbi lib clbi
UHC -> UHC.buildLib verbosity pkg_descr lbi lib clbi
HaskellSuite {} -> HaskellSuite.buildLib verbosity pkg_descr lbi lib clbi
_ -> die "Building is not supported with this compiler."
buildExe :: Verbosity -> PackageDescription -> LocalBuildInfo
buildExe :: Verbosity -> Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Executable -> ComponentLocalBuildInfo -> IO ()
buildExe verbosity pkg_descr lbi exe clbi =
buildExe verbosity numJobs pkg_descr lbi exe clbi =
case compilerFlavor (compiler lbi) of
GHC -> GHC.buildExe verbosity pkg_descr lbi exe clbi
JHC -> JHC.buildExe verbosity pkg_descr lbi exe clbi
LHC -> LHC.buildExe verbosity pkg_descr lbi exe clbi
Hugs -> Hugs.buildExe verbosity pkg_descr lbi exe clbi
NHC -> NHC.buildExe verbosity pkg_descr lbi exe clbi
UHC -> UHC.buildExe verbosity pkg_descr lbi exe clbi
GHC -> GHC.buildExe verbosity numJobs pkg_descr lbi exe clbi
JHC -> JHC.buildExe verbosity pkg_descr lbi exe clbi
LHC -> LHC.buildExe verbosity pkg_descr lbi exe clbi
Hugs -> Hugs.buildExe verbosity pkg_descr lbi exe clbi
NHC -> NHC.buildExe verbosity pkg_descr lbi exe clbi
UHC -> UHC.buildExe verbosity pkg_descr lbi exe clbi
_ -> die "Building is not supported with this compiler."
......@@ -491,14 +496,16 @@ replLib :: Verbosity -> PackageDescription -> LocalBuildInfo
-> Library -> ComponentLocalBuildInfo -> IO ()
replLib verbosity pkg_descr lbi lib clbi =
case compilerFlavor (compiler lbi) of
GHC -> GHC.replLib verbosity pkg_descr lbi lib clbi
-- '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
_ -> die "A REPL is not supported for this compiler."
replExe :: Verbosity -> PackageDescription -> LocalBuildInfo
-> Executable -> ComponentLocalBuildInfo -> IO ()
replExe verbosity pkg_descr lbi exe clbi =
case compilerFlavor (compiler lbi) of
GHC -> GHC.replExe verbosity pkg_descr lbi exe clbi
GHC -> GHC.replExe verbosity NoFlag pkg_descr lbi exe clbi
_ -> die "A REPL is not supported for this compiler."
......
......@@ -111,7 +111,10 @@ import qualified Distribution.Simple.Program.HcPkg as HcPkg
import qualified Distribution.Simple.Program.Ar as Ar
import qualified Distribution.Simple.Program.Ld as Ld
import Distribution.Simple.Program.GHC
import Distribution.Simple.Setup (toFlag, fromFlag)
import Distribution.Simple.Setup
( toFlag, fromFlag, fromFlagOrDefault )
import qualified Distribution.Simple.Setup as Cabal
( Flag )
import Distribution.Simple.Compiler
( CompilerFlavor(..), CompilerId(..), Compiler(..), compilerVersion
, OptimisationLevel(..), PackageDB(..), PackageDBStack
......@@ -681,22 +684,23 @@ substTopDir topDir ipo
-- | Build a library with GHC.
--
buildLib, replLib :: Verbosity
buildLib, replLib :: Verbosity -> Cabal.Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Library -> ComponentLocalBuildInfo -> IO ()
buildLib = buildOrReplLib False
replLib = buildOrReplLib True
buildOrReplLib :: Bool -> Verbosity
buildOrReplLib :: Bool -> Verbosity -> Cabal.Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Library -> ComponentLocalBuildInfo -> IO ()
buildOrReplLib forRepl verbosity pkg_descr lbi lib clbi = do
buildOrReplLib forRepl verbosity numJobsFlag pkg_descr lbi lib clbi = do
libName <- case componentLibraries clbi of
[libName] -> return libName
[] -> die "No library name found when building library"
_ -> die "Multiple library names found when building library"
let libTargetDir = buildDir lbi
numJobs = fromMaybe 1 $ fromFlagOrDefault Nothing numJobsFlag
pkgid = packageId pkg_descr
whenVanillaLib forceVanilla =
when (not forRepl && (forceVanilla || withVanillaLib lbi))
......@@ -728,6 +732,7 @@ buildOrReplLib forRepl verbosity pkg_descr lbi lib clbi = do
baseOpts = componentGhcOptions verbosity lbi libBi clbi libTargetDir
vanillaOpts = baseOpts `mappend` mempty {
ghcOptMode = toFlag GhcModeMake,
ghcOptNumJobs = toFlag numJobs,
ghcOptPackageName = toFlag pkgid,
ghcOptInputModules = libModules lib
}
......@@ -755,7 +760,8 @@ buildOrReplLib forRepl verbosity pkg_descr lbi lib clbi = do
}
replOpts = vanillaOpts {
ghcOptExtra = filterGhciFlags
(ghcOptExtra vanillaOpts)
(ghcOptExtra vanillaOpts),
ghcOptNumJobs = mempty
}
`mappend` linkerOpts
`mappend` mempty {
......@@ -920,20 +926,22 @@ buildOrReplLib forRepl verbosity pkg_descr lbi lib clbi = do
-- | Build an executable with GHC.
--
buildExe, replExe :: Verbosity
buildExe, replExe :: Verbosity -> Cabal.Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Executable -> ComponentLocalBuildInfo -> IO ()
buildExe = buildOrReplExe False
replExe = buildOrReplExe True
buildOrReplExe :: Bool -> Verbosity
buildOrReplExe :: Bool -> Verbosity -> Cabal.Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Executable -> ComponentLocalBuildInfo -> IO ()
buildOrReplExe forRepl verbosity _pkg_descr lbi
buildOrReplExe forRepl verbosity numJobsFlag _pkg_descr lbi
exe@Executable { exeName = exeName', modulePath = modPath } clbi = do
(ghcProg, _) <- requireProgram verbosity ghcProgram (withPrograms lbi)
let comp = compiler lbi
numJobs = fromMaybe 1 $
fromFlagOrDefault Nothing numJobsFlag
runGhcProg = runGHC verbosity ghcProg comp
exeBi <- hackThreadedFlag verbosity
......@@ -1042,10 +1050,12 @@ buildOrReplExe forRepl verbosity _pkg_descr lbi
-- Build static/dynamic object files for TH, if needed.
when compileForTH $
runGhcProg compileTHOpts { ghcOptNoLink = toFlag True }
runGhcProg compileTHOpts { ghcOptNoLink = toFlag True
, ghcOptNumJobs = toFlag numJobs }
unless forRepl $
runGhcProg compileOpts { ghcOptNoLink = toFlag True }
runGhcProg compileOpts { ghcOptNoLink = toFlag True
, ghcOptNumJobs = toFlag numJobs }
-- build any C sources
unless (null cSrcs) $ do
......
......@@ -641,7 +641,7 @@ testAction (testFlags, buildFlags, buildExFlags) extraArgs globalFlags = do
globalFlags noAddSource (buildNumJobs buildFlags) checkFlags
maybeWithSandboxDirOnSearchPath useSandbox $
build verbosity distPref mempty extraArgs
build verbosity distPref buildFlags extraArgs
maybeWithSandboxDirOnSearchPath useSandbox $
setupWrapper verbosity setupOptions Nothing
......@@ -671,7 +671,7 @@ benchmarkAction (benchmarkFlags, buildFlags, buildExFlags)
checkFlags
maybeWithSandboxDirOnSearchPath useSandbox $
build verbosity distPref mempty extraArgs
build verbosity distPref buildFlags extraArgs
maybeWithSandboxDirOnSearchPath useSandbox $
setupWrapper verbosity setupOptions Nothing
......
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