Skip to content

Commit

Permalink
Allow empty stack init (fixes #2465)
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Apr 2, 2019
1 parent e0ca0ea commit 7d8b6e1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ Other enhancements:
installation based on the version suffix, allowing you to more easily switch
between various system-installed GHCs. See
[#2433](https://github.com/commercialhaskell/stack/issues/2433).
* `stack init` will now support create a `stack.yaml` file without any local
packages. See [#2465](https://github.com/commercialhaskell/stack/issues/2465)

Bug fixes:

Expand Down
16 changes: 8 additions & 8 deletions src/Stack/Init.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@ initProject currDir initOpts mresolver = do
" exists, use '--force' to overwrite it.")

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

relpaths <- mapM prettyPath cabaldirs
logInfo "Using cabal packages:"
Expand Down
11 changes: 11 additions & 0 deletions test/integration/tests/2465-init-no-packages/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import StackTest
import System.Directory
import Control.Monad (unless)

main :: IO ()
main = do
removeFileIgnore "stack.yaml"
stack ["init"]
exists <- doesFileExist "stack.yaml"
unless exists $ error "stack.yaml not created!"
stack ["build"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stack.yaml

0 comments on commit 7d8b6e1

Please sign in to comment.