Skip to content

Commit

Permalink
Avoid spurious warnings from -with-rtsopts (fix #4255)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulysses4ever committed May 31, 2022
1 parent 5cf4ab7 commit e436535
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 11 deletions.
28 changes: 17 additions & 11 deletions Cabal/src/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -871,42 +871,43 @@ checkGhcOptions fieldName getOptions pkg =
++ "should only be used for executables."

, checkAlternatives fieldName "extensions"
[ (flag, prettyShow extension) | flag <- all_ghc_options
[ (flag, prettyShow extension) | flag <- ghc_options_no_rtsopts
, Just extension <- [ghcExtension flag] ]

, checkAlternatives fieldName "extensions"
[ (flag, extension) | flag@('-':'X':extension) <- all_ghc_options ]
[ (flag, extension) | flag@('-':'X':extension) <- ghc_options_no_rtsopts ]

, checkAlternatives fieldName "cpp-options" $
[ (flag, flag) | flag@('-':'D':_) <- all_ghc_options ]
++ [ (flag, flag) | flag@('-':'U':_) <- all_ghc_options ]
[ (flag, flag) | flag@('-':'D':_) <- ghc_options_no_rtsopts ]
++ [ (flag, flag) | flag@('-':'U':_) <- ghc_options_no_rtsopts ]

, checkAlternatives fieldName "include-dirs"
[ (flag, dir) | flag@('-':'I':dir) <- all_ghc_options ]
[ (flag, dir) | flag@('-':'I':dir) <- ghc_options_no_rtsopts ]

, checkAlternatives fieldName "extra-libraries"
[ (flag, lib) | flag@('-':'l':lib) <- all_ghc_options ]
[ (flag, lib) | flag@('-':'l':lib) <- ghc_options_no_rtsopts ]

, checkAlternatives fieldName "extra-libraries-static"
[ (flag, lib) | flag@('-':'l':lib) <- all_ghc_options ]
[ (flag, lib) | flag@('-':'l':lib) <- ghc_options_no_rtsopts ]

, checkAlternatives fieldName "extra-lib-dirs"
[ (flag, dir) | flag@('-':'L':dir) <- all_ghc_options ]
[ (flag, dir) | flag@('-':'L':dir) <- ghc_options_no_rtsopts ]

, checkAlternatives fieldName "extra-lib-dirs-static"
[ (flag, dir) | flag@('-':'L':dir) <- all_ghc_options ]
[ (flag, dir) | flag@('-':'L':dir) <- ghc_options_no_rtsopts ]

, checkAlternatives fieldName "frameworks"
[ (flag, fmwk) | (flag@"-framework", fmwk) <-
zip all_ghc_options (safeTail all_ghc_options) ]
zip ghc_options_no_rtsopts (safeTail ghc_options_no_rtsopts) ]

, checkAlternatives fieldName "extra-framework-dirs"
[ (flag, dir) | (flag@"-framework-path", dir) <-
zip all_ghc_options (safeTail all_ghc_options) ]
zip ghc_options_no_rtsopts (safeTail ghc_options_no_rtsopts) ]
]

where
all_ghc_options = concatMap getOptions (allBuildInfo pkg)
ghc_options_no_rtsopts = rmRtsOpts all_ghc_options
lib_ghc_options = concatMap (getOptions . libBuildInfo)
(allLibraries pkg)
test_ghc_options = concatMap (getOptions . testBuildInfo)
Expand Down Expand Up @@ -967,6 +968,11 @@ checkGhcOptions fieldName getOptions pkg =
enable e = Just (EnableExtension e)
disable e = Just (DisableExtension e)

rmRtsOpts :: [String] -> [String]
rmRtsOpts ("-rtsopts":_:xs) = rmRtsOpts xs
rmRtsOpts (x:xs) = x : rmRtsOpts xs
rmRtsOpts [] = []

checkCCOptions :: PackageDescription -> [PackageCheck]
checkCCOptions = checkCLikeOptions "C" "cc-options" ccOptions

Expand Down
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/RtsOptsClean/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LICENSE
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/RtsOptsClean/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main where

main :: IO ()
main = undefined
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/RtsOptsClean/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
19 changes: 19 additions & 0 deletions cabal-testsuite/PackageTests/RtsOptsClean/my.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: RtsOptsClean
version: 0.1
author: Artem Pelenitsyn
synopsis: Make sure -with-rtsopts do not produce spurious warnings (fix #4255)
category: PackageTests
build-type: Simple
cabal-version: 2.0

description:
Make sure -with-rtsopts do not produce spurious warnings

Executable RtsOptsClean
default-language: Haskell2010
build-depends: base <5.0
main-is:
Main.hs
ghc-options:
-rtsopts
-with-rtsopts "-I0"
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/RtsOptsClean/setup.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Test.Cabal.Prelude

-- Test that setup shows all the 'autogen-modules' warnings.
main = setupAndCabalTest $ do
setup' "configure" [] >>=
assertOutputDoesNotContain "Warning: Instead of 'ghc-options: -I0' use 'include-dirs: 0'"
4 changes: 4 additions & 0 deletions changelog.d/issue-4255
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
synopsis: Avoid spurious warnings from -with-rtsopts
packages: Cabal
issues: #4255
prs: #8183

0 comments on commit e436535

Please sign in to comment.