@@ -158,6 +158,7 @@ import Distribution.Types.ComponentName
158158import Distribution.Types.UnqualComponentName
159159 ( UnqualComponentName
160160 , packageNameToUnqualComponentName
161+ , unUnqualComponentName
161162 )
162163
163164import Distribution.PackageDescription.Configuration
@@ -196,6 +197,8 @@ import Distribution.Simple.Utils
196197 , noticeNoWrap
197198 , ordNub
198199 , warn
200+ , installExecutableFile
201+ , infoNoWrap
199202 )
200203import Distribution.Types.Flag
201204 ( FlagAssignment
@@ -205,7 +208,7 @@ import Distribution.Types.Flag
205208import Distribution.Utils.NubList
206209 ( fromNubList
207210 )
208- import Distribution.Utils.Path (makeSymbolicPath )
211+ import Distribution.Utils.Path (makeSymbolicPath , (</>) )
209212import Distribution.Verbosity
210213#ifdef MIN_VERSION_unix
211214import System.Posix.Signals (sigKILL , sigSEGV )
@@ -478,8 +481,8 @@ runProjectPostBuildPhase _ ProjectBaseContext{buildSettings} _ _
478481 return ()
479482runProjectPostBuildPhase
480483 verbosity
481- ProjectBaseContext {.. }
482- ProjectBuildContext {.. }
484+ baseCtx @ ProjectBaseContext {.. }
485+ buildCtx @ ProjectBuildContext {.. }
483486 buildOutcomes = do
484487 -- Update other build artefacts
485488 -- TODO: currently none, but could include:
@@ -496,6 +499,8 @@ runProjectPostBuildPhase
496499 pkgsBuildStatus
497500 buildOutcomes
498501
502+ installExecutables verbosity baseCtx buildCtx postBuildStatus
503+
499504 -- Write the .ghc.environment file (if allowed by the env file write policy).
500505 let writeGhcEnvFilesPolicy =
501506 projectConfigWriteGhcEnvironmentFilesPolicy . projectConfigShared $
@@ -526,6 +531,31 @@ runProjectPostBuildPhase
526531 -- an exception to terminate the program
527532 dieOnBuildFailures verbosity currentCommand elaboratedPlanToExecute buildOutcomes
528533
534+ installExecutables :: Verbosity -> ProjectBaseContext -> ProjectBuildContext -> PostBuildProjectStatus -> IO ()
535+ installExecutables
536+ verbosity
537+ ProjectBaseContext {distDirLayout}
538+ ProjectBuildContext {elaboratedPlanOriginal, elaboratedShared, targetsMap}
539+ postBuildStatus =
540+ unless (null srcdst) $ do
541+ infoNoWrap verbosity $ " Copying executables to " <> bindir
542+ -- Create the bin directory if it does not exist
543+ createDirectoryIfMissingVerbose verbosity True bindir
544+ -- Install the executables
545+ for_ srcdst $ \ (exe, src) -> do
546+ installExecutableFile verbosity src (bindir </> exe)
547+ where
548+ bindir = distBinDirectory distDirLayout
549+ srcdst = [ (exe, dir </> exe)
550+ | (pkg, targets) <- Map. toList targetsMap
551+ , stageOf pkg == Host
552+ , pkg `Set.member` packagesDefinitelyUpToDate postBuildStatus
553+ , Just (InstallPlan. Configured elab) <- [InstallPlan. lookup elaboratedPlanOriginal pkg]
554+ , (ComponentTarget (CExeName cname) _subtarget, _targetSelectors) <- targets
555+ , let exe = unUnqualComponentName cname
556+ , let dir = binDirectoryFor distDirLayout elaboratedShared elab exe
557+ ]
558+
529559-- Note that it is a deliberate design choice that the 'buildTargets' is
530560-- not passed to phase 1, and the various bits of input config is not
531561-- passed to phase 2.
0 commit comments