Skip to content

Commit

Permalink
Reinstate 'initialBuildSteps' function
Browse files Browse the repository at this point in the history
This patch reinstates the 'initialBuildSteps' function, as it is
used by stack in its implementation of the multi-repl feature.

A warning has been added to that function: calling it does not suffice
to prepare the sources for a package, as there are other steps that one
might also need to perform:

  - running pre-processors (such as alex/happy)
  - running pre-build hooks or custom logic (in build-type: Hooks
    or build-type: Custom or Configure)

Consumers wanting to prepare the sources of a package, e.g. in order to
launch a REPL session, are advised to run
`Setup repl --repl-multi-file=<fn>` instead.

Fixes #9856
  • Loading branch information
sheaf committed Apr 29, 2024
1 parent bccc59f commit 2dde79e
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion Cabal/src/Distribution/Simple/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ module Distribution.Simple.Build
, writeBuiltinAutogenFiles
, writeAutogenFiles

-- ** Legacy functions
, componentInitialBuildSteps
, initialBuildSteps

-- * Internal package database creation
, createInternalPackageDB
) where
Expand Down Expand Up @@ -1029,6 +1033,53 @@ replFLib flags pkg_descr lbi exe clbi =
GHC -> GHC.replFLib flags NoFlag pkg_descr lbi exe clbi
_ -> dieWithException verbosity REPLNotSupported

-- | Runs 'componentInitialBuildSteps' on every configured component.
--
-- Legacy function: does not run pre-build hooks or pre-processors. This function
-- is insufficient on its own to prepare the build for a package.
--
-- Consumers wanting to prepare the sources of a package, e.g. in order to
-- launch a REPL session, are advised to run @Setup repl --repl-multi-file=<fn>@
-- instead.
initialBuildSteps
:: FilePath
-- ^ "dist" prefix
-> PackageDescription
-- ^ mostly information from the .cabal file
-> LocalBuildInfo
-- ^ Configuration information
-> Verbosity
-- ^ The verbosity to use
-> IO ()
initialBuildSteps distPref pkg_descr lbi verbosity =
withAllComponentsInBuildOrder pkg_descr lbi $ \_comp clbi ->
componentInitialBuildSteps distPref pkg_descr lbi clbi verbosity

-- | Creates the autogenerated files for a particular configured component.
--
-- Legacy function: does not run pre-build hooks or pre-processors. This function
-- is insufficient on its own to prepare the build for a component.
--
-- Consumers wanting to prepare the sources of a component, e.g. in order to
-- launch a REPL session, are advised to run
-- @Setup repl <compName> --repl-multi-file=<fn>@ instead.
componentInitialBuildSteps
:: FilePath
-- ^ "dist" prefix
-> PackageDescription
-- ^ mostly information from the .cabal file
-> LocalBuildInfo
-- ^ Configuration information
-> ComponentLocalBuildInfo
-- ^ Build info about the component
-> Verbosity
-- ^ The verbosity to use
-> IO ()
componentInitialBuildSteps _distPref pkg_descr lbi clbi verbosity = do
let compBuildDir = interpretSymbolicPathLBI lbi $ componentBuildDir lbi clbi
createDirectoryIfMissingVerbose verbosity True compBuildDir
writeBuiltinAutogenFiles verbosity pkg_descr lbi clbi

-- | Creates the autogenerated files for a particular configured component,
-- and runs the pre-build hook.
preBuildComponent
Expand All @@ -1042,7 +1093,8 @@ preBuildComponent
preBuildComponent preBuildHook verbosity lbi tgt = do
let pkg_descr = localPkgDescr lbi
clbi = targetCLBI tgt
createDirectoryIfMissingVerbose verbosity True (interpretSymbolicPathLBI lbi $ componentBuildDir lbi clbi)
compBuildDir = interpretSymbolicPathLBI lbi $ componentBuildDir lbi clbi
createDirectoryIfMissingVerbose verbosity True compBuildDir
writeBuiltinAutogenFiles verbosity pkg_descr lbi clbi
preBuildHook lbi tgt

Expand Down

0 comments on commit 2dde79e

Please sign in to comment.