Skip to content

Commit

Permalink
Add “Add default-language” suggestion
Browse files Browse the repository at this point in the history
As a warning (“Hackage would reject this package”), to prepare users
to GHC language editions.
  • Loading branch information
ffaf1 committed Mar 14, 2024
1 parent aaf16c4 commit 199d290
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Cabal-tests/tests/ParserTests/regressions/issue-6288-d.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ version: 6288
build-type: Simple
synopsis: default-language optionality
category: Test
description: Field is introduced in 1.10, defaulted in 3.4
description: Field is introduced in 1.10, defaulted in 3.4,
suggested in cabal 3.12.
license: BSD3
license-file: LICENSE
maintainer: Cabal Contributors
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[add-language] Without `default-language`, cabal will default to Haskell98, which is probably not what you want. Please add `default-language` to all targets.
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ library
GHC.Hs.Type
hs-source-dirs:
compat-8.10
default-language: Haskell2010
2 changes: 2 additions & 0 deletions Cabal-tests/tests/ParserTests/regressions/issue-7776-b.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ library
-- the base lower bound makes the package not buildable with ghc < 6.8
-- but cabal is not smart enough to know it :-P
build-depends: base >= 4.5 && < 4.15
default-language: Haskell2010

benchmark benchmarks
main-is: Benchmarks.hs
Expand All @@ -25,3 +26,4 @@ benchmark benchmarks
Ghc-options: -fwarn-tabs
else
other-modules: Data.Hashable.RandomSource
default-language: Haskell2010
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ library
compat
other-modules:
GHC.Hs.Type
default-language: Haskell2010
18 changes: 12 additions & 6 deletions Cabal/src/Distribution/PackageDescription/Check/Target.hs
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,7 @@ checkBuildInfoFeatures bi sv = do
(isJust $ defaultLanguage bi)
(PackageBuildWarning CVDefaultLanguage)
-- CheckSpecVer sv.
checkP
( sv >= CabalSpecV1_10
&& sv < CabalSpecV3_4
&& isNothing (defaultLanguage bi)
)
(PackageBuildWarning CVDefaultLanguageComponent)
checkDefaultLanguage
-- Check use of 'extra-framework-dirs' field.
checkSpecVer
CabalSpecV1_24
Expand Down Expand Up @@ -534,6 +529,17 @@ checkBuildInfoFeatures bi sv = do
(not . null $ cvs)
(PackageDistInexcusable CVSources)

checkDefaultLanguage :: Monad m => CheckM m ()
checkDefaultLanguage = do
-- < 1.10 has no `default-language` field.
when
(sv >= CabalSpecV1_10 && isNothing (defaultLanguage bi))
-- < 3.4 mandatory, after just a suggestion.
( if sv < CabalSpecV3_4
then tellP (PackageBuildWarning CVDefaultLanguageComponent)
else tellP (PackageDistInexcusable CVDefaultLanguageComponentSoft)
)

-- Tests for extensions usage which can break Cabal < 1.4.
checkBuildInfoExtensions :: Monad m => BuildInfo -> CheckM m ()
checkBuildInfoExtensions bi = do
Expand Down
8 changes: 8 additions & 0 deletions Cabal/src/Distribution/PackageDescription/Check/Warning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ data CheckExplanation
| CVTestSuite
| CVDefaultLanguage
| CVDefaultLanguageComponent
| CVDefaultLanguageComponentSoft
| CVExtraDocFiles
| CVMultiLib
| CVReexported
Expand Down Expand Up @@ -394,6 +395,7 @@ data CheckExplanationID
| CICVTestSuite
| CICVDefaultLanguage
| CICVDefaultLanguageComponent
| CICVDefaultLanguageComponentSoft
| CICVExtraDocFiles
| CICVMultiLib
| CICVReexported
Expand Down Expand Up @@ -534,6 +536,7 @@ checkExplanationId (FilePathEmpty{}) = CIFilePathEmpty
checkExplanationId (CVTestSuite{}) = CICVTestSuite
checkExplanationId (CVDefaultLanguage{}) = CICVDefaultLanguage
checkExplanationId (CVDefaultLanguageComponent{}) = CICVDefaultLanguageComponent
checkExplanationId (CVDefaultLanguageComponentSoft{}) = CICVDefaultLanguageComponentSoft
checkExplanationId (CVExtraDocFiles{}) = CICVExtraDocFiles
checkExplanationId (CVMultiLib{}) = CICVMultiLib
checkExplanationId (CVReexported{}) = CICVReexported
Expand Down Expand Up @@ -679,6 +682,7 @@ ppCheckExplanationId CIFilePathEmpty = "empty-path"
ppCheckExplanationId CICVTestSuite = "test-cabal-ver"
ppCheckExplanationId CICVDefaultLanguage = "default-language"
ppCheckExplanationId CICVDefaultLanguageComponent = "no-default-language"
ppCheckExplanationId CICVDefaultLanguageComponentSoft = "add-language"
ppCheckExplanationId CICVExtraDocFiles = "extra-doc-files"
ppCheckExplanationId CICVMultiLib = "multilib"
ppCheckExplanationId CICVReexported = "reexported-modules"
Expand Down Expand Up @@ -1163,6 +1167,10 @@ ppExplanation CVDefaultLanguageComponent =
++ "Haskell98 or Haskell2010). If a component uses different languages "
++ "in different modules then list the other ones in the "
++ "'other-languages' field."
ppExplanation CVDefaultLanguageComponentSoft =
"Without `default-language`, cabal will default to Haskell98, which is "
++ "probably not what you want. Please add `default-language` to all "
++ "targets."
ppExplanation CVExtraDocFiles =
"To use the 'extra-doc-files' field the package needs to specify "
++ "'cabal-version: 1.18' or higher."
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# cabal check
The following errors will cause portability problems on other environments:
Error: [add-language] Without `default-language`, cabal will default to Haskell98, which is probably not what you want. Please add `default-language` to all targets.
Error: Hackage would reject this package.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.Cabal.Prelude

-- Please specify `default-language`.
main = cabalTest $
fails $ cabal "check" []
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cabal-version: 3.4
name: pkg
synopsis: synopsis
description: description
version: 0
category: example
maintainer: [email protected]
license: GPL-3.0-or-later

library
exposed-modules: Module
11 changes: 11 additions & 0 deletions changelog.d/pr-9766
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
synopsis: Warn on missing `default-language`
packages: Cabalcabal-install
prs: #9766
issues: #9620

description: {

- To help the adoption of GHC language editions, `cabal check` will now
warn about missing `default-language`.

}
1 change: 1 addition & 0 deletions doc/cabal-commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,7 @@ A list of all warnings with their constructor:
- ``test-cabal-ver``: ``test-suite`` used with ``cabal-version`` < 1.10.
- ``default-language``: ``default-language`` used with ``cabal-version`` < 1.10.
- ``no-default-language``: missing ``default-language``.
- ``add-default-language``: suggested ``default-language``.
- ``extra-doc-files``: ``extra-doc-files`` used with ``cabal-version`` < 1.18.
- ``multilib``: multiple ``library`` sections with ``cabal-version`` < 2.0.
- ``reexported-modules``: ``reexported-modules`` with ``cabal-version`` < 1.22.
Expand Down

0 comments on commit 199d290

Please sign in to comment.