Skip to content
Open
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
27 changes: 25 additions & 2 deletions Cabal-tests/tests/UnitTests/Distribution/Simple/Program/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import Distribution.Types.ParStrat
import Distribution.Simple.Flag
import Distribution.Simple.Compiler (Compiler(..), CompilerId(..), CompilerFlavor(..), AbiTag(NoAbiTag))
import Distribution.PackageDescription (emptyPackageDescription)
import Distribution.Simple.Program.GHC (normaliseGhcArgs, renderGhcOptions, ghcOptNumJobs)
import Distribution.Version (mkVersion)
import Distribution.Simple.Program.GHC (GhcOptions, normaliseGhcArgs, renderGhcOptions, ghcOptNumJobs, ghcOptJSppOptions)
import Distribution.Version (mkVersion, Version)

tests :: TestTree
tests = testGroup "Distribution.Simple.Program.GHC"
Expand Down Expand Up @@ -59,9 +59,32 @@ tests = testGroup "Distribution.Simple.Program.GHC"
(Platform X86_64 Linux)
(mempty { ghcOptNumJobs = Flag (NumJobs (Just 4)) })
assertListEquals flags ["-j4", "-clear-package-db"]
, testCase "JS preprocessor options (GHC >= 9.10.2)" $ do
let flags = renderWith (mkVersion [9,12,1])
(mempty { ghcOptJSppOptions = ["-DJS"] })
assertBool ("expected -optJSP-DJS in " ++ show flags) ("-optJSP-DJS" `elem` flags)
, testCase "JS preprocessor options gated out before GHC 9.10.2" $ do
let flags = renderWith (mkVersion [9,10,1])
(mempty { ghcOptJSppOptions = ["-DJS"] })
assertBool ("unexpected -optJSP in " ++ show flags) ("-optJSP-DJS" `notElem` flags)
]
]

-- | Render 'GhcOptions' as GHC arguments for a GHC of the given version.
renderWith :: Version -> GhcOptions -> [String]
renderWith ver =
renderGhcOptions
(Compiler
{ compilerId = CompilerId GHC ver
, compilerAbiTag = NoAbiTag
, compilerCompat = []
, compilerLanguages = []
, compilerExtensions = []
, compilerProperties = Map.singleton "Support parallel --make" "YES"
, compilerWiredInUnitIds = Nothing
})
(Platform X86_64 Linux)

assertListEquals :: (Eq a, Show a) => [a] -> [a] -> Assertion
assertListEquals xs ys
| xs == ys = return ()
Expand Down
10 changes: 8 additions & 2 deletions Cabal/src/Distribution/Simple/Program/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ data GhcOptions = GhcOptions
, ghcOptCppOptions :: [String]
-- ^ Options to pass through to CPP; the @ghc -optP@ flag.
, ghcOptJSppOptions :: [String]
-- ^ Options to pass through to CPP; the @ghc -optJSP@ flag. @since 3.16.0.0
-- ^ Options to pass through to the JavaScript preprocessor; the
-- @ghc -optJSP@ flag (GHC >= 9.10.2). @since 3.16.0.0
, ghcOptCppIncludePath :: NubListR (SymbolicPath Pkg (Dir Include))
-- ^ Search path for CPP includes like header files; the @ghc -I@ flag.
, ghcOptCppIncludes :: NubListR (SymbolicPath Pkg File)
Expand Down Expand Up @@ -874,7 +875,12 @@ renderGhcOptions comp _platform@(Platform _arch os) opts

["-I" ++ u dir | dir <- flags ghcOptCppIncludePath]
, ["-optP" ++ opt | opt <- ghcOptCppOptions opts]
, ["-optJSP" ++ opt | opt <- ghcOptJSppOptions opts]
, -- The JavaScript preprocessor flag (-optJSP) only exists since GHC
-- 9.10.2; passing it to an older GHC is an error.
let ghc912 = case compilerCompatVersion GHC comp of
Just v -> v >= mkVersion [9, 10, 2]
Nothing -> False
in ["-optJSP" ++ opt | ghc912, opt <- ghcOptJSppOptions opts]
, concat
[ ["-optP-include", "-optP" ++ u inc]
| inc <- flags ghcOptCppIncludes
Expand Down
11 changes: 11 additions & 0 deletions changelog.d/jspp-options-ghc-912.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
synopsis: Do not pass `-optJSP` to GHC older than 9.10.2
packages: [Cabal]
prs: 12398
significance:
---

The `jspp-options` field is rendered as `ghc -optJSP<opt>`, but that flag only
exists since GHC 9.10.2. Passing it to an older GHC made the invocation fail, so
a package using `jspp-options` could not be built at all with GHC < 9.10.2. The
options are now omitted when the compiler is older than 9.10.2.
Loading