Skip to content

Commit 8703783

Browse files
zlonastSwordlash
andcommitted
Add JSPOptions test, use 3.14 as min required cabal version
Co-authored-by: Mateusz Goslinowski <mateusz.goslinowski@gmail.com>
1 parent df09931 commit 8703783

File tree

23 files changed

+136
-34
lines changed

23 files changed

+136
-34
lines changed

Cabal-syntax/src/Distribution/CabalSpecVersion.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ data CabalSpecVersion
3535
| -- 3.10: no changes
3636
CabalSpecV3_12
3737
| CabalSpecV3_14
38+
| CabalSpecV3_16
3839
deriving (Eq, Ord, Show, Read, Enum, Bounded, Data, Generic)
3940

4041
instance Binary CabalSpecVersion
@@ -45,6 +46,7 @@ instance NFData CabalSpecVersion where rnf = genericRnf
4546
--
4647
-- @since 3.0.0.0
4748
showCabalSpecVersion :: CabalSpecVersion -> String
49+
showCabalSpecVersion CabalSpecV3_16 = "3.16"
4850
showCabalSpecVersion CabalSpecV3_14 = "3.14"
4951
showCabalSpecVersion CabalSpecV3_12 = "3.12"
5052
showCabalSpecVersion CabalSpecV3_8 = "3.8"
@@ -67,13 +69,14 @@ showCabalSpecVersion CabalSpecV1_2 = "1.2"
6769
showCabalSpecVersion CabalSpecV1_0 = "1.0"
6870

6971
cabalSpecLatest :: CabalSpecVersion
70-
cabalSpecLatest = CabalSpecV3_14
72+
cabalSpecLatest = CabalSpecV3_16
7173

7274
-- | Parse 'CabalSpecVersion' from version digits.
7375
--
7476
-- It may fail if for recent versions the version is not exact.
7577
cabalSpecFromVersionDigits :: [Int] -> Maybe CabalSpecVersion
7678
cabalSpecFromVersionDigits v
79+
| v == [3, 16] = Just CabalSpecV3_16
7780
| v == [3, 14] = Just CabalSpecV3_14
7881
| v == [3, 12] = Just CabalSpecV3_12
7982
| v == [3, 8] = Just CabalSpecV3_8
@@ -98,6 +101,7 @@ cabalSpecFromVersionDigits v
98101

99102
-- | @since 3.4.0.0
100103
cabalSpecToVersionDigits :: CabalSpecVersion -> [Int]
104+
cabalSpecToVersionDigits CabalSpecV3_16 = [3, 16]
101105
cabalSpecToVersionDigits CabalSpecV3_14 = [3, 14]
102106
cabalSpecToVersionDigits CabalSpecV3_12 = [3, 12]
103107
cabalSpecToVersionDigits CabalSpecV3_8 = [3, 8]

Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,8 @@ buildInfoFieldGrammar =
621621
<*> monoidalFieldAla "cc-options" (alaList' NoCommaFSep Token') L.ccOptions
622622
<*> monoidalFieldAla "cxx-options" (alaList' NoCommaFSep Token') L.cxxOptions
623623
^^^ availableSince CabalSpecV2_2 []
624-
<*> monoidalFieldAla "jsp-options" (alaList' NoCommaFSep Token') L.jspOptions
625-
^^^ availableSince CabalSpecV3_14 []
624+
<*> monoidalFieldAla "jspp-options" (alaList' NoCommaFSep Token') L.jsppOptions
625+
^^^ availableSince CabalSpecV3_16 []
626626
<*> monoidalFieldAla "ld-options" (alaList' NoCommaFSep Token') L.ldOptions
627627
<*> monoidalFieldAla "hsc2hs-options" (alaList' NoCommaFSep Token') L.hsc2hsOptions
628628
^^^ availableSince CabalSpecV3_6 []

Cabal-syntax/src/Distribution/Types/BuildInfo.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ data BuildInfo = BuildInfo
6161
-- ^ options for C compiler
6262
, cxxOptions :: [String]
6363
-- ^ options for C++ compiler
64-
, jspOptions :: [String]
65-
-- ^ options for pre-processing JavaScript code
64+
, jsppOptions :: [String]
65+
-- ^ options for pre-processing JavaScript code @since 3.16.0.0
6666
, ldOptions :: [String]
6767
-- ^ options for linker
6868
, hsc2hsOptions :: [String]
@@ -163,7 +163,7 @@ instance Monoid BuildInfo where
163163
, cmmOptions = []
164164
, ccOptions = []
165165
, cxxOptions = []
166-
, jspOptions = []
166+
, jsppOptions = []
167167
, ldOptions = []
168168
, hsc2hsOptions = []
169169
, pkgconfigDepends = []
@@ -217,7 +217,7 @@ instance Semigroup BuildInfo where
217217
, cmmOptions = combine cmmOptions
218218
, ccOptions = combine ccOptions
219219
, cxxOptions = combine cxxOptions
220-
, jspOptions = combine jspOptions
220+
, jsppOptions = combine jsppOptions
221221
, ldOptions = combine ldOptions
222222
, hsc2hsOptions = combine hsc2hsOptions
223223
, pkgconfigDepends = combine pkgconfigDepends

