Skip to content

Commit 37a91b5

Browse files
committed
Allow empty stack init (fixes commercialhaskell#2465)
1 parent cddd7df commit 37a91b5

4 files changed

Lines changed: 22 additions & 8 deletions

File tree

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ Other enhancements:
168168
installation based on the version suffix, allowing you to more easily switch
169169
between various system-installed GHCs. See
170170
[#2433](https://github.com/commercialhaskell/stack/issues/2433).
171+
* `stack init` will now support create a `stack.yaml` file without any local
172+
packages. See [#2465](https://github.com/commercialhaskell/stack/issues/2465)
171173

172174
Bug fixes:
173175

src/Stack/Init.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,11 @@ initProject currDir initOpts mresolver = do
6565
" exists, use '--force' to overwrite it.")
6666

6767
dirs <- mapM (resolveDir' . T.unpack) (searchDirs initOpts)
68-
let noPkgMsg = "In order to init, you should have an existing .cabal \
69-
\file. Please try \"stack new\" instead."
70-
find = findCabalDirs (includeSubDirs initOpts)
68+
let find = findCabalDirs (includeSubDirs initOpts)
7169
dirs' = if null dirs then [currDir] else dirs
7270
logInfo "Looking for .cabal or package.yaml files to use to init the project."
7371
cabaldirs <- Set.toList . Set.unions <$> mapM find dirs'
74-
(bundle, dupPkgs) <- cabalPackagesCheck cabaldirs noPkgMsg Nothing
72+
(bundle, dupPkgs) <- cabalPackagesCheck cabaldirs Nothing
7573
let makeRelDir dir =
7674
case stripProperPrefix currDir dir of
7775
Nothing
@@ -507,14 +505,16 @@ ignoredDirs = Set.fromList
507505
cabalPackagesCheck
508506
:: (HasConfig env, HasGHCVariant env)
509507
=> [Path Abs Dir]
510-
-> String
511508
-> Maybe String
512509
-> RIO env
513510
( Map PackageName (Path Abs File, C.GenericPackageDescription)
514511
, [Path Abs File])
515-
cabalPackagesCheck cabaldirs noPkgMsg dupErrMsg = do
516-
when (null cabaldirs) $
517-
error noPkgMsg
512+
cabalPackagesCheck cabaldirs dupErrMsg = do
513+
when (null cabaldirs) $ do
514+
logWarn "We didn't find any local package directories"
515+
logWarn "You may want to create a package with \"stack new\" instead"
516+
logWarn "Create an empty project for now"
517+
logWarn "If this isn't what you want, please delete the generated \"stack.yaml\""
518518

519519
relpaths <- mapM prettyPath cabaldirs
520520
logInfo "Using cabal packages:"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import StackTest
2+
import System.Directory
3+
import Control.Monad (unless)
4+
5+
main :: IO ()
6+
main = do
7+
removeFileIgnore "stack.yaml"
8+
stack ["init"]
9+
exists <- doesFileExist "stack.yaml"
10+
unless exists $ error "stack.yaml not created!"
11+
stack ["build"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
stack.yaml

0 commit comments

Comments
 (0)