Skip to content

Commit 5490191

Browse files
committed
Adds hpack support for when building initing projects.
This allows stack templates to define only a `package.yaml` file instead of a `.cabal` file.
1 parent 704764f commit 5490191

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/Stack/New.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ applyTemplate project template nonceParams dir templateText = do
205205
throwM (InvalidTemplate template (show e)))
206206
when (M.null files) $
207207
throwM (InvalidTemplate template "Template does not contain any files")
208-
unless (any (".cabal" `isSuffixOf`) . M.keys $ files) $
209-
throwM (InvalidTemplate template "Template does not contain a .cabal\
208+
unless (any (\x -> or [".cabal" `isSuffixOf` x, x == "package.yaml"]) . M.keys $ files) $
209+
throwM (InvalidTemplate template "Template does not contain a .cabal or `package.yaml`\
210210
\ file")
211211
liftM
212212
M.fromList

src/Stack/Package.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module Stack.Package
2121
,readPackageUnresolvedBS
2222
,resolvePackage
2323
,findOrGenerateCabalFile
24+
,hpack
2425
,Package(..)
2526
,GetPackageFiles(..)
2627
,GetPackageOpts(..)

src/Stack/Solver.hs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import Prelude
5252
import Stack.BuildPlan
5353
import Stack.Constants (stackDotYaml)
5454
import Stack.Package (printCabalFileWarning
55+
, hpack
5556
, readPackageUnresolved)
5657
import Stack.Setup
5758
import Stack.Setup.Installed
@@ -468,12 +469,20 @@ checkResolverSpec gpds flags resolver = do
468469
-- TODO support custom resolver for stack init
469470
ResolverCustom {} -> return $ BuildPlanCheckPartial Map.empty Map.empty
470471

471-
-- | Finds all files with a .cabal extension under a given directory.
472+
-- | Finds all files with a .cabal extension under a given directory. If
473+
-- a `hpack` `package.yaml` file exists, this will be used to generate a cabal
474+
-- file.
472475
-- Subdirectories can be included depending on the @recurse@ parameter.
473476
findCabalFiles :: MonadIO m => Bool -> Path Abs Dir -> m [Path Abs File]
474-
findCabalFiles recurse dir =
475-
liftIO $ findFiles dir isCabal (\subdir -> recurse && not (isIgnored subdir))
477+
findCabalFiles recurse dir = do
478+
hpackFiles <- liftIO $ findFiles dir isHpack dirFilter
479+
liftIO $ do
480+
forM_ hpackFiles (hpack . parent)
481+
findFiles dir isCabal dirFilter
476482
where
483+
isHpack = (== "package.yaml") . toFilePath . filename
484+
485+
dirFilter subdir = recurse && not (isIgnored subdir)
477486
isCabal path = ".cabal" `isSuffixOf` toFilePath path
478487

479488
isIgnored path = FP.dropTrailingPathSeparator (toFilePath (dirname path))

0 commit comments

Comments
 (0)