Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid spurious warnings from -with-rtsopts (fix #4255) #8183

Merged
merged 1 commit into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ("-with-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
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"
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/RtsOptsClean/setup.cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Setup configure
Configuring RtsOptsClean-0.1...
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/RtsOptsClean/setup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Setup configure
Configuring RtsOptsClean-0.1...
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'"
Comment on lines +3 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the behaviour without your fix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This is documented in #4255 and reproduces today.

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