@@ -158,6 +158,7 @@ import Distribution.Types.ComponentName
158
158
import Distribution.Types.UnqualComponentName
159
159
( UnqualComponentName
160
160
, packageNameToUnqualComponentName
161
+ , unUnqualComponentName
161
162
)
162
163
163
164
import Distribution.PackageDescription.Configuration
@@ -196,6 +197,8 @@ import Distribution.Simple.Utils
196
197
, noticeNoWrap
197
198
, ordNub
198
199
, warn
200
+ , installExecutableFile
201
+ , infoNoWrap
199
202
)
200
203
import Distribution.Types.Flag
201
204
( FlagAssignment
@@ -205,7 +208,7 @@ import Distribution.Types.Flag
205
208
import Distribution.Utils.NubList
206
209
( fromNubList
207
210
)
208
- import Distribution.Utils.Path (makeSymbolicPath )
211
+ import Distribution.Utils.Path (makeSymbolicPath , (</>) )
209
212
import Distribution.Verbosity
210
213
#ifdef MIN_VERSION_unix
211
214
import System.Posix.Signals (sigKILL , sigSEGV )
@@ -478,8 +481,8 @@ runProjectPostBuildPhase _ ProjectBaseContext{buildSettings} _ _
478
481
return ()
479
482
runProjectPostBuildPhase
480
483
verbosity
481
- ProjectBaseContext {.. }
482
- ProjectBuildContext {.. }
484
+ baseCtx @ ProjectBaseContext {.. }
485
+ buildCtx @ ProjectBuildContext {.. }
483
486
buildOutcomes = do
484
487
-- Update other build artefacts
485
488
-- TODO: currently none, but could include:
@@ -496,6 +499,8 @@ runProjectPostBuildPhase
496
499
pkgsBuildStatus
497
500
buildOutcomes
498
501
502
+ installExecutables verbosity baseCtx buildCtx postBuildStatus
503
+
499
504
-- Write the .ghc.environment file (if allowed by the env file write policy).
500
505
let writeGhcEnvFilesPolicy =
501
506
projectConfigWriteGhcEnvironmentFilesPolicy . projectConfigShared $
@@ -526,6 +531,31 @@ runProjectPostBuildPhase
526
531
-- an exception to terminate the program
527
532
dieOnBuildFailures verbosity currentCommand elaboratedPlanToExecute buildOutcomes
528
533
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
+
529
559
-- Note that it is a deliberate design choice that the 'buildTargets' is
530
560
-- not passed to phase 1, and the various bits of input config is not
531
561
-- passed to phase 2.
0 commit comments