From f9d2af427ae11ab8dde00f64a0fc74772f85baca Mon Sep 17 00:00:00 2001 From: Francesco Ariis Date: Fri, 1 Mar 2024 17:39:31 +0100 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=9CAdd=20default-language=E2=80=9D?= =?UTF-8?q?=20suggestion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As a warning (“Hackage would reject this package”), to prepare users to GHC language editions. --- .../ParserTests/regressions/issue-6288-d.cabal | 3 ++- .../ParserTests/regressions/issue-6288-f.check | 1 + .../ParserTests/regressions/issue-7776-a.cabal | 1 + .../ParserTests/regressions/issue-7776-b.cabal | 2 ++ .../ParserTests/regressions/issue-7776-c.cabal | 1 + .../PackageDescription/Check/Target.hs | 18 ++++++++++++------ .../PackageDescription/Check/Warning.hs | 8 ++++++++ .../CabalVersion/DefaultLanguageSoft/cabal.out | 4 ++++ .../DefaultLanguageSoft/cabal.test.hs | 5 +++++ .../CabalVersion/DefaultLanguageSoft/pkg.cabal | 11 +++++++++++ changelog.d/pr-9766 | 11 +++++++++++ doc/cabal-commands.rst | 1 + 12 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/DefaultLanguageSoft/cabal.out create mode 100644 cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/DefaultLanguageSoft/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/DefaultLanguageSoft/pkg.cabal create mode 100644 changelog.d/pr-9766 diff --git a/Cabal-tests/tests/ParserTests/regressions/issue-6288-d.cabal b/Cabal-tests/tests/ParserTests/regressions/issue-6288-d.cabal index 3b435bdd17d..800ff470e51 100644 --- a/Cabal-tests/tests/ParserTests/regressions/issue-6288-d.cabal +++ b/Cabal-tests/tests/ParserTests/regressions/issue-6288-d.cabal @@ -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 diff --git a/Cabal-tests/tests/ParserTests/regressions/issue-6288-f.check b/Cabal-tests/tests/ParserTests/regressions/issue-6288-f.check index e69de29bb2d..424bf39bd42 100644 --- a/Cabal-tests/tests/ParserTests/regressions/issue-6288-f.check +++ b/Cabal-tests/tests/ParserTests/regressions/issue-6288-f.check @@ -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. diff --git a/Cabal-tests/tests/ParserTests/regressions/issue-7776-a.cabal b/Cabal-tests/tests/ParserTests/regressions/issue-7776-a.cabal index b5517d56b1e..3c63ca27a21 100644 --- a/Cabal-tests/tests/ParserTests/regressions/issue-7776-a.cabal +++ b/Cabal-tests/tests/ParserTests/regressions/issue-7776-a.cabal @@ -24,3 +24,4 @@ library GHC.Hs.Type hs-source-dirs: compat-8.10 + default-language: Haskell2010 diff --git a/Cabal-tests/tests/ParserTests/regressions/issue-7776-b.cabal b/Cabal-tests/tests/ParserTests/regressions/issue-7776-b.cabal index 464d6ba334f..0a92165b208 100644 --- a/Cabal-tests/tests/ParserTests/regressions/issue-7776-b.cabal +++ b/Cabal-tests/tests/ParserTests/regressions/issue-7776-b.cabal @@ -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 @@ -25,3 +26,4 @@ benchmark benchmarks Ghc-options: -fwarn-tabs else other-modules: Data.Hashable.RandomSource + default-language: Haskell2010 diff --git a/Cabal-tests/tests/ParserTests/regressions/issue-7776-c.cabal b/Cabal-tests/tests/ParserTests/regressions/issue-7776-c.cabal index 07755c16e5a..8ef8aa6af54 100644 --- a/Cabal-tests/tests/ParserTests/regressions/issue-7776-c.cabal +++ b/Cabal-tests/tests/ParserTests/regressions/issue-7776-c.cabal @@ -17,3 +17,4 @@ library compat other-modules: GHC.Hs.Type + default-language: Haskell2010 diff --git a/Cabal/src/Distribution/PackageDescription/Check/Target.hs b/Cabal/src/Distribution/PackageDescription/Check/Target.hs index e6cfba74928..a610b5875a5 100644 --- a/Cabal/src/Distribution/PackageDescription/Check/Target.hs +++ b/Cabal/src/Distribution/PackageDescription/Check/Target.hs @@ -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 @@ -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 diff --git a/Cabal/src/Distribution/PackageDescription/Check/Warning.hs b/Cabal/src/Distribution/PackageDescription/Check/Warning.hs index f7a048f7913..6f21d5d0da6 100644 --- a/Cabal/src/Distribution/PackageDescription/Check/Warning.hs +++ b/Cabal/src/Distribution/PackageDescription/Check/Warning.hs @@ -233,6 +233,7 @@ data CheckExplanation | CVTestSuite | CVDefaultLanguage | CVDefaultLanguageComponent + | CVDefaultLanguageComponentSoft | CVExtraDocFiles | CVMultiLib | CVReexported @@ -394,6 +395,7 @@ data CheckExplanationID | CICVTestSuite | CICVDefaultLanguage | CICVDefaultLanguageComponent + | CICVDefaultLanguageComponentSoft | CICVExtraDocFiles | CICVMultiLib | CICVReexported @@ -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 @@ -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" @@ -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." diff --git a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/DefaultLanguageSoft/cabal.out b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/DefaultLanguageSoft/cabal.out new file mode 100644 index 00000000000..a45ec56e686 --- /dev/null +++ b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/DefaultLanguageSoft/cabal.out @@ -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. diff --git a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/DefaultLanguageSoft/cabal.test.hs b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/DefaultLanguageSoft/cabal.test.hs new file mode 100644 index 00000000000..dc290190595 --- /dev/null +++ b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/DefaultLanguageSoft/cabal.test.hs @@ -0,0 +1,5 @@ +import Test.Cabal.Prelude + +-- Please specify `default-language`. +main = cabalTest $ + fails $ cabal "check" [] diff --git a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/DefaultLanguageSoft/pkg.cabal b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/DefaultLanguageSoft/pkg.cabal new file mode 100644 index 00000000000..f89c160813a --- /dev/null +++ b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/DefaultLanguageSoft/pkg.cabal @@ -0,0 +1,11 @@ +cabal-version: 3.4 +name: pkg +synopsis: synopsis +description: description +version: 0 +category: example +maintainer: none@example.com +license: GPL-3.0-or-later + +library + exposed-modules: Module diff --git a/changelog.d/pr-9766 b/changelog.d/pr-9766 new file mode 100644 index 00000000000..3d10abb659f --- /dev/null +++ b/changelog.d/pr-9766 @@ -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`. + +} diff --git a/doc/cabal-commands.rst b/doc/cabal-commands.rst index 3508d64e817..35297d2937b 100644 --- a/doc/cabal-commands.rst +++ b/doc/cabal-commands.rst @@ -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.