Skip to content

Commit 519f2f7

Browse files
authored
Merge pull request #9766 from ffaf1/soft-warn-language
Add “Add default-language” suggestion
2 parents 2ee79c3 + f9d2af4 commit 519f2f7

File tree

12 files changed

+59
-7
lines changed

12 files changed

+59
-7
lines changed

Cabal-tests/tests/ParserTests/regressions/issue-6288-d.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ version: 6288
44
build-type: Simple
55
synopsis: default-language optionality
66
category: Test
7-
description: Field is introduced in 1.10, defaulted in 3.4
7+
description: Field is introduced in 1.10, defaulted in 3.4,
8+
suggested in cabal 3.12.
89
license: BSD3
910
license-file: LICENSE
1011
maintainer: Cabal Contributors
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

Cabal-tests/tests/ParserTests/regressions/issue-7776-a.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ library
2424
GHC.Hs.Type
2525
hs-source-dirs:
2626
compat-8.10
27+
default-language: Haskell2010

Cabal-tests/tests/ParserTests/regressions/issue-7776-b.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ library
1515
-- the base lower bound makes the package not buildable with ghc < 6.8
1616
-- but cabal is not smart enough to know it :-P
1717
build-depends: base >= 4.5 && < 4.15
18+
default-language: Haskell2010
1819

1920
benchmark benchmarks
2021
main-is: Benchmarks.hs
@@ -25,3 +26,4 @@ benchmark benchmarks
2526
Ghc-options: -fwarn-tabs
2627
else
2728
other-modules: Data.Hashable.RandomSource
29+
default-language: Haskell2010

Cabal-tests/tests/ParserTests/regressions/issue-7776-c.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ library
1717
compat
1818
other-modules:
1919
GHC.Hs.Type
20+
default-language: Haskell2010

Cabal/src/Distribution/PackageDescription/Check/Target.hs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,12 +483,7 @@ checkBuildInfoFeatures bi sv = do
483483
(isJust $ defaultLanguage bi)
484484
(PackageBuildWarning CVDefaultLanguage)
485485
-- CheckSpecVer sv.
486-
checkP
487-
( sv >= CabalSpecV1_10
488-
&& sv < CabalSpecV3_4
489-
&& isNothing (defaultLanguage bi)
490-
)
491-
(PackageBuildWarning CVDefaultLanguageComponent)
486+
checkDefaultLanguage
492487
-- Check use of 'extra-framework-dirs' field.
493488
checkSpecVer
494489
CabalSpecV1_24
@@ -534,6 +529,17 @@ checkBuildInfoFeatures bi sv = do
534529
(not . null $ cvs)
535530
(PackageDistInexcusable CVSources)
536531

532+
checkDefaultLanguage :: Monad m => CheckM m ()
533+
checkDefaultLanguage = do
534+
-- < 1.10 has no `default-language` field.
535+
when
536+
(sv >= CabalSpecV1_10 && isNothing (defaultLanguage bi))
537+
-- < 3.4 mandatory, after just a suggestion.
538+
( if sv < CabalSpecV3_4
539+
then tellP (PackageBuildWarning CVDefaultLanguageComponent)
540+
else tellP (PackageDistInexcusable CVDefaultLanguageComponentSoft)
541+
)
542+
537543
-- Tests for extensions usage which can break Cabal < 1.4.
538544
checkBuildInfoExtensions :: Monad m => BuildInfo -> CheckM m ()
539545
checkBuildInfoExtensions bi = do

Cabal/src/Distribution/PackageDescription/Check/Warning.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ data CheckExplanation
233233
| CVTestSuite
234234
| CVDefaultLanguage
235235
| CVDefaultLanguageComponent
236+
| CVDefaultLanguageComponentSoft
236237
| CVExtraDocFiles
237238
| CVMultiLib
238239
| CVReexported
@@ -394,6 +395,7 @@ data CheckExplanationID
394395
| CICVTestSuite
395396
| CICVDefaultLanguage
396397
| CICVDefaultLanguageComponent
398+
| CICVDefaultLanguageComponentSoft
397399
| CICVExtraDocFiles
398400
| CICVMultiLib
399401
| CICVReexported
@@ -534,6 +536,7 @@ checkExplanationId (FilePathEmpty{}) = CIFilePathEmpty
534536
checkExplanationId (CVTestSuite{}) = CICVTestSuite
535537
checkExplanationId (CVDefaultLanguage{}) = CICVDefaultLanguage
536538
checkExplanationId (CVDefaultLanguageComponent{}) = CICVDefaultLanguageComponent
539+
checkExplanationId (CVDefaultLanguageComponentSoft{}) = CICVDefaultLanguageComponentSoft
537540
checkExplanationId (CVExtraDocFiles{}) = CICVExtraDocFiles
538541
checkExplanationId (CVMultiLib{}) = CICVMultiLib
539542
checkExplanationId (CVReexported{}) = CICVReexported
@@ -679,6 +682,7 @@ ppCheckExplanationId CIFilePathEmpty = "empty-path"
679682
ppCheckExplanationId CICVTestSuite = "test-cabal-ver"
680683
ppCheckExplanationId CICVDefaultLanguage = "default-language"
681684
ppCheckExplanationId CICVDefaultLanguageComponent = "no-default-language"
685+
ppCheckExplanationId CICVDefaultLanguageComponentSoft = "add-language"
682686
ppCheckExplanationId CICVExtraDocFiles = "extra-doc-files"
683687
ppCheckExplanationId CICVMultiLib = "multilib"
684688
ppCheckExplanationId CICVReexported = "reexported-modules"
@@ -1163,6 +1167,10 @@ ppExplanation CVDefaultLanguageComponent =
11631167
++ "Haskell98 or Haskell2010). If a component uses different languages "
11641168
++ "in different modules then list the other ones in the "
11651169
++ "'other-languages' field."
1170+
ppExplanation CVDefaultLanguageComponentSoft =
1171+
"Without `default-language`, cabal will default to Haskell98, which is "
1172+
++ "probably not what you want. Please add `default-language` to all "
1173+
++ "targets."
11661174
ppExplanation CVExtraDocFiles =
11671175
"To use the 'extra-doc-files' field the package needs to specify "
11681176
++ "'cabal-version: 1.18' or higher."
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# cabal check
2+
The following errors will cause portability problems on other environments:
3+
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.
4+
Error: Hackage would reject this package.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Test.Cabal.Prelude
2+
3+
-- Please specify `default-language`.
4+
main = cabalTest $
5+
fails $ cabal "check" []
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cabal-version: 3.4
2+
name: pkg
3+
synopsis: synopsis
4+
description: description
5+
version: 0
6+
category: example
7+
maintainer: [email protected]
8+
license: GPL-3.0-or-later
9+
10+
library
11+
exposed-modules: Module

0 commit comments

Comments
 (0)