Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Major changes:

Behavior changes:

* When applicable, Stack reports that build type `Hooks` is unsupported.

Other enhancements:

* Consider Cabal 3.18 to be a tested library and remove warnings.
Expand Down
5 changes: 5 additions & 0 deletions doc/commands/build_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ custom setup. That should list the dependencies needed to compile `Setup.hs`.
Stack further customises the setup, using the `Cabal` package. If that package
is not listed, Stack will warn and add the GHC boot package as a dependency.

!!! note

Version 3.14 of the Cabal package description format specification
introduced the `Hooks` build type. Stack does not support the build type.

In addition to specifying targets, you can also control what gets built, or
retained, with the flags and options listed below. You can also affect what gets
built by specifying Cabal (the library) options for the configure step
Expand Down
8 changes: 7 additions & 1 deletion doc/maintainers/stack_errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
In connection with considering Stack's support of the
[Haskell Error Index](https://errors.haskell.org/) initiative, this page seeks
to take stock of the errors that Stack itself can raise, by reference to the
`master` branch of the Stack repository. Last updated: 2026-07-07.
`master` branch of the Stack repository. Last updated: 2026-10-20.

* `Stack.main`: catches exceptions from action `commandLineHandler`.

Expand Down Expand Up @@ -228,6 +228,12 @@ to take stock of the errors that Stack itself can raise, by reference to the
[S-2016] | Couldn'tParseField Text [Line]
~~~

- `Stack.PackageFile.PackageFilePrettyException`

~~~haskell
[S-2211] = HooksBuildTypeUnsupported PackageName
~~~

- `Stack.Query.QueryException`

~~~haskell
Expand Down
48 changes: 34 additions & 14 deletions src/Stack/PackageFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ import Stack.Types.PackageFile
import qualified System.FilePath as FilePath
import System.IO.Error ( isUserError )

-- | Type representing \'pretty\' exceptions thrown by functions exported by the
-- "Stack.PackageFile" module.
newtype PackageFilePrettyException
= HooksBuildTypeUnsupported PackageName
deriving Show

instance Pretty PackageFilePrettyException where
pretty (HooksBuildTypeUnsupported pkgName) =
"[S-2211]"
<> line
<> fillSep
[ flow "The package"
, style Error . fromPackageName $ pkgName
, flow "specifies build type"
, style Shell "Hooks"
, flow "but that build type is unsupported."
]

instance Exception PackageFilePrettyException

-- | Resolve the file, if it can't be resolved, warn for the user
-- (purely to be helpful).
resolveFileOrWarn ::
Expand Down Expand Up @@ -156,20 +176,20 @@ getPackageFile pkg cabalFP =
runRIO
(GetPackageFileContext cabalFP distDir bc cabalVer)
(packageDescModulesAndFiles pkg)
setupFiles <-
if pkg.buildType == Cabal.Custom
then do
let setupHsPath = pkgDir </> relFileSetupHs
setupLhsPath = pkgDir </> relFileSetupLhs
setupHsExists <- doesFileExist setupHsPath
if setupHsExists
then pure (S.singleton setupHsPath)
else do
setupLhsExists <- doesFileExist setupLhsPath
if setupLhsExists
then pure (S.singleton setupLhsPath)
else pure S.empty
else pure S.empty
setupFiles <- case pkg.buildType of
Cabal.Custom -> do
let setupHsPath = pkgDir </> relFileSetupHs
setupLhsPath = pkgDir </> relFileSetupLhs
setupHsExists <- doesFileExist setupHsPath
if setupHsExists
then pure (S.singleton setupHsPath)
else do
setupLhsExists <- doesFileExist setupLhsPath
if setupLhsExists
then pure (S.singleton setupLhsPath)
else pure S.empty
Cabal.Hooks -> prettyThrowM $ HooksBuildTypeUnsupported pkg.name
_ -> pure S.empty
moreBuildFiles <- fmap (S.insert cabalFP . S.union setupFiles) $ do
let hpackPath = pkgDir </> relFileHpackPackageConfig
hpackExists <- doesFileExist hpackPath
Expand Down
Loading