@@ -317,10 +317,11 @@ executePlan :: M env m
317
317
-> BaseConfigOpts
318
318
-> [LocalPackage ]
319
319
-> SourceMap
320
+ -> InstalledMap
320
321
-> Plan
321
322
-> m ()
322
- executePlan menv bopts baseConfigOpts locals sourceMap plan = do
323
- withExecuteEnv menv bopts baseConfigOpts locals sourceMap (executePlan' plan)
323
+ executePlan menv bopts baseConfigOpts locals sourceMap installedMap plan = do
324
+ withExecuteEnv menv bopts baseConfigOpts locals sourceMap (executePlan' installedMap plan)
324
325
325
326
unless (Map. null $ planInstallExes plan) $ do
326
327
snapBin <- (</> bindirSuffix) `liftM` installationRootDeps
@@ -400,10 +401,11 @@ windowsRenameCopy src dest = do
400
401
401
402
-- | Perform the actual plan (internal)
402
403
executePlan' :: M env m
403
- => Plan
404
+ => InstalledMap
405
+ -> Plan
404
406
-> ExecuteEnv
405
407
-> m ()
406
- executePlan' plan ee@ ExecuteEnv {.. } = do
408
+ executePlan' installedMap plan ee@ ExecuteEnv {.. } = do
407
409
wc <- getWhichCompiler
408
410
case Map. toList $ planUnregisterLocal plan of
409
411
[] -> return ()
@@ -424,7 +426,7 @@ executePlan' plan ee@ExecuteEnv {..} = do
424
426
-- stack always using transformer stacks that are safe for this use case.
425
427
runInBase <- liftBaseWith $ \ run -> return (void . run)
426
428
427
- let actions = concatMap (toActions runInBase ee) $ Map. elems $ Map. mergeWithKey
429
+ let actions = concatMap (toActions installedMap runInBase ee) $ Map. elems $ Map. mergeWithKey
428
430
(\ _ b f -> Just (Just b, Just f))
429
431
(fmap (\ b -> (Just b, Nothing )))
430
432
(fmap (\ f -> (Nothing , Just f)))
@@ -468,11 +470,12 @@ executePlan' plan ee@ExecuteEnv {..} = do
468
470
when (toCoverage $ boptsTestOpts eeBuildOpts) generateHpcMarkupIndex
469
471
470
472
toActions :: M env m
471
- => (m () -> IO () )
473
+ => InstalledMap
474
+ -> (m () -> IO () )
472
475
-> ExecuteEnv
473
476
-> (Maybe Task , Maybe (Task , LocalPackageTB )) -- build and final
474
477
-> [Action ]
475
- toActions runInBase ee (mbuild, mfinal) =
478
+ toActions installedMap runInBase ee (mbuild, mfinal) =
476
479
abuild ++ afinal
477
480
where
478
481
abuild =
@@ -483,7 +486,7 @@ toActions runInBase ee (mbuild, mfinal) =
483
486
{ actionId = ActionId taskProvides ATBuild
484
487
, actionDeps =
485
488
(Set. map (\ ident -> ActionId ident ATBuild ) (tcoMissing taskConfigOpts))
486
- , actionDo = \ ac -> runInBase $ singleBuild ac ee task
489
+ , actionDo = \ ac -> runInBase $ singleBuild ac ee task installedMap
487
490
}
488
491
]
489
492
afinal =
@@ -496,9 +499,9 @@ toActions runInBase ee (mbuild, mfinal) =
496
499
(Set. map (\ ident -> ActionId ident ATBuild ) (tcoMissing taskConfigOpts))
497
500
, actionDo = \ ac -> runInBase $ do
498
501
unless (Set. null $ lptbTests lptb) $ do
499
- singleTest topts lptb ac ee task
502
+ singleTest topts lptb ac ee task installedMap
500
503
unless (Set. null $ lptbBenches lptb) $ do
501
- singleBench beopts lptb ac ee task
504
+ singleBench beopts lptb ac ee task installedMap
502
505
}
503
506
]
504
507
where
@@ -752,10 +755,22 @@ singleBuild :: M env m
752
755
=> ActionContext
753
756
-> ExecuteEnv
754
757
-> Task
758
+ -> InstalledMap
755
759
-> m ()
756
- singleBuild ac@ ActionContext {.. } ee@ ExecuteEnv {.. } task@ Task {.. } =
760
+ singleBuild ac@ ActionContext {.. } ee@ ExecuteEnv {.. } task@ Task {.. } installedMap =
757
761
withSingleContext ac ee task Nothing $ \ package cabalfp pkgDir cabal announce console _mlogFile -> do
758
- (cache, _neededConfig) <- ensureConfig pkgDir ee task (announce " configure" ) cabal cabalfp []
762
+ (cache, _neededConfig) <- ensureConfig pkgDir ee task (announce " configure" ) cabal cabalfp $
763
+ -- We enable tests if the test suite dependencies are already
764
+ -- installed, so that we avoid unnecessary recompilation based on
765
+ -- cabal_macros.h changes when switching between 'stack build' and
766
+ -- 'stack test'. See:
767
+ -- https://github.com/commercialhaskell/stack/issues/805
768
+ case taskType of
769
+ TTLocal lp -> concat
770
+ [ [" --enable-tests" | depsPresent installedMap $ lpTestDeps lp]
771
+ , [" --enable-benchmarks" | depsPresent installedMap $ lpBenchDeps lp]
772
+ ]
773
+ _ -> []
759
774
wc <- getWhichCompiler
760
775
761
776
markExeNotInstalled (taskLocation task) taskProvides
@@ -821,16 +836,32 @@ singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} =
821
836
(PackageIdentifier (packageName package) (packageVersion package))
822
837
Set. empty
823
838
839
+ -- | Determine if all of the dependencies given are installed
840
+ depsPresent :: InstalledMap -> Map PackageName VersionRange -> Bool
841
+ depsPresent installedMap deps = all
842
+ (\ (name, range) ->
843
+ case Map. lookup name installedMap of
844
+ Just (version, _, _) -> version `withinRange` range
845
+ Nothing -> False )
846
+ (Map. toList deps)
847
+
824
848
singleTest :: M env m
825
849
=> TestOpts
826
850
-> LocalPackageTB
827
851
-> ActionContext
828
852
-> ExecuteEnv
829
853
-> Task
854
+ -> InstalledMap
830
855
-> m ()
831
- singleTest topts lptb ac ee task =
856
+ singleTest topts lptb ac ee task installedMap =
832
857
withSingleContext ac ee task (Just " test" ) $ \ package cabalfp pkgDir cabal announce console mlogFile -> do
833
- (_cache, neededConfig) <- ensureConfig pkgDir ee task (announce " configure (test)" ) cabal cabalfp [" --enable-tests" ]
858
+ (_cache, neededConfig) <- ensureConfig pkgDir ee task (announce " configure (test)" ) cabal cabalfp $
859
+ case taskType task of
860
+ TTLocal lp -> concat
861
+ [ [" --enable-tests" ]
862
+ , [" --enable-benchmarks" | depsPresent installedMap $ lpBenchDeps lp]
863
+ ]
864
+ _ -> []
834
865
config <- asks getConfig
835
866
836
867
testBuilt <- checkTestBuilt pkgDir
@@ -968,10 +999,17 @@ singleBench :: M env m
968
999
-> ActionContext
969
1000
-> ExecuteEnv
970
1001
-> Task
1002
+ -> InstalledMap
971
1003
-> m ()
972
- singleBench beopts _lptb ac ee task =
1004
+ singleBench beopts _lptb ac ee task installedMap =
973
1005
withSingleContext ac ee task (Just " bench" ) $ \ _package cabalfp pkgDir cabal announce console _mlogFile -> do
974
- (_cache, neededConfig) <- ensureConfig pkgDir ee task (announce " configure (benchmarks)" ) cabal cabalfp [" --enable-benchmarks" ]
1006
+ (_cache, neededConfig) <- ensureConfig pkgDir ee task (announce " configure (benchmarks)" ) cabal cabalfp $
1007
+ case taskType task of
1008
+ TTLocal lp -> concat
1009
+ [ [" --enable-tests" | depsPresent installedMap $ lpTestDeps lp]
1010
+ , [" --enable-benchmarks" ]
1011
+ ]
1012
+ _ -> []
975
1013
976
1014
benchBuilt <- checkBenchBuilt pkgDir
977
1015
0 commit comments