Skip to content

Commit

Permalink
Split up Distribution.Simple.Setup (#8130)
Browse files Browse the repository at this point in the history
* Split Distribution.Simple.Setup into smaller modules

The main motivation is to improve parallelism of the module graph.
This improves compile times as we can benefit more from multiple cores,
but also because GHC is superlinear in the size and complexity of source
files.

Each set of command line options is moved to its own file, and common
utilities are moved into .Common.

The interface is kept the same and new modules aren't exposed.

* Refine some imports of Distribution.Simple.Setup

* fixup! Split Distribution.Simple.Setup into smaller modules

fix whitespace

* Refine imports of Distribution.Simple.Setup in Cabal

Replace imports of Distribution.Simple.Setup with direct imports of
the modules that it re-exports. Some imports are left if most
re-exported modules are used.

* Add a changelog entry

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
TeofilC and mergify[bot] authored Feb 28, 2023
1 parent b016e59 commit ab24689
Show file tree
Hide file tree
Showing 40 changed files with 3,100 additions and 2,517 deletions.
14 changes: 14 additions & 0 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,20 @@ library
Distribution.Simple.GHC.Internal
Distribution.Simple.GHC.ImplInfo
Distribution.Simple.ConfigureScript
Distribution.Simple.Setup.Benchmark
Distribution.Simple.Setup.Build
Distribution.Simple.Setup.Clean
Distribution.Simple.Setup.Common
Distribution.Simple.Setup.Config
Distribution.Simple.Setup.Copy
Distribution.Simple.Setup.Global
Distribution.Simple.Setup.Haddock
Distribution.Simple.Setup.Hscolour
Distribution.Simple.Setup.Install
Distribution.Simple.Setup.Register
Distribution.Simple.Setup.Repl
Distribution.Simple.Setup.SDist
Distribution.Simple.Setup.Test
Distribution.ZinzaPrelude
Paths_Cabal

Expand Down
2 changes: 1 addition & 1 deletion Cabal/src/Distribution/Backpack/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.Simple.PackageIndex (InstalledPackageIndex)
import Distribution.PackageDescription
import Distribution.ModuleName
import Distribution.Simple.Setup as Setup
import Distribution.Simple.Flag
import Distribution.Simple.LocalBuildInfo
import Distribution.Types.AnnotatedId
import Distribution.Types.ComponentRequestedSpec
Expand Down
2 changes: 1 addition & 1 deletion Cabal/src/Distribution/Backpack/ConfiguredComponent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Distribution.Types.ComponentInclude
import Distribution.Package
import Distribution.PackageDescription
import Distribution.Simple.BuildToolDepends
import Distribution.Simple.Setup as Setup
import Distribution.Simple.Flag ( Flag )
import Distribution.Simple.LocalBuildInfo
import Distribution.Utils.LogProgress
import Distribution.Utils.MapAccum
Expand Down
2 changes: 1 addition & 1 deletion Cabal/src/Distribution/Backpack/Id.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Distribution.Compat.Prelude
import Distribution.Types.UnqualComponentName
import Distribution.Simple.Compiler
import Distribution.PackageDescription
import Distribution.Simple.Setup as Setup
import Distribution.Simple.Flag ( Flag(..) )
import qualified Distribution.Simple.InstallDirs as InstallDirs
import Distribution.Simple.LocalBuildInfo
import Distribution.Types.ComponentId
Expand Down
3 changes: 2 additions & 1 deletion Cabal/src/Distribution/Simple/Bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import Distribution.Simple.BuildPaths
import Distribution.Simple.Compiler
import Distribution.Simple.InstallDirs
import qualified Distribution.Simple.LocalBuildInfo as LBI
import Distribution.Simple.Setup
import Distribution.Simple.Flag ( fromFlag )
import Distribution.Simple.Setup.Benchmark
import Distribution.Simple.UserHooks
import Distribution.Simple.Utils
import Distribution.Pretty
Expand Down
5 changes: 4 additions & 1 deletion Cabal/src/Distribution/Simple/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ import qualified Distribution.InstalledPackageInfo as IPI
import Distribution.InstalledPackageInfo (InstalledPackageInfo)
import qualified Distribution.ModuleName as ModuleName

import Distribution.Simple.Setup
import Distribution.Simple.Flag
import Distribution.Simple.Setup.Build
import Distribution.Simple.Setup.Config
import Distribution.Simple.Setup.Repl
import Distribution.Simple.BuildTarget
import Distribution.Simple.BuildToolDepends
import Distribution.Simple.PreProcess
Expand Down
3 changes: 2 additions & 1 deletion Cabal/src/Distribution/Simple/BuildPaths.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ import Distribution.ModuleName as ModuleName
import Distribution.Compiler
import Distribution.PackageDescription
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Setup
import Distribution.Simple.Setup.Haddock (HaddockTarget(..))
import Distribution.Simple.Setup.Common (defaultDistPref)
import Distribution.Pretty
import Distribution.System
import Distribution.Verbosity
Expand Down
3 changes: 2 additions & 1 deletion Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ import Distribution.PackageDescription.Configuration
import Distribution.PackageDescription.Check hiding (doesFileExist)
import Distribution.Simple.BuildToolDepends
import Distribution.Simple.Program
import Distribution.Simple.Setup as Setup
import Distribution.Simple.Setup.Config as Setup
import Distribution.Simple.Setup.Common as Setup
import Distribution.Simple.BuildTarget
import Distribution.Simple.LocalBuildInfo
import Distribution.Types.PackageVersionConstraint
Expand Down
3 changes: 2 additions & 1 deletion Cabal/src/Distribution/Simple/ConfigureScript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import Distribution.Compat.Prelude
import Distribution.PackageDescription
import Distribution.Simple.Program
import Distribution.Simple.Program.Db
import Distribution.Simple.Setup
import Distribution.Simple.Setup.Common
import Distribution.Simple.Setup.Config

import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Utils
Expand Down
23 changes: 12 additions & 11 deletions Cabal/src/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ import qualified Distribution.Simple.Program.Ar as Ar
import qualified Distribution.Simple.Program.Ld as Ld
import qualified Distribution.Simple.Program.Strip as Strip
import Distribution.Simple.Program.GHC
import Distribution.Simple.Setup
import qualified Distribution.Simple.Setup as Cabal
import Distribution.Simple.Flag ( Flag(Flag), fromFlag, fromFlagOrDefault, toFlag )
import Distribution.Simple.Setup.Config
import Distribution.Simple.Setup.Repl
import Distribution.Simple.Compiler
import Distribution.Version
import Distribution.System
Expand Down Expand Up @@ -491,19 +492,19 @@ getInstalledPackagesMonitorFiles verbosity platform progdb =
-- -----------------------------------------------------------------------------
-- Building a library

buildLib :: Verbosity -> Cabal.Flag (Maybe Int)
buildLib :: Verbosity -> Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Library -> ComponentLocalBuildInfo -> IO ()
buildLib = buildOrReplLib Nothing

replLib :: ReplOptions -> Verbosity
-> Cabal.Flag (Maybe Int) -> PackageDescription
-> Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> Library
-> ComponentLocalBuildInfo -> IO ()
replLib = buildOrReplLib . Just

buildOrReplLib :: Maybe ReplOptions -> Verbosity
-> Cabal.Flag (Maybe Int) -> PackageDescription
-> Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> Library
-> ComponentLocalBuildInfo -> IO ()
buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
Expand Down Expand Up @@ -658,7 +659,7 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
then do
runGhcProg vanillaSharedOpts
case (hpcdir Hpc.Dyn, hpcdir Hpc.Vanilla) of
(Cabal.Flag dynDir, Cabal.Flag vanillaDir) ->
(Flag dynDir, Flag vanillaDir) ->
-- When the vanilla and shared library builds are done
-- in one pass, only one set of HPC module interfaces
-- are generated. This set should suffice for both
Expand Down Expand Up @@ -1001,14 +1002,14 @@ startInterpreter verbosity progdb comp platform packageDBs = do

-- | Build a foreign library
buildFLib
:: Verbosity -> Cabal.Flag (Maybe Int)
:: Verbosity -> Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> ForeignLib -> ComponentLocalBuildInfo -> IO ()
buildFLib v njobs pkg lbi = gbuild v njobs pkg lbi . GBuildFLib

replFLib
:: ReplOptions -> Verbosity
-> Cabal.Flag (Maybe Int) -> PackageDescription
-> Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> ForeignLib
-> ComponentLocalBuildInfo -> IO ()
replFLib replFlags v njobs pkg lbi =
Expand All @@ -1017,14 +1018,14 @@ replFLib replFlags v njobs pkg lbi =
-- | Build an executable with GHC.
--
buildExe
:: Verbosity -> Cabal.Flag (Maybe Int)
:: Verbosity -> Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Executable -> ComponentLocalBuildInfo -> IO ()
buildExe v njobs pkg lbi = gbuild v njobs pkg lbi . GBuildExe

replExe
:: ReplOptions -> Verbosity
-> Cabal.Flag (Maybe Int) -> PackageDescription
-> Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> Executable
-> ComponentLocalBuildInfo -> IO ()
replExe replFlags v njobs pkg lbi =
Expand Down Expand Up @@ -1312,7 +1313,7 @@ replNoLoad replFlags l
| otherwise = l

-- | Generic build function. See comment for 'GBuildMode'.
gbuild :: Verbosity -> Cabal.Flag (Maybe Int)
gbuild :: Verbosity -> Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> GBuildMode -> ComponentLocalBuildInfo -> IO ()
gbuild verbosity numJobs pkg_descr lbi bm clbi = do
Expand Down
2 changes: 1 addition & 1 deletion Cabal/src/Distribution/Simple/GHC/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import Distribution.PackageDescription
import Distribution.Lex
import Distribution.Simple.Compiler
import Distribution.Simple.Program.GHC
import Distribution.Simple.Setup
import Distribution.Simple.Flag ( Flag, maybeToFlag, toFlag )
import qualified Distribution.ModuleName as ModuleName
import Distribution.Simple.Program
import Distribution.Simple.LocalBuildInfo
Expand Down
22 changes: 11 additions & 11 deletions Cabal/src/Distribution/Simple/GHCJS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ import Distribution.Simple.Program
import qualified Distribution.Simple.Program.HcPkg as HcPkg
import qualified Distribution.Simple.Program.Strip as Strip
import Distribution.Simple.Program.GHC
import Distribution.Simple.Setup
import qualified Distribution.Simple.Setup as Cabal
import Distribution.Simple.Flag
import Distribution.Simple.Setup.Config
import Distribution.Simple.Compiler
import Distribution.CabalSpecVersion
import Distribution.Version
Expand Down Expand Up @@ -372,19 +372,19 @@ toJSLibName lib
-- -----------------------------------------------------------------------------
-- Building a library

buildLib :: Verbosity -> Cabal.Flag (Maybe Int) -> PackageDescription
buildLib :: Verbosity -> Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> Library -> ComponentLocalBuildInfo
-> IO ()
buildLib = buildOrReplLib Nothing

replLib :: [String] -> Verbosity
-> Cabal.Flag (Maybe Int) -> PackageDescription
-> Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> Library
-> ComponentLocalBuildInfo -> IO ()
replLib = buildOrReplLib . Just

buildOrReplLib :: Maybe [String] -> Verbosity
-> Cabal.Flag (Maybe Int) -> PackageDescription
-> Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> Library
-> ComponentLocalBuildInfo -> IO ()
buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
Expand Down Expand Up @@ -493,7 +493,7 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
then do
runGhcjsProg vanillaSharedOpts
case (hpcdir Hpc.Dyn, hpcdir Hpc.Vanilla) of
(Cabal.Flag dynDir, Cabal.Flag vanillaDir) ->
(Flag dynDir, Flag vanillaDir) ->
-- When the vanilla and shared library builds are done
-- in one pass, only one set of HPC module interfaces
-- are generated. This set should suffice for both
Expand Down Expand Up @@ -740,14 +740,14 @@ startInterpreter verbosity progdb comp platform packageDBs = do

-- | Build a foreign library
buildFLib
:: Verbosity -> Cabal.Flag (Maybe Int)
:: Verbosity -> Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> ForeignLib -> ComponentLocalBuildInfo -> IO ()
buildFLib v njobs pkg lbi = gbuild v njobs pkg lbi . GBuildFLib

replFLib
:: [String] -> Verbosity
-> Cabal.Flag (Maybe Int) -> PackageDescription
-> Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> ForeignLib
-> ComponentLocalBuildInfo -> IO ()
replFLib replFlags v njobs pkg lbi =
Expand All @@ -756,14 +756,14 @@ replFLib replFlags v njobs pkg lbi =
-- | Build an executable with GHC.
--
buildExe
:: Verbosity -> Cabal.Flag (Maybe Int)
:: Verbosity -> Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> Executable -> ComponentLocalBuildInfo -> IO ()
buildExe v njobs pkg lbi = gbuild v njobs pkg lbi . GBuildExe

replExe
:: [String] -> Verbosity
-> Cabal.Flag (Maybe Int) -> PackageDescription
-> Flag (Maybe Int) -> PackageDescription
-> LocalBuildInfo -> Executable
-> ComponentLocalBuildInfo -> IO ()
replExe replFlags v njobs pkg lbi =
Expand Down Expand Up @@ -1044,7 +1044,7 @@ isHaskell :: FilePath -> Bool
isHaskell fp = elem (takeExtension fp) [".hs", ".lhs"]

-- | Generic build function. See comment for 'GBuildMode'.
gbuild :: Verbosity -> Cabal.Flag (Maybe Int)
gbuild :: Verbosity -> Flag (Maybe Int)
-> PackageDescription -> LocalBuildInfo
-> GBuildMode -> ComponentLocalBuildInfo -> IO ()
gbuild verbosity numJobs pkg_descr lbi bm clbi = do
Expand Down
4 changes: 3 additions & 1 deletion Cabal/src/Distribution/Simple/Haddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ import Distribution.Simple.Program.GHC
import Distribution.Simple.Program.ResponseFile
import Distribution.Simple.Program
import Distribution.Simple.PreProcess
import Distribution.Simple.Setup
import Distribution.Simple.Flag
import Distribution.Simple.Setup.Haddock
import Distribution.Simple.Setup.Hscolour
import Distribution.Simple.Build
import Distribution.Simple.BuildTarget
import Distribution.Simple.InstallDirs
Expand Down
8 changes: 6 additions & 2 deletions Cabal/src/Distribution/Simple/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ import Distribution.Simple.Utils
, die', info, noticeNoWrap, warn )
import Distribution.Simple.Compiler
( CompilerFlavor(..), compilerFlavor )
import Distribution.Simple.Setup
( CopyFlags(..), fromFlag, HaddockTarget(ForDevelopment) )
import Distribution.Simple.Flag
( fromFlag )
import Distribution.Simple.Setup.Copy
( CopyFlags(..) )
import Distribution.Simple.Setup.Haddock
( HaddockTarget(ForDevelopment) )
import Distribution.Simple.BuildTarget
import Distribution.Utils.Path (getSymbolicPath)

Expand Down
6 changes: 4 additions & 2 deletions Cabal/src/Distribution/Simple/Program/Ar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ import Distribution.Simple.Program.ResponseFile
import Distribution.Simple.Program.Run
( programInvocation, multiStageProgramInvocation
, runProgramInvocation )
import Distribution.Simple.Setup
( fromFlagOrDefault, configUseResponseFiles )
import Distribution.Simple.Flag
( fromFlagOrDefault )
import Distribution.Simple.Setup.Config
( configUseResponseFiles )
import Distribution.Simple.Utils
( defaultTempFileOptions, dieWithLocation', withTempDirectory )
import Distribution.System
Expand Down
6 changes: 4 additions & 2 deletions Cabal/src/Distribution/Simple/Program/Ld.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import Distribution.Simple.Program.Run
, runProgramInvocation )
import Distribution.Simple.Program.Types
( ConfiguredProgram(..) )
import Distribution.Simple.Setup
( fromFlagOrDefault, configUseResponseFiles )
import Distribution.Simple.Flag
( fromFlagOrDefault )
import Distribution.Simple.Setup.Config
( configUseResponseFiles )
import Distribution.Simple.Utils
( defaultTempFileOptions )
import Distribution.Verbosity
Expand Down
3 changes: 2 additions & 1 deletion Cabal/src/Distribution/Simple/Register.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ import Distribution.Simple.Compiler
import Distribution.Simple.Program
import Distribution.Simple.Program.Script
import qualified Distribution.Simple.Program.HcPkg as HcPkg
import Distribution.Simple.Setup
import Distribution.Simple.Flag
import Distribution.Simple.Setup.Register
import Distribution.PackageDescription
import Distribution.Package
import Distribution.License (licenseToSPDX, licenseFromSPDX)
Expand Down
Loading

0 comments on commit ab24689

Please sign in to comment.