@@ -156,6 +156,7 @@ import Distribution.Types.ComponentName
156156import Distribution.Types.UnqualComponentName
157157 ( UnqualComponentName
158158 , packageNameToUnqualComponentName
159+ , unUnqualComponentName
159160 )
160161
161162import Distribution.Solver.Types.OptionalStanza
@@ -192,6 +193,8 @@ import Distribution.Simple.Utils
192193 , noticeNoWrap
193194 , ordNub
194195 , warn
196+ , installExecutableFile
197+ , infoNoWrap
195198 )
196199import Distribution.Types.Flag
197200 ( FlagAssignment
@@ -201,7 +204,7 @@ import Distribution.Types.Flag
201204import Distribution.Utils.NubList
202205 ( fromNubList
203206 )
204- import Distribution.Utils.Path (makeSymbolicPath )
207+ import Distribution.Utils.Path (makeSymbolicPath , (</>) )
205208import Distribution.Verbosity
206209#ifdef MIN_VERSION_unix
207210import System.Posix.Signals (sigKILL , sigSEGV )
@@ -474,8 +477,8 @@ runProjectPostBuildPhase _ ProjectBaseContext{buildSettings} _ _
474477 return ()
475478runProjectPostBuildPhase
476479 verbosity
477- ProjectBaseContext {.. }
478- ProjectBuildContext {.. }
480+ baseCtx @ ProjectBaseContext {.. }
481+ buildCtx @ ProjectBuildContext {.. }
479482 buildOutcomes = do
480483 -- Update other build artefacts
481484 -- TODO: currently none, but could include:
@@ -492,6 +495,8 @@ runProjectPostBuildPhase
492495 pkgsBuildStatus
493496 buildOutcomes
494497
498+ installExecutables verbosity baseCtx buildCtx postBuildStatus
499+
495500 -- Write the .ghc.environment file (if allowed by the env file write policy).
496501 let writeGhcEnvFilesPolicy =
497502 projectConfigWriteGhcEnvironmentFilesPolicy . projectConfigShared $
@@ -521,6 +526,31 @@ runProjectPostBuildPhase
521526 -- an exception to terminate the program
522527 dieOnBuildFailures verbosity currentCommand elaboratedPlanToExecute buildOutcomes
523528
529+ installExecutables :: Verbosity -> ProjectBaseContext -> ProjectBuildContext -> PostBuildProjectStatus -> IO ()
530+ installExecutables
531+ verbosity
532+ ProjectBaseContext {distDirLayout}
533+ ProjectBuildContext {elaboratedPlanOriginal, elaboratedShared, targetsMap}
534+ postBuildStatus =
535+ unless (null srcdst) $ do
536+ infoNoWrap verbosity $ " Copying executables to " <> bindir
537+ -- Create the bin directory if it does not exist
538+ createDirectoryIfMissingVerbose verbosity True bindir
539+ -- Install the executables
540+ for_ srcdst $ \ (exe, src) -> do
541+ installExecutableFile verbosity src (bindir </> exe)
542+ where
543+ bindir = distBinDirectory distDirLayout
544+ srcdst = [ (exe, dir </> exe)
545+ | (pkg, targets) <- Map. toList targetsMap
546+ , stageOf pkg == Host
547+ , pkg `Set.member` packagesDefinitelyUpToDate postBuildStatus
548+ , Just (InstallPlan. Configured elab) <- [InstallPlan. lookup elaboratedPlanOriginal pkg]
549+ , (ComponentTarget (CExeName cname) _subtarget, _targetSelectors) <- targets
550+ , let exe = unUnqualComponentName cname
551+ , let dir = binDirectoryFor distDirLayout elaboratedShared elab exe
552+ ]
553+
524554-- Note that it is a deliberate design choice that the 'buildTargets' is
525555-- not passed to phase 1, and the various bits of input config is not
526556-- passed to phase 2.
0 commit comments