Cabal-syntax/src/Distribution/Types/BuildInfo/Lens.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ class HasBuildInfo a where
5959
cxxOptions = buildInfo . cxxOptions
6060
{-# INLINE cxxOptions #-}
6161

62-
jspOptions :: Lens' a [String]
63-
jspOptions = buildInfo . jspOptions
64-
{-# INLINE jspOptions #-}
62+
jsppOptions :: Lens' a [String]
63+
jsppOptions = buildInfo . jsppOptions
64+
{-# INLINE jsppOptions #-}
6565

6666
ldOptions :: Lens' a [String]
6767
ldOptions = buildInfo . ldOptions

Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ md5Check proxy md5Int = structureHash proxy @?= md5FromInteger md5Int
2929

3030
md5CheckGenericPackageDescription :: Proxy GenericPackageDescription -> Assertion
3131
md5CheckGenericPackageDescription proxy = md5Check proxy
32-
0xe95038393adbd46b119188757a3a2b63
32+
0x42685b0be2909b20bfcd2f32c503ec7b
3333

3434
md5CheckLocalBuildInfo :: Proxy LocalBuildInfo -> Assertion
3535
md5CheckLocalBuildInfo proxy = md5Check proxy
36-
0x364f8e404df9ada84ea3b4e3b3084a10
36+
0x3d5f7afb3f2f9d8a8ea0e9487a74a006

Cabal/src/Distribution/PackageDescription/Check/Target.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ checkBuildInfoOptions t bi = do
814814
checkCLikeOptions LangC "cc-options" (ccOptions bi) ldOpts
815815
checkCLikeOptions LangCPlusPlus "cxx-options" (cxxOptions bi) ldOpts
816816
checkCPPOptions (cppOptions bi)
817-
checkJSPOptions (jspOptions bi)
817+
checkJSPOptions (jsppOptions bi)
818818

819819
-- | Checks GHC options for commonly misused or non-portable flags.
820820
checkGHCOptions
@@ -907,7 +907,7 @@ checkGHCOptions title t opts = do
907907
)
908908
checkAlternatives
909909
title
910-
"jsp-options"
910+
"jspp-options"
911911
( [(flag, flag) | flag@('-' : 'D' : _) <- ghcNoRts]
912912
++ [(flag, flag) | flag@('-' : 'U' : _) <- ghcNoRts]
913913
)
@@ -1107,14 +1107,13 @@ checkJSPOptions
11071107
-> CheckM m ()
11081108
checkJSPOptions opts = do
11091109
checkAlternatives
1110-
"jsp-options"
1110+
"jspp-options"
11111111
"include-dirs"
11121112
[(flag, dir) | flag@('-' : 'I' : dir) <- opts]
11131113
mapM_
11141114
( \opt ->
11151115
checkP
11161116
(not $ any (`isPrefixOf` opt) ["-D", "-U", "-I"])
1117-
(PackageBuildWarning (OptJSP opt))
1117+
(PackageBuildWarning (OptJSPP opt))
11181118
)
11191119
opts
1120-

Cabal/src/Distribution/PackageDescription/Check/Warning.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ data CheckExplanation
214214
| OptWithRts String
215215
| COptONumber String WarnLang
216216
| COptCPP String
217-
| OptJSP String
217+
| OptJSPP String
218218
| OptAlternatives String String [(String, String)]
219219
| RelativeOutside String FilePath
220220
| AbsolutePath String FilePath
@@ -381,7 +381,7 @@ data CheckExplanationID
381381
| CIOptWithRts
382382
| CICOptONumber
383383
| CICOptCPP
384-
| CIOptJSP
384+
| CIOptJSPP
385385
| CIOptAlternatives
386386
| CIRelativeOutside
387387
| CIAbsolutePath
@@ -527,7 +527,7 @@ checkExplanationId (OptRts{}) = CIOptRts
527527
checkExplanationId (OptWithRts{}) = CIOptWithRts
528528
checkExplanationId (COptONumber{}) = CICOptONumber
529529
checkExplanationId (COptCPP{}) = CICOptCPP
530-
checkExplanationId (OptJSP{}) = CIOptJSP
530+
checkExplanationId (OptJSPP{}) = CIOptJSPP
531531
checkExplanationId (OptAlternatives{}) = CIOptAlternatives
532532
checkExplanationId (RelativeOutside{}) = CIRelativeOutside
533533
checkExplanationId (AbsolutePath{}) = CIAbsolutePath
@@ -680,7 +680,7 @@ ppCheckExplanationId CIOptRts = "option-rtsopts"
680680
ppCheckExplanationId CIOptWithRts = "option-with-rtsopts"
681681
ppCheckExplanationId CICOptONumber = "option-opt-c"
682682
ppCheckExplanationId CICOptCPP = "cpp-options"
683-
ppCheckExplanationId CIOptJSP = "jsp-options"
683+
ppCheckExplanationId CIOptJSPP = "jspp-options"
684684
ppCheckExplanationId CIOptAlternatives = "misplaced-c-opt"
685685
ppCheckExplanationId CIRelativeOutside = "relative-path-outside"
686686
ppCheckExplanationId CIAbsolutePath = "absolute-path"
@@ -1090,8 +1090,8 @@ ppExplanation (COptONumber prefix label) =
10901090
++ " --disable-optimization flag."
10911091
ppExplanation (COptCPP opt) =
10921092
"'cpp-options: " ++ opt ++ "' is not a portable C-preprocessor flag."
1093-
ppExplanation (OptJSP opt) =
1094-
"'jsp-options: " ++ opt ++ "' is not a portable C-preprocessor flag."
1093+
ppExplanation (OptJSPP opt) =
1094+
"'jspp-options: " ++ opt ++ "' not a portable JavaScript-preprocessor flag."
10951095
ppExplanation (OptAlternatives badField goodField flags) =
10961096
"Instead of "
10971097
++ quote (badField ++ ": " ++ unwords badFlags)

Cabal/src/Distribution/Simple/GHC/Internal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ componentJsGhcOptions verbosity lbi bi clbi odir filename =
510510
, ghcOptPackageDBs = withPackageDB lbi
511511
, ghcOptPackages = toNubListR $ mkGhcOptPackages (promisedPkgs lbi) clbi
512512
, ghcOptObjDir = toFlag odir
513-
, ghcOptExtra = jspOptions bi <> hcOptions GHC bi
513+
, ghcOptExtra = jsppOptions bi <> hcOptions GHC bi
514514
}
515515

516516
componentGhcOptions
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# cabal check
2+
The following errors are likely to affect your build negatively:
3+
Error: [jspp-options] 'jspp-options: -Q' is not a portable C-preprocessor flag.
4+
Error: Hackage would reject this package.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Test.Cabal.Prelude
2+
3+
-- `jspp-options`, do not use use non portable flags.
4+
main = cabalTest $
5+
fails $ cabal "check" []
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cabal-version: 3.0
2+
name: pkg
3+
synopsis: synopsis
4+
description: description
5+
version: 0
6+
category: example
7+
maintainer: none@example.com
8+
license: GPL-3.0-or-later
9+
10+
library
11+
exposed-modules: Module
12+
default-language: Haskell2010
13+
if arch(JavaScript)
14+
jspp-options: -Q
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Main where
2+
3+
import Lib
4+
5+
main :: IO ()
6+
main = foo
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Test.Cabal.Prelude
2+
3+
main = do
4+
skipUnlessJavaScript
5+
skipIfWindows ""
6+
setupAndCabalTest $ do
7+
skipUnlessGhcVersion ">= 9.12"
8+
res <- cabal' "v2-run" ["demo"]
9+
assertOutputContains "Hello definition!" res
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//#OPTIONS: CPP
2+
3+
function foo() {
4+
#ifdef PRINT_DEF
5+
console.log("Hello definition!");
6+
#else
7+
console.log("Hello!");
8+
#endif
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cabal-version: 3.0
2+
name: jsppoptions
3+
version: 0
4+
build-type: Simple
5+
6+
library
7+
default-language: Haskell2010
8+
js-sources: jsbits/lib.js
9+
if arch(JavaScript)
10+
jspp-options: -DPRINT_DEF
11+
hs-source-dirs: src
12+
exposed-modules: Lib
13+
build-depends: base
14+
15+
executable demo
16+
default-language: Haskell2010
17+
main-is: Main.hs
18+
hs-source-dirs: demo
19+
build-depends: base, jsppoptions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# cabal v2-run
2+
Configuration is affected by the following files:
3+
- cabal.project
4+
Resolving dependencies...
5+
Build profile: -w ghc-<GHCVER> -O1
6+
In order, the following will be built:
7+
- jsppoptions-0 (lib) (first run)
8+
- jsppoptions-0 (exe:demo) (first run)
9+
Configuring library for jsppoptions-0...
10+
Preprocessing library for jsppoptions-0...
11+
Building library for jsppoptions-0...
12+
Configuring executable 'demo' for jsppoptions-0...
13+
Preprocessing executable 'demo' for jsppoptions-0...
14+
Building executable 'demo' for jsppoptions-0...
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Test.Cabal.Prelude
2+
3+
main = do
4+
skipIfJavaScript
5+
cabalTest $ do
6+
-- Ensure the field `js-sources` does not raise issues
7+
res <- cabal' "v2-run" ["demo"]
8+
assertOutputContains "Not JS foo" res
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{-# LANGUAGE CPP #-}
2+
module Lib where
3+
4+
#if defined(javascript_HOST_ARCH)
5+
foreign import javascript foo :: IO ()
6+
#else
7+
foo :: IO ()
8+
foo = putStrLn "Not JS foo"
9+
#endif

doc/buildinfo-fields-reference.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,6 @@ cmm-sources
256256
.. math::
257257
\mathrm{commalist}\left\{ \mathop{\mathit{hs\text{-}string}}\mid{{[\mathop{\mathord{``}\mathtt{\ }\mathord{"}}\mathop{\mathord{``}\mathtt{\text{,}}\mathord{"}}]^c}}^+_{} \right\}
258258
259-
jsp-options
260-
* Monoidal field
261-
* Documentation of :pkg-field:`library:jsp-options`
262-
263-
.. math::
264-
{\left\{ \mathop{\mathit{hs\text{-}string}}\mid{{[\mathop{\mathord{``}\mathtt{\ }\mathord{"}}]^c}}^+_{} \right\}}^\ast_{\bullet}
265-
266259
cpp-options
267260
* Monoidal field
268261
* Documentation of :pkg-field:`library:cpp-options`
@@ -492,6 +485,14 @@ js-sources
492485
.. math::
493486
\mathrm{commalist}\left\{ \mathop{\mathit{hs\text{-}string}}\mid{{[\mathop{\mathord{``}\mathtt{\ }\mathord{"}}\mathop{\mathord{``}\mathtt{\text{,}}\mathord{"}}]^c}}^+_{} \right\}
494487
488+
jspp-options
489+
* Monoidal field
490+
* Available since ``cabal-version: 3.16``.
491+
* Documentation of :pkg-field:`library:jspp-options`
492+
493+
.. math::
494+
{\left\{ \mathop{\mathit{hs\text{-}string}}\mid{{[\mathop{\mathord{``}\mathtt{\ }\mathord{"}}]^c}}^+_{} \right\}}^\ast_{\bullet}
495+
495496
ld-options
496497
* Monoidal field
497498
* Documentation of :pkg-field:`library:ld-options`

doc/cabal-commands.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ A list of all warnings with their constructor:
14051405
- ``option-with-rtsopts``: unnecessary ``-with-rtsopts``.
14061406
- ``option-opt-c``: unnecessary ``-O[n]`` in C code.
14071407
- ``cpp-options``: unportable ``-cpp-options`` flag.
1408-
- ``jsp-options``: unportable ``-jsp-options`` flag.
1408+
- ``jspp-options``: unportable ``-jspp-options`` flag.
14091409
- ``misplaced-c-opt``: C-like options in wrong cabal field.
14101410
- ``relative-path-outside``: relative path outside of source tree.
14111411
- ``absolute-path``: absolute path where not allowed.

doc/cabal-package-description-file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@ system-dependent values for these fields.
19921992
arguments are compiler-dependent, this field is more useful with the
19931993
setup described in the section on `system-dependent parameters`_.
19941994

1995-
.. pkg-field:: jsp-options: token list
1995+
.. pkg-field:: jspp-options: token list
19961996

19971997
Command-line arguments for pre-processing Haskell code. Applies to
19981998
Haskell source and other pre-processed Haskell source like .js.

editors/vim/syntax/cabal.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ syn keyword cabalFieldName contained
6565
\ cmm-options
6666
\ cmm-sources
6767
\ copyright
68-
\ jsp-options
68+
\ jspp-options
6969
\ cpp-options
7070
\ cxx-options
7171
\ cxx-sources

0 commit comments

Comments
 (0)