Skip to content

Commit 15da6e4

Browse files
committed
Only rebuild test suites if necessary
1 parent 49c54c4 commit 15da6e4

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/Stack/Build/Execute.hs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ ensureConfig :: M env m
339339
-> m () -- ^ announce
340340
-> (Bool -> [String] -> m ()) -- ^ cabal
341341
-> [Text]
342-
-> m ConfigCache
342+
-> m (ConfigCache, Bool)
343343
ensureConfig pkgDir ExecuteEnv {..} Task {..} announce cabal extra = do
344344
-- Determine the old and new configuration in the local directory, to
345345
-- determine if we need to reconfigure.
@@ -363,7 +363,8 @@ ensureConfig pkgDir ExecuteEnv {..} Task {..} announce cabal extra = do
363363
, configCacheDeps = allDeps
364364
}
365365

366-
when (mOldConfigCache /= Just newConfigCache) $ withMVar eeConfigureLock $ \_ -> do
366+
let needConfig = mOldConfigCache /= Just newConfigCache
367+
when needConfig $ withMVar eeConfigureLock $ \_ -> do
367368
deleteCaches pkgDir
368369
withMVar eeInstallLock $ \(done,total) ->
369370
$logSticky ("Progress: " <> T.pack (show done) <> "/" <> T.pack (show total))
@@ -372,7 +373,7 @@ ensureConfig pkgDir ExecuteEnv {..} Task {..} announce cabal extra = do
372373
$logDebug $ T.pack $ show configOpts
373374
writeConfigCache pkgDir newConfigCache
374375

375-
return newConfigCache
376+
return (newConfigCache, needConfig)
376377

377378
withSingleContext :: M env m
378379
=> ActionContext
@@ -507,7 +508,7 @@ singleBuild :: M env m
507508
-> m ()
508509
singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} =
509510
withSingleContext ac ee task $ \package cabalfp pkgDir cabal announce console _mlogFile -> do
510-
cache <- ensureConfig pkgDir ee task (announce "configure") cabal []
511+
(cache, _neededConfig) <- ensureConfig pkgDir ee task (announce "configure") cabal []
511512

512513
fileModTimes <- getPackageFileModTimes package cabalfp
513514
writeBuildCache pkgDir fileModTimes
@@ -553,11 +554,16 @@ singleTest :: M env m
553554
singleTest ac ee task =
554555
withSingleContext ac ee task $ \package _cabalfp pkgDir cabal announce console mlogFile ->
555556
unless (Set.null $ packageTests package) $ do
556-
_cache <- ensureConfig pkgDir ee task (announce "configure (test)") cabal ["--enable-tests"]
557-
558-
announce "build (test)" -- TODO only rebuild as necessary
557+
(_cache, neededConfig) <- ensureConfig pkgDir ee task (announce "configure (test)") cabal ["--enable-tests"]
559558
config <- asks getConfig
560-
cabal (console && configHideTHLoading config) ["build"]
559+
560+
let needBuild = neededConfig ||
561+
(case taskType task of
562+
TTLocal lp -> lpDirtyFiles lp
563+
_ -> assert False True)
564+
when needBuild $ do
565+
announce "build (test)"
566+
cabal (console && configHideTHLoading config) ["build"]
561567

562568
bconfig <- asks getBuildConfig
563569
distRelativeDir' <- distRelativeDir
@@ -621,11 +627,16 @@ singleBench :: M env m
621627
singleBench ac ee task =
622628
withSingleContext ac ee task $ \package _cabalfp pkgDir cabal announce console _mlogFile ->
623629
unless (Set.null $ packageBenchmarks package) $ do
624-
_cache <- ensureConfig pkgDir ee task (announce "configure (benchmarks)") cabal ["--enable-benchmarks"]
625-
626-
announce "build (benchmarks)" -- TODO only rebuild as necessary
627-
config <- asks getConfig
628-
cabal (console && configHideTHLoading config) ["build"]
630+
(_cache, neededConfig) <- ensureConfig pkgDir ee task (announce "configure (benchmarks)") cabal ["--enable-benchmarks"]
631+
632+
let needBuild = neededConfig ||
633+
(case taskType task of
634+
TTLocal lp -> lpDirtyFiles lp
635+
_ -> assert False True)
636+
when needBuild $ do
637+
announce "build (benchmarks)"
638+
config <- asks getConfig
639+
cabal (console && configHideTHLoading config) ["build"]
629640

630641
announce "benchmarks"
631642
cabal False ["bench"]

0 commit comments

Comments
 (0)