@@ -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 )
@@ -467,8 +470,8 @@ runProjectPostBuildPhase _ ProjectBaseContext{buildSettings} _ _
467470 return ()
468471runProjectPostBuildPhase
469472 verbosity
470- ProjectBaseContext {.. }
471- ProjectBuildContext {.. }
473+ baseCtx @ ProjectBaseContext {.. }
474+ buildCtx @ ProjectBuildContext {.. }
472475 buildOutcomes = do
473476 -- Update other build artefacts
474477 -- TODO: currently none, but could include:
@@ -485,6 +488,8 @@ runProjectPostBuildPhase
485488 pkgsBuildStatus
486489 buildOutcomes
487490
491+ installExecutables verbosity baseCtx buildCtx postBuildStatus
492+
488493 -- Write the .ghc.environment file (if allowed by the env file write policy).
489494 let writeGhcEnvFilesPolicy =
490495 projectConfigWriteGhcEnvironmentFilesPolicy . projectConfigShared $
@@ -515,6 +520,31 @@ runProjectPostBuildPhase
515520 -- an exception to terminate the program
516521 dieOnBuildFailures verbosity currentCommand elaboratedPlanToExecute buildOutcomes
517522
523+ installExecutables :: Verbosity -> ProjectBaseContext -> ProjectBuildContext -> PostBuildProjectStatus -> IO ()
524+ installExecutables
525+ verbosity
526+ ProjectBaseContext {distDirLayout}
527+ ProjectBuildContext {elaboratedPlanOriginal, elaboratedShared, targetsMap}
528+ postBuildStatus =
529+ unless (null srcdst) $ do
530+ infoNoWrap verbosity $ " Copying executables to " <> bindir
531+ -- Create the bin directory if it does not exist
532+ createDirectoryIfMissingVerbose verbosity True bindir
533+ -- Install the executables
534+ for_ srcdst $ \ (exe, src) -> do
535+ installExecutableFile verbosity src (bindir </> exe)
536+ where
537+ bindir = distBinDirectory distDirLayout
538+ srcdst = [ (exe, dir </> exe)
539+ | (pkg, targets) <- Map. toList targetsMap
540+ , stageOf pkg == Host
541+ , pkg `Set.member` packagesDefinitelyUpToDate postBuildStatus
542+ , Just (InstallPlan. Configured elab) <- [InstallPlan. lookup elaboratedPlanOriginal pkg]
543+ , (ComponentTarget (CExeName cname) _subtarget, _targetSelectors) <- targets
544+ , let exe = unUnqualComponentName cname
545+ , let dir = binDirectoryFor distDirLayout elaboratedShared elab exe
546+ ]
547+
518548-- Note that it is a deliberate design choice that the 'buildTargets' is
519549-- not passed to phase 1, and the various bits of input config is not
520550-- passed to phase 2.
0 commit comments