From 53653350cd730208e82f40728a955c6f8c4d8846 Mon Sep 17 00:00:00 2001 From: Martijn Bastiaan Date: Tue, 2 Aug 2022 15:49:27 +0200 Subject: [PATCH] Don't warn about 'prepositive-qualified-module' in Paths_pkgs Enabling '-Wprepositive-qualified-module' in a project leads to warnings when used in combination with Cabal's Paths_* feature. Given that this is code outside of a user's control, this warning should be disabled locally. --- .../Distribution/Simple/Build/PathsModule/Z.hs | 8 ++++++++ .../PathsModule/ImportQualifiedPost/Main.hs | 4 ++++ .../PathsModule/ImportQualifiedPost/my.cabal | 17 +++++++++++++++++ .../ImportQualifiedPost/setup.cabal.out | 5 +++++ .../PathsModule/ImportQualifiedPost/setup.out | 5 +++++ .../ImportQualifiedPost/setup.test.hs | 4 ++++ templates/Paths_pkg.template.hs | 5 +++++ 7 files changed, 48 insertions(+) create mode 100644 cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/Main.hs create mode 100644 cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/my.cabal create mode 100644 cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/setup.cabal.out create mode 100644 cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/setup.out create mode 100644 cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/setup.test.hs diff --git a/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs b/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs index 6488ea06101..9100dc629ec 100644 --- a/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs +++ b/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs @@ -41,6 +41,14 @@ render z_root = execWriter $ do return () else do return () + if (zSupportsCpp z_root) + then do + tell "#if __GLASGOW_HASKELL__ >= 810\n" + tell "{-# OPTIONS_GHC -Wno-prepositive-qualified-module #-}\n" + tell "#endif\n" + return () + else do + return () tell "{-# OPTIONS_GHC -fno-warn-missing-import-lists #-}\n" tell "{-# OPTIONS_GHC -w #-}\n" tell "module Paths_" diff --git a/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/Main.hs b/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/Main.hs new file mode 100644 index 00000000000..d82a4bd93b7 --- /dev/null +++ b/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/Main.hs @@ -0,0 +1,4 @@ +module Main where + +main :: IO () +main = return () diff --git a/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/my.cabal b/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/my.cabal new file mode 100644 index 00000000000..8ad771ececd --- /dev/null +++ b/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/my.cabal @@ -0,0 +1,17 @@ +name: PathsModule +version: 0.1 +license: BSD3 +author: Martijn Bastiaan +category: PackageTests +build-type: Simple +Cabal-version: >= 1.2 + +description: + Check that the generated paths module compiles. + +Executable TestPathsModule + main-is: Main.hs + if impl(ghc >= 8.10.0) + ghc-options: -Werror -fwarn-prepositive-qualified-module + other-modules: Paths_PathsModule + build-depends: base diff --git a/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/setup.cabal.out b/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/setup.cabal.out new file mode 100644 index 00000000000..bead24d62fd --- /dev/null +++ b/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/setup.cabal.out @@ -0,0 +1,5 @@ +# Setup configure +Configuring PathsModule-0.1... +# Setup build +Preprocessing executable 'TestPathsModule' for PathsModule-0.1.. +Building executable 'TestPathsModule' for PathsModule-0.1.. diff --git a/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/setup.out b/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/setup.out new file mode 100644 index 00000000000..bead24d62fd --- /dev/null +++ b/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/setup.out @@ -0,0 +1,5 @@ +# Setup configure +Configuring PathsModule-0.1... +# Setup build +Preprocessing executable 'TestPathsModule' for PathsModule-0.1.. +Building executable 'TestPathsModule' for PathsModule-0.1.. diff --git a/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/setup.test.hs b/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/setup.test.hs new file mode 100644 index 00000000000..ac477fa7567 --- /dev/null +++ b/cabal-testsuite/PackageTests/PathsModule/ImportQualifiedPost/setup.test.hs @@ -0,0 +1,4 @@ +import Test.Cabal.Prelude +-- Test that Paths module is generated and available for executables. +main = setupAndCabalTest $ setup_build [] + diff --git a/templates/Paths_pkg.template.hs b/templates/Paths_pkg.template.hs index 6bc6b7875e6..8e1e03d27e4 100644 --- a/templates/Paths_pkg.template.hs +++ b/templates/Paths_pkg.template.hs @@ -7,6 +7,11 @@ {% if not absolute %} {-# LANGUAGE ForeignFunctionInterface #-} {% endif %} +{% if supportsCpp %} +#if __GLASGOW_HASKELL__ >= 810 +{-# OPTIONS_GHC -Wno-prepositive-qualified-module #-} +#endif +{% endif %} {-# OPTIONS_GHC -fno-warn-missing-import-lists #-} {-# OPTIONS_GHC -w #-} module Paths_{{ manglePkgName packageName }} (