diff --git a/ChangeLog.md b/ChangeLog.md index 1cf38aad74..07efeba147 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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: diff --git a/src/Stack/Init.hs b/src/Stack/Init.hs index 0522eb322d..7a2026f77b 100644 --- a/src/Stack/Init.hs +++ b/src/Stack/Init.hs @@ -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 @@ -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:" diff --git a/test/integration/tests/2465-init-no-packages/Main.hs b/test/integration/tests/2465-init-no-packages/Main.hs new file mode 100644 index 0000000000..f4c6831c4d --- /dev/null +++ b/test/integration/tests/2465-init-no-packages/Main.hs @@ -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"] diff --git a/test/integration/tests/2465-init-no-packages/files/.gitignore b/test/integration/tests/2465-init-no-packages/files/.gitignore new file mode 100644 index 0000000000..684dbffa96 --- /dev/null +++ b/test/integration/tests/2465-init-no-packages/files/.gitignore @@ -0,0 +1 @@ +stack.yaml