@@ -156,6 +156,7 @@ import Distribution.Types.ComponentName
156
156
import Distribution.Types.UnqualComponentName
157
157
( UnqualComponentName
158
158
, packageNameToUnqualComponentName
159
+ , unUnqualComponentName
159
160
)
160
161
161
162
import Distribution.Solver.Types.OptionalStanza
@@ -192,6 +193,8 @@ import Distribution.Simple.Utils
192
193
, noticeNoWrap
193
194
, ordNub
194
195
, warn
196
+ , installExecutableFile
197
+ , infoNoWrap
195
198
)
196
199
import Distribution.Types.Flag
197
200
( FlagAssignment
@@ -201,7 +204,7 @@ import Distribution.Types.Flag
201
204
import Distribution.Utils.NubList
202
205
( fromNubList
203
206
)
204
- import Distribution.Utils.Path (makeSymbolicPath )
207
+ import Distribution.Utils.Path (makeSymbolicPath , (</>) )
205
208
import Distribution.Verbosity
206
209
#ifdef MIN_VERSION_unix
207
210
import System.Posix.Signals (sigKILL , sigSEGV )
@@ -474,8 +477,8 @@ runProjectPostBuildPhase _ ProjectBaseContext{buildSettings} _ _
474
477
return ()
475
478
runProjectPostBuildPhase
476
479
verbosity
477
- ProjectBaseContext {.. }
478
- ProjectBuildContext {.. }
480
+ baseCtx @ ProjectBaseContext {.. }
481
+ buildCtx @ ProjectBuildContext {.. }
479
482
buildOutcomes = do
480
483
-- Update other build artefacts
481
484
-- TODO: currently none, but could include:
@@ -492,6 +495,8 @@ runProjectPostBuildPhase
492
495
pkgsBuildStatus
493
496
buildOutcomes
494
497
498
+ installExecutables verbosity baseCtx buildCtx postBuildStatus
499
+
495
500
-- Write the .ghc.environment file (if allowed by the env file write policy).
496
501
let writeGhcEnvFilesPolicy =
497
502
projectConfigWriteGhcEnvironmentFilesPolicy . projectConfigShared $
@@ -521,6 +526,31 @@ runProjectPostBuildPhase
521
526
-- an exception to terminate the program
522
527
dieOnBuildFailures verbosity currentCommand elaboratedPlanToExecute buildOutcomes
523
528
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
+
524
554
-- Note that it is a deliberate design choice that the 'buildTargets' is
525
555
-- not passed to phase 1, and the various bits of input config is not
526
556
-- passed to phase 2.
0 commit comments