@@ -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)))
@@ -467,11 +469,12 @@ executePlan' plan ee@ExecuteEnv {..} = do
467
469
when (toCoverage $ boptsTestOpts eeBuildOpts) generateHpcMarkupIndex
468
470
469
471
toActions :: M env m
470
- => (m () -> IO () )
472
+ => InstalledMap
473
+ -> (m () -> IO () )
471
474
-> ExecuteEnv
472
475
-> (Maybe Task , Maybe (Task , LocalPackageTB )) -- build and final
473
476
-> [Action ]
474
- toActions runInBase ee (mbuild, mfinal) =
477
+ toActions installedMap runInBase ee (mbuild, mfinal) =
475
478
abuild ++ afinal
476
479
where
477
480
abuild =
@@ -482,7 +485,7 @@ toActions runInBase ee (mbuild, mfinal) =
482
485
{ actionId = ActionId taskProvides ATBuild
483
486
, actionDeps =
484
487
(Set. map (\ ident -> ActionId ident ATBuild ) (tcoMissing taskConfigOpts))
485
- , actionDo = \ ac -> runInBase $ singleBuild ac ee task
488
+ , actionDo = \ ac -> runInBase $ singleBuild ac ee task installedMap
486
489
}
487
490
]
488
491
afinal =
@@ -495,9 +498,9 @@ toActions runInBase ee (mbuild, mfinal) =
495
498
(Set. map (\ ident -> ActionId ident ATBuild ) (tcoMissing taskConfigOpts))
496
499
, actionDo = \ ac -> runInBase $ do
497
500
unless (Set. null $ lptbTests lptb) $ do
498
- singleTest topts lptb ac ee task
501
+ singleTest topts lptb ac ee task installedMap
499
502
unless (Set. null $ lptbBenches lptb) $ do
500
- singleBench beopts lptb ac ee task
503
+ singleBench beopts lptb ac ee task installedMap
501
504
}
502
505
]
503
506
where
@@ -751,10 +754,22 @@ singleBuild :: M env m
751
754
=> ActionContext
752
755
-> ExecuteEnv
753
756
-> Task
757
+ -> InstalledMap
754
758
-> m ()
755
- singleBuild ac@ ActionContext {.. } ee@ ExecuteEnv {.. } task@ Task {.. } =
759
+ singleBuild ac@ ActionContext {.. } ee@ ExecuteEnv {.. } task@ Task {.. } installedMap =
756
760
withSingleContext ac ee task Nothing $ \ package cabalfp pkgDir cabal announce console _mlogFile -> do
757
- (cache, _neededConfig) <- ensureConfig pkgDir ee task (announce " configure" ) cabal cabalfp []
761
+ (cache, _neededConfig) <- ensureConfig pkgDir ee task (announce " configure" ) cabal cabalfp $
762
+ -- We enable tests if the test suite dependencies are already
763
+ -- installed, so that we avoid unnecessary recompilation based on
764
+ -- cabal_macros.h changes when switching between 'stack build' and
765
+ -- 'stack test'. See:
766
+ -- https://github.com/commercialhaskell/stack/issues/805
767
+ case taskType of
768
+ TTLocal lp -> concat
769
+ [ [" --enable-tests" | depsPresent installedMap $ lpTestDeps lp]
770
+ , [" --enable-benchmarks" | depsPresent installedMap $ lpBenchDeps lp]
771
+ ]
772
+ _ -> []
758
773
wc <- getWhichCompiler
759
774
760
775
markExeNotInstalled (taskLocation task) taskProvides
@@ -826,16 +841,32 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} =
826
841
(PackageIdentifier (packageName package) (packageVersion package))
827
842
Set. empty
828
843
844
+ -- | Determine if all of the dependencies given are installed
845
+ depsPresent :: InstalledMap -> Map PackageName VersionRange -> Bool
846
+ depsPresent installedMap deps = all
847
+ (\ (name, range) ->
848
+ case Map. lookup name installedMap of
849
+ Just (version, _, _) -> version `withinRange` range
850
+ Nothing -> False )
851
+ (Map. toList deps)
852
+
829
853
singleTest :: M env m
830
854
=> TestOpts
831
855
-> LocalPackageTB
832
856
-> ActionContext
833
857
-> ExecuteEnv
834
858
-> Task
859
+ -> InstalledMap
835
860
-> m ()
836
- singleTest topts lptb ac ee task =
861
+ singleTest topts lptb ac ee task installedMap =
837
862
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" ]
863
+ (_cache, neededConfig) <- ensureConfig pkgDir ee task (announce " configure (test)" ) cabal cabalfp $
864
+ case taskType task of
865
+ TTLocal lp -> concat
866
+ [ [" --enable-tests" ]
867
+ , [" --enable-benchmarks" | depsPresent installedMap $ lpBenchDeps lp]
868
+ ]
869
+ _ -> []
839
870
config <- asks getConfig
840
871
841
872
testBuilt <- checkTestBuilt pkgDir
@@ -973,10 +1004,17 @@ singleBench :: M env m
973
1004
-> ActionContext
974
1005
-> ExecuteEnv
975
1006
-> Task
1007
+ -> InstalledMap
976
1008
-> m ()
977
- singleBench beopts _lptb ac ee task =
1009
+ singleBench beopts _lptb ac ee task installedMap =
978
1010
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" ]
1011
+ (_cache, neededConfig) <- ensureConfig pkgDir ee task (announce " configure (benchmarks)" ) cabal cabalfp $
1012
+ case taskType task of
1013
+ TTLocal lp -> concat
1014
+ [ [" --enable-tests" | depsPresent installedMap $ lpTestDeps lp]
1015
+ , [" --enable-benchmarks" ]
1016
+ ]
1017
+ _ -> []
980
1018
981
1019
benchBuilt <- checkBenchBuilt pkgDir
982
1020
0 commit comments