@@ -316,10 +316,11 @@ executePlan :: M env m
316
316
-> BaseConfigOpts
317
317
-> [LocalPackage ]
318
318
-> SourceMap
319
+ -> InstalledMap
319
320
-> Plan
320
321
-> m ()
321
- executePlan menv bopts baseConfigOpts locals sourceMap plan = do
322
- withExecuteEnv menv bopts baseConfigOpts locals sourceMap (executePlan' plan)
322
+ executePlan menv bopts baseConfigOpts locals sourceMap installedMap plan = do
323
+ withExecuteEnv menv bopts baseConfigOpts locals sourceMap (executePlan' installedMap plan)
323
324
324
325
unless (Map. null $ planInstallExes plan) $ do
325
326
snapBin <- (</> bindirSuffix) `liftM` installationRootDeps
@@ -399,10 +400,11 @@ windowsRenameCopy src dest = do
399
400
400
401
-- | Perform the actual plan (internal)
401
402
executePlan' :: M env m
402
- => Plan
403
+ => InstalledMap
404
+ -> Plan
403
405
-> ExecuteEnv
404
406
-> m ()
405
- executePlan' plan ee@ ExecuteEnv {.. } = do
407
+ executePlan' installedMap plan ee@ ExecuteEnv {.. } = do
406
408
wc <- getWhichCompiler
407
409
case Map. toList $ planUnregisterLocal plan of
408
410
[] -> return ()
@@ -423,7 +425,7 @@ executePlan' plan ee@ExecuteEnv {..} = do
423
425
-- stack always using transformer stacks that are safe for this use case.
424
426
runInBase <- liftBaseWith $ \ run -> return (void . run)
425
427
426
- let actions = concatMap (toActions runInBase ee) $ Map. elems $ Map. mergeWithKey
428
+ let actions = concatMap (toActions installedMap' runInBase ee) $ Map. elems $ Map. mergeWithKey
427
429
(\ _ b f -> Just (Just b, Just f))
428
430
(fmap (\ b -> (Just b, Nothing )))
429
431
(fmap (\ f -> (Nothing , Just f)))
@@ -465,13 +467,20 @@ executePlan' plan ee@ExecuteEnv {..} = do
465
467
generateDepsHaddockIndex eeEnvOverride wc eeBaseConfigOpts eeLocals
466
468
generateSnapHaddockIndex eeEnvOverride wc eeBaseConfigOpts eeGlobalDB
467
469
when (toCoverage $ boptsTestOpts eeBuildOpts) generateHpcMarkupIndex
470
+ where
471
+ installedMap' = Map. difference installedMap
472
+ $ Map. fromList
473
+ $ map (\ gid -> (packageIdentifierName $ ghcPkgIdPackageIdentifier gid, () ))
474
+ $ Map. keys
475
+ $ planUnregisterLocal plan
468
476
469
477
toActions :: M env m
470
- => (m () -> IO () )
478
+ => InstalledMap
479
+ -> (m () -> IO () )
471
480
-> ExecuteEnv
472
481
-> (Maybe Task , Maybe (Task , LocalPackageTB )) -- build and final
473
482
-> [Action ]
474
- toActions runInBase ee (mbuild, mfinal) =
483
+ toActions installedMap runInBase ee (mbuild, mfinal) =
475
484
abuild ++ afinal
476
485
where
477
486
abuild =
@@ -482,7 +491,7 @@ toActions runInBase ee (mbuild, mfinal) =
482
491
{ actionId = ActionId taskProvides ATBuild
483
492
, actionDeps =
484
493
(Set. map (\ ident -> ActionId ident ATBuild ) (tcoMissing taskConfigOpts))
485
- , actionDo = \ ac -> runInBase $ singleBuild ac ee task
494
+ , actionDo = \ ac -> runInBase $ singleBuild ac ee task installedMap
486
495
}
487
496
]
488
497
afinal =
@@ -495,9 +504,9 @@ toActions runInBase ee (mbuild, mfinal) =
495
504
(Set. map (\ ident -> ActionId ident ATBuild ) (tcoMissing taskConfigOpts))
496
505
, actionDo = \ ac -> runInBase $ do
497
506
unless (Set. null $ lptbTests lptb) $ do
498
- singleTest topts lptb ac ee task
507
+ singleTest topts lptb ac ee task installedMap
499
508
unless (Set. null $ lptbBenches lptb) $ do
500
- singleBench beopts lptb ac ee task
509
+ singleBench beopts lptb ac ee task installedMap
501
510
}
502
511
]
503
512
where
@@ -751,10 +760,22 @@ singleBuild :: M env m
751
760
=> ActionContext
752
761
-> ExecuteEnv
753
762
-> Task
763
+ -> InstalledMap
754
764
-> m ()
755
- singleBuild ac@ ActionContext {.. } ee@ ExecuteEnv {.. } task@ Task {.. } =
765
+ singleBuild ac@ ActionContext {.. } ee@ ExecuteEnv {.. } task@ Task {.. } installedMap =
756
766
withSingleContext ac ee task Nothing $ \ package cabalfp pkgDir cabal announce console _mlogFile -> do
757
- (cache, _neededConfig) <- ensureConfig pkgDir ee task (announce " configure" ) cabal cabalfp []
767
+ (cache, _neededConfig) <- ensureConfig pkgDir ee task (announce " configure" ) cabal cabalfp $
768
+ -- We enable tests if the test suite dependencies are already
769
+ -- installed, so that we avoid unnecessary recompilation based on
770
+ -- cabal_macros.h changes when switching between 'stack build' and
771
+ -- 'stack test'. See:
772
+ -- https://github.com/commercialhaskell/stack/issues/805
773
+ case taskType of
774
+ TTLocal lp -> concat
775
+ [ [" --enable-tests" | depsPresent installedMap $ lpTestDeps lp]
776
+ , [" --enable-benchmarks" | depsPresent installedMap $ lpBenchDeps lp]
777
+ ]
778
+ _ -> []
758
779
wc <- getWhichCompiler
759
780
760
781
markExeNotInstalled (taskLocation task) taskProvides
@@ -826,16 +847,32 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} =
826
847
(PackageIdentifier (packageName package) (packageVersion package))
827
848
Set. empty
828
849
850
+ -- | Determine if all of the dependencies given are installed
851
+ depsPresent :: InstalledMap -> Map PackageName VersionRange -> Bool
852
+ depsPresent installedMap deps = all
853
+ (\ (name, range) ->
854
+ case Map. lookup name installedMap of
855
+ Just (version, _, _) -> version `withinRange` range
856
+ Nothing -> False )
857
+ (Map. toList deps)
858
+
829
859
singleTest :: M env m
830
860
=> TestOpts
831
861
-> LocalPackageTB
832
862
-> ActionContext
833
863
-> ExecuteEnv
834
864
-> Task
865
+ -> InstalledMap
835
866
-> m ()
836
- singleTest topts lptb ac ee task =
867
+ singleTest topts lptb ac ee task installedMap =
837
868
withSingleContext ac ee task (Just " test" ) $ \ package cabalfp pkgDir cabal announce console mlogFile -> do
838
- (_cache, neededConfig) <- ensureConfig pkgDir ee task (announce " configure (test)" ) cabal cabalfp [" --enable-tests" ]
869
+ (_cache, neededConfig) <- ensureConfig pkgDir ee task (announce " configure (test)" ) cabal cabalfp $
870
+ case taskType task of
871
+ TTLocal lp -> concat
872
+ [ [" --enable-tests" ]
873
+ , [" --enable-benchmarks" | depsPresent installedMap $ lpBenchDeps lp]
874
+ ]
875
+ _ -> []
839
876
config <- asks getConfig
840
877
841
878
testBuilt <- checkTestBuilt pkgDir
@@ -973,10 +1010,17 @@ singleBench :: M env m
973
1010
-> ActionContext
974
1011
-> ExecuteEnv
975
1012
-> Task
1013
+ -> InstalledMap
976
1014
-> m ()
977
- singleBench beopts _lptb ac ee task =
1015
+ singleBench beopts _lptb ac ee task installedMap =
978
1016
withSingleContext ac ee task (Just " bench" ) $ \ _package cabalfp pkgDir cabal announce console _mlogFile -> do
979
- (_cache, neededConfig) <- ensureConfig pkgDir ee task (announce " configure (benchmarks)" ) cabal cabalfp [" --enable-benchmarks" ]
1017
+ (_cache, neededConfig) <- ensureConfig pkgDir ee task (announce " configure (benchmarks)" ) cabal cabalfp $
1018
+ case taskType task of
1019
+ TTLocal lp -> concat
1020
+ [ [" --enable-tests" | depsPresent installedMap $ lpTestDeps lp]
1021
+ , [" --enable-benchmarks" ]
1022
+ ]
1023
+ _ -> []
980
1024
981
1025
benchBuilt <- checkBenchBuilt pkgDir
982
1026
0 commit comments