From c31b0178d0ce7475f3e35492272de1ca6da143da Mon Sep 17 00:00:00 2001
From: Oleg Grenrus <oleg.grenrus@iki.fi>
Date: Wed, 30 Dec 2020 16:09:29 +0200
Subject: [PATCH] Add -Wno-missing-safe-haskell-mode to Paths_pkg.hs

Otherwise enabling `-Wmissing-safe-haskell-mode`
would cause annoying warnings.
---
 Cabal/src/Distribution/Simple/Build/PathsModule.hs   | 8 +++++---
 Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs | 7 +++++++
 cabal-dev-scripts/src/GenPathsModule.hs              | 1 +
 templates/Paths_pkg.template.hs                      | 3 +++
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/Cabal/src/Distribution/Simple/Build/PathsModule.hs b/Cabal/src/Distribution/Simple/Build/PathsModule.hs
index 8288d28790..2ec2968922 100644
--- a/Cabal/src/Distribution/Simple/Build/PathsModule.hs
+++ b/Cabal/src/Distribution/Simple/Build/PathsModule.hs
@@ -41,6 +41,7 @@ generatePathsModule pkg_descr lbi clbi = Z.render Z.Z
     , Z.zVersionDigits              = show $ versionNumbers $ packageVersion pkg_descr
     , Z.zSupportsCpp                = supports_cpp
     , Z.zSupportsNoRebindableSyntax = supports_rebindable_syntax
+    , Z.zSupportsNoMissingSafeHaskellMode = supports_missing_safehaskell
     , Z.zAbsolute                   = absolute
     , Z.zRelocatable                = relocatable lbi
     , Z.zIsWindows                  = isWindows
@@ -58,9 +59,10 @@ generatePathsModule pkg_descr lbi clbi = Z.render Z.Z
     , Z.zSysconfdir = zSysconfdir
     }
   where
-    supports_cpp               = supports_language_pragma
-    supports_rebindable_syntax = ghc_newer_than (mkVersion [7,0,1])
-    supports_language_pragma   = ghc_newer_than (mkVersion [6,6,1])
+    supports_cpp                 = supports_language_pragma
+    supports_rebindable_syntax   = ghc_newer_than (mkVersion [7,0,1])
+    supports_language_pragma     = ghc_newer_than (mkVersion [6,6,1])
+    supports_missing_safehaskell = ghc_newer_than (mkVersion [8,10,1])
 
     ghc_newer_than minVersion =
         case compilerCompatVersion GHC (compiler lbi) of
diff --git a/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs b/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs
index 03bf83e536..928a8b2d96 100644
--- a/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs
+++ b/Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs
@@ -6,6 +6,7 @@ data Z
          zVersionDigits :: String,
          zSupportsCpp :: Bool,
          zSupportsNoRebindableSyntax :: Bool,
+         zSupportsNoMissingSafeHaskellMode :: Bool,
          zAbsolute :: Bool,
          zRelocatable :: Bool,
          zIsWindows :: Bool,
@@ -42,6 +43,12 @@ render z_root = execWriter $ do
   else do
     return ()
   tell "{-# OPTIONS_GHC -fno-warn-missing-import-lists #-}\n"
+  if (zSupportsNoMissingSafeHaskellMode z_root)
+  then do
+    tell "{-# OPTIONS_GHC -Wno-missing-safe-haskell-mode #-}\n"
+    return ()
+  else do
+    return ()
   tell "module Paths_"
   tell (zManglePkgName z_root (zPackageName z_root))
   tell " (\n"
diff --git a/cabal-dev-scripts/src/GenPathsModule.hs b/cabal-dev-scripts/src/GenPathsModule.hs
index e4b930635c..c3f54082f3 100644
--- a/cabal-dev-scripts/src/GenPathsModule.hs
+++ b/cabal-dev-scripts/src/GenPathsModule.hs
@@ -27,6 +27,7 @@ $(capture "decls" [d|
         , zVersionDigits              :: String
         , zSupportsCpp                :: Bool
         , zSupportsNoRebindableSyntax :: Bool
+        , zSupportsNoMissingSafeHaskellMode :: Bool
         , zAbsolute                   :: Bool
         , zRelocatable                :: Bool
         , zIsWindows                  :: Bool
diff --git a/templates/Paths_pkg.template.hs b/templates/Paths_pkg.template.hs
index 15bbf6e4dc..62807ada57 100644
--- a/templates/Paths_pkg.template.hs
+++ b/templates/Paths_pkg.template.hs
@@ -8,6 +8,9 @@
 {-# LANGUAGE ForeignFunctionInterface #-}
 {% endif %}
 {-# OPTIONS_GHC -fno-warn-missing-import-lists #-}
+{% if supportsNoMissingSafeHaskellMode %}
+{-# OPTIONS_GHC -Wno-missing-safe-haskell-mode #-}
+{% endif %}
 module Paths_{{ manglePkgName packageName }} (
     version,
     getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir,
-- 
GitLab