Skip to content

Commit eb01438

Browse files
committed
Suggest stack init when using implicit global
1 parent 1637c98 commit eb01438

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

src/Stack/Build/Source.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ loadSourceMap bopts = do
8787
workingDir <- getWorkingDir
8888
(cliExtraDeps, targets) <-
8989
parseTargets
90+
(bcImplicitGlobal bconfig)
9091
(boptsTests bopts)
9192
(boptsBenchmarks bopts)
9293
(mpiVersion <$> mbpPackages mbp0)

src/Stack/Build/Target.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,16 @@ simplifyTargets includeTests includeBenches =
285285
getLocalComp _ = Left ()
286286

287287
parseTargets :: (MonadThrow m, MonadIO m)
288-
=> Bool -- ^ include tests
288+
=> Bool -- ^ using implicit global?
289+
-> Bool -- ^ include tests
289290
-> Bool -- ^ include benchmarks
290291
-> Map PackageName Version -- ^ snapshot
291292
-> Map PackageName Version -- ^ extra deps
292293
-> Map PackageName LocalPackageView
293294
-> Path Abs Dir -- ^ current directory
294295
-> [Text] -- ^ command line targets
295296
-> m (Map PackageName Version, Map PackageName SimpleTarget)
296-
parseTargets includeTests includeBenches snap extras locals currDir textTargets' = do
297+
parseTargets implicitGlobal includeTests includeBenches snap extras locals currDir textTargets' = do
297298
let textTargets =
298299
if null textTargets'
299300
then map (T.pack . packageNameString) $ Map.keys $ Map.filter (not . lpvExtraDep) locals
@@ -310,8 +311,9 @@ parseTargets includeTests includeBenches snap extras locals currDir textTargets'
310311

311312
if null errs
312313
then if Map.null targets
313-
-- TODO perhaps check if we're using the implicit global and,
314-
-- if so, recommend running stack init/new?
315-
then throwM $ TargetParseException ["The specified targets matched no packages"]
314+
then throwM $ TargetParseException
315+
$ if implicitGlobal
316+
then ["The specified targets matched no packages.\nPerhaps you need to run 'stack init'?"]
317+
else ["The specified targets matched no packages"]
316318
else return (Map.unions newExtras, targets)
317319
else throwM $ TargetParseException errs

src/Stack/Config.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ loadBuildConfig mproject config stackRoot mresolver = do
296296
, bcExtraDeps = projectExtraDeps project
297297
, bcStackYaml = stackYamlFP
298298
, bcFlags = projectFlags project
299+
, bcImplicitGlobal = isNothing mproject
299300
}
300301

301302
-- | Resolve a PackageEntry into a list of paths, downloading and cloning as

src/Stack/Types/Config.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ data BuildConfig = BuildConfig
240240
-- different from bcRoot </> "stack.yaml"
241241
, bcFlags :: !(Map PackageName (Map FlagName Bool))
242242
-- ^ Per-package flag overrides
243+
, bcImplicitGlobal :: !Bool
244+
-- ^ Are we loading from the implicit global stack.yaml? This is useful
245+
-- for providing better error messages.
243246
}
244247

245248
-- | Directory containing the project's stack.yaml file

0 commit comments

Comments
 (0)