Skip to content

Commit 53d70ae

Browse files
committed
Make "stack ghci" skip build for local targets if in DB
1 parent c21ab19 commit 53d70ae

File tree

5 files changed

+44
-19
lines changed

5 files changed

+44
-19
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Other enhancements:
3737
* `--[no-]haddock-hyperlink-source` flag added which allows toggling
3838
of sources being included in Haddock output.
3939
See [#3099](https://github.com/commercialhaskell/stack/issues/3099)
40+
* `stack ghci` will now skip building all local targets, even if they have
41+
downstream deps, as long as it's registered in the DB.
4042

4143
Bug fixes:
4244

src/Stack/Build.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ build setLocalFiles mbuildLk boptsCli = fixCodePage $ do
118118

119119
baseConfigOpts <- mkBaseConfigOpts boptsCli
120120
plan <- withLoadPackage $ \loadPackage ->
121-
constructPlan mbp baseConfigOpts locals extraToBuild localDumpPkgs loadPackage sourceMap installedMap
121+
constructPlan mbp baseConfigOpts locals extraToBuild localDumpPkgs loadPackage sourceMap installedMap (boptsCLIInitialBuildSteps boptsCli)
122122

123123
allowLocals <- view $ configL.to configAllowLocals
124124
unless allowLocals $ case justLocals plan of

src/Stack/Build/ConstructPlan.hs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ constructPlan :: forall env m. (StackM env m, HasEnvConfig env)
178178
-> (PackageName -> Version -> Map FlagName Bool -> [Text] -> IO Package) -- ^ load upstream package
179179
-> SourceMap
180180
-> InstalledMap
181+
-> Bool
181182
-> m Plan
182-
constructPlan mbp0 baseConfigOpts0 locals extraToBuild0 localDumpPkgs loadPackage0 sourceMap installedMap = do
183+
constructPlan mbp0 baseConfigOpts0 locals extraToBuild0 localDumpPkgs loadPackage0 sourceMap installedMap initialBuildSteps = do
183184
$logDebug "Constructing the build plan"
184185
getVersions0 <- getPackageVersionsIO
185186

@@ -210,7 +211,7 @@ constructPlan mbp0 baseConfigOpts0 locals extraToBuild0 localDumpPkgs loadPackag
210211
return $ takeSubset Plan
211212
{ planTasks = tasks
212213
, planFinals = M.fromList finals
213-
, planUnregisterLocal = mkUnregisterLocal tasks dirtyReason localDumpPkgs sourceMap
214+
, planUnregisterLocal = mkUnregisterLocal tasks dirtyReason localDumpPkgs sourceMap initialBuildSteps
214215
, planInstallExes =
215216
if boptsInstallExes $ bcoBuildOpts baseConfigOpts0
216217
then installExes
@@ -260,8 +261,11 @@ mkUnregisterLocal :: Map PackageName Task
260261
-> [DumpPackage () () ()]
261262
-- ^ Local package database dump
262263
-> SourceMap
264+
-> Bool
265+
-- ^ If true, we're doing a special initialBuildSteps
266+
-- build - don't unregister target packages.
263267
-> Map GhcPkgId (PackageIdentifier, Text)
264-
mkUnregisterLocal tasks dirtyReason localDumpPkgs sourceMap =
268+
mkUnregisterLocal tasks dirtyReason localDumpPkgs sourceMap initialBuildSteps =
265269
-- We'll take multiple passes through the local packages. This
266270
-- will allow us to detect that a package should be unregistered,
267271
-- as well as all packages directly or transitively depending on
@@ -304,9 +308,12 @@ mkUnregisterLocal tasks dirtyReason localDumpPkgs sourceMap =
304308

305309
go' toUnregister ident deps
306310
-- If we're planning on running a task on it, then it must be
307-
-- unregistered
308-
| Just _ <- Map.lookup name tasks
309-
= Just $ fromMaybe "" $ Map.lookup name dirtyReason
311+
-- unregistered, unless it's a target and an initial-build-steps
312+
-- build is being done.
313+
| Just task <- Map.lookup name tasks
314+
= if initialBuildSteps && taskIsTarget task && taskProvides task == ident
315+
then Nothing
316+
else Just $ fromMaybe "" $ Map.lookup name dirtyReason
310317
-- Check if we're no longer using the local version
311318
| Just (PSUpstream _ Snap _ _ _) <- Map.lookup name sourceMap
312319
= Just "Switching to snapshot installed package"

src/Stack/Build/Execute.hs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ toActions installedMap runInBase ee (mbuild, mfinal) =
753753
getConfigCache :: (StackM env m, HasEnvConfig env)
754754
=> ExecuteEnv m -> Task -> InstalledMap -> Bool -> Bool
755755
-> m (Map PackageIdentifier GhcPkgId, ConfigCache)
756-
getConfigCache ExecuteEnv {..} Task {..} installedMap enableTest enableBench = do
756+
getConfigCache ExecuteEnv {..} task@Task {..} installedMap enableTest enableBench = do
757757
useExactConf <- view $ configL.to configAllowNewer
758758
let extra =
759759
-- We enable tests if the test suite dependencies are already
@@ -772,9 +772,16 @@ getConfigCache ExecuteEnv {..} Task {..} installedMap enableTest enableBench = d
772772
idMap <- liftIO $ readTVarIO eeGhcPkgIds
773773
let getMissing ident =
774774
case Map.lookup ident idMap of
775-
Nothing -> error "singleBuild: invariant violated, missing package ID missing"
776-
Just (Library ident' x) -> assert (ident == ident') $ Just (ident, x)
777-
Just (Executable _) -> Nothing
775+
Nothing
776+
-- Expect to instead find it in installedMap if it's
777+
-- an initialBuildSteps target.
778+
| boptsCLIInitialBuildSteps eeBuildOptsCLI && taskIsTarget task,
779+
Just (_, installed) <- Map.lookup (packageIdentifierName ident) installedMap
780+
-> installedToGhcPkgId ident installed
781+
Just installed -> installedToGhcPkgId ident installed
782+
_ -> error "singleBuild: invariant violated, missing package ID missing"
783+
installedToGhcPkgId ident (Library ident' x) = assert (ident == ident') $ Just (ident, x)
784+
installedToGhcPkgId _ (Executable _) = Nothing
778785
missing' = Map.fromList $ mapMaybe getMissing $ Set.toList missing
779786
TaskConfigOpts missing mkOpts = taskConfigOpts
780787
opts = mkOpts missing'
@@ -1294,23 +1301,25 @@ singleBuild runInBase ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} in
12941301
$ \package cabalfp pkgDir cabal announce _console _mlogFile -> do
12951302
_neededConfig <- ensureConfig cache pkgDir ee (announce ("configure" <> annSuffix)) cabal cabalfp
12961303

1304+
let installedMapHasThisPkg :: Bool
1305+
installedMapHasThisPkg =
1306+
case Map.lookup (packageName package) installedMap of
1307+
Just (_, Library ident _) -> ident == taskProvides
1308+
Just (_, Executable _) -> True
1309+
_ -> False
1310+
12971311
case ( boptsCLIOnlyConfigure eeBuildOptsCLI
1298-
, boptsCLIInitialBuildSteps eeBuildOptsCLI && isTarget
1299-
, acDownstream) of
1312+
, boptsCLIInitialBuildSteps eeBuildOptsCLI && taskIsTarget task) of
13001313
-- A full build is done if there are downstream actions,
13011314
-- because their configure step will require that this
13021315
-- package is built. See
13031316
-- https://github.com/commercialhaskell/stack/issues/2787
1304-
(True, _, []) -> return Nothing
1305-
(_, True, []) -> do
1317+
(True, _) | null acDownstream -> return Nothing
1318+
(_, True) | null acDownstream || installedMapHasThisPkg -> do
13061319
initialBuildSteps cabal announce
13071320
return Nothing
13081321
_ -> liftM Just $ realBuild cache package pkgDir cabal announce
13091322

1310-
isTarget = case taskType of
1311-
TTLocal lp -> lpWanted lp
1312-
_ -> False
1313-
13141323
initialBuildSteps cabal announce = do
13151324
() <- announce ("initial-build-steps" <> annSuffix)
13161325
cabal False ["repl", "stack-initial-build-steps"]

src/Stack/Types/Build.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module Stack.Types.Build
1818
,Installed(..)
1919
,PackageInstallInfo(..)
2020
,Task(..)
21+
,taskIsTarget
2122
,taskLocation
2223
,LocalPackage(..)
2324
,BaseConfigOpts(..)
@@ -449,6 +450,12 @@ data TaskType = TTLocal LocalPackage
449450
| TTUpstream Package InstallLocation (Maybe GitSHA1)
450451
deriving Show
451452

453+
taskIsTarget :: Task -> Bool
454+
taskIsTarget t =
455+
case taskType t of
456+
TTLocal lp -> lpWanted lp
457+
_ -> False
458+
452459
taskLocation :: Task -> InstallLocation
453460
taskLocation task =
454461
case taskType task of

0 commit comments

Comments
 (0)