Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
alt-romes committed Jan 11, 2024
1 parent c756bb4 commit 4aec4b5
Show file tree
Hide file tree
Showing 7 changed files with 496 additions and 493 deletions.
10 changes: 5 additions & 5 deletions Cabal/src/Distribution/Simple/Build/Monad.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE NamedFieldPuns #-}

module Distribution.Simple.Build.Monad
( BuildM (..)
, runBuildM
Expand All @@ -26,14 +27,14 @@ where

import Control.Monad.Reader

import Distribution.Simple.Compiler
import Distribution.Simple.Setup (BuildingWhat (..), buildingWhatDistPref, buildingWhatVerbosity)
import Distribution.Types.BuildInfo
import Distribution.Types.Component
import Distribution.Types.ComponentLocalBuildInfo
import Distribution.Types.LocalBuildInfo
import Distribution.Types.TargetInfo
import Distribution.Verbosity
import Distribution.Types.Component
import Distribution.Types.ComponentLocalBuildInfo
import Distribution.Types.BuildInfo
import Distribution.Simple.Compiler

-- | The information required for a build computation (@'BuildM'@)
-- which is available right before building each component, i.e. the pre-build
Expand Down Expand Up @@ -96,4 +97,3 @@ buildCompiler = compiler <$> buildLBI
buildTarget :: BuildM TargetInfo
buildTarget = asks targetInfo
{-# INLINE buildTarget #-}

28 changes: 14 additions & 14 deletions Cabal/src/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ import qualified Distribution.InstalledPackageInfo as InstalledPackageInfo
import Distribution.Package
import Distribution.PackageDescription as PD
import Distribution.Pretty
import Distribution.Simple.Build.Monad (runBuildM)
import Distribution.Simple.BuildPaths
import Distribution.Simple.Compiler
import Distribution.Simple.Errors
import Distribution.Simple.Flag (Flag (..), toFlag)
import qualified Distribution.Simple.GHC.Build as GHC
import Distribution.Simple.Build.Monad (runBuildM)
import Distribution.Simple.GHC.Build.Utils
import Distribution.Simple.GHC.EnvironmentParser
import Distribution.Simple.GHC.ImplInfo
Expand All @@ -104,7 +104,6 @@ import Distribution.Simple.PackageIndex (InstalledPackageIndex)
import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.Simple.Program
import Distribution.Simple.Program.Builtin (runghcProgram)
import Distribution.Types.TargetInfo
import Distribution.Simple.Program.GHC
import qualified Distribution.Simple.Program.HcPkg as HcPkg
import qualified Distribution.Simple.Program.Strip as Strip
Expand All @@ -114,6 +113,7 @@ import Distribution.Simple.Utils
import Distribution.System
import Distribution.Types.ComponentLocalBuildInfo
import Distribution.Types.ParStrat
import Distribution.Types.TargetInfo
import Distribution.Utils.NubList
import Distribution.Verbosity
import Distribution.Version
Expand Down Expand Up @@ -566,8 +566,8 @@ buildLib
-> Library
-> ComponentLocalBuildInfo
-> IO ()
buildLib flags numJobs pkg lbi lib clbi
= runBuildM (BuildNormal flags) lbi (TargetInfo clbi (CLib lib)) (GHC.build numJobs pkg)
buildLib flags numJobs pkg lbi lib clbi =
runBuildM (BuildNormal flags) lbi (TargetInfo clbi (CLib lib)) (GHC.build numJobs pkg)

replLib
:: ReplFlags
Expand All @@ -577,8 +577,8 @@ replLib
-> Library
-> ComponentLocalBuildInfo
-> IO ()
replLib flags numJobs pkg lbi lib clbi
= runBuildM (BuildRepl flags) lbi (TargetInfo clbi (CLib lib)) (GHC.build numJobs pkg)
replLib flags numJobs pkg lbi lib clbi =
runBuildM (BuildRepl flags) lbi (TargetInfo clbi (CLib lib)) (GHC.build numJobs pkg)

-- | Start a REPL without loading any source files.
startInterpreter
Expand Down Expand Up @@ -610,8 +610,8 @@ buildFLib
-> ForeignLib
-> ComponentLocalBuildInfo
-> IO ()
buildFLib v njobs pkg lbi flib clbi
= runBuildM (BuildNormal mempty{buildVerbosity = toFlag v}) lbi (TargetInfo clbi (CFLib flib)) (GHC.build njobs pkg)
buildFLib v njobs pkg lbi flib clbi =
runBuildM (BuildNormal mempty{buildVerbosity = toFlag v}) lbi (TargetInfo clbi (CFLib flib)) (GHC.build njobs pkg)

replFLib
:: ReplFlags
Expand All @@ -621,8 +621,8 @@ replFLib
-> ForeignLib
-> ComponentLocalBuildInfo
-> IO ()
replFLib replFlags njobs pkg lbi flib clbi
= runBuildM (BuildRepl replFlags) lbi (TargetInfo clbi (CFLib flib)) (GHC.build njobs pkg)
replFLib replFlags njobs pkg lbi flib clbi =
runBuildM (BuildRepl replFlags) lbi (TargetInfo clbi (CFLib flib)) (GHC.build njobs pkg)

-- | Build an executable with GHC.
buildExe
Expand All @@ -633,8 +633,8 @@ buildExe
-> Executable
-> ComponentLocalBuildInfo
-> IO ()
buildExe v njobs pkg lbi exe clbi
= runBuildM (BuildNormal mempty{buildVerbosity = toFlag v}) lbi (TargetInfo clbi (CExe exe)) (GHC.build njobs pkg)
buildExe v njobs pkg lbi exe clbi =
runBuildM (BuildNormal mempty{buildVerbosity = toFlag v}) lbi (TargetInfo clbi (CExe exe)) (GHC.build njobs pkg)

replExe
:: ReplFlags
Expand All @@ -644,8 +644,8 @@ replExe
-> Executable
-> ComponentLocalBuildInfo
-> IO ()
replExe replFlags njobs pkg lbi exe clbi
= runBuildM (BuildRepl replFlags) lbi (TargetInfo clbi (CExe exe)) (GHC.build njobs pkg)
replExe replFlags njobs pkg lbi exe clbi =
runBuildM (BuildRepl replFlags) lbi (TargetInfo clbi (CExe exe)) (GHC.build njobs pkg)

-- | Extracts a String representing a hash of the ABI of a built
-- library. It can fail if the library has not yet been built.
Expand Down
84 changes: 42 additions & 42 deletions Cabal/src/Distribution/Simple/GHC/Build.hs
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
{-# LANGUAGE BlockArguments #-}

module Distribution.Simple.GHC.Build where

import Distribution.Compat.Prelude
import Prelude ()

import Data.Function
import Control.Monad.IO.Class
import Data.Function
import qualified Data.Set as Set
import Distribution.PackageDescription as PD hiding (buildInfo)
import Distribution.Simple.Build.Monad
import Distribution.Simple.Flag (Flag)
import Distribution.Simple.GHC.Build.ExtraSources
import Distribution.Simple.GHC.Build.Link
import Distribution.Simple.GHC.Build.Modules
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Program
import Distribution.Simple.Utils
import Distribution.Types.ParStrat
import System.Directory hiding (exeExtension)
import System.FilePath
import Distribution.Simple.Build.Monad
import Distribution.Simple.GHC.Build.ExtraSources
import Distribution.Simple.GHC.Build.Modules
import Distribution.Simple.GHC.Build.Link
import Distribution.Types.ParStrat
import qualified Data.Set as Set

{-
Note [Build Target Dir vs Target Dir]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Where to place the build result (targetDir) and the build artifacts (buildTargetDir).
* For libraries, targetDir == buildTargetDir, where both the library and
\* For libraries, targetDir == buildTargetDir, where both the library and
artifacts are put together.
* For executables or foreign libs, buildTargetDir == targetDir/<name-of-target-dir>-tmp, where
\* For executables or foreign libs, buildTargetDir == targetDir/<name-of-target-dir>-tmp, where
the targetDir is the location where the target (e.g. the executable) is written to
and buildTargetDir is where the compilation artifacts (e.g. Main.o) will live
Arguably, this difference should not exist (#9498) (TODO)
Expand All @@ -52,28 +53,28 @@ prefixes. To minimize the likelihood, we use

-- | The main build phase of building a component.
-- Includes building Haskell modules, extra build sources, and linking.
build :: Flag ParStrat
-> PackageDescription
-> BuildM ()
build
:: Flag ParStrat
-> PackageDescription
-> BuildM ()
build numJobs pkg_descr = do
verbosity <- buildVerbosity
component <- buildComponent
lbi <- buildLBI
clbi <- buildCLBI
lbi <- buildLBI
clbi <- buildCLBI

let isLib | CLib{} <- component = True
| otherwise = False
let isLib
| CLib{} <- component = True
| otherwise = False

-- See Note [Build Target Dir vs Target Dir]
let targetDir_absolute = componentBuildDir lbi clbi
buildTargetDir_absolute
-- Libraries use the target dir for building (see above)
| isLib = targetDir_absolute

-- In other cases, use targetDir/<name-of-target-dir>-tmp
| targetDirName:_ <- reverse $ splitDirectories targetDir_absolute
= targetDir_absolute </> (targetDirName ++ "-tmp")

| targetDirName : _ <- reverse $ splitDirectories targetDir_absolute =
targetDir_absolute </> (targetDirName ++ "-tmp")
| otherwise = error "GHC.build: targetDir is empty"

liftIO do
Expand All @@ -87,28 +88,28 @@ build numJobs pkg_descr = do
let
-- wantVanilla is underspecified, maybe we could deprecated it? (TODO)
wantVanilla = if isLib then withVanillaLib lbi else False
wantStatic = if isLib then withStaticLib lbi else withFullyStaticExe lbi
wantStatic = if isLib then withStaticLib lbi else withFullyStaticExe lbi
wantDynamic = if isLib then withSharedLib lbi else withDynExe lbi
wantProf = if isLib then withProfLib lbi else withProfExe lbi
wantProf = if isLib then withProfLib lbi else withProfExe lbi

-- See also Note [Building Haskell Modules accounting for TH] in Distribution.Simple.GHC.Build.Modules
wantedWays
= Set.fromList
$ [StaticWay | wantStatic]
<> [DynWay | wantDynamic ]
<> [ProfWay | wantProf ]
-- If no way is explicitly wanted, we take vanilla
<> [VanillaWay | wantVanilla || not (wantStatic || wantDynamic || wantProf) ]
-- ROMES:TODO: Is vanilla necessarily the same as defaultGhcWay? If so,
-- we can deal away with VanillaWay and be explicit in -dynamic vs
-- -static, or always default to -static. Would simplify further.
-- ROMES:TODO: Perhaps, if the component is indefinite, we only pick Vanilla?
-- To mimick the old behaviour we need at least profiled too (Vanilla +
-- Prof), and there's even a test for profiled signature, whatever that
-- means. So only doing vanilla way for indefinite components before seems wrong.
-- Consider...
-- ROMES:TODO: Perhaps for executables we want to limit the "wanted"
-- ways to just one?
wantedWays =
Set.fromList $
[StaticWay | wantStatic]
<> [DynWay | wantDynamic]
<> [ProfWay | wantProf]
-- If no way is explicitly wanted, we take vanilla
<> [VanillaWay | wantVanilla || not (wantStatic || wantDynamic || wantProf)]
-- ROMES:TODO: Is vanilla necessarily the same as defaultGhcWay? If so,
-- we can deal away with VanillaWay and be explicit in -dynamic vs
-- -static, or always default to -static. Would simplify further.
-- ROMES:TODO: Perhaps, if the component is indefinite, we only pick Vanilla?
-- To mimick the old behaviour we need at least profiled too (Vanilla +
-- Prof), and there's even a test for profiled signature, whatever that
-- means. So only doing vanilla way for indefinite components before seems wrong.
-- Consider...
-- ROMES:TODO: Perhaps for executables we want to limit the "wanted"
-- ways to just one?

-- ROMES:TODO: From #3294, this may now be possible, after the refactor?
-- In the case that there are no C source files that depend on FFI exports, I
Expand All @@ -125,8 +126,7 @@ build numJobs pkg_descr = do
-- We need a separate build and link phase, and C sources must be compiled
-- after Haskell modules, because C sources may depend on stub headers
-- generated from compiling Haskell modules (#842).
(vanillaOpts, wantedWaysMap)
<- buildHaskellModules numJobs ghcProg pkg_descr buildTargetDir wantedWays
(vanillaOpts, wantedWaysMap) <-
buildHaskellModules numJobs ghcProg pkg_descr buildTargetDir wantedWays
extraSources <- buildAllExtraSources ghcProg
linkOrLoadComponent ghcProg pkg_descr extraSources (buildTargetDir, targetDir) vanillaOpts wantedWaysMap

66 changes: 33 additions & 33 deletions Cabal/src/Distribution/Simple/GHC/Build/ExtraSources.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,33 @@ import Distribution.Types.TargetInfo

import Distribution.Simple.GHC.Build.Utils
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Program.Types
import Distribution.System (Arch (JavaScript), Platform (..))
import Distribution.Types.ComponentLocalBuildInfo
import Distribution.Types.ComponentName (componentNameRaw)
import Distribution.Types.Executable
import Distribution.Verbosity (Verbosity)
import System.FilePath
import Distribution.Simple.Program.Types
import Distribution.System (Platform(..), Arch(JavaScript))
import Distribution.Types.ComponentLocalBuildInfo

import Distribution.Simple.Build.Monad

-- | An action that builds all the extra build sources of a component, i.e. C,
-- C++, Js, Asm, C-- sources.
buildAllExtraSources :: ConfiguredProgram
-- ^ The GHC configured program
-> BuildM [FilePath]
-- ^ Returns the list of extra sources that were built
buildAllExtraSources
:: ConfiguredProgram
-- ^ The GHC configured program
-> BuildM [FilePath]
-- ^ Returns the list of extra sources that were built
buildAllExtraSources =
fmap concat
. sequence
. sequence
[ buildCSources
, buildCxxSources
, buildJsSources
, buildAsmSources
, buildCmmSources
]
. sequence
. sequence
[ buildCSources
, buildCxxSources
, buildJsSources
, buildAsmSources
, buildCmmSources
]

buildCSources
, buildCxxSources
Expand Down Expand Up @@ -83,15 +84,14 @@ buildJsSources ghcProg = do
"JS Sources"
Internal.componentJsGhcOptions
False
( \c ->
if hasJsSupport
then -- JS files are C-like with GHC's JS backend: they are
-- "compiled" into `.o` files (renamed with a header).
-- This is a difference from GHCJS, for which we only
-- pass the JS files at link time.
jsSources (componentBuildInfo c)
else mempty

( \c ->
if hasJsSupport
then -- JS files are C-like with GHC's JS backend: they are
-- "compiled" into `.o` files (renamed with a header).
-- This is a difference from GHCJS, for which we only
-- pass the JS files at link time.
jsSources (componentBuildInfo c)
else mempty
)
ghcProg
buildAsmSources =
Expand Down Expand Up @@ -147,7 +147,6 @@ buildExtraSources description componentSourceGhcOptions wantDyn viewSources ghcP
runGhcProg = runGHC verbosity ghcProg comp platform

buildAction sourceFile = do

let baseSrcOpts =
componentSourceGhcOptions
verbosity
Expand Down Expand Up @@ -231,11 +230,12 @@ buildExtraSources description componentSourceGhcOptions wantDyn viewSources ghcP
| CNotLibName{} <- cname =
componentBuildDir lbi clbi
</> componentNameRaw cname <> "-tmp"
in do
-- build any sources
if (null sources || componentIsIndefinite clbi) then do
info verbosity ("Building " ++ description ++ "...")
traverse_ buildAction sources
return sources
else
return []
in
do
-- build any sources
if (null sources || componentIsIndefinite clbi)
then do
info verbosity ("Building " ++ description ++ "...")
traverse_ buildAction sources
return sources
else return []
Loading

0 comments on commit 4aec4b5

Please sign in to comment.