@@ -158,6 +158,7 @@ import Distribution.Types.ComponentName
158158import Distribution.Types.UnqualComponentName
159159 ( UnqualComponentName
160160 , packageNameToUnqualComponentName
161+ , unUnqualComponentName
161162 )
162163
163164import Distribution.PackageDescription.Configuration
@@ -194,6 +195,8 @@ import Distribution.Simple.Utils
194195 , noticeNoWrap
195196 , ordNub
196197 , warn
198+ , installExecutableFile
199+ , infoNoWrap
197200 )
198201import Distribution.Types.Flag
199202 ( FlagAssignment
@@ -203,7 +206,7 @@ import Distribution.Types.Flag
203206import Distribution.Utils.NubList
204207 ( fromNubList
205208 )
206- import Distribution.Utils.Path (makeSymbolicPath )
209+ import Distribution.Utils.Path (makeSymbolicPath , (</>) )
207210import Distribution.Verbosity
208211#ifdef MIN_VERSION_unix
209212import System.Posix.Signals (sigKILL , sigSEGV )
@@ -470,8 +473,8 @@ runProjectPostBuildPhase _ ProjectBaseContext{buildSettings} _ _
470473 return ()
471474runProjectPostBuildPhase
472475 verbosity
473- ProjectBaseContext {.. }
474- ProjectBuildContext {.. }
476+ baseCtx @ ProjectBaseContext {.. }
477+ buildCtx @ ProjectBuildContext {.. }
475478 buildOutcomes = do
476479 -- Update other build artefacts
477480 -- TODO: currently none, but could include:
@@ -488,6 +491,8 @@ runProjectPostBuildPhase
488491 pkgsBuildStatus
489492 buildOutcomes
490493
494+ installExecutables verbosity baseCtx buildCtx postBuildStatus
495+
491496 -- Write the .ghc.environment file (if allowed by the env file write policy).
492497 let writeGhcEnvFilesPolicy =
493498 projectConfigWriteGhcEnvironmentFilesPolicy . projectConfigShared $
@@ -518,6 +523,31 @@ runProjectPostBuildPhase
518523 -- an exception to terminate the program
519524 dieOnBuildFailures verbosity currentCommand elaboratedPlanToExecute buildOutcomes
520525
526+ installExecutables :: Verbosity -> ProjectBaseContext -> ProjectBuildContext -> PostBuildProjectStatus -> IO ()
527+ installExecutables
528+ verbosity
529+ ProjectBaseContext {distDirLayout}
530+ ProjectBuildContext {elaboratedPlanOriginal, elaboratedShared, targetsMap}
531+ postBuildStatus =
532+ unless (null srcdst) $ do
533+ infoNoWrap verbosity $ " Copying executables to " <> bindir
534+ -- Create the bin directory if it does not exist
535+ createDirectoryIfMissingVerbose verbosity True bindir
536+ -- Install the executables
537+ for_ srcdst $ \ (exe, src) -> do
538+ installExecutableFile verbosity src (bindir </> exe)
539+ where
540+ bindir = distBinDirectory distDirLayout
541+ srcdst = [ (exe, dir </> exe)
542+ | (pkg, targets) <- Map. toList targetsMap
543+ , stageOf pkg == Host
544+ , pkg `Set.member` packagesDefinitelyUpToDate postBuildStatus
545+ , Just (InstallPlan. Configured elab) <- [InstallPlan. lookup elaboratedPlanOriginal pkg]
546+ , (ComponentTarget (CExeName cname) _subtarget, _targetSelectors) <- targets
547+ , let exe = unUnqualComponentName cname
548+ , let dir = binDirectoryFor distDirLayout elaboratedShared elab exe
549+ ]
550+
521551-- Note that it is a deliberate design choice that the 'buildTargets' is
522552-- not passed to phase 1, and the various bits of input config is not
523553-- passed to phase 2.
0 commit comments